Merge branch 'development' of gitlab.com:mbugroup/lti-web-client into dev/hotfix/restu

This commit is contained in:
rstubryan
2026-01-23 17:34:10 +07:00
2 changed files with 59 additions and 52 deletions
+5
View File
@@ -31,6 +31,11 @@ export const formatNumber = (
}).format(value); }).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) => { export const formatTitleCase = (value: string) => {
return value return value
.toLowerCase() .toLowerCase()
+46 -44
View File
@@ -1,6 +1,6 @@
import * as XLSX from 'xlsx'; import * as XLSX from 'xlsx';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import { formatDate } from '@/lib/helper'; import { formatDate, safeRound } from '@/lib/helper';
import { isResponseSuccess } from '@/lib/api-helper'; import { isResponseSuccess } from '@/lib/api-helper';
import { BaseApiService } from '@/services/api/base'; import { BaseApiService } from '@/services/api/base';
import { httpClient, httpClientFetcher } from '@/services/http/client'; import { httpClient, httpClientFetcher } from '@/services/http/client';
@@ -32,21 +32,21 @@ export class ProductionResultReportApiService extends BaseApiService<
const mappedProductionResults: { const mappedProductionResults: {
projectFlockKandang: BaseProjectFlockKandang; projectFlockKandang: BaseProjectFlockKandang;
productionResult: ProductionResult[] | null; productionResult: ProductionResult[] | null;
}[] = []; }[] = await Promise.all(
(projectFlockKandangs || []).map(async (projectFlockKandang) => {
projectFlockKandangs?.forEach(async (projectFlockKandang) => {
const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`; const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`;
const getProductionResultRes = await httpClient< const getProductionResultRes = await httpClient<
BaseApiResponse<ProductionResult[]> BaseApiResponse<ProductionResult[]>
>(getProductionResultPath); >(getProductionResultPath);
mappedProductionResults.push({ return {
projectFlockKandang, projectFlockKandang,
productionResult: isResponseSuccess(getProductionResultRes) productionResult: isResponseSuccess(getProductionResultRes)
? getProductionResultRes.data ? getProductionResultRes.data
: null, : null,
}); };
}); })
);
const rows = mappedProductionResults; const rows = mappedProductionResults;
if (!rows || rows.length === 0) { if (!rows || rows.length === 0) {
@@ -68,44 +68,46 @@ export class ProductionResultReportApiService extends BaseApiService<
row.productionResult?.forEach((productionResult) => { row.productionResult?.forEach((productionResult) => {
groupedData[kandangName].push({ groupedData[kandangName].push({
woa: productionResult.woa, woa: safeRound(productionResult.woa, 2),
bw: productionResult.bw, bw: safeRound(productionResult.bw, 2),
std_bw: productionResult.std_bw, std_bw: safeRound(productionResult.std_bw, 2),
uniformity: productionResult.uniformity, uniformity: safeRound(productionResult.uniformity, 2),
std_uniformity: productionResult.std_uniformity, std_uniformity: productionResult.std_uniformity,
dep_kum: productionResult.dep_kum, dep_kum: safeRound(productionResult.dep_kum, 2),
dep_std: productionResult.dep_std, dep_std: safeRound(productionResult.dep_std, 2),
butiran_utuh: productionResult.butiran_utuh, butiran_utuh: safeRound(productionResult.butiran_utuh, 2),
butiran_putih: productionResult.butiran_putih, butiran_putih: safeRound(productionResult.butiran_putih, 2),
butiran_retak: productionResult.butiran_retak, butiran_retak: safeRound(productionResult.butiran_retak, 2),
butiran_pecah: productionResult.butiran_pecah, butiran_pecah: safeRound(productionResult.butiran_pecah, 2),
butiran_jumlah: productionResult.butiran_jumlah, butiran_jumlah: safeRound(productionResult.butiran_jumlah, 2),
total_butir: productionResult.total_butir, total_butir: safeRound(productionResult.total_butir, 2),
kg_utuh: productionResult.kg_utuh, kg_utuh: safeRound(productionResult.kg_utuh, 2),
kg_putih: productionResult.kg_putih, kg_putih: safeRound(productionResult.kg_putih, 2),
kg_retak: productionResult.kg_retak, kg_retak: safeRound(productionResult.kg_retak, 2),
kg_pecah: productionResult.kg_pecah, kg_pecah: safeRound(productionResult.kg_pecah, 2),
kg_jumlah: productionResult.kg_jumlah, kg_jumlah: safeRound(productionResult.kg_jumlah, 2),
total_kg: productionResult.total_kg, total_kg: safeRound(productionResult.total_kg, 2),
persen_utuh: productionResult.persen_utuh, persen_utuh: safeRound(productionResult.persen_utuh, 2),
persen_putih: productionResult.persen_putih, persen_putih: safeRound(productionResult.persen_putih, 2),
persen_retak: productionResult.persen_retak, persen_retak: safeRound(productionResult.persen_retak, 2),
persen_pecah: productionResult.persen_pecah, persen_pecah: safeRound(productionResult.persen_pecah, 2),
hd: productionResult.hd, hd: safeRound(productionResult.hd, 2),
hd_std: productionResult.hd_std, hd_std: safeRound(productionResult.hd_std, 2),
fi: productionResult.fi, fi: safeRound(productionResult.fi, 2),
fi_std: productionResult.fi_std, fi_std: safeRound(productionResult.fi_std, 2),
em: productionResult.em, em: safeRound(productionResult.em, 2),
em_std: productionResult.em_std, em_std: safeRound(productionResult.em_std, 2),
ew: productionResult.ew, ew: safeRound(productionResult.ew, 2),
ew_std: productionResult.ew_std, ew_std: safeRound(productionResult.ew_std, 2),
fcr: productionResult.fcr, fcr: safeRound(productionResult.fcr, 2),
fcr_std: productionResult.fcr_std, fcr_std: safeRound(productionResult.fcr_std, 2),
hh: productionResult.hh, hh: safeRound(productionResult.hh, 2),
hh_std: productionResult.hh_std, hh_std: safeRound(productionResult.hh_std, 2),
project_flock_name: productionResult.project_flock.name, project_flock_name:
project_flock_category: productionResult.project_flock.category, row.projectFlockKandang.project_flock.flock_name,
kandang_name: productionResult.project_flock.kandang.name, project_flock_category:
row.projectFlockKandang.project_flock.category,
kandang_name: row.projectFlockKandang.kandang.name,
created_at: formatDate(productionResult.created_at, 'YYYY-MM-DD'), created_at: formatDate(productionResult.created_at, 'YYYY-MM-DD'),
updated_at: formatDate(productionResult.updated_at, 'YYYY-MM-DD'), updated_at: formatDate(productionResult.updated_at, 'YYYY-MM-DD'),
}); });