From c8d259d1ba0ac8db8cef23e4b2db8c8c5869229b Mon Sep 17 00:00:00 2001 From: Samandar Turg'unboev Date: Thu, 29 May 2025 09:51:29 +0500 Subject: [PATCH] exel --- messages/cn.json | 3 +- messages/en.json | 2 +- messages/ru.json | 1 + messages/uz.json | 1 + src/data/party/party.requests.ts | 3 + .../private/parties/DashboardPartiesPage.tsx | 65 +++++++++++++------ 6 files changed, 53 insertions(+), 22 deletions(-) diff --git a/messages/cn.json b/messages/cn.json index 2669bb9..48de271 100644 --- a/messages/cn.json +++ b/messages/cn.json @@ -210,5 +210,6 @@ "update_packet": "編輯套件", "party_weight": "大量重量", "qr_code": "二维码", - "created_at": "添加日期" + "created_at": "添加日期", + "download_all_items_exel": "将所有产品上传至Excel" } \ No newline at end of file diff --git a/messages/en.json b/messages/en.json index c2e3f11..32c5c1e 100644 --- a/messages/en.json +++ b/messages/en.json @@ -209,7 +209,7 @@ "weight_of_items": "Products weight", "update_packet": "Edit Paket", "party_weight": "Batch weight", - + "download_all_items_exel": "Upload all products in Excel", "qr_code": "QR Code", "created_at": "Date of joining" } \ No newline at end of file diff --git a/messages/ru.json b/messages/ru.json index e4aa6d6..2bef067 100644 --- a/messages/ru.json +++ b/messages/ru.json @@ -222,6 +222,7 @@ "weight_of_items": "Вес продукта", "update_packet": "Редактировать пакет", "party_weight": "Вес партии", + "download_all_items_exel": "Загрузить все товары в Excel", "qr_code": "QR код", "created_at": "Дата добавления" diff --git a/messages/uz.json b/messages/uz.json index 389d01a..c0edc3a 100644 --- a/messages/uz.json +++ b/messages/uz.json @@ -216,6 +216,7 @@ "date_of_birth": "Tug'ilgan kuni", "are_you_sure_delete_client_id": "Rostdan ham {id} id lik klientni o'chirmoqchimisiz?", "download_all_items": "Barcha mahsulotlarni yuklab olish", + "download_all_items_exel": "Barcha mahsulotlarni exelda yuklash", "download_all_clients": "Barcha mijozlarni yuklab olish", "are_you_sure_delete_party": "{name} yuk partiyasini o'chirishga ishonchingiz komilmi?", "passport": "Pasport", diff --git a/src/data/party/party.requests.ts b/src/data/party/party.requests.ts index ce8c755..a03042d 100644 --- a/src/data/party/party.requests.ts +++ b/src/data/party/party.requests.ts @@ -35,4 +35,7 @@ export const party_requests = { async downloadPartyItemsExcel(params: { partyId: number | string }) { return request.get('/parties/items/download', { params, responseType: 'blob' }); }, + async downloadPartyItemsAllExcel(params: { partyId: number | string }) { + return request.get('/parties/download/box-order', { params, responseType: 'blob' }); + }, }; diff --git a/src/routes/private/parties/DashboardPartiesPage.tsx b/src/routes/private/parties/DashboardPartiesPage.tsx index 44ccf12..6367c5a 100644 --- a/src/routes/private/parties/DashboardPartiesPage.tsx +++ b/src/routes/private/parties/DashboardPartiesPage.tsx @@ -40,6 +40,7 @@ const DashboardPartiesPage = (props: Props) => { const [deleteIds, setDeleteIds] = useState([]); const [downloadIds, setDownloadIds] = useState([]); const [downloadItemIds, setDownloadItemIds] = useState([]); + const [downloadItemIdsExel, setDownloadItemIdsExel] = useState([]); const [changeStatusIds, setChangeStatusIds] = useState([]); const partyStatusOptions = useMemo(() => { @@ -145,6 +146,21 @@ const DashboardPartiesPage = (props: Props) => { } }; + const onDownloadPartyItemsExel = async (id: number, name: string) => { + if (downloadItemIds.includes(id)) return; + + try { + setDownloadItemIdsExel(p => [...p, id]); + const response = await party_requests.downloadPartyItemsAllExcel({ partyId: id }); + const file = new File([response.data], `${name}.xlsx`, { type: response.data.type }); + file_service.download(file); + } catch (error) { + notifyUnknownError(error); + } finally { + setDownloadItemIdsExel(prev => prev.filter(i => i !== id)); + } + }; + const onChangeStatus = async (id: number, newStatus: PartyStatus) => { if (changeStatusIds.includes(id)) return; @@ -290,29 +306,38 @@ const DashboardPartiesPage = (props: Props) => { }, ...(isAdmin ? [ - { - icon: , - label: t('download_all_items'), - onClick: () => { - onDownloadPartyItems(data.id); - }, - dontCloseOnClick: true, - loading: downloadItemIds.includes(data.id), - }, - ] + { + icon: , + label: t('download_all_items'), + onClick: () => { + onDownloadPartyItems(data.id); + }, + dontCloseOnClick: true, + loading: downloadItemIds.includes(data.id), + }, + ] : []), + { + icon: , + label: t('download_all_items_exel'), + onClick: () => { + onDownloadPartyItemsExel(data.id, data.name); + }, + dontCloseOnClick: true, + loading: downloadItemIdsExel.includes(data.id), + }, ...(Boolean(data.partyStatus === 'ON_THE_WAY' || data.partyStatus === 'ARRIVED') ? [ - { - icon: , - label: t('download_excel'), - onClick: () => { - onDownloadExcel(data.id); - }, - loading: downloadIds.includes(data.id), - dontCloseOnClick: true, - }, - ] + { + icon: , + label: t('download_excel'), + onClick: () => { + onDownloadExcel(data.id); + }, + loading: downloadIds.includes(data.id), + dontCloseOnClick: true, + }, + ] : []), ]} />