shareneus 1.6.42 → 1.6.43

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.
@@ -11,7 +11,10 @@ function buildDataRow(item, index, headerConfig, fixedTo = 2) {
11
11
  var _a;
12
12
  if (column.type === 'tax') {
13
13
  const taxValue = getTaxValue(item, column.dbField, column.taxKind);
14
- const renderedTaxValue = formatNumericLikeValue(taxValue, fixedTo);
14
+ const signedTaxValue = shouldRenderNegativeTaxAmount(item, column)
15
+ ? negateNumericLikeValue(taxValue)
16
+ : taxValue;
17
+ const renderedTaxValue = formatNumericLikeValue(signedTaxValue, fixedTo);
15
18
  return { text: renderedTaxValue, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: getNumericAlignment(renderedTaxValue) };
16
19
  }
17
20
  const header = column.header;
@@ -50,7 +53,10 @@ function formatFieldValue(item, fieldConfig, fixedTo) {
50
53
  if (isExpiryField(fieldConfig)) {
51
54
  return formatExpiryDateValue(rawValue);
52
55
  }
53
- return formatNumericLikeValue(rawValue, fixedTo, shouldSkipFixedTo(fieldConfig));
56
+ const signedValue = shouldRenderNegativeField(item, fieldConfig)
57
+ ? negateNumericLikeValue(rawValue)
58
+ : rawValue;
59
+ return formatNumericLikeValue(signedValue, fixedTo, shouldSkipFixedTo(fieldConfig));
54
60
  }
55
61
  function getTaxValue(item, taxName, taxKind) {
56
62
  if (taxName === 'IGST') {
@@ -62,6 +68,30 @@ function getTaxValue(item, taxName, taxKind) {
62
68
  : [`${taxName}Amt`, taxName];
63
69
  return getFirstFieldValue(item, fields);
64
70
  }
71
+ function shouldRenderNegativeTaxAmount(item, column) {
72
+ return !!(item === null || item === void 0 ? void 0 : item.Ret) && (column === null || column === void 0 ? void 0 : column.taxKind) === 'amount';
73
+ }
74
+ function shouldRenderNegativeField(item, fieldConfig) {
75
+ var _a;
76
+ if (!(item === null || item === void 0 ? void 0 : item.Ret)) {
77
+ return false;
78
+ }
79
+ const headerText = String((_a = fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.text) !== null && _a !== void 0 ? _a : '').trim().toUpperCase();
80
+ return headerText === 'QTY'
81
+ || headerText === 'OFFER QTY'
82
+ || headerText === 'PRICE'
83
+ || headerText === 'LINE TOTAL';
84
+ }
85
+ function negateNumericLikeValue(value) {
86
+ if (!isNumericLike(String(value !== null && value !== void 0 ? value : ''))) {
87
+ return value;
88
+ }
89
+ const normalized = Number(String(value).replace(/,/g, '').trim());
90
+ if (!Number.isFinite(normalized)) {
91
+ return value;
92
+ }
93
+ return String(normalized === 0 ? 0 : -Math.abs(normalized));
94
+ }
65
95
  function getFirstFieldValue(item, dbFields = []) {
66
96
  for (const field of dbFields) {
67
97
  const value = readValue(item, field);
@@ -88,13 +88,14 @@ function getAvailablePageWidth(pageSize, orientation, margins) {
88
88
  }
89
89
  function calculateSectionTotals(rows) {
90
90
  return rows.reduce((acc, row) => {
91
- acc.qty += readNumericValue(row, ['Qty']);
92
- acc.priceTotal += readNumericValue(row, ['UnPr', 'Pr', 'UnCo']);
93
- acc.discountAmount += readNumericValue(row, ['Disc']);
94
- acc.cgstAmount += readNumericValue(row, ['CGSTAmt', 'CGST']);
95
- acc.sgstAmount += readNumericValue(row, ['SGSTAmt', 'SGST']);
96
- acc.igstAmount += readNumericValue(row, ['IGSTAmt', 'IGST']);
97
- acc.lineTotal += readNumericValue(row, ['LineTotal']);
91
+ const sign = (row === null || row === void 0 ? void 0 : row.Ret) ? -1 : 1;
92
+ acc.qty += sign * readNumericValue(row, ['Qty']);
93
+ acc.priceTotal += sign * readNumericValue(row, ['UnPr', 'Pr', 'UnCo']);
94
+ acc.discountAmount += sign * readNumericValue(row, ['Disc']);
95
+ acc.cgstAmount += sign * readNumericValue(row, ['CGSTAmt', 'CGST']);
96
+ acc.sgstAmount += sign * readNumericValue(row, ['SGSTAmt', 'SGST']);
97
+ acc.igstAmount += sign * readNumericValue(row, ['IGSTAmt', 'IGST']);
98
+ acc.lineTotal += sign * readNumericValue(row, ['LineTotal']);
98
99
  return acc;
99
100
  }, {
100
101
  qty: 0,
@@ -169,7 +170,7 @@ function buildFallbackDataRow(item, index, fallbackHeaderRow, fixedTo) {
169
170
  return { text: renderedValue, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: (0, pdf_table_row_1.getNumericAlignment)(renderedValue) };
170
171
  }
171
172
  else if (header.taxKind === 'amount') {
172
- const value = (0, pdf_table_row_1.getFirstFieldValue)(item, ['CGSTAmt']);
173
+ const value = getDisplayValueForFallbackRow(item, ['CGSTAmt'], true);
173
174
  const renderedValue = formatNumericLikeValue(value, fixedTo);
174
175
  return { text: renderedValue, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: (0, pdf_table_row_1.getNumericAlignment)(renderedValue) };
175
176
  }
@@ -181,7 +182,7 @@ function buildFallbackDataRow(item, index, fallbackHeaderRow, fixedTo) {
181
182
  return { text: renderedValue, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: (0, pdf_table_row_1.getNumericAlignment)(renderedValue) };
182
183
  }
183
184
  else if (header.taxKind === 'amount') {
184
- const value = (0, pdf_table_row_1.getFirstFieldValue)(item, ['SGSTAmt']);
185
+ const value = getDisplayValueForFallbackRow(item, ['SGSTAmt'], true);
185
186
  const renderedValue = formatNumericLikeValue(value, fixedTo);
186
187
  return { text: renderedValue, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: (0, pdf_table_row_1.getNumericAlignment)(renderedValue) };
187
188
  }
@@ -192,7 +193,7 @@ function buildFallbackDataRow(item, index, fallbackHeaderRow, fixedTo) {
192
193
  return { text: renderedValue, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: (0, pdf_table_row_1.getNumericAlignment)(renderedValue) };
193
194
  }
194
195
  if (header.text === 'IGST Amt') {
195
- const value = (0, pdf_table_row_1.getFirstFieldValue)(item, ['IGSTAmt']);
196
+ const value = getDisplayValueForFallbackRow(item, ['IGSTAmt'], true);
196
197
  const renderedValue = formatNumericLikeValue(value, fixedTo);
197
198
  return { text: renderedValue, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: (0, pdf_table_row_1.getNumericAlignment)(renderedValue) };
198
199
  }
@@ -200,7 +201,7 @@ function buildFallbackDataRow(item, index, fallbackHeaderRow, fixedTo) {
200
201
  const value = String(index + 1);
201
202
  return { text: value, fontSize: pdf_table_config_1.pdfTableStyleConfig.bodyFontSize, color: pdf_table_config_1.pdfTableStyleConfig.bodyFontColor, alignment: (0, pdf_table_row_1.getNumericAlignment)(value) };
202
203
  }
203
- const mainValue = formatNumericLikeValue((0, pdf_table_row_1.getFirstFieldValue)(item, header.dbFields), fixedTo);
204
+ const mainValue = formatNumericLikeValue(getDisplayValueForFallbackRow(item, header.dbFields, shouldNegateFallbackHeaderValue(item, header.text)), fixedTo);
204
205
  const stackedLines = ((_a = header.stackFields) !== null && _a !== void 0 ? _a : [])
205
206
  .map((stackField) => {
206
207
  const stackValue = formatNumericLikeValue((0, pdf_table_row_1.getFirstFieldValue)(item, stackField.dbFields), fixedTo);
@@ -325,6 +326,27 @@ function resolveFixedTo(value) {
325
326
  }
326
327
  return Math.floor(parsed);
327
328
  }
329
+ function shouldNegateFallbackHeaderValue(item, headerText) {
330
+ if (!(item === null || item === void 0 ? void 0 : item.Ret)) {
331
+ return false;
332
+ }
333
+ const normalized = String(headerText !== null && headerText !== void 0 ? headerText : '').trim().toUpperCase();
334
+ return normalized === 'QTY'
335
+ || normalized === 'OFFER QTY'
336
+ || normalized === 'PRICE'
337
+ || normalized === 'LINE TOTAL';
338
+ }
339
+ function getDisplayValueForFallbackRow(item, dbFields = [], shouldNegate = false) {
340
+ const value = (0, pdf_table_row_1.getFirstFieldValue)(item, dbFields);
341
+ if (!shouldNegate) {
342
+ return value;
343
+ }
344
+ const normalized = Number(String(value !== null && value !== void 0 ? value : '').replace(/,/g, '').trim());
345
+ if (!Number.isFinite(normalized)) {
346
+ return value;
347
+ }
348
+ return String(normalized === 0 ? 0 : -Math.abs(normalized));
349
+ }
328
350
  function formatNumericLikeValue(value, fixedTo) {
329
351
  if (!value) {
330
352
  return value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareneus",
3
- "version": "1.6.42",
3
+ "version": "1.6.43",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",