import moment from 'moment'; import { IMAGE_ROOT } from '@/shared/constants/common'; import { motion } from 'framer-motion'; import { snackBar } from '@/shared/lib'; import { toPng } from 'html-to-image'; import { useTranslation } from 'react-i18next'; import { useEffect, useState } from 'react'; import { NumericFormat } from 'react-number-format'; import { FilterMotionDuration, FilterMotionVariants } from '../model/constant'; import { RecipientInfo, SupplierInfo, TransactionDetails } from '@/entities/vat-return/model/types'; import '@/shared/ui/assets/css/style-tax-invoice.css'; import { useAppBridge } from '@/hooks/useAppBridge'; export interface TaxInvoiceSampleProps { taxInvoiceSampleOn: boolean; setTaxInvoiceSampleOn: (taxInvoiceSampleOn: boolean) => void; supplierInfo?: SupplierInfo; recipientInfo?: RecipientInfo; issueDate?: string; supplyAmount?: number; taxAmount?: number totalAmount?: number; transactionDetails?: TransactionDetails; }; export const TaxInvoiceSample = ({ taxInvoiceSampleOn, setTaxInvoiceSampleOn, supplierInfo, recipientInfo, issueDate, supplyAmount, taxAmount, totalAmount, transactionDetails }: TaxInvoiceSampleProps) => { const { t } = useTranslation(); const { isIOS, saveImage } = useAppBridge(); const [newSupplyAmount, setNewSupplyAmount] = useState>([]); const [newTaxAmount, setNewTaxAmount] = useState>([]); const downloadImage = async () => { const section = document.getElementById('image-section') as HTMLElement; try { const imageDataUrl = await toPng(section); const fileName = 'tax-invoice-' + moment().format('YYMMDDHHmmss'); // iOS 네이티브 환경인 경우 네이티브 브릿지 사용 if (isIOS) { try { // data:image/png;base64, 부분 제거하고 순수 base64 데이터만 추출 const base64Data = imageDataUrl.split(',')[1]; if (!base64Data) { throw new Error('Failed to extract base64 data'); } const result = await saveImage({ imageData: base64Data, fileName: fileName + '.png', mimeType: 'image/png' }); if (result?.filePath) { snackBar(t('common.imageSaved'), function(){ onClickToClose(); }); } else { throw new Error('Failed to save image'); } } catch (error) { console.error('Native image save failed:', error); snackBar(t('common.imageSaveFailed')); } } else { // Android 또는 웹 환경인 경우 기존 방식 사용 (다운로드 링크) const link = document.createElement('a'); link.download = fileName + '.png'; link.href = imageDataUrl + '#' + fileName + '.png'; link.click(); snackBar(t('common.imageRequested'), function(){ onClickToClose(); }); } } catch (error) { console.error('Image generation failed:', error); snackBar(t('common.imageGenerationFailed')); } }; const onClickToClose = () => { setTaxInvoiceSampleOn(false); }; const showNewSupplyAmount = () => { let rs = []; let emptyCnt = 11 - newSupplyAmount.length; for(let i=0;i  ); } for(let i=0;i{ str } ); } return rs; }; const showNewTaxAmount = () => { let rs = []; let emptyCnt = 10 - newTaxAmount.length; for(let i=0;i  ); } for(let i=0;i{ str } ); } return rs; }; const refactSupplyAmount = () => { let supplyAmountArr: Array = []; if(supplyAmount){ let newSupplyAmt = ''+supplyAmount; supplyAmountArr = newSupplyAmt.split(''); } setNewSupplyAmount(supplyAmountArr); }; const refactTaxAmount = () => { let taxAmountArr: Array = []; if(taxAmount){ let newTaxAmt = ''+taxAmount; taxAmountArr = newTaxAmt.split(''); } setNewTaxAmount(taxAmountArr); }; useEffect(() => { if(!!taxInvoiceSampleOn){ setTimeout(() => { downloadImage(); }, 500); } }, [taxInvoiceSampleOn]); useEffect(() => { refactSupplyAmount(); refactTaxAmount(); }, []); return ( <>
NICEPAY
세금계산서
세금계산서
승인번호  
관리번호  


등록번호 { supplierInfo?.businessRegistrationNumber }
상호(법인명) { supplierInfo?.companyName } 성명 { supplierInfo?.ceoName }
사업장 주소 { supplierInfo?.address }
업태 { supplierInfo?.businessType } 종목 { supplierInfo?.businessItem }




등록번호 { recipientInfo?.businessRegistrationNumber }
상호(법인명) { recipientInfo?.companyName } 성명 { recipientInfo?.ceoName }
사업장 주소 { recipientInfo?.address }
업태 { recipientInfo?.businessType } 종목 { recipientInfo?.businessItem }
작성
{ (!!issueDate)? moment(issueDate).format('YYYY'): '' } { (!!issueDate)? moment(issueDate).format('MM'): '' } { (!!issueDate)? moment(issueDate).format('DD'): '' }
공급가액
{ showNewSupplyAmount() }
세액
{ showNewTaxAmount() }
수정사유
 
비고
월/일
{ (!!transactionDetails?.transactionPeriod)? moment(transactionDetails.transactionPeriod).format('MM/DD'): '' }
 
 
비고
품목 규격 수량 단가 공급가액 세액 비고
{ transactionDetails?.itemName } { transactionDetails?.specification } { transactionDetails?.remarks }
             
             
합계금액 현금 수표 어음 외상미수금
이금액을 청구함
NICEPAY 사업자 등록번호 : 815-81-00527 | 결제대금예치업 등록번호 : 02-006-00041
주소 : 서울특별시 영등포구 문래로28길 25 (문래동3가) 세미콜론문래 N타워 9층 나이스페이먼츠(주)
우편번호 : 03456 | www.nicepay.co.kr
); };