import moment from 'moment'; import { useTranslation } from 'react-i18next'; import { SectionTitleArrow } from '@/entities/common/ui/section-title-arrow'; import { AmountInfo, CashReceiptReceiptDownloadParams, CashReceiptReceiptDownloadResponse, CashReceiptReceiptSendEmailParams, CashReceiptReceiptSendEmailResponse, CustomerInfo, InfoSectionKeys, InfoSectionProps, IssueInfo, MerchantInfo, ProductInfo, TransactionCategory, TransactionInfo } from '../../model/types'; import { SlideDown } from 'react-slidedown'; import 'react-slidedown/lib/slidedown.css'; import { snackBar } from '@/shared/lib'; import { useCashReceiptReceiptDownloadMutation } from '../../api/use-cash-receipt-receipt-download-mutation'; import { useState } from 'react'; import { DownloadBottomSheet, DownloadSelectedMode } from '@/entities/common/ui/download-bottom-sheet'; import { CashReceiptSample } from '@/entities/common/ui/cash-receipt-sample'; import { useCashReceiptReceiptSendEmailMutation } from '../../api/use-cash-receipt-receipt-send-email-mutation'; import { useDownloadBottomSheetOnStore } from '@/shared/model/store'; export const AmountInfoSection = ({ transactionCategory, amountInfo, isOpen, tid, serviceCode, onClickToOpenInfo, canDownloadReceipt }: InfoSectionProps) => { const { t } = useTranslation(); const { mutateAsync: cashReceiptReceiptDownload } = useCashReceiptReceiptDownloadMutation(); const { mutateAsync: cashReceiptReceiptSendEamil } = useCashReceiptReceiptSendEmailMutation(); const { downloadBottomSheetOn, setDownloadBottomSheetOn } = useDownloadBottomSheetOnStore(); const [cashReceiptSampleOn, setCashReceiptSampleOn] = useState(false); const [receiptIssueInfo, setReceiptIssueInfo] = useState({}); const [receiptMerchantInfo, setReceiptMerchantInfo] = useState({}); const [receiptTransactionInfo, setReceiptTransactionInfo] = useState({}); const [receiptAmountInfo, setReceiptAmountInfo] = useState({}); const [receiptCustomerInfo, setReceiptCustomerInfo] = useState(); const [receiptProductInfo, setReceiptProductInfo] = useState(); let newAmountInfo: Record | undefined = amountInfo; const subItems: Record> = { transactionRequestAmount: {name: t('transaction.fields.transactionRequestAmount'), type: 'number'}, transactionAmount: {name: t('transaction.fields.transactionAmount'), type: 'number'}, pointAmount: {name: t('transaction.fields.pointAmount'), type: 'number'}, couponAmount: {name: t('transaction.fields.couponAmount'), type: 'number'}, escrowFee: {name: t('transaction.fields.escrowFee'), type: 'number'}, kakaoMoneyAmount: {name: t('transaction.fields.kakaoMoneyAmount'), type: 'number'}, kakaoPointAmount: {name: t('transaction.fields.kakaoPointAmount'), type: 'number'}, kakaoDiscountAmount: {name: t('transaction.fields.kakaoDiscountAmount'), type: 'number'}, naverPointAmount: {name: t('transaction.fields.naverPointAmount'), type: 'number'}, tossMoneyAmount: {name: t('transaction.fields.tossMoneyAmount'), type: 'number'}, tossDiscountAmount: {name: t('transaction.fields.tossDiscountAmount'), type: 'number'}, paycoPointAmount: {name: t('transaction.fields.paycoPointAmount'), type: 'number'}, paycoCouponAmount: {name: t('transaction.fields.paycoCouponAmount'), type: 'number'}, }; const openSubItems: Record> = { // 신용카드 '01': ['transactionAmount', 'pointAmount', 'couponAmount', 'escrowFee'], // 계좌이체 '02': ['transactionRequestAmount', 'transactionAmount', 'escrowFee'], // 가상계좌 '03': ['transactionRequestAmount', 'transactionAmount'], // 휴대폰 '05': ['transactionRequestAmount', 'transactionAmount'], // 문화상품권 '14': ['transactionAmount'], // SSG머니 '21': ['transactionAmount'], // SSG은행계좌 '24': ['transactionAmount'], // 계좌간편결제 '26': ['transactionAmount', 'escrowFee'], // 티머니페이 '31': ['transactionAmount'], }; if(newAmountInfo?.partServiceCode === 'E015'){ openSubItems['01']?.push('paycoPointAmount'); openSubItems['01']?.push('paycoCouponAmount'); } else if(newAmountInfo?.partServiceCode === 'E016'){ openSubItems['01']?.push('kakaoMoneyAmount'); openSubItems['01']?.push('kakaoPointAmount'); openSubItems['01']?.push('kakaoDiscountAmount'); } else if(newAmountInfo?.partServiceCode === 'E020'){ openSubItems['01']?.push('naverPointAmount'); } else if(newAmountInfo?.partServiceCode === 'E025'){ openSubItems['01']?.push('tossMoneyAmount'); openSubItems['01']?.push('tossDiscountAmount'); } const checkValue = (val: any) => { return (!!val || val === 0); }; const getAmountValue = (k?: string) => { let value = 0; let rs = []; if(!!k){ let value = 0; if(k === 'kakaoMoneyAmount' && newAmountInfo?.partServiceCode === 'E016' ){ value = newAmountInfo['multiPointAmount'] || 0; } else if(k === 'kakaoPointAmount' && newAmountInfo?.partServiceCode === 'E016' ){ value = newAmountInfo['multiCouponAmount'] || 0; } else if(k === 'naverPointAmount' && newAmountInfo?.partServiceCode === 'E020' ){ value = newAmountInfo['multiPointAmount'] || 0; } else if(k === 'tossMoneyAmount' && newAmountInfo?.partServiceCode === 'E025' ){ value = newAmountInfo['multiPointAmount'] || 0; } else if(k === 'paycoPointAmount' && newAmountInfo?.partServiceCode === 'E015' ){ value = newAmountInfo['multiPointAmount'] || 0; } else if(k === 'paycoCouponAmount' && newAmountInfo?.partServiceCode === 'E015' ){ value = newAmountInfo['multiCouponAmount'] || 0; } else{ if(newAmountInfo){ value = newAmountInfo[k] || 0; } } rs.push( t('home.money', { value: new Intl.NumberFormat('en-US').format(value || 0) }) ) } return rs; }; const subLi = () => { let rs = []; if(!!newAmountInfo && !!serviceCode && !!openSubItems[serviceCode]){ for(let i=0;i ·  { name } { (checkValue(newAmountInfo[k]) && subItems[k]?.type === 'string') && newAmountInfo[k] } { (subItems[k]?.type === 'number') && getAmountValue(k) /* */ } { (checkValue(newAmountInfo[k]) && subItems[k]?.type === 'date') && moment(newAmountInfo[k]).format('YYYY.MM.DD') } ); } } } return rs; } const onClickToSetShowInfo = () => { if(!!onClickToOpenInfo){ onClickToOpenInfo(InfoSectionKeys.Amount); } }; const onClickToOpenDownloadBottomSheet = () => { setDownloadBottomSheetOn(true); }; const onRequestDownload = ( selectedMode: DownloadSelectedMode, userEmail?: string ) => { if(!!tid){ if(selectedMode === DownloadSelectedMode.EMAIL && !!userEmail ){ let params: CashReceiptReceiptSendEmailParams = { tid: tid, email: userEmail }; cashReceiptReceiptSendEamil(params).then((rs: CashReceiptReceiptSendEmailResponse) => { console.log(rs); if(rs.message){ snackBar(rs.message); } }).catch((e: any) => { if(e.response?.data?.error?.message){ snackBar(e.response?.data?.error?.message); return; } }); } else if(selectedMode === DownloadSelectedMode.IMAGE){ let params: CashReceiptReceiptDownloadParams = { tid: tid }; cashReceiptReceiptDownload(params).then((rs: CashReceiptReceiptDownloadResponse) => { /* if(rs?.merchantInfo){ rs.merchantInfo.merchantName = '나이스페이먼츠'; } */ setReceiptIssueInfo(rs?.issueInfo); setReceiptMerchantInfo(rs?.merchantInfo); setReceiptTransactionInfo(rs?.transactionInfo); setReceiptAmountInfo(rs?.amountInfo); setReceiptCustomerInfo(rs?.customerInfo); setReceiptProductInfo(rs?.productInfo); setCashReceiptSampleOn(true); }).catch((e: any) => { if(e.response?.data?.error?.message){ snackBar(e.response?.data?.error?.message); return; } }); } } }; return ( <>
{ (transactionCategory === TransactionCategory.AllTransaction) && (serviceCode === '01' || serviceCode === '02' || serviceCode === '03' || serviceCode === '26') && t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.transactionRequestAmount || 0) }) } { (transactionCategory === TransactionCategory.AllTransaction) && (serviceCode === '05' || serviceCode === '14' || serviceCode === '21' || serviceCode === '24' || serviceCode === '31') && t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.transactionAmount || 0) }) } { (transactionCategory === TransactionCategory.CashReceipt) && t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.amount || 0) }) } { (transactionCategory === TransactionCategory.Escrow) && t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.approvalRequestAmount || 0) }) } { (transactionCategory === TransactionCategory.Billing) && t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.transactionAmount || 0) }) }
{ (transactionCategory === TransactionCategory.AllTransaction) && (serviceCode === '01' || serviceCode === '02' || serviceCode === '03' || serviceCode === '26') && } { ((transactionCategory === TransactionCategory.CashReceipt) || (transactionCategory === TransactionCategory.Escrow) || (transactionCategory === TransactionCategory.Billing)) && }
{ !!isOpen &&
    { (transactionCategory === TransactionCategory.AllTransaction) && subLi() } { (transactionCategory === TransactionCategory.CashReceipt) && <>
  • ·  {t('transaction.fields.supplyAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.supplyAmount || 0) })}
  • ·  {t('transaction.fields.vat')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.vat || 0) })}
  • ·  {t('transaction.fields.serviceAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.serviceAmount || 0) })}
  • ·  {t('transaction.fields.taxFreeAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.taxFreeAmount || 0) })}
  • } { (transactionCategory === TransactionCategory.Escrow) && <> { (serviceCode === '02' || serviceCode === '03') &&
  • ·  {t('transaction.fields.transactionAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.transactionAmount || 0) })}
  • } { (serviceCode === '01') && <>
  • ·  {t('transaction.fields.cardAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.cardAmount || 0) })}
  • ·  {t('transaction.fields.pointAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.pointAmount || 0) })}
  • ·  {t('transaction.fields.couponAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.couponAmount || 0) })}
  • } { (serviceCode === '01' || serviceCode === '02') &&
  • ·  {t('transaction.fields.escrowFee')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.escrowFee || 0) })}
  • } { (serviceCode === '01') && <> { (amountInfo?.simplePaymentServiceCode === 'E016') && <>
  • ·  {t('transaction.fields.kakaoMoneyAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.multiPointAmount || 0) })}
  • ·  {t('transaction.fields.kakaoPointAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.multiCouponAmount || 0) })}
  • ·  {t('transaction.fields.kakaoDiscountAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.kakaoDiscountAmount || 0) })}
  • } { (amountInfo?.simplePaymentServiceCode === 'E020') &&
  • ·  {t('transaction.fields.naverPointAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.multiPointAmount || 0) })}
  • } { (amountInfo?.simplePaymentServiceCode === 'E025') && <>
  • ·  {t('transaction.fields.tossMoneyAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.multiPointAmount || 0) })}
  • ·  {t('transaction.fields.tossDiscountAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.tossDiscountAmount || 0) })}
  • } { (amountInfo?.simplePaymentServiceCode === 'E015') && <>
  • ·  {t('transaction.fields.paycoPointAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.multiPointAmount || 0) })}
  • ·  {t('transaction.fields.paycoCouponAmount')} {t('home.money', { value: new Intl.NumberFormat('en-US').format(amountInfo?.multiCouponAmount || 0) })}
  • } } }
}
{ ((transactionCategory === TransactionCategory.AllTransaction) || (transactionCategory === TransactionCategory.Escrow)) &&
{ amountInfo?.mid }
} { (transactionCategory === TransactionCategory.CashReceipt) &&
{ amountInfo?.customerName }
}
{ (transactionCategory === TransactionCategory.CashReceipt) && !!canDownloadReceipt && }
{ !!downloadBottomSheetOn && } { !!cashReceiptSampleOn && } ); };