From f6c0c98d37d3fa7536236384a48ff7b70076e21f Mon Sep 17 00:00:00 2001 From: Arif Rahman Hakim Date: Fri, 6 Sep 2024 19:16:14 +0800 Subject: [PATCH] feat: sync volume for report using data in contract --- src/api/contractApi.ts | 29 +++++++++++++++++++ .../report/FormReportByActivity.vue | 19 +++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/api/contractApi.ts b/src/api/contractApi.ts index 4e9e149..b5678d8 100644 --- a/src/api/contractApi.ts +++ b/src/api/contractApi.ts @@ -60,6 +60,35 @@ export const getContractStatistic = async () => { return result.data; }; +export const getContractActivityVolume = async ( + outputId: string, + period: string +) => { + const auth = useAuthStore(); + + const query = { + outputId: outputId, + period: period, + }; + + const response = await fetch( + `${BASE_URL}/v1/contracts/activity/volume?` + new URLSearchParams(query), + { + headers: { + Authorization: `Bearer ${auth.token}`, + }, + } + ); + + const result = await response.json(); + + if (!response.ok) { + throw new Error(result.message); + } + + return result.data; +}; + export const printContracts = async (payload: any) => { const auth = useAuthStore(); diff --git a/src/components/report/FormReportByActivity.vue b/src/components/report/FormReportByActivity.vue index 6ba8c2b..a28145c 100644 --- a/src/components/report/FormReportByActivity.vue +++ b/src/components/report/FormReportByActivity.vue @@ -4,13 +4,11 @@ {{ output.name }} - + "> {{ output.activity.name }} @@ -44,6 +42,7 @@ Unduh Master Data Mitra Template Impor Mitra + Sinkronisasi Mitra @@ -64,6 +63,7 @@ import { getOutputs } from "@/api/outputApi"; import { generatePeriods } from "@/utils/date"; import { downloadPartners, getPartners } from "@/api/partnerApi"; import { downloadTemplatePartner } from "@/api/reportApi"; +import { getContractActivityVolume } from "@/api/contractApi"; const formRef = ref(); const fileInput = ref(); @@ -122,6 +122,17 @@ const downloadTemplateImportPartner = () => { downloadTemplatePartner() } +const syncPartner = async () => { + const result = await getContractActivityVolume(form.output.outputId, form.contract.period) + + result.forEach((rawPartner: any) => { + form.partners.push({ + partnerId: rawPartner.partnerId, + total: rawPartner.volume, + }); + }); +} + const handleFileChange = async (uploadFile: UploadFile, uploadFiles: UploadFiles) => { const raw = await uploadFile.raw?.text();