Merge branch 'fix/marketing-export' into 'development'

[FIX/FE] Marketing Export

See merge request mbugroup/lti-web-client!424
This commit is contained in:
Rivaldi A N S
2026-04-22 16:34:37 +00:00
2 changed files with 19 additions and 55 deletions
@@ -835,7 +835,7 @@ const MarketingTable = () => {
className='w-full p-3 justify-start text-sm text-base-content/50 font-semibold text-nowrap' className='w-full p-3 justify-start text-sm text-base-content/50 font-semibold text-nowrap'
> >
<Icon icon='heroicons:table-cells' width={20} height={20} /> <Icon icon='heroicons:table-cells' width={20} height={20} />
Export to Excel Ekspor ke Excel
</Button> </Button>
<Button <Button
+18 -54
View File
@@ -149,67 +149,31 @@ class MarketingExportService extends BaseApiService<
} }
} }
/**
* Export to Excel
*/
async exportToExcel(initialQueryString: string) { async exportToExcel(initialQueryString: string) {
const params = new URLSearchParams(initialQueryString); const params = new URLSearchParams(initialQueryString);
params.set('export', 'excel');
params.set('type', 'all');
params.set('page', '1');
params.set('limit', '99999999999');
const queryString = `?${params.toString()}`; const queryString = `?${params.toString()}`;
try { const res = await httpClient<Blob>(`${this.basePath}${queryString}`, {
const marketingData = await httpClientFetcher< method: 'GET',
BaseApiResponse<Marketing[]> responseType: 'blob',
>(`${this.basePath}${queryString}`);
if (isResponseError(marketingData)) {
toast.error('Gagal melakukan export marketing! Coba lagi.');
return;
}
const rows = marketingData.data;
const formattedRows = [];
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const approval = row.latest_approval;
const isRejected = approval?.action === 'REJECTED';
// Calculate grand total from sales_order products
const grandTotal =
row.sales_order
?.map((product) => product.total_price)
.reduce((a, b) => a + b, 0) ?? 0;
// Get product names
const products =
row.sales_order
?.map((product) => product.product_warehouse?.product?.name)
.filter(Boolean)
.join(', ') ?? '';
formattedRows.push({
'No. Order': row.so_number,
Tanggal: formatDate(row.so_date, 'DD-MM-YYYY'),
Status: isRejected
? 'Ditolak'
: formatTitleCase(approval?.step_name || ''),
Customer: row.customer?.name || '',
'Grand Total': formatCurrency(grandTotal),
Products: products,
Notes: row.notes || '',
}); });
}
const ws = XLSX.utils.json_to_sheet(formattedRows); const url = window.URL.createObjectURL(new Blob([res]));
const wb = XLSX.utils.book_new(); const link = document.createElement('a');
XLSX.utils.book_append_sheet(wb, ws, 'marketing'); link.href = url;
// triggers download in browser const fileName = `penjualan-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`;
XLSX.writeFile(wb, 'marketing.xlsx'); link.setAttribute('download', fileName);
} catch {
toast.error('Gagal melakukan export marketing! Coba lagi.'); document.body.appendChild(link);
} link.click();
link.remove();
} }
async exportInputProgressToExcel(startDate: string, endDate: string) { async exportInputProgressToExcel(startDate: string, endDate: string) {