Enhance ReportPreviewOverlay to display DOC weight and improve KPI row styling. Update dashboard report payload to include docWeight, and adjust report summary to incorporate it. Add tests for docWeight functionality.

This commit is contained in:
Alberto-Audrix committed 2026-09-07 14:18:32 +07:00
1 parent 75eb218558
commit 3ba6fed189
7 files changed
+123 -18

No files matched your search

+45 -4
View File
@@ -13,6 +13,7 @@ const COLORS = {
headerFill: 'FFF8FAFC',
headerFont: 'FF475569',
accentFill: 'FF6D28D0',
accentDeep: 'FF5B21B6',
accentFont: 'FFFFFFFF',
totalFill: 'FFF1F5F9',
zebraFill: 'FFFAFAFA',
@@ -98,6 +99,30 @@ function styleTotalRow(row: ExcelJS.Row, colCount: number): void {
}
}
function styleHighlightKpiRow(row: ExcelJS.Row, colCount: number): void {
row.height = 28;
const highlightBorder: Partial<ExcelJS.Borders> = {
top: { style: 'medium', color: { argb: COLORS.accentDeep } },
left: { style: 'medium', color: { argb: COLORS.accentDeep } },
bottom: { style: 'medium', color: { argb: COLORS.accentDeep } },
right: { style: 'medium', color: { argb: COLORS.accentDeep } },
};
for (let c = 1; c <= colCount; c += 1) {
const cell = row.getCell(c);
cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: COLORS.accentFill } };
cell.font = {
bold: true,
size: c === 2 ? 14 : 11,
color: { argb: COLORS.accentFont },
};
cell.alignment = {
vertical: 'middle',
horizontal: c === 2 ? 'center' : 'left',
};
cell.border = highlightBorder;
}
}
function autoFitColumns(sheet: ExcelJS.Worksheet, min = 10, max = 42): void {
sheet.columns.forEach((column) => {
let maxLen = min;
@@ -189,6 +214,12 @@ function addSummarySheet(workbook: ExcelJS.Workbook, payload: DashboardReportPay
`Hari ke-0 s/d ke-${payload.upToDay} (${formatDateId(payload.cycleStart)} - ${formatDateId(lastDate)})`
);
addMeta('Siklus', formatDateRange(payload.cycleStart, payload.cycleEnd));
addMeta(
'Berat DOC',
payload.docWeight == null || !Number.isFinite(payload.docWeight)
? '—'
: `${formatNumber(payload.docWeight, 1, 0, true)} gram`
);
addMeta('Dicetak', printedDate);
sheet.addRow([]);
@@ -204,16 +235,26 @@ function addSummarySheet(workbook: ExcelJS.Workbook, payload: DashboardReportPay
styleHeaderRow(kpiHeader, 3);
const summary = buildReportSummary(payload);
let insertedHighlightGap = false;
summary.metrics.forEach((metric, index) => {
const isHighlight = metric.key === 'fcr' || metric.key === 'eef';
if (isHighlight && !insertedHighlightGap) {
sheet.addRow([]);
insertedHighlightGap = true;
}
const row = sheet.addRow([
metric.label,
formatSummaryValue(metric),
metric.unit || '—',
]);
styleDataRow(row, 3, index % 2 === 1);
row.getCell(1).alignment = { vertical: 'middle', horizontal: 'left' };
row.getCell(2).alignment = { vertical: 'middle', horizontal: 'right' };
row.getCell(3).alignment = { vertical: 'middle', horizontal: 'left' };
if (isHighlight) {
styleHighlightKpiRow(row, 3);
} else {
styleDataRow(row, 3, index % 2 === 1);
row.getCell(1).alignment = { vertical: 'middle', horizontal: 'left' };
row.getCell(2).alignment = { vertical: 'middle', horizontal: 'right' };
row.getCell(3).alignment = { vertical: 'middle', horizontal: 'left' };
}
});
sheet.addRow([]);