shareneus 1.5.75 → 1.5.77

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.
@@ -76,7 +76,7 @@ function buildPdfDocDefinition(PDFInvoiceData = {}, PrintConfigData = {}, printC
76
76
  const invoiceHeaderContent = (0, pdf_header_footer_section_1.buildDocumentHeaderSection)(PrintConfig, PDFInvoiceData);
77
77
  const invoiceHeadingContent = (0, pdf_header_footer_section_1.buildDocumentHeadingSection)(PDFInvoiceData, PrintConfig, availableWidth);
78
78
  const invoicePartyDetailsContent = (0, pdf_party_details_section_1.buildInvoicePartyDetailsSection)(PDFInvoiceData, PrintConfig === null || PrintConfig === void 0 ? void 0 : PrintConfig.Customer);
79
- const invoiceTotalsAndNotesContent = (0, pdf_totals_section_1.buildInvoiceTotalsAndNotesSection)(PDFInvoiceData, availableWidth);
79
+ const invoiceTotalsAndNotesContent = (0, pdf_totals_section_1.buildInvoiceTotalsAndNotesSection)(PDFInvoiceData, availableWidth, PrintConfigData);
80
80
  const signatureContent = (0, pdf_totals_section_1.buildSignatureSection)(PrintConfig, PDFInvoiceData, availableWidth);
81
81
  const tableData = (0, pdf_table_section_1.buildInvoiceTableData)(PDFInvoiceData, PrintConfig, availableWidth);
82
82
  if (index > 0) {
@@ -76,7 +76,7 @@ function buildPdfDocDefinition(PDFInvoiceData = {}, PrintConfigData = {}, printC
76
76
  const invoiceHeaderContent = (0, pdf_header_footer_section_1.buildDocumentHeaderSection)(PrintConfig, PDFInvoiceData);
77
77
  const invoiceHeadingContent = (0, pdf_header_footer_section_1.buildDocumentHeadingSection)(PDFInvoiceData, PrintConfig, availableWidth);
78
78
  const invoicePartyDetailsContent = (0, pdf_party_details_section_1.buildPurchasePartyDetailsSection)(PDFInvoiceData, PrintConfig === null || PrintConfig === void 0 ? void 0 : PrintConfig.Customer);
79
- const invoiceTotalsAndNotesContent = (0, pdf_totals_section_1.buildInvoiceTotalsAndNotesSection)(PDFInvoiceData, availableWidth);
79
+ const invoiceTotalsAndNotesContent = (0, pdf_totals_section_1.buildInvoiceTotalsAndNotesSection)(PDFInvoiceData, availableWidth, PrintConfigData);
80
80
  const signatureContent = (0, pdf_totals_section_1.buildSignatureSection)(PrintConfig, PDFInvoiceData, availableWidth);
81
81
  const tableData = (0, pdf_table_section_1.buildInvoiceTableData)(PDFInvoiceData, PrintConfig, availableWidth);
82
82
  if (index > 0) {
@@ -63,7 +63,7 @@ function getAvailablePageWidth(pageSize, orientation, margins) {
63
63
  function calculateSectionTotals(rows) {
64
64
  return rows.reduce((acc, row) => {
65
65
  acc.qty += readNumericValue(row, ['Qty']);
66
- acc.priceTotal += readNumericValue(row, ['UnPr', 'Pr']);
66
+ acc.priceTotal += readNumericValue(row, ['UnPr', 'Pr', 'UnCo']);
67
67
  acc.discountAmount += readNumericValue(row, ['Disc']);
68
68
  acc.cgstAmount += readNumericValue(row, ['CGSTAmt', 'CGST']);
69
69
  acc.sgstAmount += readNumericValue(row, ['SGSTAmt', 'SGST']);
@@ -1,4 +1,4 @@
1
- export declare function buildInvoiceTotalsAndNotesSection(invoiceData: any, availableWidth: number): ({
1
+ export declare function buildInvoiceTotalsAndNotesSection(invoiceData: any, availableWidth: number, PrintConfigData?: any): ({
2
2
  canvas: {
3
3
  type: string;
4
4
  x1: number;
@@ -5,18 +5,20 @@ exports.buildSignatureSection = buildSignatureSection;
5
5
  const pdf_header_footer_section_1 = require("../header-footer-section/pdf-header-footer.section");
6
6
  const pdf_shared_utils_1 = require("../header-footer-section/pdf-shared.utils");
7
7
  const pdf_table_section_1 = require("../table-section/pdf-table.section");
8
- function buildInvoiceTotalsAndNotesSection(invoiceData, availableWidth) {
8
+ function buildInvoiceTotalsAndNotesSection(invoiceData, availableWidth, PrintConfigData = {}) {
9
9
  const normalizedInvoice = invoiceData || {};
10
10
  const taxSummary = resolveTaxSummary(normalizedInvoice);
11
- const bankDetails = resolveBankDetails(normalizedInvoice);
12
- const totals = resolveTotals(normalizedInvoice, taxSummary.totalTax);
11
+ const showBankDetails = resolveShowBankDetails(normalizedInvoice, PrintConfigData);
12
+ const showDueSection = shouldShowDueSection(PrintConfigData);
13
+ const bankDetails = showBankDetails ? resolveBankDetails(normalizedInvoice) : { lines: [], hasData: false };
14
+ const totals = resolveTotals(normalizedInvoice, taxSummary.totalTax, PrintConfigData);
13
15
  const totalInWords = resolveTotalInWords(normalizedInvoice);
14
16
  const notes = (0, pdf_shared_utils_1.firstValue)(normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.Notes, normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.Note, normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.Remarks, normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.Remark);
15
17
  const terms = (0, pdf_shared_utils_1.firstValue)(normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.TermsAndConditions, normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.TermsCondition, normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.Terms, normalizedInvoice === null || normalizedInvoice === void 0 ? void 0 : normalizedInvoice.TC);
16
18
  const dueInfo = resolveDueInfo(normalizedInvoice, totals);
17
19
  const qrPayload = resolveQrPayload(normalizedInvoice);
18
20
  const hasTopSection = taxSummary.hasData || bankDetails.hasData || totals.hasData;
19
- const hasBottomSection = !!(notes || terms || totalInWords || dueInfo.hasData || qrPayload);
21
+ const hasBottomSection = !!(notes || terms || totalInWords || (showDueSection && dueInfo.hasData) || qrPayload);
20
22
  if (!hasTopSection && !hasBottomSection) {
21
23
  return [];
22
24
  }
@@ -29,7 +31,7 @@ function buildInvoiceTotalsAndNotesSection(invoiceData, availableWidth) {
29
31
  const topColumns = {
30
32
  columns: [
31
33
  { width: '42%', stack: buildTaxSummaryTableStack(null, taxSummary.rows) },
32
- { width: '28%', stack: buildInfoCardStack('Bank Details', bankDetails.lines) },
34
+ { width: '28%', stack: showBankDetails ? buildInfoCardStack('Bank Details', bankDetails.lines) : [{ text: '' }] },
33
35
  { width: '30%', stack: buildInfoCardStack(null, totals.lines, { rightAlign: true }) }
34
36
  ],
35
37
  columnGap: 20,
@@ -41,7 +43,8 @@ function buildInvoiceTotalsAndNotesSection(invoiceData, availableWidth) {
41
43
  terms,
42
44
  paidAmount: dueInfo.paid,
43
45
  dueAmount: dueInfo.due,
44
- qrPayload
46
+ qrPayload,
47
+ showDueSection
45
48
  });
46
49
  if (hasTopSection && hasBottomSection) {
47
50
  return [dividerLine, topColumns, bottomColumns];
@@ -55,8 +58,6 @@ function buildPostTotalsInfoSection(data) {
55
58
  const hasQr = !!(0, pdf_shared_utils_1.firstValue)(data.qrPayload);
56
59
  const inWords = data.totalInWords || '-';
57
60
  const termsText = (0, pdf_shared_utils_1.firstValue)(data.terms);
58
- const paidText = `Paid : Rs.${formatAmountFixed2(data.paidAmount)}`;
59
- const dueText = `Due : Rs.${formatAmountFixed2(data.dueAmount)}`;
60
61
  const leftStack = [
61
62
  {
62
63
  columns: [
@@ -65,8 +66,12 @@ function buildPostTotalsInfoSection(data) {
65
66
  ],
66
67
  columnGap: 6,
67
68
  margin: [0, 0, 0, 4]
68
- },
69
- {
69
+ }
70
+ ];
71
+ if (data.showDueSection) {
72
+ const paidText = `Paid : Rs.${formatAmountFixed2(data.paidAmount)}`;
73
+ const dueText = `Due : Rs.${formatAmountFixed2(data.dueAmount)}`;
74
+ leftStack.push({
70
75
  table: {
71
76
  widths: ['*', '*'],
72
77
  body: [[
@@ -81,8 +86,8 @@ function buildPostTotalsInfoSection(data) {
81
86
  vLineColor: () => '#d3d3d3'
82
87
  },
83
88
  margin: [0, 0, 0, 6]
84
- }
85
- ];
89
+ });
90
+ }
86
91
  if (termsText) {
87
92
  leftStack.push({
88
93
  text: `\u2022 ${termsText}`,
@@ -295,11 +300,14 @@ function buildInfoCardStack(title, lines, options = {}) {
295
300
  {
296
301
  table: {
297
302
  widths: isRightAlign ? ['*', 6, 'auto'] : ['auto', 6, '*'],
298
- body: (body.length > 0 ? body : [{ label: '', value: '-' }]).map((line) => ([
299
- { text: line.label || '', bold: true, fontSize: 8, color: '#111827', alignment: isRightAlign ? 'right' : 'left' },
300
- { text: ':', bold: true, fontSize: 8, color: '#111827', alignment: 'center' },
301
- { text: line.value || '-', fontSize: 8, color: '#111827', alignment: isRightAlign ? 'right' : 'left' }
302
- ]))
303
+ body: (body.length > 0 ? body : [{ label: '', value: '-' }]).map((line) => {
304
+ const displayValue = hasDisplayValue(line === null || line === void 0 ? void 0 : line.value) ? String(line.value) : '-';
305
+ return [
306
+ { text: line.label || '', bold: true, fontSize: 8, color: '#111827', alignment: isRightAlign ? 'right' : 'left' },
307
+ { text: ':', bold: true, fontSize: 8, color: '#111827', alignment: 'center' },
308
+ { text: displayValue, fontSize: 8, color: '#111827', alignment: isRightAlign ? 'right' : 'left' }
309
+ ];
310
+ })
303
311
  },
304
312
  layout: 'noBorders'
305
313
  }
@@ -392,9 +400,56 @@ function resolveBankDetails(invoiceData) {
392
400
  hasData: lines.length > 0
393
401
  };
394
402
  }
395
- function resolveTotals(invoiceData, totalTax) {
403
+ function resolveShowBankDetails(invoiceData, printConfigData = {}) {
404
+ var _a;
405
+ const value = (0, pdf_shared_utils_1.firstValue)(printConfigData === null || printConfigData === void 0 ? void 0 : printConfigData.ShowBankDetails, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.ShowBankDetails, (_a = invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Entity) === null || _a === void 0 ? void 0 : _a.ShowBankDetails);
406
+ return isTruthy(value);
407
+ }
408
+ function shouldShowDueSection(printConfigData = {}) {
409
+ const type = (0, pdf_shared_utils_1.firstValue)(printConfigData === null || printConfigData === void 0 ? void 0 : printConfigData.Type);
410
+ if (!type) {
411
+ return false;
412
+ }
413
+ const normalizedType = String(type).trim().toLowerCase();
414
+ return normalizedType === 'invoice' || normalizedType === 'bill';
415
+ }
416
+ function isTruthy(value) {
417
+ if (typeof value === 'boolean') {
418
+ return value;
419
+ }
420
+ if (typeof value === 'number') {
421
+ return value !== 0;
422
+ }
423
+ if (typeof value === 'string') {
424
+ const normalized = value.trim().toLowerCase();
425
+ return normalized === 'true' || normalized === '1' || normalized === 'yes';
426
+ }
427
+ return false;
428
+ }
429
+ function hasDisplayValue(value) {
430
+ if (value === undefined || value === null) {
431
+ return false;
432
+ }
433
+ if (typeof value === 'number') {
434
+ return Number.isFinite(value);
435
+ }
436
+ if (typeof value === 'string') {
437
+ return value.trim().length > 0;
438
+ }
439
+ return true;
440
+ }
441
+ function resolveTotals(invoiceData, totalTax, printConfigData = {}) {
396
442
  const subtotal = (0, pdf_table_section_1.readNumericValue)(invoiceData, ['SubTotal', 'SubTot', 'TaxableAmount', 'TaxableValue']);
397
- const discount = (0, pdf_table_section_1.readNumericValue)(invoiceData, ['Disc', 'Discount', 'TotDisc']);
443
+ const showDetailedDisc = isTruthy((0, pdf_shared_utils_1.firstValue)(printConfigData === null || printConfigData === void 0 ? void 0 : printConfigData.ShowDetailedDisc));
444
+ const itemsDiscount = parseNumber((0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.PDisc));
445
+ const servicesDiscount = parseNumber((0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.LDisc));
446
+ const overallDiscount = parseNumber((0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Disc, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Discount, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.TotDisc));
447
+ const hasDetailedDiscSource = (0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.PDisc) !== ''
448
+ || (0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.LDisc) !== ''
449
+ || (0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Disc, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.Discount, invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.TotDisc) !== '';
450
+ const discount = hasDetailedDiscSource
451
+ ? itemsDiscount + servicesDiscount + overallDiscount
452
+ : (0, pdf_table_section_1.readNumericValue)(invoiceData, ['Disc', 'Discount', 'TotDisc']);
398
453
  const roundOff = (0, pdf_table_section_1.readNumericValue)(invoiceData, ['Round', 'RoundOff']);
399
454
  const taxFromInvoice = (0, pdf_table_section_1.readNumericValue)(invoiceData, ['TotalTax', 'TaxTotal', 'TaxAmt', 'GSTTotal']);
400
455
  const totalTaxValue = taxFromInvoice !== 0 ? taxFromInvoice : totalTax;
@@ -413,9 +468,18 @@ function resolveTotals(invoiceData, totalTax) {
413
468
  }
414
469
  }
415
470
  const resolvedFinalTotal = finalTotalRaw ? finalTotal : totalBeforeRound + roundOff;
471
+ const discountLines = showDetailedDisc
472
+ ? [
473
+ { label: 'Items Discount', value: formatAmountFixed2(itemsDiscount) },
474
+ { label: 'Services Discount', value: formatAmountFixed2(servicesDiscount) },
475
+ { label: 'Overall Discount', value: formatAmountFixed2(overallDiscount) }
476
+ ]
477
+ : [
478
+ { label: 'Discount', value: formatAmountFixed2(discount) }
479
+ ];
416
480
  const lines = [
417
481
  { label: 'SubTotal', value: formatAmountFixed2(subtotal) },
418
- { label: 'Discount', value: formatAmountFixed2(discount) },
482
+ ...discountLines,
419
483
  { label: 'Total Tax', value: formatAmountFixed2(totalTaxValue) },
420
484
  { label: 'Total', value: formatAmountFixed2(totalBeforeRound) },
421
485
  { label: 'Rounding', value: formatAmountFixed2(roundOff) },
@@ -423,7 +487,7 @@ function resolveTotals(invoiceData, totalTax) {
423
487
  ];
424
488
  return {
425
489
  lines,
426
- hasData: lines.some((line) => !!line.value)
490
+ hasData: lines.some((line) => hasDisplayValue(line === null || line === void 0 ? void 0 : line.value))
427
491
  };
428
492
  }
429
493
  function resolveDueInfo(invoiceData, totals) {
@@ -451,7 +515,36 @@ function parseNumber(value) {
451
515
  if (value === undefined || value === null) {
452
516
  return 0;
453
517
  }
454
- const numeric = Number(String(value).replace(/,/g, '').trim());
518
+ if (typeof value === 'number') {
519
+ return Number.isFinite(value) ? value : 0;
520
+ }
521
+ const raw = String(value).trim();
522
+ if (!raw) {
523
+ return 0;
524
+ }
525
+ const cleaned = raw.replace(/\s/g, '').replace(/[^0-9,.-]/g, '');
526
+ if (!cleaned) {
527
+ return 0;
528
+ }
529
+ const commaCount = (cleaned.match(/,/g) || []).length;
530
+ const dotCount = (cleaned.match(/\./g) || []).length;
531
+ let normalized = cleaned;
532
+ if (commaCount > 0 && dotCount > 0) {
533
+ const lastCommaIndex = cleaned.lastIndexOf(',');
534
+ const lastDotIndex = cleaned.lastIndexOf('.');
535
+ const decimalSeparator = lastCommaIndex > lastDotIndex ? ',' : '.';
536
+ if (decimalSeparator === ',') {
537
+ normalized = cleaned.replace(/\./g, '').replace(',', '.');
538
+ }
539
+ else {
540
+ normalized = cleaned.replace(/,/g, '');
541
+ }
542
+ }
543
+ else if (commaCount > 0) {
544
+ const isCommaDecimal = /^-?\d+,\d{1,2}$/.test(cleaned);
545
+ normalized = isCommaDecimal ? cleaned.replace(',', '.') : cleaned.replace(/,/g, '');
546
+ }
547
+ const numeric = Number(normalized);
455
548
  return Number.isFinite(numeric) ? numeric : 0;
456
549
  }
457
550
  function formatTaxRate(value) {
@@ -466,7 +559,7 @@ function formatTaxRate(value) {
466
559
  return Number.isFinite(numericValue) ? `${normalized}%` : normalized;
467
560
  }
468
561
  function resolveTotalInWords(invoiceData) {
469
- const roundedTotal = parseNumber((0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.CustRoundedTotal));
562
+ const roundedTotal = parseNumber((0, pdf_shared_utils_1.firstValue)((invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.CustRoundedTotal) || (invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.RoundedTotal)));
470
563
  if (roundedTotal > 0) {
471
564
  return convertAmountToWordsINR(roundedTotal);
472
565
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareneus",
3
- "version": "1.5.75",
3
+ "version": "1.5.77",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",