shareneus 1.5.92 → 1.5.94

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.
@@ -73,38 +73,62 @@ function getHeadersBySequence(headers) {
73
73
  .map((entry) => entry.header);
74
74
  }
75
75
  function getRenderableColumns(headerConfig) {
76
- const hasTaxPercent = headerConfig.some((header) => header.text === 'Tax %');
77
- const hasTaxAmount = headerConfig.some((header) => header.text === 'Tax Amount');
76
+ const hasTaxPercent = headerConfig.some((header) => isTaxPercentHeader(header));
77
+ const hasTaxAmount = headerConfig.some((header) => isTaxAmountHeader(header));
78
78
  const hasTaxGroup = hasTaxPercent && hasTaxAmount;
79
79
  const columns = [];
80
80
  for (const header of headerConfig) {
81
- if (hasTaxGroup && header.text === 'Tax %') {
81
+ if (hasTaxGroup && isTaxPercentHeader(header)) {
82
82
  columns.push({
83
83
  type: 'tax',
84
84
  taxKind: 'rate',
85
- taxName: '%',
86
85
  dbField: 'CGST',
87
86
  width: getTaxSubWidth(header.width),
88
87
  }, {
89
88
  type: 'tax',
90
89
  taxKind: 'amount',
91
90
  dbField: 'CGST',
92
- taxName: 'Amount',
93
91
  width: getTaxSubWidth(header.width),
94
92
  });
95
93
  continue;
96
94
  }
97
- if (hasTaxGroup && header.text === 'Tax Amount') {
95
+ if (hasTaxGroup && isTaxAmountHeader(header)) {
98
96
  columns.push({
99
97
  type: 'tax',
100
98
  taxKind: 'rate',
101
- taxName: '%',
102
99
  dbField: 'SGST',
103
100
  width: getTaxSubWidth(header.width),
104
101
  }, {
105
102
  type: 'tax',
106
103
  taxKind: 'amount',
107
- taxName: 'Amount',
104
+ dbField: 'SGST',
105
+ width: getTaxSubWidth(header.width),
106
+ });
107
+ continue;
108
+ }
109
+ if (!hasTaxGroup && isTaxPercentHeader(header)) {
110
+ columns.push({
111
+ type: 'tax',
112
+ taxKind: 'rate',
113
+ dbField: 'CGST',
114
+ width: getTaxSubWidth(header.width),
115
+ }, {
116
+ type: 'tax',
117
+ taxKind: 'rate',
118
+ dbField: 'SGST',
119
+ width: getTaxSubWidth(header.width),
120
+ });
121
+ continue;
122
+ }
123
+ if (!hasTaxGroup && isTaxAmountHeader(header)) {
124
+ columns.push({
125
+ type: 'tax',
126
+ taxKind: 'amount',
127
+ dbField: 'CGST',
128
+ width: getTaxSubWidth(header.width),
129
+ }, {
130
+ type: 'tax',
131
+ taxKind: 'amount',
108
132
  dbField: 'SGST',
109
133
  width: getTaxSubWidth(header.width),
110
134
  });
@@ -119,13 +143,13 @@ function getRenderableColumns(headerConfig) {
119
143
  return columns;
120
144
  }
121
145
  function buildHeaderRows(headerConfig) {
122
- const hasTaxPercent = headerConfig.some((header) => header.text === 'Tax %');
123
- const hasTaxAmount = headerConfig.some((header) => header.text === 'Tax Amount');
146
+ const hasTaxPercent = headerConfig.some((header) => isTaxPercentHeader(header));
147
+ const hasTaxAmount = headerConfig.some((header) => isTaxAmountHeader(header));
124
148
  const hasTaxGroup = hasTaxPercent && hasTaxAmount;
125
149
  const hasDiscPercent = headerConfig.some((header) => header.text === 'Disc %');
126
150
  const hasDiscAmount = headerConfig.some((header) => isDiscountAmountHeader(header.text));
127
151
  const hasDiscGroup = hasDiscPercent && hasDiscAmount;
128
- const hasGroupedHeaders = hasTaxGroup || hasDiscGroup;
152
+ const hasGroupedHeaders = hasTaxPercent || hasTaxAmount || hasDiscGroup;
129
153
  if (!hasGroupedHeaders) {
130
154
  const singleRow = headerConfig.map((header) => (Object.assign({ text: header.text, dbFields: header.dbFields, stackFields: header.stackFields }, getHeaderCellStyle())));
131
155
  return [singleRow];
@@ -133,16 +157,26 @@ function buildHeaderRows(headerConfig) {
133
157
  const topRow = [];
134
158
  const subRow = [];
135
159
  for (const header of headerConfig) {
136
- if (hasTaxGroup && header.text === 'Tax %') {
160
+ if (hasTaxGroup && isTaxPercentHeader(header)) {
137
161
  topRow.push(Object.assign({ text: 'CGST', colSpan: 2, alignment: 'center' }, getHeaderCellStyle()), {});
138
162
  subRow.push(Object.assign({ text: '%', alignment: 'center' }, getHeaderCellStyle()), Object.assign({ text: 'Amt', alignment: 'center' }, getHeaderCellStyle()));
139
163
  continue;
140
164
  }
141
- if (hasTaxGroup && header.text === 'Tax Amount') {
165
+ if (hasTaxGroup && isTaxAmountHeader(header)) {
142
166
  topRow.push(Object.assign({ text: 'SGST/UGST', colSpan: 2, alignment: 'center' }, getHeaderCellStyle()), {});
143
167
  subRow.push(Object.assign({ text: '%', alignment: 'center' }, getHeaderCellStyle()), Object.assign({ text: 'Amt', alignment: 'center' }, getHeaderCellStyle()));
144
168
  continue;
145
169
  }
170
+ if (!hasTaxGroup && isTaxPercentHeader(header)) {
171
+ topRow.push(Object.assign({ text: header.text, colSpan: 2, alignment: 'center' }, getHeaderCellStyle()), {});
172
+ subRow.push(Object.assign({ text: 'CGST', alignment: 'center' }, getHeaderCellStyle()), Object.assign({ text: 'SGST/UGST', alignment: 'center' }, getHeaderCellStyle()));
173
+ continue;
174
+ }
175
+ if (!hasTaxGroup && isTaxAmountHeader(header)) {
176
+ topRow.push(Object.assign({ text: header.text, colSpan: 2, alignment: 'center' }, getHeaderCellStyle()), {});
177
+ subRow.push(Object.assign({ text: 'CGST', alignment: 'center' }, getHeaderCellStyle()), Object.assign({ text: 'SGST/UGST', alignment: 'center' }, getHeaderCellStyle()));
178
+ continue;
179
+ }
146
180
  if (hasDiscGroup && header.text === 'Disc %') {
147
181
  topRow.push(Object.assign({ text: 'Discount', colSpan: 2, alignment: 'center' }, getHeaderCellStyle()), {});
148
182
  subRow.push(Object.assign({ text: '%', alignment: 'center' }, getHeaderCellStyle()), Object.assign({ text: 'Amt', alignment: 'center' }, getHeaderCellStyle()));
@@ -165,6 +199,18 @@ function getTaxSubWidth(width) {
165
199
  function isDiscountAmountHeader(text) {
166
200
  return text === 'Disc Amount' || text === 'Adisc Amount';
167
201
  }
202
+ function isTaxPercentHeader(header) {
203
+ return normalizeHeaderText(header === null || header === void 0 ? void 0 : header.text) === 'TAX%';
204
+ }
205
+ function isTaxAmountHeader(header) {
206
+ return normalizeHeaderText(header === null || header === void 0 ? void 0 : header.text) === 'TAXAMOUNT';
207
+ }
208
+ function normalizeHeaderText(value) {
209
+ return String(value !== null && value !== void 0 ? value : '')
210
+ .replace(/\s+/g, '')
211
+ .trim()
212
+ .toUpperCase();
213
+ }
168
214
  function getHeaderCellStyle() {
169
215
  return {
170
216
  bold: true,
@@ -46,12 +46,6 @@ function buildDataRow(item, index, headerConfig, fixedTo = 2) {
46
46
  });
47
47
  }
48
48
  function formatFieldValue(item, fieldConfig, fixedTo) {
49
- if (isTaxPercentHeader(fieldConfig)) {
50
- return formatCombinedTaxValue(item, 'rate', fixedTo);
51
- }
52
- if (isTaxAmountHeader(fieldConfig)) {
53
- return formatCombinedTaxValue(item, 'amount', fixedTo);
54
- }
55
49
  const rawValue = getFirstFieldValue(item, fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.dbFields);
56
50
  if (isExpiryField(fieldConfig)) {
57
51
  return formatExpiryDateValue(rawValue);
@@ -182,33 +176,3 @@ function shouldSkipFixedTo(header) {
182
176
  return normalized === 'BN' || normalized === 'BNO' || normalized.endsWith('.BN');
183
177
  });
184
178
  }
185
- function isTaxPercentHeader(fieldConfig) {
186
- const normalized = normalizeHeaderText(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.text);
187
- return normalized === 'TAX%';
188
- }
189
- function isTaxAmountHeader(fieldConfig) {
190
- const normalized = normalizeHeaderText(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.text);
191
- return normalized === 'TAXAMOUNT';
192
- }
193
- function normalizeHeaderText(value) {
194
- return String(value !== null && value !== void 0 ? value : '')
195
- .replace(/\s+/g, '')
196
- .trim()
197
- .toUpperCase();
198
- }
199
- function formatCombinedTaxValue(item, kind, fixedTo) {
200
- const cgstField = kind === 'rate' ? 'CGSTPerc' : 'CGSTAmt';
201
- const sgstField = kind === 'rate' ? 'SGSTPerc' : 'SGSTAmt';
202
- const cgstValue = formatNumericLikeValue(getFirstFieldValue(item, [cgstField, 'CGST']), fixedTo);
203
- const sgstValue = formatNumericLikeValue(getFirstFieldValue(item, [sgstField, 'SGST']), fixedTo);
204
- if (cgstValue && sgstValue) {
205
- return `CGST: ${cgstValue} | SGST/UGST: ${sgstValue}`;
206
- }
207
- if (cgstValue) {
208
- return `CGST: ${cgstValue}`;
209
- }
210
- if (sgstValue) {
211
- return `SGST/UGST: ${sgstValue}`;
212
- }
213
- return '';
214
- }
@@ -186,10 +186,10 @@ function buildFallbackDataRow(item, index, fallbackHeaderRow, fixedTo) {
186
186
  const value = String(index + 1);
187
187
  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) };
188
188
  }
189
- const mainValue = formatFallbackFieldValue(item, header, fixedTo);
189
+ const mainValue = formatNumericLikeValue((0, pdf_table_row_1.getFirstFieldValue)(item, header.dbFields), fixedTo);
190
190
  const stackedLines = ((_a = header.stackFields) !== null && _a !== void 0 ? _a : [])
191
191
  .map((stackField) => {
192
- const stackValue = formatFallbackFieldValue(item, stackField, fixedTo);
192
+ const stackValue = formatNumericLikeValue((0, pdf_table_row_1.getFirstFieldValue)(item, stackField.dbFields), fixedTo);
193
193
  if (!stackValue) {
194
194
  return null;
195
195
  }
@@ -315,40 +315,3 @@ function formatNumericLikeValue(value, fixedTo) {
315
315
  }
316
316
  return normalized.toFixed(fixedTo);
317
317
  }
318
- function formatFallbackFieldValue(item, fieldConfig, fixedTo) {
319
- if (isTaxPercentHeader(fieldConfig)) {
320
- return formatCombinedTaxValue(item, 'rate', fixedTo);
321
- }
322
- if (isTaxAmountHeader(fieldConfig)) {
323
- return formatCombinedTaxValue(item, 'amount', fixedTo);
324
- }
325
- return formatNumericLikeValue((0, pdf_table_row_1.getFirstFieldValue)(item, fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.dbFields), fixedTo);
326
- }
327
- function isTaxPercentHeader(fieldConfig) {
328
- return normalizeHeaderText(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.text) === 'TAX%';
329
- }
330
- function isTaxAmountHeader(fieldConfig) {
331
- return normalizeHeaderText(fieldConfig === null || fieldConfig === void 0 ? void 0 : fieldConfig.text) === 'TAXAMOUNT';
332
- }
333
- function normalizeHeaderText(value) {
334
- return String(value !== null && value !== void 0 ? value : '')
335
- .replace(/\s+/g, '')
336
- .trim()
337
- .toUpperCase();
338
- }
339
- function formatCombinedTaxValue(item, kind, fixedTo) {
340
- const cgstField = kind === 'rate' ? 'CGSTPerc' : 'CGSTAmt';
341
- const sgstField = kind === 'rate' ? 'SGSTPerc' : 'SGSTAmt';
342
- const cgstValue = formatNumericLikeValue((0, pdf_table_row_1.getFirstFieldValue)(item, [cgstField, 'CGST']), fixedTo);
343
- const sgstValue = formatNumericLikeValue((0, pdf_table_row_1.getFirstFieldValue)(item, [sgstField, 'SGST']), fixedTo);
344
- if (cgstValue && sgstValue) {
345
- return `CGST: ${cgstValue} | SGST/UGST: ${sgstValue}`;
346
- }
347
- if (cgstValue) {
348
- return `CGST: ${cgstValue}`;
349
- }
350
- if (sgstValue) {
351
- return `SGST/UGST: ${sgstValue}`;
352
- }
353
- return '';
354
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareneus",
3
- "version": "1.5.92",
3
+ "version": "1.5.94",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",