@qrwise/pos-calculations 0.0.23 → 0.0.25
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 +5 -19
- package/dist/index.js +5 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -416,17 +416,6 @@ function voucherVatNet(transaction, voucher, discount) {
|
|
|
416
416
|
const eligibleGross = itemizedGross > 0 ? itemizedGross : percentageGross > 0 ? percentageGross : gross;
|
|
417
417
|
return format2(Math.min(gross, eligibleGross) / 1.12);
|
|
418
418
|
}
|
|
419
|
-
function itemizedVoucherCount(transaction) {
|
|
420
|
-
const splits = transaction.metadata?.split_discounts;
|
|
421
|
-
if (!Array.isArray(splits)) return 0;
|
|
422
|
-
return splits.reduce((count, rawSplit) => {
|
|
423
|
-
if (!rawSplit || typeof rawSplit !== "object") return count;
|
|
424
|
-
const rawVoucher = rawSplit.voucher;
|
|
425
|
-
if (!rawVoucher || typeof rawVoucher !== "object") return count;
|
|
426
|
-
const voucher = rawVoucher;
|
|
427
|
-
return Math.abs(toMoneyNumber(voucher.discount_amount)) > 0 ? count + 1 : count;
|
|
428
|
-
}, 0);
|
|
429
|
-
}
|
|
430
419
|
function buildTransactionProjection(transaction, options = {}) {
|
|
431
420
|
const status = `${transaction.status} ${transaction.payment_status}`.toLowerCase();
|
|
432
421
|
const state = status.includes("refund") || status.includes("return") ? "RETURNED" : status.includes("cancel") || status.includes("void") ? "CANCELLED" : "SUCCESS";
|
|
@@ -434,13 +423,10 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
434
423
|
const gross = toMoneyNumber(transaction.gross_amount);
|
|
435
424
|
const discount = Math.abs(toMoneyNumber(transaction.discount_amount));
|
|
436
425
|
const voucher = Math.abs(toMoneyNumber(transaction.voucher_discount_amount));
|
|
437
|
-
const voucherRate = toMoneyNumber(transaction.voucher_rate);
|
|
438
426
|
const hasVoucher = voucher > 0;
|
|
439
427
|
const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
|
|
440
428
|
const scopedVoucherVatNet = voucherVatNet(transaction, voucher, discount);
|
|
441
|
-
const voucherForBirDiscount =
|
|
442
|
-
transaction.voucher_type?.toLowerCase() === "fixed" ? scopedVoucherVatNet - format2(voucherRate) : scopedVoucherVatNet * format2(voucherRate / 100)
|
|
443
|
-
);
|
|
429
|
+
const voucherForBirDiscount = -format2(voucher / 1.12);
|
|
444
430
|
const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
|
|
445
431
|
const otherDiscountAdjustment = -format2(Math.abs(otherDiscount * 0.12));
|
|
446
432
|
const storedVat = Math.abs(toMoneyNumber(transaction.vat_amount));
|
|
@@ -449,9 +435,9 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
449
435
|
const storedZeroRatedSales = toMoneyNumber(transaction.zero_rated_sales);
|
|
450
436
|
const storedNonTaxableSales = toMoneyNumber(transaction.non_taxable_sales);
|
|
451
437
|
const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
|
|
452
|
-
const
|
|
453
|
-
const
|
|
454
|
-
const netOfVat =
|
|
438
|
+
const reconstructsVoidedVoucherSale = !isSuccessful && hasVoucher && gross > 0 && options.isVatRegistered !== void 0;
|
|
439
|
+
const voidedVoucherNet = reconstructsVoidedVoucherSale ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
|
|
440
|
+
const netOfVat = voidedVoucherNet || storedNetOfVat || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
|
|
455
441
|
const returned = state === "RETURNED" ? -format2(netOfVat) : 0;
|
|
456
442
|
const cancelled = state === "CANCELLED" ? -format2(netOfVat) : 0;
|
|
457
443
|
const { counts, discountWeights, vatExemptWeights } = discountAllocation(transaction, options);
|
|
@@ -489,7 +475,7 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
489
475
|
};
|
|
490
476
|
const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
491
477
|
let vatAmount = format2(
|
|
492
|
-
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 :
|
|
478
|
+
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsVoidedVoucherSale ? gross - netOfVat : netOfVat * 0.12
|
|
493
479
|
);
|
|
494
480
|
const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
|
|
495
481
|
if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
|
package/dist/index.js
CHANGED
|
@@ -383,17 +383,6 @@ function voucherVatNet(transaction, voucher, discount) {
|
|
|
383
383
|
const eligibleGross = itemizedGross > 0 ? itemizedGross : percentageGross > 0 ? percentageGross : gross;
|
|
384
384
|
return format2(Math.min(gross, eligibleGross) / 1.12);
|
|
385
385
|
}
|
|
386
|
-
function itemizedVoucherCount(transaction) {
|
|
387
|
-
const splits = transaction.metadata?.split_discounts;
|
|
388
|
-
if (!Array.isArray(splits)) return 0;
|
|
389
|
-
return splits.reduce((count, rawSplit) => {
|
|
390
|
-
if (!rawSplit || typeof rawSplit !== "object") return count;
|
|
391
|
-
const rawVoucher = rawSplit.voucher;
|
|
392
|
-
if (!rawVoucher || typeof rawVoucher !== "object") return count;
|
|
393
|
-
const voucher = rawVoucher;
|
|
394
|
-
return Math.abs(toMoneyNumber(voucher.discount_amount)) > 0 ? count + 1 : count;
|
|
395
|
-
}, 0);
|
|
396
|
-
}
|
|
397
386
|
function buildTransactionProjection(transaction, options = {}) {
|
|
398
387
|
const status = `${transaction.status} ${transaction.payment_status}`.toLowerCase();
|
|
399
388
|
const state = status.includes("refund") || status.includes("return") ? "RETURNED" : status.includes("cancel") || status.includes("void") ? "CANCELLED" : "SUCCESS";
|
|
@@ -401,13 +390,10 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
401
390
|
const gross = toMoneyNumber(transaction.gross_amount);
|
|
402
391
|
const discount = Math.abs(toMoneyNumber(transaction.discount_amount));
|
|
403
392
|
const voucher = Math.abs(toMoneyNumber(transaction.voucher_discount_amount));
|
|
404
|
-
const voucherRate = toMoneyNumber(transaction.voucher_rate);
|
|
405
393
|
const hasVoucher = voucher > 0;
|
|
406
394
|
const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
|
|
407
395
|
const scopedVoucherVatNet = voucherVatNet(transaction, voucher, discount);
|
|
408
|
-
const voucherForBirDiscount =
|
|
409
|
-
transaction.voucher_type?.toLowerCase() === "fixed" ? scopedVoucherVatNet - format2(voucherRate) : scopedVoucherVatNet * format2(voucherRate / 100)
|
|
410
|
-
);
|
|
396
|
+
const voucherForBirDiscount = -format2(voucher / 1.12);
|
|
411
397
|
const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
|
|
412
398
|
const otherDiscountAdjustment = -format2(Math.abs(otherDiscount * 0.12));
|
|
413
399
|
const storedVat = Math.abs(toMoneyNumber(transaction.vat_amount));
|
|
@@ -416,9 +402,9 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
416
402
|
const storedZeroRatedSales = toMoneyNumber(transaction.zero_rated_sales);
|
|
417
403
|
const storedNonTaxableSales = toMoneyNumber(transaction.non_taxable_sales);
|
|
418
404
|
const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
|
|
419
|
-
const
|
|
420
|
-
const
|
|
421
|
-
const netOfVat =
|
|
405
|
+
const reconstructsVoidedVoucherSale = !isSuccessful && hasVoucher && gross > 0 && options.isVatRegistered !== void 0;
|
|
406
|
+
const voidedVoucherNet = reconstructsVoidedVoucherSale ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
|
|
407
|
+
const netOfVat = voidedVoucherNet || storedNetOfVat || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
|
|
422
408
|
const returned = state === "RETURNED" ? -format2(netOfVat) : 0;
|
|
423
409
|
const cancelled = state === "CANCELLED" ? -format2(netOfVat) : 0;
|
|
424
410
|
const { counts, discountWeights, vatExemptWeights } = discountAllocation(transaction, options);
|
|
@@ -456,7 +442,7 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
456
442
|
};
|
|
457
443
|
const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
458
444
|
let vatAmount = format2(
|
|
459
|
-
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 :
|
|
445
|
+
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsVoidedVoucherSale ? gross - netOfVat : netOfVat * 0.12
|
|
460
446
|
);
|
|
461
447
|
const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
|
|
462
448
|
if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
|