From 6755ce3084f6182ec4194ee2d3f8ca6dbc47d990 Mon Sep 17 00:00:00 2001 From: Abhijit Date: Thu, 26 Nov 2026 10:17:48 +0530 Subject: [PATCH] added formatted in horizon reports --- src/views/horizonreport/Report.jsx | 24 +++++++---- src/views/horizonreport/exportXlsx.js | 60 +++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/views/horizonreport/Report.jsx b/src/views/horizonreport/Report.jsx index b39edc9..655f577 100644 --- a/src/views/horizonreport/Report.jsx +++ b/src/views/horizonreport/Report.jsx @@ -6,6 +6,7 @@ import PageMetaData from '@/components/PageMetaData'; import { exportFieldWorkReport } from './exportXlsx'; const TITLE = 'Monthly Field Work Report'; +const HEADER_COLOR = '#95B3D7'; const REPORT_TIMEOUT = 120000; const FIRST_MONTH = new Date(2026, 10, 1); const IDENTITY = [ @@ -163,22 +164,29 @@ export default function HorizonFieldWorkReport() {
- + +
{IDENTITY.map((label) => ( - + ))} {days.map((day) => ( - + ))} - + {days.map((day) => ( - - + + ))} @@ -216,8 +224,8 @@ export default function HorizonFieldWorkReport() { )) : null} {rows.length ? ( - - + + ) : ( diff --git a/src/views/horizonreport/exportXlsx.js b/src/views/horizonreport/exportXlsx.js index e7f49d7..4890fd8 100644 --- a/src/views/horizonreport/exportXlsx.js +++ b/src/views/horizonreport/exportXlsx.js @@ -14,6 +14,12 @@ function dayLabel(iso) { return `${day}-${month}-${year}`; } +const HEADER_FILL = { + type: 'pattern', + pattern: 'solid', + fgColor: { argb: 'FF95B3D7' }, +}; + function textCell(sheet, row, column, value) { const cell = sheet.getCell(row, column); cell.value = value === null || value === undefined ? '' : String(value); @@ -21,6 +27,27 @@ function textCell(sheet, row, column, value) { return cell; } +function numberCell(sheet, row, column, value) { + const cell = sheet.getCell(row, column); + const text = value === null || value === undefined ? '' : String(value).trim(); + if (text !== '' && /^-?\d+$/.test(text)) { + cell.value = Number(text); + cell.numFmt = '0'; + } else { + cell.value = text; + } + cell.alignment = { vertical: 'middle', horizontal: 'center', wrapText: true }; + return cell; +} + +function paintHeader(sheet, row, start, end) { + for (let column = start; column <= end; column += 1) { + const cell = sheet.getCell(row, column); + cell.fill = HEADER_FILL; + cell.font = { ...(cell.font || {}), bold: true }; + } +} + export async function exportFieldWorkReport(report, filename) { const { default: ExcelJS } = await import('exceljs'); const workbook = new ExcelJS.Workbook(); @@ -38,21 +65,22 @@ export async function exportFieldWorkReport(report, filename) { const column = index + 1; textCell(sheet, 2, column, label); sheet.mergeCells(2, column, 3, column); - sheet.getCell(2, column).font = { bold: true }; + paintHeader(sheet, 2, column, column); + paintHeader(sheet, 3, column, column); }); days.forEach((day, index) => { const column = identityCount + index * 2 + 1; textCell(sheet, 2, column, dayLabel(day)); sheet.mergeCells(2, column, 2, column + 1); - sheet.getCell(2, column).font = { bold: true }; textCell(sheet, 3, column, 'Link'); textCell(sheet, 3, column + 1, 'Time'); - sheet.getCell(3, column).font = { bold: true }; - sheet.getCell(3, column + 1).font = { bold: true }; + paintHeader(sheet, 2, column, column + 1); + paintHeader(sheet, 3, column, column + 1); }); textCell(sheet, 2, lastColumn, 'RBM/ZBM wise Total'); sheet.mergeCells(2, lastColumn, 3, lastColumn); - sheet.getCell(2, lastColumn).font = { bold: true }; + paintHeader(sheet, 2, lastColumn, lastColumn); + paintHeader(sheet, 3, lastColumn, lastColumn); rows.forEach((row, rowIndex) => { const excelRow = rowIndex + 4; @@ -67,7 +95,9 @@ export async function exportFieldWorkReport(report, filename) { row.manager_2_name, ]; values.forEach((value, index) => { - const cell = textCell(sheet, excelRow, index + 1, value); + const cell = index === 1 || index === 4 || index === 6 + ? numberCell(sheet, excelRow, index + 1, value) + : textCell(sheet, excelRow, index + 1, value); if (index === 0 || index === 2 || index === 3 || index === 5 || index === 7) { cell.alignment = { vertical: 'middle', horizontal: 'left' }; } @@ -89,7 +119,7 @@ export async function exportFieldWorkReport(report, filename) { textCell(sheet, excelRow, column, ''); } }); - textCell(sheet, excelRow, lastColumn, row.total ?? 0); + numberCell(sheet, excelRow, lastColumn, row.total ?? 0); }); if (rows.length) { @@ -98,8 +128,22 @@ export async function exportFieldWorkReport(report, filename) { textCell(sheet, totalRow, 1, 'Total'); sheet.getCell(totalRow, 1).font = { bold: true }; sheet.getCell(totalRow, 1).alignment = { vertical: 'middle', horizontal: 'left' }; - textCell(sheet, totalRow, lastColumn, columnTotal); + numberCell(sheet, totalRow, lastColumn, columnTotal); sheet.getCell(totalRow, lastColumn).font = { bold: true }; + paintHeader(sheet, totalRow, 1, lastColumn); + } + + const gridBorder = { + top: { style: 'thin' }, + left: { style: 'thin' }, + bottom: { style: 'thin' }, + right: { style: 'thin' }, + }; + const lastRow = rows.length ? rows.length + 4 : 3; + for (let row = 2; row <= lastRow; row += 1) { + for (let column = 1; column <= lastColumn; column += 1) { + sheet.getCell(row, column).border = gridBorder; + } } for (let column = 1; column <= lastColumn; column += 1) {
{label}{label}{dayLabel(day)}{dayLabel(day)}RBM/ZBM wise TotalRBM/ZBM wise Total
LinkTimeLinkTime
Total{rows.reduce((sum, row) => sum + Number(row.total || 0), 0)}Total{rows.reduce((sum, row) => sum + Number(row.total || 0), 0)}