shareneus 1.5.76 → 1.5.78

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.
@@ -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']);
@@ -9,15 +9,16 @@ function buildInvoiceTotalsAndNotesSection(invoiceData, availableWidth, PrintCon
9
9
  const normalizedInvoice = invoiceData || {};
10
10
  const taxSummary = resolveTaxSummary(normalizedInvoice);
11
11
  const showBankDetails = resolveShowBankDetails(normalizedInvoice, PrintConfigData);
12
+ const showDueSection = shouldShowDueSection(PrintConfigData);
12
13
  const bankDetails = showBankDetails ? resolveBankDetails(normalizedInvoice) : { lines: [], hasData: false };
13
- const totals = resolveTotals(normalizedInvoice, taxSummary.totalTax);
14
+ const totals = resolveTotals(normalizedInvoice, taxSummary.totalTax, PrintConfigData);
14
15
  const totalInWords = resolveTotalInWords(normalizedInvoice);
15
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);
16
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);
17
18
  const dueInfo = resolveDueInfo(normalizedInvoice, totals);
18
19
  const qrPayload = resolveQrPayload(normalizedInvoice);
19
20
  const hasTopSection = taxSummary.hasData || bankDetails.hasData || totals.hasData;
20
- const hasBottomSection = !!(notes || terms || totalInWords || dueInfo.hasData || qrPayload);
21
+ const hasBottomSection = !!(notes || terms || totalInWords || (showDueSection && dueInfo.hasData) || qrPayload);
21
22
  if (!hasTopSection && !hasBottomSection) {
22
23
  return [];
23
24
  }
@@ -42,7 +43,8 @@ function buildInvoiceTotalsAndNotesSection(invoiceData, availableWidth, PrintCon
42
43
  terms,
43
44
  paidAmount: dueInfo.paid,
44
45
  dueAmount: dueInfo.due,
45
- qrPayload
46
+ qrPayload,
47
+ showDueSection
46
48
  });
