shareneus 1.7.339 → 1.7.341

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.
@@ -37,6 +37,7 @@ export declare class TransactionCalculationEngine {
37
37
  qty: number;
38
38
  total: number;
39
39
  disc: number;
40
+ perc?: string;
40
41
  recDisc: number;
41
42
  noDisc: boolean;
42
43
  taxRows: unknown;
@@ -71,7 +71,6 @@ function getReverseTaxBreakdown(taxes, qty) {
71
71
  var _a, _b, _c;
72
72
  const calcMethod = normalizeCalcMethod((_a = row === null || row === void 0 ? void 0 : row.CalcMethod) !== null && _a !== void 0 ? _a : row === null || row === void 0 ? void 0 : row.calcMethod);
73
73
  const rate = toNum((_b = row === null || row === void 0 ? void 0 : row.Rate) !== null && _b !== void 0 ? _b : row === null || row === void 0 ? void 0 : row.rate);
74
- console.log('Reverse tax row', { row, calcMethod, rate, qty });
75
74
  switch (calcMethod) {
76
75
  case 'PerUnit':
77
76
  summary.fixedTaxAmount = (0, math_operations_1.Add)(summary.fixedTaxAmount, getPerUnitTaxAmount(row, qty));
@@ -170,7 +169,6 @@ class TransactionCalculationEngine {
170
169
  return total;
171
170
  }
172
171
  const taxBreakdown = getReverseTaxBreakdown(input.taxRows, toNum(input.qty) || 1);
173
- console.log('Reverse tax breakdown', taxBreakdown);
174
172
  const totalAfterFixedTax = (0, math_operations_1.Subtract)(total, taxBreakdown.fixedTaxAmount);
175
173
  if (taxBreakdown.percentTaxRate) {
176
174
  const divisor = (0, math_operations_1.Add)(1, (0, math_operations_1.Divide)(taxBreakdown.percentTaxRate, 100));
@@ -187,10 +185,21 @@ class TransactionCalculationEngine {
187
185
  qty,
188
186
  });
189
187
  const disc = toNum(input.disc);
188
+ const perc = toNum(input.perc);
190
189
  const recDisc = toNum(input.recDisc);
191
- const amount = input.noDisc
192
- ? subtotal
193
- : (0, math_operations_1.Add)(subtotal, (0, math_operations_1.Add)(disc, recDisc));
190
+ let amount = subtotal;
191
+ if (!input.noDisc) {
192
+ if (!isNullOrEmpty(input.perc) && perc !== 0) {
193
+ const discountRate = (0, math_operations_1.Divide)(perc, 100);
194
+ const priceFactor = (0, math_operations_1.Subtract)(1, discountRate);
195
+ amount = priceFactor === 0
196
+ ? subtotal
197
+ : (0, math_operations_1.Divide)((0, math_operations_1.Add)(subtotal, recDisc), priceFactor);
198
+ }
199
+ else {
200
+ amount = (0, math_operations_1.Add)(subtotal, (0, math_operations_1.Add)(disc, recDisc));
201
+ }
202
+ }
194
203
  const unitPrice = (0, math_operations_1.Divide)(amount, qty);
195
204
  return { amount, unitPrice };
196
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shareneus",
3
- "version": "1.7.339",
3
+ "version": "1.7.341",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -106,7 +106,7 @@ function getReverseTaxBreakdown(taxes: any, qty: number): {
106
106
  (summary, row) => {
107
107
  const calcMethod = normalizeCalcMethod(row?.CalcMethod ?? row?.calcMethod);
108
108
  const rate = toNum(row?.Rate ?? row?.rate);
109
- console.log('Reverse tax row', { row, calcMethod, rate, qty });
109
+
110
110
  switch (calcMethod) {
111
111
  case 'PerUnit':
112
112
  summary.fixedTaxAmount = Add(
@@ -243,7 +243,6 @@ export class TransactionCalculationEngine {
243
243
  input.taxRows,
244
244
  toNum(input.qty) || 1,
245
245
  );
246
- console.log('Reverse tax breakdown', taxBreakdown);
247
246
  const totalAfterFixedTax = Subtract(total, taxBreakdown.fixedTaxAmount);
248
247
 
249
248
  if (taxBreakdown.percentTaxRate) {
@@ -254,14 +253,15 @@ export class TransactionCalculationEngine {
254
253
  return totalAfterFixedTax;
255
254
  }
256
255
 
257
- static reverseCalculateAmountAndUnitPriceFromTotal(input: {
258
- qty: number;
259
- total: number;
260
- disc: number;
261
- recDisc: number;
262
- noDisc: boolean;
263
- taxRows: unknown;
264
- includeTaxInTotal: boolean;
256
+ static reverseCalculateAmountAndUnitPriceFromTotal(input: {
257
+ qty: number;
258
+ total: number;
259
+ disc: number;
260
+ perc?: string;
261
+ recDisc: number;
262
+ noDisc: boolean;
263
+ taxRows: unknown;
264
+ includeTaxInTotal: boolean;
265
265
  }): { amount: number; unitPrice: number } {
266
266
  const qty = toNum(input.qty) || 1;
267
267
  const subtotal =
@@ -271,16 +271,28 @@ export class TransactionCalculationEngine {
271
271
  includeTaxInTotal: input.includeTaxInTotal,
272
272
  qty,
273
273
  });
274
-
275
- const disc = toNum(input.disc);
276
- const recDisc = toNum(input.recDisc);
277
- const amount = input.noDisc
278
- ? subtotal
279
- : Add(subtotal, Add(disc, recDisc));
280
- const unitPrice = Divide(amount, qty);
281
-
282
- return { amount, unitPrice };
283
- }
274
+
275
+ const disc = toNum(input.disc);
276
+ const perc = toNum(input.perc);
277
+ const recDisc = toNum(input.recDisc);
278
+ let amount = subtotal;
279
+
280
+ if (!input.noDisc) {
281
+ if (!isNullOrEmpty(input.perc) && perc !== 0) {
282
+ const discountRate = Divide(perc, 100);
283
+ const priceFactor = Subtract(1, discountRate);
284
+ amount = priceFactor === 0
285
+ ? subtotal
286
+ : Divide(Add(subtotal, recDisc), priceFactor);
287
+ } else {
288
+ amount = Add(subtotal, Add(disc, recDisc));
289
+ }
290
+ }
291
+
292
+ const unitPrice = Divide(amount, qty);
293
+
294
+ return { amount, unitPrice };
295
+ }
284
296
 
285
297
  // Shared reverse-calculation formula. Components only need to supply their own field mapping.
286
298
  static calculatePriceFromTotal(input: ReverseCalculationInput): number {