mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
Merge branch 'fix/marketing-export' into 'development'
[FIX/FE] Marketing Export See merge request mbugroup/lti-web-client!424
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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)) {
|
const url = window.URL.createObjectURL(new Blob([res]));
|
||||||
toast.error('Gagal melakukan export marketing! Coba lagi.');
|
const link = document.createElement('a');
|
||||||
return;
|
link.href = url;
|
||||||
}
|
|
||||||
|
|
||||||
const rows = marketingData.data;
|
const fileName = `penjualan-${formatDate(Date.now(), 'DD-MM-YYYY')}.xlsx`;
|
||||||
|
link.setAttribute('download', fileName);
|
||||||
|
|
||||||
const formattedRows = [];
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
for (let i = 0; i < rows.length; i++) {
|
link.remove();
|
||||||
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 wb = XLSX.utils.book_new();
|
|
||||||
XLSX.utils.book_append_sheet(wb, ws, 'marketing');
|
|
||||||
|
|
||||||
// triggers download in browser
|
|
||||||
XLSX.writeFile(wb, 'marketing.xlsx');
|
|
||||||
} catch {
|
|
||||||
toast.error('Gagal melakukan export marketing! Coba lagi.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async exportInputProgressToExcel(startDate: string, endDate: string) {
|
async exportInputProgressToExcel(startDate: string, endDate: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user