Skip to content

Commit abf1e79

Browse files
committed
fix: simplify contractor settlement PDF
1 parent 1678a27 commit abf1e79

2 files changed

Lines changed: 29 additions & 35 deletions

File tree

apps/backend/src/services/contractorPayments/__tests__/service.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'node:test';
22
import assert from 'node:assert/strict';
33

44
import { computePayablePreview, resolveRow, resolveConeTypeId, recomputeSettlementTotals, diffSettlementProduction } from '../service.js';
5-
import { groupLines } from '../../../utils/pdf/contractorSettlementPdf.js';
5+
import { generateContractorSettlementPdf, groupLines } from '../../../utils/pdf/contractorSettlementPdf.js';
66

77
// Minimal Prisma stub — computePayablePreview only reads (findMany) and does no
88
// writes, so a plain in-memory stub is sufficient (no DB required).
@@ -362,6 +362,30 @@ test('PDF groupLines splits a quality group by rate version', () => {
362362
}
363363
});
364364

365+
test('contractor settlement PDF is summary-only', async () => {
366+
const pdf = await generateContractorSettlementPdf({
367+
contractor: { name: 'Birendra bhai', phone: '9999999999' },
368+
process: 'coning',
369+
periodFrom: '2026-03-05',
370+
periodTo: '2026-03-06',
371+
status: 'paid',
372+
paymentDate: '2026-03-07',
373+
paymentMode: 'Cash',
374+
productionAmount: 125,
375+
adjustmentsTotal: 0,
376+
finalPayable: 125,
377+
lines: [{
378+
itemId: null, yarnId: 'Y1', yarnName: '40s', cutId: 'C1', cutName: '40',
379+
twistId: 'T1', twistName: 'TW', side: 'SINGLE', coneTypeId: 'CT1', coneTypeName: 'Big',
380+
ratePerKg: 10, netKg: 12.5, amount: 125, date: '2026-03-05', barcode: 'B1',
381+
}],
382+
adjustments: [],
383+
});
384+
assert.ok(pdf.length > 0);
385+
assert.equal(pdf.includes('Quality & Side Breakdown'), true);
386+
assert.equal(pdf.includes('Production Rows'), false);
387+
});
388+
365389
test('diffSettlementProduction flags no drift on an unchanged snapshot', () => {
366390
const stored = [{ sourceRowId: 'r1', netKg: 10, ratePerKg: 8, amount: 80, barcode: 'B1' }];
367391
const current = [{ sourceRowId: 'r1', netKg: 10, ratePerKg: 8, amount: 80 }];

apps/backend/src/utils/pdf/contractorSettlementPdf.js

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Contractor Settlement PDF
3-
* Contractor/process/period, quality & Side breakdown, row details,
4-
* adjustments, final payable, and payment reference.
3+
* Contractor/process/period, quality & Side summary, adjustments,
4+
* final payable, and payment reference.
55
*/
66

77
import { getJsPDF, formatDateDDMMYYYY, formatWeight, drawHeader, drawTable, drawFooter } from './pdfHelpers.js';
@@ -71,7 +71,7 @@ export async function generateContractorSettlementPdf(settlement) {
7171
const adjustments = Array.isArray(settlement.adjustments) ? settlement.adjustments : [];
7272

7373
let y = drawHeader(doc, {
74-
title: `Contractor Settlement ${titleCase(process)}`,
74+
title: `Contractor Settlement - ${titleCase(process)}`,
7575
date: settlement.paymentDate || settlement.periodTo,
7676
pageWidth,
7777
});
@@ -94,7 +94,7 @@ export async function generateContractorSettlementPdf(settlement) {
9494
});
9595
y += Math.ceil(info.length / 2) * 6 + 4;
9696

97-
// --- Quality & Side breakdown --------------------------------------------
97+
// --- Quality & Side summary ----------------------------------------------
9898
const groups = groupLines(process, lines);
9999
if (groups.length) {
100100
const showSide = process === 'coning';
@@ -144,36 +144,6 @@ export async function generateContractorSettlementPdf(settlement) {
144144
y = drawTable(doc, { y, title: 'Quality & Side Breakdown', headers, rows, colWidths, pageWidth });
145145
}
146146

147-
// --- Row detail -----------------------------------------------------------
148-
if (lines.length) {
149-
const showSide = process === 'coning';
150-
const headers = [
151-
{ text: 'Date', align: 'left' },
152-
{ text: 'Barcode / Lot', align: 'left', wrap: true },
153-
{ text: 'Quality', align: 'left', wrap: true },
154-
...(showSide ? [{ text: 'Side', align: 'center' }] : []),
155-
{ text: 'Net KG', align: 'right' },
156-
{ text: 'Rate', align: 'right' },
157-
{ text: 'Amount', align: 'right' },
158-
];
159-
const colWidths = showSide ? [22, 34, 40, 14, 24, 22, 24] : [24, 40, 46, 26, 22, 22];
160-
const rows = lines.map((l) => {
161-
const cells = [
162-
{ text: formatDateDDMMYYYY(l.date) },
163-
{ text: l.barcode || l.lotNo || '—' },
164-
{ text: [qualityLabel(process, l), l.cutName].filter(Boolean).join(' · ') || '—' },
165-
];
166-
if (showSide) cells.push({ text: sideLabel(l.side), align: 'center' });
167-
cells.push(
168-
{ text: formatWeight(l.netKg), align: 'right' },
169-
{ text: money(l.ratePerKg), align: 'right' },
170-
{ text: money(l.amount), align: 'right' },
171-
);
172-
return { cells };
173-
});
174-
y = drawTable(doc, { y, title: 'Production Rows', headers, rows, colWidths, pageWidth });
175-
}
176-
177147
// --- Adjustments ----------------------------------------------------------
178148
if (adjustments.length) {
179149
const headers = [

0 commit comments

Comments
 (0)