@qrwise/pos-calculations 0.0.21 → 0.0.23

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.
package/dist/index.cjs CHANGED
@@ -448,7 +448,10 @@ function buildTransactionProjection(transaction, options = {}) {
448
448
  const storedVatExemptSales = toMoneyNumber(transaction.vat_exempt_sales);
449
449
  const storedZeroRatedSales = toMoneyNumber(transaction.zero_rated_sales);
450
450
  const storedNonTaxableSales = toMoneyNumber(transaction.non_taxable_sales);
451
- const netOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
451
+ const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
452
+ const reconstructsFullyDiscountedCancellation = !isSuccessful && storedNetOfVat === 0 && toMoneyNumber(transaction.amount_payable) === 0 && gross > 0 && options.isVatRegistered !== void 0;
453
+ const fullyDiscountedCancellationNet = reconstructsFullyDiscountedCancellation ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
454
+ const netOfVat = storedNetOfVat || fullyDiscountedCancellationNet || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
452
455
  const returned = state === "RETURNED" ? -format2(netOfVat) : 0;
453
456
  const cancelled = state === "CANCELLED" ? -format2(netOfVat) : 0;
454
457
  const { counts, discountWeights, vatExemptWeights } = discountAllocation(transaction, options);
@@ -486,9 +489,10 @@ function buildTransactionProjection(transaction, options = {}) {
486
489
  };
487
490
  const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
488
491
  let vatAmount = format2(
489
- isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : netOfVat * 0.12
492
+ isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsFullyDiscountedCancellation ? gross - netOfVat : netOfVat * 0.12
490
493
  );
491
- if (hasVoucherAndDiscount) {
494
+ const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
495
+ if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
492
496
  vatAmount = format2(
493
497
  storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
494
498
  );
package/dist/index.d.cts CHANGED
@@ -138,6 +138,7 @@ interface FinancialTransactionInput {
138
138
  }
139
139
  interface TransactionProjectionOptions {
140
140
  discountRatesById?: Record<string, number>;
141
+ isVatRegistered?: boolean;
141
142
  }
142
143
  declare function buildTransactionProjection(transaction: FinancialTransactionInput, options?: TransactionProjectionOptions): {
143
144
  state: string;
package/dist/index.d.ts CHANGED
@@ -138,6 +138,7 @@ interface FinancialTransactionInput {
138
138
  }
139
139
  interface TransactionProjectionOptions {
140
140
  discountRatesById?: Record<string, number>;
141
+ isVatRegistered?: boolean;
141
142
  }
142
143
  declare function buildTransactionProjection(transaction: FinancialTransactionInput, options?: TransactionProjectionOptions): {
143
144
  state: string;
package/dist/index.js CHANGED
@@ -415,7 +415,10 @@ function buildTransactionProjection(transaction, options = {}) {
415
415
  const storedVatExemptSales = toMoneyNumber(transaction.vat_exempt_sales);
416
416
  const storedZeroRatedSales = toMoneyNumber(transaction.zero_rated_sales);
417
417
  const storedNonTaxableSales = toMoneyNumber(transaction.non_taxable_sales);
418
- const netOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
418
+ const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
419
+ const reconstructsFullyDiscountedCancellation = !isSuccessful && storedNetOfVat === 0 && toMoneyNumber(transaction.amount_payable) === 0 && gross > 0 && options.isVatRegistered !== void 0;
420
+ const fullyDiscountedCancellationNet = reconstructsFullyDiscountedCancellation ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
421
+ const netOfVat = storedNetOfVat || fullyDiscountedCancellationNet || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
419
422
  const returned = state === "RETURNED" ? -format2(netOfVat) : 0;
420
423
  const cancelled = state === "CANCELLED" ? -format2(netOfVat) : 0;
421
424
  const { counts, discountWeights, vatExemptWeights } = discountAllocation(transaction, options);
@@ -453,9 +456,10 @@ function buildTransactionProjection(transaction, options = {}) {
453
456
  };
454
457
  const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
455
458
  let vatAmount = format2(
456
- isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : netOfVat * 0.12
459
+ isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsFullyDiscountedCancellation ? gross - netOfVat : netOfVat * 0.12
457
460
  );
458
- if (hasVoucherAndDiscount) {
461
+ const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
462
+ if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
459
463
  vatAmount = format2(
460
464
  storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
461
465
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrwise/pos-calculations",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
4
4
  "description": "Shared POS calculations for QR Wise POS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",