47
49
  if (hasTopSection && hasBottomSection) {
48
50
  return [dividerLine, topColumns, bottomColumns];
@@ -56,8 +58,6 @@ function buildPostTotalsInfoSection(data) {
56
58
  const hasQr = !!(0, pdf_shared_utils_1.firstValue)(data.qrPayload);
57
59
  const inWords = data.totalInWords || '-';
58
60
  const termsText = (0, pdf_shared_utils_1.firstValue)(data.terms);
59
- const paidText = `Paid : Rs.${formatAmountFixed2(data.paidAmount)}`;
60
- const dueText = `Due : Rs.${formatAmountFixed2(data.dueAmount)}`;
61
61
  const leftStack = [
62
62
  {
63
63
  columns: [
@@ -66,8 +66,12 @@ function buildPostTotalsInfoSection(data) {
66
66
  ],
67
67
  columnGap: 6,
68
68
  margin: [0, 0, 0, 4]
69
- },
70
- {
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({
71
75
  table: {
72
76
  widths: ['*', '*'],
73
77
  body: [[
@@ -82,8 +86,8 @@ function buildPostTotalsInfoSection(data) {
82
86
  vLineColor: () => '#d3d3d3'
83
87
  },
84
88
  margin: [0, 0, 0, 6]
85
- }
86
- ];
89
+ });
90
+ }
87
91
  if (termsText) {
88
92
  leftStack.push({
89
93
  text: `\u2022 ${termsText}`,
@@ -296,11 +300,14 @@ function buildInfoCardStack(title, lines, options = {}) {
296
300
  {
297
301
  table: {
298
302
  widths: isRightAlign ? ['*', 6, 'auto'] : ['auto', 6, '*'],
299
- body: (body.length > 0 ? body : [{ label: '', value: '-' }]).map((line) => ([
300
- { text: line.label || '', bold: true, fontSize: 8, color: '#111827', alignment: isRightAlign ? 'right' : 'left' },
301
- { text: ':', bold: true, fontSize: 8, color: '#111827', alignment: 'center' },
302
- { text: line.value || '-', fontSize: 8, color: '#111827', alignment: isRightAlign ? 'right' : 'left' }
303
- ]))
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
+ })
304
311
  },
305
312
  layout: 'noBorders'
306
313
  }
@@ -398,6 +405,14 @@ function resolveShowBankDetails(invoiceData, printConfigData = {}) {
398
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);
399
406
  return isTruthy(value);
400
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
+ }
401
416
  function isTruthy(value) {
402
417
  if (typeof value === 'boolean') {
403
418
  return value;
@@ -411,9 +426,30 @@ function isTruthy(value) {
411
426
  }
412
427
  return false;
413
428
  }
414
- function resolveTotals(invoiceData, totalTax) {
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 = {}) {
415
442
  const subtotal = (0, pdf_table_section_1.readNumericValue)(invoiceData, ['SubTotal', 'SubTot', 'TaxableAmount', 'TaxableValue']);
416
- 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']);
417
453
  const roundOff = (0, pdf_table_section_1.readNumericValue)(invoiceData, ['Round', 'RoundOff']);
418
454
  const taxFromInvoice = (0, pdf_table_section_1.readNumericValue)(invoiceData, ['TotalTax', 'TaxTotal', 'TaxAmt', 'GSTTotal']);
419
455
  const totalTaxValue = taxFromInvoice !== 0 ? taxFromInvoice : totalTax;
@@ -432,9 +468,20 @@ function resolveTotals(invoiceData, totalTax) {
432
468
  }
433
469
  }
434
470
  const resolvedFinalTotal = finalTotalRaw ? finalTotal : totalBeforeRound + roundOff;
471
+ const discountLines = (showDetailedDisc
472
+ ? [
473
+ { label: 'Items Discount', amount: itemsDiscount },
474
+ { label: 'Services Discount', amount: servicesDiscount },
475
+ { label: 'Overall Discount', amount: overallDiscount }
476
+ ]
477
+ : [
478
+ { label: 'Discount', amount: discount }
479
+ ])
480
+ .filter((line) => Math.abs(parseNumber(line === null || line === void 0 ? void 0 : line.amount)) > 0)
481
+ .map((line) => ({ label: line.label, value: formatAmountFixed2(line.amount) }));
435
482
  const lines = [
436
483
  { label: 'SubTotal', value: formatAmountFixed2(subtotal) },
437
- { label: 'Discount', value: formatAmountFixed2(discount) },
484
+ ...discountLines,
438
485
  { label: 'Total Tax', value: formatAmountFixed2(totalTaxValue) },
439
486
  { label: 'Total', value: formatAmountFixed2(totalBeforeRound) },
440
487
  { label: 'Rounding', value: formatAmountFixed2(roundOff) },
@@ -442,7 +489,7 @@ function resolveTotals(invoiceData, totalTax) {
442
489
  ];
443
490
  return {
444
491
  lines,
445
- hasData: lines.some((line) => !!line.value)
492
+ hasData: lines.some((line) => hasDisplayValue(line === null || line === void 0 ? void 0 : line.value))
446
493
  };
447
494
  }
448
495
  function resolveDueInfo(invoiceData, totals) {
@@ -470,7 +517,36 @@ function parseNumber(value) {
470
517
  if (value === undefined || value === null) {
471
518
  return 0;
472
519
  }
473
- const numeric = Number(String(value).replace(/,/g, '').trim());
520
+ if (typeof value === 'number') {
521
+ return Number.isFinite(value) ? value : 0;
522
+ }
523
+ const raw = String(value).trim();
524
+ if (!raw) {
525
+ return 0;
526
+ }
527
+ const cleaned = raw.replace(/\s/g, '').replace(/[^0-9,.-]/g, '');
528
+ if (!cleaned) {
529
+ return 0;
530
+ }
531
+ const commaCount = (cleaned.match(/,/g) || []).length;
532
+ const dotCount = (cleaned.match(/\./g) || []).length;
533
+ let normalized = cleaned;
534
+ if (commaCount > 0 && dotCount > 0) {
535
+ const lastCommaIndex = cleaned.lastIndexOf(',');
536
+ const lastDotIndex = cleaned.lastIndexOf('.');
537
+ const decimalSeparator = lastCommaIndex > lastDotIndex ? ',' : '.';
538
+ if (decimalSeparator === ',') {
539
+ normalized = cleaned.replace(/\./g, '').replace(',', '.');
540
+ }
541
+ else {
542
+ normalized = cleaned.replace(/,/g, '');
543
+ }
544
+ }
545
+ else if (commaCount > 0) {
546
+ const isCommaDecimal = /^-?\d+,\d{1,2}$/.test(cleaned);
547
+ normalized = isCommaDecimal ? cleaned.replace(',', '.') : cleaned.replace(/,/g, '');
548
+ }
549
+ const numeric = Number(normalized);
474
550
  return Number.isFinite(numeric) ? numeric : 0;
475
551
  }
476
552
  function formatTaxRate(value) {
@@ -485,7 +561,7 @@ function formatTaxRate(value) {
485
561
  return Number.isFinite(numericValue) ? `${normalized}%` : normalized;
486
562
  }
487
563
  function resolveTotalInWords(invoiceData) {
488
- const roundedTotal = parseNumber((0, pdf_shared_utils_1.firstValue)(invoiceData === null || invoiceData === void 0 ? void 0 : invoiceData.CustRoundedTotal));
564
+ 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)));
489
565
  if (roundedTotal > 0) {
490
566
  return convertAmountToWordsINR(roundedTotal);
491
567
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareneus",
3
- "version": "1.5.76",
3
+ "version": "1.5.78",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",