diff --git a/src/entities/settlement/api/use-settlements-history-excel-mutation.ts b/src/entities/settlement/api/use-settlements-history-excel-mutation.ts new file mode 100644 index 0000000..1655138 --- /dev/null +++ b/src/entities/settlement/api/use-settlements-history-excel-mutation.ts @@ -0,0 +1,39 @@ +import axios from 'axios'; +import { API_URL_SETTLEMENT } from '@/shared/api/api-url-settlement'; +import { resultify } from '@/shared/lib/resultify'; +import { NiceAxiosError } from '@/shared/@types/error'; +import { + SettlementsHistoryExcelParams, + SettlementsHistoryExcelResponse +} from '../model/types'; +import { + useMutation, + UseMutationOptions +} from '@tanstack/react-query'; +import { getHeaderUserAgent } from '@/shared/constants/url'; + +export const settlementsHistoryExcel = (params: SettlementsHistoryExcelParams) => { + let headerOptions = { + menuId: 37, + apiType: 'DOWNLOAD' + }; + let options = { + headers: { + 'X-User-Agent': getHeaderUserAgent(headerOptions) + } + }; + return resultify( + axios.post(API_URL_SETTLEMENT.settlementsHistoryExcel(), params, options), + ); +}; + +export const useSettlementsHistoryExcelMutation = (options?: UseMutationOptions) => { + const mutation = useMutation({ + ...options, + mutationFn: (params: SettlementsHistoryExcelParams) => settlementsHistoryExcel(params), + }); + + return { + ...mutation, + }; +}; diff --git a/src/entities/settlement/model/types.ts b/src/entities/settlement/model/types.ts index e773f96..dcd2fab 100644 --- a/src/entities/settlement/model/types.ts +++ b/src/entities/settlement/model/types.ts @@ -213,4 +213,14 @@ export interface TransactionInfoWrapProps { transactionInfo?: TransactionInfo; isOpen: boolean; onClickToShowInfo: (infoWrapKey: InfoWrapKeys) => void; -}; \ No newline at end of file +}; + +export interface SettlementsHistoryExcelParams { + email: string; + mid: string; + periodType: SettlementPeriodType + startDate: string; + endDate: string; + paymentMethod: SettlementPaymentMethod; +}; +export interface SettlementsHistoryExcelResponse {}; \ No newline at end of file diff --git a/src/entities/vat-return/api/use-vat-return-download-excel-mutation.ts b/src/entities/vat-return/api/use-vat-return-download-excel-mutation.ts new file mode 100644 index 0000000..3540019 --- /dev/null +++ b/src/entities/vat-return/api/use-vat-return-download-excel-mutation.ts @@ -0,0 +1,39 @@ +import axios from 'axios'; +import { API_URL_VAT_RETURN } from '@/shared/api/api-url-vat-return'; +import { resultify } from '@/shared/lib/resultify'; +import { NiceAxiosError } from '@/shared/@types/error'; +import { + VatReturnDownloadExcelParams, + VatReturnDownloadExcelResponse +} from '../model/types'; +import { + useMutation, + UseMutationOptions +} from '@tanstack/react-query'; +import { getHeaderUserAgent } from '@/shared/constants/url'; + +export const vatReturnDownloadExcel = (params: VatReturnDownloadExcelParams) => { + let headerOptions = { + menuId: 48, + apiType: 'SELECT' + }; + let options = { + headers: { + 'X-User-Agent': getHeaderUserAgent(headerOptions) + } + }; + return resultify( + axios.post(API_URL_VAT_RETURN.vatReturnDownloadExcel(), params, options), + ); +}; + +export const useVatReturnDownloadExcelMutation = (options?: UseMutationOptions) => { + const mutation = useMutation({ + ...options, + mutationFn: (params: VatReturnDownloadExcelParams) => vatReturnDownloadExcel(params), + }); + + return { + ...mutation, + }; +}; diff --git a/src/entities/vat-return/model/types.ts b/src/entities/vat-return/model/types.ts index 91ca674..9ef9b8d 100644 --- a/src/entities/vat-return/model/types.ts +++ b/src/entities/vat-return/model/types.ts @@ -165,4 +165,13 @@ export interface TransactionDetails { supplyAmount: number; taxAmount: number; remarks: string; -}; \ No newline at end of file +}; +export interface VatReturnDownloadExcelParams { + email: string; + mid: string; + startMonth: string; + endMonth: string; + receiptType: VatReturnReceiptType; + targetType: VatReturnTargetType; +}; +export interface VatReturnDownloadExcelResponse {}; \ No newline at end of file diff --git a/src/entities/vat-return/ui/list-wrap.tsx b/src/entities/vat-return/ui/list-wrap.tsx index 67c3fdf..06626fa 100644 --- a/src/entities/vat-return/ui/list-wrap.tsx +++ b/src/entities/vat-return/ui/list-wrap.tsx @@ -8,6 +8,8 @@ import { DefaultRequestPagination, SortTypeKeys } from '@/entities/common/model/ import { DEFAULT_PAGE_PARAM } from '@/entities/common/model/constant'; import { DetailData, + VatReturnDownloadExcelParams, + VatReturnDownloadExcelResponse, VatReturnListContent, VatReturnListParams, VatReturnListResponse, @@ -22,7 +24,8 @@ import useIntersectionObserver from '@/widgets/intersection-observer'; import { TaxInvoiceDetail } from './detail/tax-invoice-detail'; import { showAlert } from '@/widgets/show-alert'; import { checkGrant } from '@/shared/lib/check-grant'; -import { TaxInvoiceSample } from '@/entities/common/ui/tax-invoice-sample'; +import { useVatReturnDownloadExcelMutation } from '../api/use-vat-return-download-excel-mutation'; +import { snackBar } from '@/shared/lib'; /* 세금계산서 48 */ const menuId = 48; @@ -42,11 +45,12 @@ export const ListWrap = () => { const [targetType, setTargetType] = useState(VatReturnTargetType.ALL); const [downloadBottomSheetOn, setDownloadBottomSheetOn] = useState(false); - const [taxInvoiceSampleOn, setTaxInvoiceSampleOn] = useState(false); - + const [detailOn, setDetailOn] = useState(false); const [detailTaxInvoiceNumber, setDetailTaxInvoiceNumber] = useState(''); + const { mutateAsync: vatReturnList } = useVatReturnListMutation(); + const { mutateAsync: vatReturnDownloadExcel } = useVatReturnDownloadExcelMutation(); const onIntersect: IntersectionObserverCallback = (entries: Array) => { entries.forEach((entry: IntersectionObserverEntry) => { @@ -132,8 +136,26 @@ export const ListWrap = () => { selectedMode: DownloadSelectedMode, userEmail?: string ) => { - if(selectedMode === DownloadSelectedMode.IMAGE){ - setTaxInvoiceSampleOn(true); + if(selectedMode === DownloadSelectedMode.EMAIL + && !!userEmail + ){ + let params: VatReturnDownloadExcelParams = { + email: userEmail, + mid: mid, + startMonth: startMonth, + endMonth: endMonth, + receiptType: receiptType, + targetType: targetType + }; + vatReturnDownloadExcel(params).then((rs: VatReturnDownloadExcelResponse) => { + console.log(rs); + snackBar('이메일로 엑셀파일 요청이 완료되었습니다.'); + }).catch((e: any) => { + if(e.response?.data?.error?.message){ + snackBar(e.response?.data?.error?.message); + return; + } + }); } }; @@ -262,13 +284,6 @@ export const ListWrap = () => { sendRequest={ onRequestDownloadExcel } > } - { !!taxInvoiceSampleOn && - - - } ); }; \ No newline at end of file diff --git a/src/shared/api/api-url-settlement.ts b/src/shared/api/api-url-settlement.ts index d07dfda..2560c74 100644 --- a/src/shared/api/api-url-settlement.ts +++ b/src/shared/api/api-url-settlement.ts @@ -33,5 +33,9 @@ export const API_URL_SETTLEMENT = { // POST: 정산내역 거래건별 조회 return `${API_BASE_URL}/api/v1/${API_URL_KEY}/settlements/calendar`; }, + settlementsHistoryExcel: () => { + // POST: 정산내역 엑셀 다운로드 + return `${API_BASE_URL}/api/v1/${API_URL_KEY}/settlements/history/excel`; + }, }; \ No newline at end of file diff --git a/src/shared/api/api-url-vat-return.ts b/src/shared/api/api-url-vat-return.ts index a8afc35..08b6940 100644 --- a/src/shared/api/api-url-vat-return.ts +++ b/src/shared/api/api-url-vat-return.ts @@ -23,5 +23,9 @@ export const API_URL_VAT_RETURN = { vatReturnBreakdown: () => { // POST: 세금계산서 세부내역 조회 return `${API_BASE_URL}/api/v1/${API_URL_KEY}/vat-return/breakdown`; - } + }, + vatReturnDownloadExcel: () => { + // POST: 세금계산서 엑셀 다운로드 + return `${API_BASE_URL}/api/v1/${API_URL_KEY}/vat-return/download/excel`; + }, }; \ No newline at end of file