shareneus 1.7.4 → 1.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/accounting/invoice/invoice-pdf/invoice-pdf.service.js +18 -45
- package/dist/accounting/invoice/reports/excel/analysis-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/category-wise-item-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/cust-wise-sales-details.js +17 -7
- package/dist/accounting/invoice/reports/excel/cust-wise-sales-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/invoice-wise-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/item-wise-doctor-sale-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/items-wise-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/manf-wise-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/operator-wise-details.js +17 -7
- package/dist/accounting/invoice/reports/excel/operator-wise-summary.js +17 -7
- package/dist/accounting/invoice/reports/excel/sa-wise-labor-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/sa-wise-part-sales-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/sale-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/sales-by-service-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/scheduled-drug-summary-excel.service.js +17 -7
- package/dist/accounting/invoice/reports/excel/scheduled-drugs-excel.service.js +17 -7
- package/dist/accounting/invoice/unified-invoice-pdf.service.d.ts +1 -1
- package/dist/accounting/payment-receive/reports/excel/cust-balance-excel.service.js +17 -7
- package/dist/accounting/payment-receive/reports/excel/payment-receive-excel.service.js +17 -7
- package/dist/common/reports/excel/product-without-owner-excel.service.js +17 -7
- package/dist/gst/excel/GSTR-RO-excel.service.js +17 -7
- package/dist/gst/excel/GSTR1-excel.service.js +17 -7
- package/dist/gst/excel/GSTR2-excel.service.js +17 -7
- package/dist/gst/excel/hsn-summary.js +17 -7
- package/dist/gst/excel/tally-sales-import.service.js +17 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -6
- package/dist/inventory/items/reports/excel/expiring-drugs-excel.service.js +17 -7
- package/dist/inventory/items/reports/excel/item-wise-mout-details.js +17 -7
- package/dist/inventory/items/reports/excel/item-wise-mout-summary.js +17 -7
- package/dist/inventory/items/reports/excel/spares-issue-excel.service.js +17 -7
- package/dist/inventory/items/reports/excel/stock-excel.service.js +17 -7
- package/dist/purchases/payment-made/reports/excel/payments-made-excel.service.js +17 -7
- package/dist/purchases/payment-made/reports/excel/ven-balance-excel.service.js +17 -7
- package/dist/services/reports/excel/insurance-expire-excel.service.js +17 -7
- package/dist/services/reports/excel/next-service-date-excel.service.js +17 -7
- package/dist/services/reports/excel/repair-orders-excel.service.js +17 -7
- package/dist/shared/table-section/pdf-table.header.d.ts +1 -1
- package/dist/shared/table-section/pdf-table.header.js +14 -2
- package/dist/shared/table-section/pdf-table.section.js +6 -13
- package/dist/{accounting/invoice/invoice-pdf.service.js → shared/transactions-pdf.service.js} +15 -15
- package/package.json +1 -1
- package/src/accounting/counter-sales/auto-sales-receipt-pdf.service.ts +569 -0
- package/src/accounting/counter-sales/pos-receipt-pdf.ts +577 -0
- package/src/accounting/counter-sales/sales-receipt-pdf.service.ts +628 -0
- package/src/accounting/counter-sales/sales-receipt-print.service.ts +506 -0
- package/src/accounting/credit-note/cn-print.service.ts +264 -0
- package/src/accounting/credit-note/credit-note-pdf.service.ts +602 -0
- package/src/accounting/credit-note/credit-note-totals.service.ts +424 -0
- package/src/accounting/debit-note/debit-note-pdf.service.ts +681 -0
- package/src/accounting/debit-note/debit-note-print.service.ts +276 -0
- package/src/accounting/debit-note/debit-note-totals.service.ts +361 -0
- package/src/accounting/invoice/hc-inv-pdf.service.ts +880 -0
- package/src/accounting/invoice/inv-pdf.service.ts +812 -0
- package/src/accounting/invoice/inv-print.service.ts +532 -0
- package/src/accounting/invoice/invoice-landscape-pdf.service.ts +947 -0
- package/src/accounting/invoice/invoice-letterhead-pdf.service.ts +813 -0
- package/src/accounting/invoice/invoice-pdf/invoice-pdf.service.ts +359 -0
- package/src/accounting/invoice/invoice-portrait-pdf.ts +972 -0
- package/src/accounting/invoice/invoice-print.service.ts +2906 -0
- package/src/accounting/invoice/invoice-total.service.ts +834 -0
- package/src/accounting/invoice/reports/excel/analysis-excel.service.ts +291 -0
- package/src/accounting/invoice/reports/excel/category-wise-item-excel.service.ts +267 -0
- package/src/accounting/invoice/reports/excel/cust-wise-sales-details.ts +321 -0
- package/src/accounting/invoice/reports/excel/cust-wise-sales-summary-excel.service.ts +300 -0
- package/src/accounting/invoice/reports/excel/invoice-wise-excel.service.ts +859 -0
- package/src/accounting/invoice/reports/excel/item-wise-doctor-sale-excel.service.ts +255 -0
- package/src/accounting/invoice/reports/excel/items-wise-sales-excel.service.ts +312 -0
- package/src/accounting/invoice/reports/excel/manf-wise-sales-excel.service.ts +273 -0
- package/src/accounting/invoice/reports/excel/operator-wise-details.ts +258 -0
- package/src/accounting/invoice/reports/excel/operator-wise-summary.ts +259 -0
- package/src/accounting/invoice/reports/excel/sa-wise-labor-sales-excel.service.ts +230 -0
- package/src/accounting/invoice/reports/excel/sa-wise-part-sales-excel.service.ts +231 -0
- package/src/accounting/invoice/reports/excel/sale-summary-excel.service.ts +326 -0
- package/src/accounting/invoice/reports/excel/sales-by-service-details-excel.service.ts +0 -0
- package/src/accounting/invoice/reports/excel/sales-by-service-summary-excel.service.ts +432 -0
- package/src/accounting/invoice/reports/excel/scheduled-drug-summary-excel.service.ts +373 -0
- package/src/accounting/invoice/reports/excel/scheduled-drugs-excel.service.ts +372 -0
- package/src/accounting/invoice/reports/pdf/analysis-pdf.service.ts +113 -0
- package/src/accounting/invoice/reports/pdf/category-wise-item-pdf.service.ts +107 -0
- package/src/accounting/invoice/reports/pdf/cust-wise-sales-details-pdf.service.ts +125 -0
- package/src/accounting/invoice/reports/pdf/cust-wise-sales-summary-pdf.service.ts +119 -0
- package/src/accounting/invoice/reports/pdf/item-wise-doctor-sale-pdf.service.ts +180 -0
- package/src/accounting/invoice/reports/pdf/item-wise-sales-pdf.service.ts +193 -0
- package/src/accounting/invoice/reports/pdf/manf-wise-sales-pdf.service.ts +188 -0
- package/src/accounting/invoice/reports/pdf/operator-wise-details-pdf.service.ts +118 -0
- package/src/accounting/invoice/reports/pdf/operator-wise-summary-pdf.ts +116 -0
- package/src/accounting/invoice/reports/pdf/sales-by-service-pdf.service.ts +132 -0
- package/src/accounting/invoice/reports/pdf/scheduled-drug-pdf.service.ts +191 -0
- package/src/accounting/invoice/reports/pdf/scheduled-drug-summary-pdf.service.ts +202 -0
- package/src/accounting/invoice/shared-inv-pdf.service.ts +787 -0
- package/src/accounting/invoice/unified-invoice-pdf.service.ts +937 -0
- package/src/accounting/payment-receive/payment-pdf.service.ts +410 -0
- package/src/accounting/payment-receive/payment-receipt-pdf/receipt-pdf.service.ts +470 -0
- package/src/accounting/payment-receive/receipt-print.service.ts +71 -0
- package/src/accounting/payment-receive/reports/excel/cust-balance-excel.service.ts +298 -0
- package/src/accounting/payment-receive/reports/excel/payment-receive-excel.service.ts +221 -0
- package/src/accounting/payment-receive/reports/pdf/customer-balances-pdf.service.ts +182 -0
- package/src/accounting/payment-receive/reports/pdf/payment-report-pdf.service.ts +116 -0
- package/src/aggregation/aggregation.ts +58 -0
- package/src/appointments/appointments/appointment-total.service.ts +298 -0
- package/src/appointments/consultations/consultation-fee-receipt.service.ts +407 -0
- package/src/appointments/consultations/consultation-full-pdf.service.ts +238 -0
- package/src/appointments/consultations/consultation-letterhead-pdf.service.ts +430 -0
- package/src/appointments/consultations/consultation-pdf.service.ts +417 -0
- package/src/common/reports/excel/product-without-owner-excel.service.ts +308 -0
- package/src/common/reports/pdf/product-without-owner-pdf.service.ts +146 -0
- package/src/enums/cache-enums.ts +33 -0
- package/src/enums/code-enums.ts +291 -0
- package/src/enums/country-enums.ts +9 -0
- package/src/enums/enums.ts +364 -0
- package/src/enums/industry-enums.ts +26 -0
- package/src/enums/treatment-enums.ts +9 -0
- package/src/gst/excel/GSTR-RO-excel.service.ts +926 -0
- package/src/gst/excel/GSTR1-excel.service.ts +313 -0
- package/src/gst/excel/GSTR2-excel.service.ts +314 -0
- package/src/gst/excel/hsn-summary.ts +314 -0
- package/src/gst/excel/tally-sales-import.service.ts +767 -0
- package/src/gst/pdf/hsn-summary-pdf.ts +176 -0
- package/src/index.ts +194 -0
- package/src/inventory/items/adjustment-pdf.service.ts +177 -0
- package/src/inventory/items/issue-parts-pdf.service.ts +795 -0
- package/src/inventory/items/item-bar-code-label-pdf.ts +194 -0
- package/src/inventory/items/item-detais-pdf.ts +141 -0
- package/src/inventory/items/item-price-for-pricelist.ts +368 -0
- package/src/inventory/items/reports/excel/expiring-drugs-excel.service.ts +290 -0
- package/src/inventory/items/reports/excel/item-wise-mout-details.ts +284 -0
- package/src/inventory/items/reports/excel/item-wise-mout-summary.ts +279 -0
- package/src/inventory/items/reports/excel/spares-issue-excel.service.ts +494 -0
- package/src/inventory/items/reports/excel/stock-excel.service.ts +319 -0
- package/src/inventory/items/reports/pdf/expiring-drugs-pdf.service.ts +172 -0
- package/src/inventory/items/reports/pdf/item-wise-mout-details-pdf.ts +122 -0
- package/src/inventory/items/reports/pdf/item-wise-mout-summary-pdf.ts +115 -0
- package/src/inventory/items/reports/pdf/reorder-point-pdf.service.ts +163 -0
- package/src/inventory/material-out/mout-pdf.service.ts +545 -0
- package/src/inventory/transfer-order/transfer-order-pdf.service.ts +154 -0
- package/src/purchases/bills/bill-pdf/bill-pdf.service.ts +211 -0
- package/src/purchases/bills/bill-pdf.service.ts +21 -0
- package/src/purchases/payment-made/reports/excel/payments-made-excel.service.ts +313 -0
- package/src/purchases/payment-made/reports/excel/ven-balance-excel.service.ts +307 -0
- package/src/purchases/payment-made/reports/pdf/vendor-balances-pdf.service.ts +114 -0
- package/src/purchases/purchase-order/po-totals.service.ts +343 -0
- package/src/purchases/purchase-order/purchase-order-pdf.service.ts +1016 -0
- package/src/purchases/purchase-order/purchase-order-print.service.ts +279 -0
- package/src/purchases/purchase-order/purchase-order-totals.service.ts +637 -0
- package/src/purchases/vendor-credit-note/vendor-credit-note-pdf.service.ts +1055 -0
- package/src/purchases/vendor-credit-note/vendor-credit-note-print.service.ts +145 -0
- package/src/purchases/vendor-credit-note/vendor-credit-note-totals.service.ts +399 -0
- package/src/purchases/vendor-debit-note/vendor-debit-note-pdf.service.ts +582 -0
- package/src/purchases/vendor-debit-note/vendor-debit-note-print.service.ts +295 -0
- package/src/purchases/vendor-debit-note/vendor-debit-note-totals.service.ts +377 -0
- package/src/sales/delivery-challan/dc-landscape-pdf.service.ts +922 -0
- package/src/sales/delivery-challan/dc-landscape-without-price-pdf.service.ts +869 -0
- package/src/sales/delivery-challan/dc-without-price-pdf.service.ts +505 -0
- package/src/sales/delivery-challan/delivery-challan-pdf.service.ts +461 -0
- package/src/sales/delivery-challan/delivery-challan-print.service.ts +229 -0
- package/src/sales/delivery-challan/delivery-challan-totals.ts +466 -0
- package/src/sales/sales/equipment-design-pdf.service.ts +153 -0
- package/src/sales/sales/pack-ship-pdf.service.ts +128 -0
- package/src/sales/sales/pack-ship-print.service.ts +198 -0
- package/src/sales/sales/sales-pdf.service.ts +658 -0
- package/src/sales/sales/sales-print.service.ts +376 -0
- package/src/sales/sales/sales-totals.service.ts +500 -0
- package/src/sales-receive/sales-receive-pdf.service.ts +602 -0
- package/src/sales-receive/sales-receive-print.service.ts +242 -0
- package/src/sales-receive/sales-receive-totals.service.ts +651 -0
- package/src/services/checklist-pdf.ts +151 -0
- package/src/services/checklists-pdf.ts +133 -0
- package/src/services/est.print-service.ts +1155 -0
- package/src/services/reports/excel/insurance-expire-excel.service.ts +292 -0
- package/src/services/reports/excel/next-service-date-excel.service.ts +317 -0
- package/src/services/reports/excel/repair-orders-excel.service.ts +249 -0
- package/src/services/reports/pdf/insurance-expire-pdf.service.ts +115 -0
- package/src/services/reports/pdf/next-service-date-pdf.service.ts +198 -0
- package/src/services/reports/pdf/repair-orders-pdf.service.ts +184 -0
- package/src/services/ro-pdf.service.ts +1917 -0
- package/src/services/ro-print-service.ts +881 -0
- package/src/services/ro-totals.service.ts +1314 -0
- package/src/services/separate-wo-print.service.ts +396 -0
- package/src/services/service-history-pdf.service.ts +145 -0
- package/src/services/service-price-for-pricelist.ts +649 -0
- package/src/services/technician-pdf.service.ts +234 -0
- package/src/services/technician-print.service.ts +95 -0
- package/src/shared/header-footer-section/pdf-header-footer.section.ts +519 -0
- package/src/shared/header-footer-section/pdf-shared.utils.ts +46 -0
- package/src/shared/math-operations.ts +208 -0
- package/src/shared/party-details-section/pdf-party-details.section.ts +602 -0
- package/src/shared/shared-pdf.service.ts +3042 -0
- package/src/shared/shared-print.service.ts +879 -0
- package/src/shared/table-section/pdf-table.config.ts +8 -0
- package/src/shared/table-section/pdf-table.header.ts +396 -0
- package/src/shared/table-section/pdf-table.row.ts +248 -0
- package/src/shared/table-section/pdf-table.section.ts +447 -0
- package/src/shared/totals-section/pdf-totals.section.ts +921 -0
- package/src/shared/transactions-pdf.service.ts +191 -0
- package/src/shared/util.ts +101 -0
- package/src/tasks/meetings/meeting-pdf.ts +410 -0
- package/src/tasks/tasks/task-pdf.service.ts +238 -0
- package/src/tasks/tasks/task-reports-pdf.service.ts +313 -0
- package/src/tax/index.ts +86 -0
- package/src/tax/tax-calculator.ts +1025 -0
- package/src/tax/tax.types.ts +535 -0
- package/src/transaction-calculations/discounts-distribution.ts +343 -0
- package/src/transaction-calculations/index.ts +3 -0
- package/src/transaction-calculations/total-calculation.ts +443 -0
- package/src/transaction-calculations/transaction-calculation-engine.ts +903 -0
- package/src/utils/my-date.ts +111 -0
- package/src/utils/tr-utils.ts +104 -0
- package/tsconfig.json +2 -2
- /package/dist/{accounting/invoice/invoice-pdf.service.d.ts → shared/transactions-pdf.service.d.ts} +0 -0
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
import { Multiply } from '../math-operations';
|
|
2
|
+
import { pdfTableStyleConfig } from './pdf-table.config';
|
|
3
|
+
import { buildHeaderRows, GetTableHeader, getRenderableColumns } from './pdf-table.header';
|
|
4
|
+
import { buildDataRow, getCellAlignment, getFirstFieldValue, getNumericAlignment } from './pdf-table.row';
|
|
5
|
+
|
|
6
|
+
const CELL_PADDING_LEFT = 4;
|
|
7
|
+
const CELL_PADDING_RIGHT = 4;
|
|
8
|
+
const BORDER_WIDTH = 0.5;
|
|
9
|
+
|
|
10
|
+
export function buildInvoiceTableData(PDFInvoiceData: any, PrintConfig: any, availableWidth: number) {
|
|
11
|
+
const items = Array.isArray(PDFInvoiceData?.Items) ? PDFInvoiceData.Items : [];
|
|
12
|
+
const services = Array.isArray(PDFInvoiceData?.Ops) ? PDFInvoiceData.Ops : [];
|
|
13
|
+
const sType = PDFInvoiceData?.SType ?? '';
|
|
14
|
+
const taxMode = resolveInvoiceTaxMode(PDFInvoiceData);
|
|
15
|
+
const showSectionSummaryRows = !resolveIsPoSPrint(PrintConfig);
|
|
16
|
+
const headerConfig = GetTableHeader(PrintConfig.TableConfig, taxMode)[0];
|
|
17
|
+
const renderColumns = getRenderableColumns(headerConfig, sType);
|
|
18
|
+
const headerRows = buildHeaderRows(headerConfig, sType);
|
|
19
|
+
const fixedTo = resolveFixedTo(PrintConfig?.fixedTo);
|
|
20
|
+
|
|
21
|
+
let body;
|
|
22
|
+
let widths: number[];
|
|
23
|
+
if (renderColumns.length === 0) {
|
|
24
|
+
const fallbackHeaderRow = headerRows[0];
|
|
25
|
+
const descriptionColumnIndex = getDescriptionColumnIndexFromHeaders(fallbackHeaderRow);
|
|
26
|
+
const itemTotals = calculateSectionTotals(items);
|
|
27
|
+
const serviceTotals = calculateSectionTotals(services);
|
|
28
|
+
const itemSectionRows = items.length > 0
|
|
29
|
+
? buildSectionRows({
|
|
30
|
+
rows: items,
|
|
31
|
+
columnsOrHeaders: fallbackHeaderRow,
|
|
32
|
+
descriptionColumnIndex,
|
|
33
|
+
label: 'Items',
|
|
34
|
+
buildRow: (item: any, index: number) => buildFallbackDataRow(item, index, fallbackHeaderRow, fixedTo),
|
|
35
|
+
buildTotalRow: () => buildFallbackSectionTotalRow(fallbackHeaderRow, 'Items Total', itemTotals, fixedTo),
|
|
36
|
+
showSectionSummaryRows
|
|
37
|
+
})
|
|
38
|
+
: [];
|
|
39
|
+
const serviceSectionRows = services.length > 0
|
|
40
|
+
? buildSectionRows({
|
|
41
|
+
rows: services,
|
|
42
|
+
columnsOrHeaders: fallbackHeaderRow,
|
|
43
|
+
descriptionColumnIndex,
|
|
44
|
+
label: 'Services',
|
|
45
|
+
buildRow: (service: any, index: number) => buildFallbackDataRow(service, index, fallbackHeaderRow, fixedTo),
|
|
46
|
+
buildTotalRow: () => buildFallbackSectionTotalRow(fallbackHeaderRow, 'Services Total', serviceTotals, fixedTo),
|
|
47
|
+
showSectionSummaryRows
|
|
48
|
+
})
|
|
49
|
+
: [];
|
|
50
|
+
body = [
|
|
51
|
+
fallbackHeaderRow,
|
|
52
|
+
...itemSectionRows,
|
|
53
|
+
...serviceSectionRows
|
|
54
|
+
];
|
|
55
|
+
widths = fitWidthsToPage(fallbackHeaderRow.map((col: any) => col?.width), availableWidth, fallbackHeaderRow.length);
|
|
56
|
+
} else {
|
|
57
|
+
const descriptionColumnIndex = getDescriptionColumnIndexFromColumns(renderColumns);
|
|
58
|
+
const itemTotals = calculateSectionTotals(items);
|
|
59
|
+
const serviceTotals = calculateSectionTotals(services);
|
|
60
|
+
const itemSectionRows = items.length > 0
|
|
61
|
+
? buildSectionRows({
|
|
62
|
+
rows: items,
|
|
63
|
+
columnsOrHeaders: renderColumns,
|
|
64
|
+
descriptionColumnIndex,
|
|
65
|
+
label: 'Items',
|
|
66
|
+
buildRow: (item: any, index: number) => buildDataRow(item, index, renderColumns, fixedTo),
|
|
67
|
+
buildTotalRow: () => buildSectionTotalRow(renderColumns, 'Items Total', itemTotals, fixedTo),
|
|
68
|
+
showSectionSummaryRows
|
|
69
|
+
})
|
|
70
|
+
: [];
|
|
71
|
+
const serviceSectionRows = services.length > 0
|
|
72
|
+
? buildSectionRows({
|
|
73
|
+
rows: services,
|
|
74
|
+
columnsOrHeaders: renderColumns,
|
|
75
|
+
descriptionColumnIndex,
|
|
76
|
+
label: 'Services',
|
|
77
|
+
buildRow: (service: any, index: number) => buildDataRow(service, index, renderColumns, fixedTo),
|
|
78
|
+
buildTotalRow: () => buildSectionTotalRow(renderColumns, 'Services Total', serviceTotals, fixedTo),
|
|
79
|
+
showSectionSummaryRows
|
|
80
|
+
})
|
|
81
|
+
: [];
|
|
82
|
+
body = [
|
|
83
|
+
...headerRows,
|
|
84
|
+
...itemSectionRows,
|
|
85
|
+
...serviceSectionRows
|
|
86
|
+
];
|
|
87
|
+
widths = fitWidthsToPage(renderColumns.map((col: any) => col?.width), availableWidth, renderColumns.length);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return { headerRows, widths, body };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function getAvailablePageWidth(
|
|
94
|
+
pageSize: 'A4' | 'LETTER' | 'LEGAL' | { width: number; height: number },
|
|
95
|
+
orientation: 'portrait' | 'landscape',
|
|
96
|
+
margins: [number, number, number, number]
|
|
97
|
+
) {
|
|
98
|
+
const pageWidths: Record<'A4' | 'LETTER' | 'LEGAL', { portrait: number; landscape: number }> = {
|
|
99
|
+
A4: { portrait: 595.28, landscape: 841.89 },
|
|
100
|
+
LETTER: { portrait: 612, landscape: 792 },
|
|
101
|
+
LEGAL: { portrait: 612, landscape: 1008 }
|
|
102
|
+
};
|
|
103
|
+
const fullWidth = typeof pageSize === 'object'
|
|
104
|
+
? (Number.isFinite(pageSize?.width) ? Number(pageSize.width) : pageWidths.A4[orientation])
|
|
105
|
+
: pageWidths[pageSize][orientation];
|
|
106
|
+
return Math.max(1, fullWidth - margins[0] - margins[2]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function calculateSectionTotals(rows: any[]) {
|
|
110
|
+
return rows.reduce((acc: any, row: any) => {
|
|
111
|
+
const sign = row?.Ret ? -1 : 1;
|
|
112
|
+
const quantity = row?.Qty == null ? 1 : readNumericValue(row, ['Qty']);
|
|
113
|
+
acc.qty += sign * quantity;
|
|
114
|
+
const taxableAmt: number = Number(Multiply(
|
|
115
|
+
quantity,
|
|
116
|
+
readNumericValue(row, ['UnPr', 'Pr', 'UnCo'])
|
|
117
|
+
));
|
|
118
|
+
acc.priceTotal += sign * (Number.isFinite(taxableAmt) ? taxableAmt : 0);
|
|
119
|
+
acc.discountAmount += sign * readNumericValue(row, ['Disc']);
|
|
120
|
+
acc.cgstAmount += sign * readNumericValue(row, ['CGSTAmt', 'CGST']);
|
|
121
|
+
acc.sgstAmount += sign * readNumericValue(row, ['SGSTAmt', 'SGST']);
|
|
122
|
+
acc.igstAmount += sign * readNumericValue(row, ['IGSTAmt', 'IGST']);
|
|
123
|
+
acc.lineTotal += sign * readNumericValue(row, ['LineTotal']);
|
|
124
|
+
return acc;
|
|
125
|
+
}, {
|
|
126
|
+
qty: 0,
|
|
127
|
+
priceTotal: 0,
|
|
128
|
+
discountAmount: 0,
|
|
129
|
+
cgstAmount: 0,
|
|
130
|
+
sgstAmount: 0,
|
|
131
|
+
igstAmount: 0,
|
|
132
|
+
lineTotal: 0
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function readNumericValue(row: any, fields: string[]) {
|
|
137
|
+
const value = getFirstFieldValue(row, fields);
|
|
138
|
+
if (!value) {
|
|
139
|
+
return 0;
|
|
140
|
+
}
|
|
141
|
+
const numeric = Number(String(value).replace(/,/g, ''));
|
|
142
|
+
return Number.isFinite(numeric) ? numeric : 0;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function formatAmount(value: number, fixedTo: number = 2) {
|
|
146
|
+
if (!Number.isFinite(value)) {
|
|
147
|
+
return '';
|
|
148
|
+
}
|
|
149
|
+
return value.toFixed(fixedTo);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function fitWidthsToPage(rawWidths: any[], availableWidth: number, columnCount: number) {
|
|
153
|
+
const tableOffsets = getTableHorizontalOffsets(columnCount);
|
|
154
|
+
const availableContentWidth = Math.max(1, availableWidth - tableOffsets);
|
|
155
|
+
const weights = rawWidths.map((width: any) => toWeight(width));
|
|
156
|
+
const totalWeight = weights.reduce((sum: number, weight: number) => sum + weight, 0) || 1;
|
|
157
|
+
const widths = weights.map((weight: number) => Number(((weight / totalWeight) * availableContentWidth).toFixed(2)));
|
|
158
|
+
|
|
159
|
+
const usedWidth = widths.reduce((sum: number, width: number) => sum + width, 0);
|
|
160
|
+
const diff = Number((availableContentWidth - usedWidth).toFixed(2));
|
|
161
|
+
if (widths.length > 0 && diff !== 0) {
|
|
162
|
+
widths[widths.length - 1] = Number((widths[widths.length - 1] + diff).toFixed(2));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return widths;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function toWeight(width: any) {
|
|
169
|
+
return typeof width === 'number' && Number.isFinite(width) && width > 0 ? width : 1;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function getTableHorizontalOffsets(columnCount: number) {
|
|
173
|
+
if (columnCount <= 0) {
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
const totalPadding = columnCount * (CELL_PADDING_LEFT + CELL_PADDING_RIGHT);
|
|
177
|
+
const totalBorders = (columnCount + 1) * BORDER_WIDTH;
|
|
178
|
+
return totalPadding + totalBorders;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function buildSectionLabelRow(columnCount: number, descriptionColumnIndex: number, label: string) {
|
|
182
|
+
const normalizedDescriptionIndex = descriptionColumnIndex >= 0 ? descriptionColumnIndex : 0;
|
|
183
|
+
return Array.from({ length: columnCount }, (_: unknown, index: number) => {
|
|
184
|
+
if (index === normalizedDescriptionIndex) {
|
|
185
|
+
return { text: label, bold: true, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor };
|
|
186
|
+
}
|
|
187
|
+
return { text: '', fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor };
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function getDescriptionColumnIndexFromColumns(columns: any[]) {
|
|
192
|
+
return columns.findIndex((column: any) => column.type === 'normal' && column.header?.text === 'Description');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function getDescriptionColumnIndexFromHeaders(headers: any[]) {
|
|
196
|
+
return headers.findIndex((header: any) => header.text === 'Description');
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function buildFallbackDataRow(item: any, index: number, fallbackHeaderRow: any[], fixedTo: number) {
|
|
200
|
+
return fallbackHeaderRow.map((header: any) => {
|
|
201
|
+
if (header.text === 'CGST') {
|
|
202
|
+
if (header.taxKind === 'rate') {
|
|
203
|
+
const value = getFirstFieldValue(item, ['CGSTPerc']);
|
|
204
|
+
const renderedValue = formatNumericLikeValue(value, fixedTo);
|
|
205
|
+
return { text: renderedValue, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(renderedValue) };
|
|
206
|
+
} else if (header.taxKind === 'amount') {
|
|
207
|
+
const value = getDisplayValueForFallbackRow(item, ['CGSTAmt'], true);
|
|
208
|
+
const renderedValue = formatNumericLikeValue(value, fixedTo);
|
|
209
|
+
return { text: renderedValue, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(renderedValue) };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (header.text === 'SGST') {
|
|
213
|
+
if (header.taxKind === 'rate') {
|
|
214
|
+
const value = getFirstFieldValue(item, ['SGSTPerc']);
|
|
215
|
+
const renderedValue = formatNumericLikeValue(value, fixedTo);
|
|
216
|
+
return { text: renderedValue, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(renderedValue) };
|
|
217
|
+
} else if (header.taxKind === 'amount') {
|
|
218
|
+
const value = getDisplayValueForFallbackRow(item, ['SGSTAmt'], true);
|
|
219
|
+
const renderedValue = formatNumericLikeValue(value, fixedTo);
|
|
220
|
+
return { text: renderedValue, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(renderedValue) };
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (header.text === 'IGST %') {
|
|
224
|
+
const value = getFirstFieldValue(item, ['IGSTPerc']);
|
|
225
|
+
const renderedValue = formatNumericLikeValue(value, fixedTo);
|
|
226
|
+
return { text: renderedValue, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(renderedValue) };
|
|
227
|
+
}
|
|
228
|
+
if (header.text === 'IGST Amt') {
|
|
229
|
+
const value = getDisplayValueForFallbackRow(item, ['IGSTAmt'], true);
|
|
230
|
+
const renderedValue = formatNumericLikeValue(value, fixedTo);
|
|
231
|
+
return { text: renderedValue, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(renderedValue) };
|
|
232
|
+
}
|
|
233
|
+
if (header.text === 'S.No') {
|
|
234
|
+
const value = String(index + 1);
|
|
235
|
+
return { text: value, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(value) };
|
|
236
|
+
}
|
|
237
|
+
const mainValue = formatNumericLikeValue(
|
|
238
|
+
getDisplayValueForFallbackRow(item, header.dbFields, shouldNegateFallbackHeaderValue(item, header.text)),
|
|
239
|
+
fixedTo
|
|
240
|
+
);
|
|
241
|
+
const stackedLines = (header.stackFields ?? [])
|
|
242
|
+
.map((stackField: any) => {
|
|
243
|
+
const stackValue = formatNumericLikeValue(getFirstFieldValue(item, stackField.dbFields), fixedTo);
|
|
244
|
+
if (!stackValue) {
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
return { text: `${stackField.text}: ${stackValue}`, fontSize: pdfTableStyleConfig.stackFieldFontSize, color: pdfTableStyleConfig.bodyFontColor, italics: true };
|
|
248
|
+
})
|
|
249
|
+
.filter((line: any) => !!line);
|
|
250
|
+
if (stackedLines.length === 0) {
|
|
251
|
+
return {
|
|
252
|
+
text: mainValue,
|
|
253
|
+
fontSize: pdfTableStyleConfig.bodyFontSize,
|
|
254
|
+
color: pdfTableStyleConfig.bodyFontColor,
|
|
255
|
+
alignment: getCellAlignment(header.text, mainValue)
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
stack: [
|
|
260
|
+
{ text: mainValue, fontSize: pdfTableStyleConfig.bodyFontSize, color: pdfTableStyleConfig.bodyFontColor },
|
|
261
|
+
...stackedLines
|
|
262
|
+
]
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function buildSectionTotalRow(columns: any[], label: string, totals: any, fixedTo: number) {
|
|
268
|
+
return columns.map((column: any) => {
|
|
269
|
+
if (column.type === 'tax') {
|
|
270
|
+
if (column.dbField === 'CGST' && column.taxKind === 'amount') {
|
|
271
|
+
return buildTotalValueCell(formatAmount(totals.cgstAmount, fixedTo));
|
|
272
|
+
}
|
|
273
|
+
if (column.dbField === 'SGST' && column.taxKind === 'amount') {
|
|
274
|
+
return buildTotalValueCell(formatAmount(totals.sgstAmount, fixedTo));
|
|
275
|
+
}
|
|
276
|
+
if (column.dbField === 'IGST' && column.taxKind === 'amount') {
|
|
277
|
+
return buildTotalValueCell(formatAmount(totals.igstAmount, fixedTo));
|
|
278
|
+
}
|
|
279
|
+
return buildTotalValueCell('');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const headerText = column.header?.text ?? '';
|
|
283
|
+
if (headerText === 'Description') {
|
|
284
|
+
return buildTotalLabelCell(label);
|
|
285
|
+
}
|
|
286
|
+
if (headerText === 'Qty') {
|
|
287
|
+
return buildTotalValueCell(formatQty(totals.qty), headerText);
|
|
288
|
+
}
|
|
289
|
+
if (headerText === 'Price') {
|
|
290
|
+
return buildTotalValueCell(formatAmount(totals.priceTotal, fixedTo));
|
|
291
|
+
}
|
|
292
|
+
if (isDiscountAmountHeader(headerText)) {
|
|
293
|
+
return buildTotalValueCell(formatAmount(totals.discountAmount, fixedTo));
|
|
294
|
+
}
|
|
295
|
+
if (headerText === 'Line Total') {
|
|
296
|
+
return buildTotalValueCell(formatAmount(totals.lineTotal, fixedTo));
|
|
297
|
+
}
|
|
298
|
+
return buildTotalValueCell('');
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function buildFallbackSectionTotalRow(fallbackHeaderRow: any[], label: string, totals: any, fixedTo: number) {
|
|
303
|
+
return fallbackHeaderRow.map((header: any) => {
|
|
304
|
+
if (header.text === 'CGST' && header.taxKind === 'amount') {
|
|
305
|
+
return buildTotalValueCell(formatAmount(totals.cgstAmount, fixedTo));
|
|
306
|
+
}
|
|
307
|
+
if (header.text === 'SGST' && header.taxKind === 'amount') {
|
|
308
|
+
return buildTotalValueCell(formatAmount(totals.sgstAmount, fixedTo));
|
|
309
|
+
}
|
|
310
|
+
if (header.text === 'IGST Amt') {
|
|
311
|
+
return buildTotalValueCell(formatAmount(totals.igstAmount, fixedTo));
|
|
312
|
+
}
|
|
313
|
+
if (header.text === 'Description') {
|
|
314
|
+
return buildTotalLabelCell(label);
|
|
315
|
+
}
|
|
316
|
+
if (header.text === 'Qty') {
|
|
317
|
+
return buildTotalValueCell(formatQty(totals.qty), header.text);
|
|
318
|
+
}
|
|
319
|
+
if (header.text === 'Price') {
|
|
320
|
+
return buildTotalValueCell(formatAmount(totals.priceTotal, fixedTo));
|
|
321
|
+
}
|
|
322
|
+
if (isDiscountAmountHeader(header.text)) {
|
|
323
|
+
return buildTotalValueCell(formatAmount(totals.discountAmount, fixedTo));
|
|
324
|
+
}
|
|
325
|
+
if (header.text === 'Line Total') {
|
|
326
|
+
return buildTotalValueCell(formatAmount(totals.lineTotal, fixedTo));
|
|
327
|
+
}
|
|
328
|
+
return buildTotalValueCell('');
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function buildTotalLabelCell(text: string) {
|
|
333
|
+
return {
|
|
334
|
+
text,
|
|
335
|
+
bold: true,
|
|
336
|
+
fontSize: pdfTableStyleConfig.bodyFontSize,
|
|
337
|
+
color: pdfTableStyleConfig.bodyFontColor
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function buildTotalValueCell(text: string, headerText: string = '') {
|
|
342
|
+
return {
|
|
343
|
+
text,
|
|
344
|
+
bold: true,
|
|
345
|
+
fontSize: pdfTableStyleConfig.bodyFontSize,
|
|
346
|
+
color: pdfTableStyleConfig.bodyFontColor,
|
|
347
|
+
alignment: headerText ? getCellAlignment(headerText, text) : getNumericAlignment(text)
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function formatQty(value: number) {
|
|
352
|
+
if (!Number.isFinite(value)) {
|
|
353
|
+
return '';
|
|
354
|
+
}
|
|
355
|
+
return Number.isInteger(value) ? String(value) : stripTrailingZeros(value.toFixed(2));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function stripTrailingZeros(value: string) {
|
|
359
|
+
return value.replace(/\.?0+$/, '');
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function isDiscountAmountHeader(text: string) {
|
|
363
|
+
return text === 'Disc Amount' || text === 'Adisc Amount';
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function resolveFixedTo(value: any) {
|
|
367
|
+
const parsed = Number(value);
|
|
368
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
369
|
+
return 2;
|
|
370
|
+
}
|
|
371
|
+
return Math.floor(parsed);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function resolveIsPoSPrint(printConfig: any) {
|
|
375
|
+
return Boolean(printConfig?.IsPoSPrint ?? printConfig?.isPoSPrint);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function resolveInvoiceTaxMode(pdfInvoiceData: any) {
|
|
379
|
+
return String(pdfInvoiceData?.Settings?.Tax ?? '').trim().toUpperCase();
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function buildSectionRows({
|
|
383
|
+
rows,
|
|
384
|
+
columnsOrHeaders,
|
|
385
|
+
descriptionColumnIndex,
|
|
386
|
+
label,
|
|
387
|
+
buildRow,
|
|
388
|
+
buildTotalRow,
|
|
389
|
+
showSectionSummaryRows
|
|
390
|
+
}: {
|
|
391
|
+
rows: any[];
|
|
392
|
+
columnsOrHeaders: any[];
|
|
393
|
+
descriptionColumnIndex: number;
|
|
394
|
+
label: string;
|
|
395
|
+
buildRow: (row: any, index: number) => any;
|
|
396
|
+
buildTotalRow: () => any;
|
|
397
|
+
showSectionSummaryRows: boolean;
|
|
398
|
+
}) {
|
|
399
|
+
const sectionRows = rows.map((row: any, index: number) => buildRow(row, index));
|
|
400
|
+
if (!showSectionSummaryRows) {
|
|
401
|
+
return sectionRows;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return [
|
|
405
|
+
buildSectionLabelRow(columnsOrHeaders.length, descriptionColumnIndex, label),
|
|
406
|
+
...sectionRows,
|
|
407
|
+
buildTotalRow()
|
|
408
|
+
];
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function shouldNegateFallbackHeaderValue(item: any, headerText: string) {
|
|
412
|
+
if (!item?.Ret) {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const normalized = String(headerText ?? '').trim().toUpperCase();
|
|
417
|
+
return normalized === 'QTY'
|
|
418
|
+
|| normalized === 'OFFER QTY'
|
|
419
|
+
|| normalized === 'PRICE'
|
|
420
|
+
|| normalized === 'LINE TOTAL';
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function getDisplayValueForFallbackRow(item: any, dbFields: string[] = [], shouldNegate: boolean = false) {
|
|
424
|
+
const value = getFirstFieldValue(item, dbFields);
|
|
425
|
+
if (!shouldNegate) {
|
|
426
|
+
return value;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const normalized = Number(String(value ?? '').replace(/,/g, '').trim());
|
|
430
|
+
if (!Number.isFinite(normalized)) {
|
|
431
|
+
return value;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
return String(normalized === 0 ? 0 : -Math.abs(normalized));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function formatNumericLikeValue(value: string, fixedTo: number) {
|
|
438
|
+
if (!value) {
|
|
439
|
+
return value;
|
|
440
|
+
}
|
|
441
|
+
const normalized = Number(String(value).replace(/,/g, '').trim());
|
|
442
|
+
if (!Number.isFinite(normalized)) {
|
|
443
|
+
return value;
|
|
444
|
+
}
|
|
445
|
+
return normalized.toFixed(fixedTo);
|
|
446
|
+
}
|
|
447
|
+
|