@qrwise/pos-calculations 0.0.21 → 0.0.22
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 +6 -3
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +6 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -448,7 +448,9 @@ 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
|
|
451
|
+
const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
|
|
452
|
+
const fullyDiscountedCancellationNet = !isSuccessful && storedNetOfVat === 0 && toMoneyNumber(transaction.amount_payable) === 0 && gross > 0 && options.isVatRegistered !== void 0 ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
|
|
453
|
+
const netOfVat = storedNetOfVat || fullyDiscountedCancellationNet || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
|
|
452
454
|
const returned = state === "RETURNED" ? -format2(netOfVat) : 0;
|
|
453
455
|
const cancelled = state === "CANCELLED" ? -format2(netOfVat) : 0;
|
|
454
456
|
const { counts, discountWeights, vatExemptWeights } = discountAllocation(transaction, options);
|
|
@@ -486,9 +488,10 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
486
488
|
};
|
|
487
489
|
const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
488
490
|
let vatAmount = format2(
|
|
489
|
-
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : netOfVat * 0.12
|
|
491
|
+
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : netOfVat * 0.12
|
|
490
492
|
);
|
|
491
|
-
|
|
493
|
+
const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
|
|
494
|
+
if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
|
|
492
495
|
vatAmount = format2(
|
|
493
496
|
storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
|
|
494
497
|
);
|
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,9 @@ 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
|
|
418
|
+
const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
|
|
419
|
+
const fullyDiscountedCancellationNet = !isSuccessful && storedNetOfVat === 0 && toMoneyNumber(transaction.amount_payable) === 0 && gross > 0 && options.isVatRegistered !== void 0 ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
|
|
420
|
+
const netOfVat = storedNetOfVat || fullyDiscountedCancellationNet || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
|
|
419
421
|
const returned = state === "RETURNED" ? -format2(netOfVat) : 0;
|
|
420
422
|
const cancelled = state === "CANCELLED" ? -format2(netOfVat) : 0;
|
|
421
423
|
const { counts, discountWeights, vatExemptWeights } = discountAllocation(transaction, options);
|
|
@@ -453,9 +455,10 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
453
455
|
};
|
|
454
456
|
const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
455
457
|
let vatAmount = format2(
|
|
456
|
-
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : netOfVat * 0.12
|
|
458
|
+
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : netOfVat * 0.12
|
|
457
459
|
);
|
|
458
|
-
|
|
460
|
+
const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
|
|
461
|
+
if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
|
|
459
462
|
vatAmount = format2(
|
|
460
463
|
storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
|
|
461
464
|
);
|