import moment from 'moment'; import { useEffect, useState } from 'react'; import { NumericFormat } from 'react-number-format'; import { IMAGE_ROOT } from '@/shared/constants/common'; import { ListDateGroup } from './list-date-group'; import { PATHS } from '@/shared/constants/paths'; import { useNavigate } from '@/shared/lib/hooks/use-navigate'; import { DEFAULT_PAGE_PARAM } from '@/entities/common/model/constant'; import { SortTypeBox } from '@/entities/common/ui/sort-type-box'; import { useSettlementsHistoryMutation } from '../api/use-settlements-history-mutation'; import { useSettlementsHistorySummaryMutation } from '../api/use-settlements-history-summary-mutation'; import { useSettlementsTransactionSummaryMutation } from '../api/use-settlements-transaction-summary-mutation'; import { useSettlementsTransactionListMutation } from '../api/use-settlements-transaction-list-mutation'; import { ListSummaryExtendSettlement } from './list-summary-extend-settlement'; import { ListSummaryExtendTransaction } from './list-summary-extend-transaction'; import SlideDown from 'react-slidedown'; import 'react-slidedown/lib/slidedown.css'; import { ListFilter } from './filter/list-filter'; import { useDownloadExcelMutation } from '@/entities/transaction/api/use-download-excel-mutation'; import { SettlementPeriodType, SettlementPaymentMethod, SettlementsHistoryContent, ListDateGroupProps, SettlementsTransactionListContent, SettlementsHistoryParams, SettlementsHistoryResponse, SettlementsHistorySummaryParams, SettlementsHistorySummaryResponse } from '../model/types'; import { DefaultRequestPagination, SortTypeKeys } from '@/entities/common/model/types'; import { useStore } from '@/shared/model/store'; import { EmailBottomSheet } from '@/entities/common/ui/email-bottom-sheet'; export interface ListWrapProps { startDateFromCalendar?: string; endDateFromCalendar?: string; }; export const ListWrap = ({ startDateFromCalendar, endDateFromCalendar }: ListWrapProps) => { const { navigate } = useNavigate(); const userMid = useStore.getState().UserStore.mid; const [sortType, setSortType] = useState(SortTypeKeys.LATEST); const [settlementDateListItems, setSettlementDateListItems] = useState>([]); const [transactionDatelistItems, setTransactionDateListItems] = useState>([]); const [filterOn, setFilterOn] = useState(false); const [pageParam, setPageParam] = useState(DEFAULT_PAGE_PARAM); const [mid, setMid] = useState(userMid); const [periodType, setPeriodType] = useState(SettlementPeriodType.SETTLEMENT_DATE); const [startDate, setStartDate] = useState(startDateFromCalendar? moment(startDateFromCalendar).format('YYYYMMDD'): moment().format('YYYYMMDD')); const [endDate, setEndDate] = useState(endDateFromCalendar? moment(endDateFromCalendar).format('YYYYMMDD'): moment().format('YYYYMMDD')); const [paymentMethod, setPaymentMethod] = useState(SettlementPaymentMethod.ALL); const [settlementAmount, setSettlementAmount] = useState(); const [transactionAmount, setTransactionAmount] = useState(); const [pgFeeAmount, setPgFeeAmount] = useState(); const [holdAmount, setHoldAmount] = useState(); const [releaseAmount, setReleaseAmount] = useState(); const [offsetAmount, setOffsetAmount] = useState(); const [paymentFeeAmount, setPaymentFeeAmount] = useState(); const [escrowFeeAmount, setEscrowFeeAmount] = useState(); const [authFeeAmount, setAuthFeeAmount] = useState(); const [vatAmount, setVatAmount] = useState(); const [preSettlementCancelOffset, setPreSettlementCancelOffset] = useState(); const [transactionIds, setTransactionIds] = useState>([]); const [isOpenSummary, setIsOpenSummary] = useState(false); const [emailBottomSheetOn, setEmailBottomSheetOn] = useState(false); const { mutateAsync: settlementsHistory } = useSettlementsHistoryMutation(); const { mutateAsync: settlementsHistorySummary} = useSettlementsHistorySummaryMutation(); const { mutateAsync: settlementsTransactionList } = useSettlementsTransactionListMutation(); const { mutateAsync: settlementsTransactionSummary } = useSettlementsTransactionSummaryMutation(); const { mutateAsync: downloadExcel } = useDownloadExcelMutation(); const callList = () => { if(periodType === SettlementPeriodType.SETTLEMENT_DATE){ callSettlementList(); } else if(periodType === SettlementPeriodType.TRANSACTION_DATE){ callTransactionList(); } }; const callSettlementList = (option?: { sortType?: SortTypeKeys, val?: string }) => { let listSummaryParams: SettlementsHistorySummaryParams = { mid: mid, periodType: periodType, startDate: startDate, endDate: endDate, paymentMethod: paymentMethod, }; let listParams: SettlementsHistoryParams = { ...listSummaryParams, ...{ page: pageParam } }; if(listParams.page){ listParams.page.sortType = (option?.sortType)? option.sortType: sortType; setPageParam(listParams.page); } settlementsHistory(listParams).then((rs: SettlementsHistoryResponse) => { setSettlementDateListItems(rs.content); }); settlementsHistorySummary(listSummaryParams).then((rs: SettlementsHistorySummaryResponse) => { setSettlementAmount(rs.settlementAmount || 0); setTransactionAmount(rs.transactionAmount || 0); setPgFeeAmount(rs.pgFeeAmount || 0); setHoldAmount(rs.holdAmount || 0); setReleaseAmount(rs.releaseAmount || 0); setOffsetAmount(rs.offsetAmount || 0); }); }; const callTransactionList = (option?: { sortType?: SortTypeKeys, val?: string }) => { let params = { mid: mid, periodType: periodType, startDate: startDate, endDate: endDate, paymentMethod: paymentMethod, page: pageParam }; let summaryParams = { ...params, ...{ transactionIds: transactionIds } }; if(params.page){ params.page.sortType = option?.sortType || sortType; setPageParam(params.page); } settlementsTransactionList(params).then((rs) => { setTransactionDateListItems(rs.content); }); settlementsTransactionSummary(summaryParams).then((rs) => { setSettlementAmount(rs.settlementAmount); setTransactionAmount(rs.transactionAmount); setPaymentFeeAmount(rs.paymentFeeAmount); setEscrowFeeAmount(rs.escrowFeeAmount); setAuthFeeAmount(rs.authFeeAmount); setVatAmount(rs.vatAmount); setPreSettlementCancelOffset(rs.preSettlementCancelOffset); }); }; const onClickToSort = (sort: SortTypeKeys) => { setSortType(sort); if(periodType === SettlementPeriodType.SETTLEMENT_DATE){ callSettlementList({ sortType: sort }); } else if(periodType === SettlementPeriodType.TRANSACTION_DATE){ callTransactionList({ sortType: sort }); } }; const changePeriodType = (val: SettlementPeriodType) => { if(val !== periodType){ setPeriodType(val); if(val === SettlementPeriodType.SETTLEMENT_DATE){ callSettlementList(); } else if(val === SettlementPeriodType.TRANSACTION_DATE){ callTransactionList(); } } }; const getSettlementDateListDateGroup = () => { let rs = []; let date = ''; let list: Array = []; for(let i=0;i 0){ rs.push( ); } date = settlementDate; list = []; } list.push(listItem); } } } if(list.length > 0){ rs.push( ); } return rs; }; const getTransactionDateListDateGroup = () => { let rs = []; let date = ''; let list: Array = []; for(let i=0;i 0){ rs.push( ); } date = settlementDate; list = []; } list.push(listItem); } } } if(list.length > 0){ rs.push( ); } return rs; }; const onClickToOpenFilter = () => { setFilterOn(!filterOn); }; const onClickToDownloadExcel = () => { setEmailBottomSheetOn(true); }; const onRequestDownloadExcel = (userEmail?: string) => { // tid??? 확인 필요 /* downloadExcel({ // tid: tid }).then((rs) => { }); */ }; useEffect(() => { setTransactionIds([ 'TXN_20250608_001', 'TXN_20250608_002' ]); }, []); useEffect(() => { callList(); }, [ mid, periodType, startDate, endDate, paymentMethod ]); return ( <>
정산금액
{ (periodType === SettlementPeriodType.SETTLEMENT_DATE) && { isOpenSummary && } } { (periodType === SettlementPeriodType.TRANSACTION_DATE) && { isOpenSummary && } }
changePeriodType(SettlementPeriodType.SETTLEMENT_DATE) } >가맹점 기준 changePeriodType(SettlementPeriodType.TRANSACTION_DATE) } >거래 기준
{ (periodType === SettlementPeriodType.SETTLEMENT_DATE) && getSettlementDateListDateGroup() } { (periodType === SettlementPeriodType.TRANSACTION_DATE) && getTransactionDateListDateGroup() }
{ !!emailBottomSheetOn && } ); };