added formatted in horizon reports
This commit is contained in:
parent
e990ae27bb
commit
6755ce3084
|
|
@ -6,6 +6,7 @@ import PageMetaData from '@/components/PageMetaData';
|
||||||
import { exportFieldWorkReport } from './exportXlsx';
|
import { exportFieldWorkReport } from './exportXlsx';
|
||||||
|
|
||||||
const TITLE = 'Monthly Field Work Report';
|
const TITLE = 'Monthly Field Work Report';
|
||||||
|
const HEADER_COLOR = '#95B3D7';
|
||||||
const REPORT_TIMEOUT = 120000;
|
const REPORT_TIMEOUT = 120000;
|
||||||
const FIRST_MONTH = new Date(2026, 10, 1);
|
const FIRST_MONTH = new Date(2026, 10, 1);
|
||||||
const IDENTITY = [
|
const IDENTITY = [
|
||||||
|
|
@ -163,22 +164,29 @@ export default function HorizonFieldWorkReport() {
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
<div className="table-responsive" style={{ maxHeight: '70vh' }}>
|
<div className="table-responsive" style={{ maxHeight: '70vh' }}>
|
||||||
<table className="table table-bordered table-sm mb-0 text-nowrap">
|
<style>{`
|
||||||
|
.horizon-field-grid,
|
||||||
|
.horizon-field-grid th,
|
||||||
|
.horizon-field-grid td {
|
||||||
|
border: 1px solid #000;
|
||||||
|
}
|
||||||
|
`}</style>
|
||||||
|
<table className="table table-bordered table-sm mb-0 text-nowrap horizon-field-grid">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{IDENTITY.map((label) => (
|
{IDENTITY.map((label) => (
|
||||||
<th key={label} rowSpan={2} className="align-middle text-center">{label}</th>
|
<th key={label} rowSpan={2} className="align-middle text-center" style={{ backgroundColor: HEADER_COLOR }}>{label}</th>
|
||||||
))}
|
))}
|
||||||
{days.map((day) => (
|
{days.map((day) => (
|
||||||
<th key={day} colSpan={2} className="text-center">{dayLabel(day)}</th>
|
<th key={day} colSpan={2} className="text-center" style={{ backgroundColor: HEADER_COLOR }}>{dayLabel(day)}</th>
|
||||||
))}
|
))}
|
||||||
<th rowSpan={2} className="align-middle text-center">RBM/ZBM wise Total</th>
|
<th rowSpan={2} className="align-middle text-center" style={{ backgroundColor: HEADER_COLOR }}>RBM/ZBM wise Total</th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
{days.map((day) => (
|
{days.map((day) => (
|
||||||
<Fragment key={day}>
|
<Fragment key={day}>
|
||||||
<th className="text-center">Link</th>
|
<th className="text-center" style={{ backgroundColor: HEADER_COLOR }}>Link</th>
|
||||||
<th className="text-center">Time</th>
|
<th className="text-center" style={{ backgroundColor: HEADER_COLOR }}>Time</th>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
))}
|
))}
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -216,8 +224,8 @@ export default function HorizonFieldWorkReport() {
|
||||||
)) : null}
|
)) : null}
|
||||||
{rows.length ? (
|
{rows.length ? (
|
||||||
<tr className="fw-semibold">
|
<tr className="fw-semibold">
|
||||||
<td colSpan={IDENTITY.length + days.length * 2}>Total</td>
|
<td colSpan={IDENTITY.length + days.length * 2} style={{ backgroundColor: HEADER_COLOR }}>Total</td>
|
||||||
<td className="text-center">{rows.reduce((sum, row) => sum + Number(row.total || 0), 0)}</td>
|
<td className="text-center" style={{ backgroundColor: HEADER_COLOR }}>{rows.reduce((sum, row) => sum + Number(row.total || 0), 0)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
) : (
|
) : (
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,12 @@ function dayLabel(iso) {
|
||||||
return `${day}-${month}-${year}`;
|
return `${day}-${month}-${year}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HEADER_FILL = {
|
||||||
|
type: 'pattern',
|
||||||
|
pattern: 'solid',
|
||||||
|
fgColor: { argb: 'FF95B3D7' },
|
||||||
|
};
|
||||||
|
|
||||||
function textCell(sheet, row, column, value) {
|
function textCell(sheet, row, column, value) {
|
||||||
const cell = sheet.getCell(row, column);
|
const cell = sheet.getCell(row, column);
|
||||||
cell.value = value === null || value === undefined ? '' : String(value);
|
cell.value = value === null || value === undefined ? '' : String(value);
|
||||||
|
|
@ -21,6 +27,27 @@ function textCell(sheet, row, column, value) {
|
||||||
return cell;
|
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) {
|
export async function exportFieldWorkReport(report, filename) {
|
||||||
const { default: ExcelJS } = await import('exceljs');
|
const { default: ExcelJS } = await import('exceljs');
|
||||||
const workbook = new ExcelJS.Workbook();
|
const workbook = new ExcelJS.Workbook();
|
||||||
|
|
@ -38,21 +65,22 @@ export async function exportFieldWorkReport(report, filename) {
|
||||||
const column = index + 1;
|
const column = index + 1;
|
||||||
textCell(sheet, 2, column, label);
|
textCell(sheet, 2, column, label);
|
||||||
sheet.mergeCells(2, column, 3, column);
|
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) => {
|
days.forEach((day, index) => {
|
||||||
const column = identityCount + index * 2 + 1;
|
const column = identityCount + index * 2 + 1;
|
||||||
textCell(sheet, 2, column, dayLabel(day));
|
textCell(sheet, 2, column, dayLabel(day));
|
||||||
sheet.mergeCells(2, column, 2, column + 1);
|
sheet.mergeCells(2, column, 2, column + 1);
|
||||||
sheet.getCell(2, column).font = { bold: true };
|
|
||||||
textCell(sheet, 3, column, 'Link');
|
textCell(sheet, 3, column, 'Link');
|
||||||
textCell(sheet, 3, column + 1, 'Time');
|
textCell(sheet, 3, column + 1, 'Time');
|
||||||
sheet.getCell(3, column).font = { bold: true };
|
paintHeader(sheet, 2, column, column + 1);
|
||||||
sheet.getCell(3, column + 1).font = { bold: true };
|
paintHeader(sheet, 3, column, column + 1);
|
||||||
});
|
});
|
||||||
textCell(sheet, 2, lastColumn, 'RBM/ZBM wise Total');
|
textCell(sheet, 2, lastColumn, 'RBM/ZBM wise Total');
|
||||||
sheet.mergeCells(2, lastColumn, 3, lastColumn);
|
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) => {
|
rows.forEach((row, rowIndex) => {
|
||||||
const excelRow = rowIndex + 4;
|
const excelRow = rowIndex + 4;
|
||||||
|
|
@ -67,7 +95,9 @@ export async function exportFieldWorkReport(report, filename) {
|
||||||
row.manager_2_name,
|
row.manager_2_name,
|
||||||
];
|
];
|
||||||
values.forEach((value, index) => {
|
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) {
|
if (index === 0 || index === 2 || index === 3 || index === 5 || index === 7) {
|
||||||
cell.alignment = { vertical: 'middle', horizontal: 'left' };
|
cell.alignment = { vertical: 'middle', horizontal: 'left' };
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +119,7 @@ export async function exportFieldWorkReport(report, filename) {
|
||||||
textCell(sheet, excelRow, column, '');
|
textCell(sheet, excelRow, column, '');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
textCell(sheet, excelRow, lastColumn, row.total ?? 0);
|
numberCell(sheet, excelRow, lastColumn, row.total ?? 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (rows.length) {
|
if (rows.length) {
|
||||||
|
|
@ -98,8 +128,22 @@ export async function exportFieldWorkReport(report, filename) {
|
||||||
textCell(sheet, totalRow, 1, 'Total');
|
textCell(sheet, totalRow, 1, 'Total');
|
||||||
sheet.getCell(totalRow, 1).font = { bold: true };
|
sheet.getCell(totalRow, 1).font = { bold: true };
|
||||||
sheet.getCell(totalRow, 1).alignment = { vertical: 'middle', horizontal: 'left' };
|
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 };
|
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) {
|
for (let column = 1; column <= lastColumn; column += 1) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue