From 28b58d9cac1597db21b0975c1e3d7fe24f2678d8 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Fri, 23 Jan 2026 15:36:16 +0700 Subject: [PATCH 1/3] fix: fix exportProductionResultToExcel method --- src/services/api/report/production-result.ts | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/services/api/report/production-result.ts b/src/services/api/report/production-result.ts index 251e3eb4..3a8d2fae 100644 --- a/src/services/api/report/production-result.ts +++ b/src/services/api/report/production-result.ts @@ -32,21 +32,21 @@ export class ProductionResultReportApiService extends BaseApiService< const mappedProductionResults: { projectFlockKandang: BaseProjectFlockKandang; productionResult: ProductionResult[] | null; - }[] = []; + }[] = await Promise.all( + (projectFlockKandangs || []).map(async (projectFlockKandang) => { + const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`; + const getProductionResultRes = await httpClient< + BaseApiResponse + >(getProductionResultPath); - projectFlockKandangs?.forEach(async (projectFlockKandang) => { - const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`; - const getProductionResultRes = await httpClient< - BaseApiResponse - >(getProductionResultPath); - - mappedProductionResults.push({ - projectFlockKandang, - productionResult: isResponseSuccess(getProductionResultRes) - ? getProductionResultRes.data - : null, - }); - }); + return { + projectFlockKandang, + productionResult: isResponseSuccess(getProductionResultRes) + ? getProductionResultRes.data + : null, + }; + }) + ); const rows = mappedProductionResults; if (!rows || rows.length === 0) { @@ -103,9 +103,11 @@ export class ProductionResultReportApiService extends BaseApiService< fcr_std: productionResult.fcr_std, hh: productionResult.hh, hh_std: productionResult.hh_std, - project_flock_name: productionResult.project_flock.name, - project_flock_category: productionResult.project_flock.category, - kandang_name: productionResult.project_flock.kandang.name, + project_flock_name: + row.projectFlockKandang.project_flock.flock_name, + project_flock_category: + row.projectFlockKandang.project_flock.category, + kandang_name: row.projectFlockKandang.kandang.name, created_at: formatDate(productionResult.created_at, 'YYYY-MM-DD'), updated_at: formatDate(productionResult.updated_at, 'YYYY-MM-DD'), }); From ed9a8021c18c8430f2a7166cfe5a7ce07b62da86 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Fri, 23 Jan 2026 15:59:31 +0700 Subject: [PATCH 2/3] feat: add safeRound helper function --- src/lib/helper.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/helper.ts b/src/lib/helper.ts index c69f610f..9abe44b4 100644 --- a/src/lib/helper.ts +++ b/src/lib/helper.ts @@ -31,6 +31,11 @@ export const formatNumber = ( }).format(value); }; +export const safeRound = (num: number, decimals: number) => { + const factor = 10 ** decimals; + return Math.round((num + Number.EPSILON) * factor) / factor; +}; + export const formatTitleCase = (value: string) => { return value .toLowerCase() From d026a3b5aeb654d80627c477f84994f97f9a747c Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Fri, 23 Jan 2026 15:59:46 +0700 Subject: [PATCH 3/3] chore: round export number to excel --- src/services/api/report/production-result.ts | 70 ++++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/services/api/report/production-result.ts b/src/services/api/report/production-result.ts index 3a8d2fae..43417aff 100644 --- a/src/services/api/report/production-result.ts +++ b/src/services/api/report/production-result.ts @@ -1,6 +1,6 @@ import * as XLSX from 'xlsx'; import toast from 'react-hot-toast'; -import { formatDate } from '@/lib/helper'; +import { formatDate, safeRound } from '@/lib/helper'; import { isResponseSuccess } from '@/lib/api-helper'; import { BaseApiService } from '@/services/api/base'; import { httpClient, httpClientFetcher } from '@/services/http/client'; @@ -68,41 +68,41 @@ export class ProductionResultReportApiService extends BaseApiService< row.productionResult?.forEach((productionResult) => { groupedData[kandangName].push({ - woa: productionResult.woa, - bw: productionResult.bw, - std_bw: productionResult.std_bw, - uniformity: productionResult.uniformity, + woa: safeRound(productionResult.woa, 2), + bw: safeRound(productionResult.bw, 2), + std_bw: safeRound(productionResult.std_bw, 2), + uniformity: safeRound(productionResult.uniformity, 2), std_uniformity: productionResult.std_uniformity, - dep_kum: productionResult.dep_kum, - dep_std: productionResult.dep_std, - butiran_utuh: productionResult.butiran_utuh, - butiran_putih: productionResult.butiran_putih, - butiran_retak: productionResult.butiran_retak, - butiran_pecah: productionResult.butiran_pecah, - butiran_jumlah: productionResult.butiran_jumlah, - total_butir: productionResult.total_butir, - kg_utuh: productionResult.kg_utuh, - kg_putih: productionResult.kg_putih, - kg_retak: productionResult.kg_retak, - kg_pecah: productionResult.kg_pecah, - kg_jumlah: productionResult.kg_jumlah, - total_kg: productionResult.total_kg, - persen_utuh: productionResult.persen_utuh, - persen_putih: productionResult.persen_putih, - persen_retak: productionResult.persen_retak, - persen_pecah: productionResult.persen_pecah, - hd: productionResult.hd, - hd_std: productionResult.hd_std, - fi: productionResult.fi, - fi_std: productionResult.fi_std, - em: productionResult.em, - em_std: productionResult.em_std, - ew: productionResult.ew, - ew_std: productionResult.ew_std, - fcr: productionResult.fcr, - fcr_std: productionResult.fcr_std, - hh: productionResult.hh, - hh_std: productionResult.hh_std, + dep_kum: safeRound(productionResult.dep_kum, 2), + dep_std: safeRound(productionResult.dep_std, 2), + butiran_utuh: safeRound(productionResult.butiran_utuh, 2), + butiran_putih: safeRound(productionResult.butiran_putih, 2), + butiran_retak: safeRound(productionResult.butiran_retak, 2), + butiran_pecah: safeRound(productionResult.butiran_pecah, 2), + butiran_jumlah: safeRound(productionResult.butiran_jumlah, 2), + total_butir: safeRound(productionResult.total_butir, 2), + kg_utuh: safeRound(productionResult.kg_utuh, 2), + kg_putih: safeRound(productionResult.kg_putih, 2), + kg_retak: safeRound(productionResult.kg_retak, 2), + kg_pecah: safeRound(productionResult.kg_pecah, 2), + kg_jumlah: safeRound(productionResult.kg_jumlah, 2), + total_kg: safeRound(productionResult.total_kg, 2), + persen_utuh: safeRound(productionResult.persen_utuh, 2), + persen_putih: safeRound(productionResult.persen_putih, 2), + persen_retak: safeRound(productionResult.persen_retak, 2), + persen_pecah: safeRound(productionResult.persen_pecah, 2), + hd: safeRound(productionResult.hd, 2), + hd_std: safeRound(productionResult.hd_std, 2), + fi: safeRound(productionResult.fi, 2), + fi_std: safeRound(productionResult.fi_std, 2), + em: safeRound(productionResult.em, 2), + em_std: safeRound(productionResult.em_std, 2), + ew: safeRound(productionResult.ew, 2), + ew_std: safeRound(productionResult.ew_std, 2), + fcr: safeRound(productionResult.fcr, 2), + fcr_std: safeRound(productionResult.fcr_std, 2), + hh: safeRound(productionResult.hh, 2), + hh_std: safeRound(productionResult.hh_std, 2), project_flock_name: row.projectFlockKandang.project_flock.flock_name, project_flock_category: