@qrwise/pos-calculations 0.0.24 → 0.0.26
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 +11 -24
- package/dist/index.js +11 -24
- 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,15 +423,13 @@ 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
|
|
426
|
+
const isNonVat = options.isVatRegistered === false;
|
|
438
427
|
const hasVoucher = voucher > 0;
|
|
439
428
|
const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
|
|
440
|
-
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 scopedVoucherVatNet = isNonVat ? 0 : voucherVatNet(transaction, voucher, discount);
|
|
430
|
+
const voucherForBirDiscount = -format2(isNonVat ? voucher : voucher / 1.12);
|
|
444
431
|
const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
|
|
445
|
-
const otherDiscountAdjustment = -format2(Math.abs(otherDiscount * 0.12));
|
|
432
|
+
const otherDiscountAdjustment = isNonVat ? 0 : -format2(Math.abs(otherDiscount * 0.12));
|
|
446
433
|
const storedVat = Math.abs(toMoneyNumber(transaction.vat_amount));
|
|
447
434
|
const storedVatSales = toMoneyNumber(transaction.vat_sales);
|
|
448
435
|
const storedVatExemptSales = toMoneyNumber(transaction.vat_exempt_sales);
|
|
@@ -468,8 +455,8 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
468
455
|
totalDeductions: 0
|
|
469
456
|
};
|
|
470
457
|
deductions.totalDeductions = Object.values(deductions).reduce((total, amount) => total + amount, 0);
|
|
471
|
-
const vatExemptSales = isSuccessful ? storedVatExemptSales : 0;
|
|
472
|
-
const allocatedVatAdjustment = allocate(vatExemptSales * 0.12, {
|
|
458
|
+
const vatExemptSales = isSuccessful ? isNonVat ? format2(storedVatSales + storedVatExemptSales + storedNonTaxableSales + voucher) : storedVatExemptSales : 0;
|
|
459
|
+
const allocatedVatAdjustment = allocate((isNonVat ? 0 : vatExemptSales) * 0.12, {
|
|
473
460
|
...vatExemptWeights ?? counts,
|
|
474
461
|
naac: 0,
|
|
475
462
|
solo: 0,
|
|
@@ -487,12 +474,12 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
487
474
|
others: 0,
|
|
488
475
|
totalAdjustments: 0
|
|
489
476
|
};
|
|
490
|
-
const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
477
|
+
const regularVat = isNonVat ? 0 : storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
491
478
|
let vatAmount = format2(
|
|
492
|
-
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsVoidedVoucherSale ? gross - netOfVat : netOfVat * 0.12
|
|
479
|
+
isSuccessful ? isNonVat ? 0 : voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsVoidedVoucherSale ? gross - netOfVat : netOfVat * 0.12
|
|
493
480
|
);
|
|
494
481
|
const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
|
|
495
|
-
if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
|
|
482
|
+
if (!isNonVat && (hasVoucherAndDiscount || hasMixedStatutoryTax)) {
|
|
496
483
|
vatAmount = format2(
|
|
497
484
|
storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
|
|
498
485
|
);
|
|
@@ -500,10 +487,10 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
500
487
|
adjustments.vatOnReturns = returned ? -vatAmount : 0;
|
|
501
488
|
adjustments.vatOnCancelled = cancelled ? -vatAmount : 0;
|
|
502
489
|
adjustments.totalAdjustments = Object.values(adjustments).reduce((total, amount) => total + amount, 0);
|
|
503
|
-
const vatableSales = isSuccessful ? hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : netOfVat;
|
|
490
|
+
const vatableSales = isSuccessful ? isNonVat ? 0 : hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : netOfVat;
|
|
504
491
|
const zeroRatedSales = isSuccessful ? storedZeroRatedSales : 0;
|
|
505
492
|
const netSales = isSuccessful ? format2(
|
|
506
|
-
vatableSales + vatExemptSales + zeroRatedSales + storedNonTaxableSales + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
|
|
493
|
+
vatableSales + vatExemptSales + zeroRatedSales + (isNonVat ? 0 : storedNonTaxableSales) + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
|
|
507
494
|
) : 0;
|
|
508
495
|
const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
|
|
509
496
|
return {
|
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,15 +390,13 @@ 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
|
|
393
|
+
const isNonVat = options.isVatRegistered === false;
|
|
405
394
|
const hasVoucher = voucher > 0;
|
|
406
395
|
const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
|
|
407
|
-
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 scopedVoucherVatNet = isNonVat ? 0 : voucherVatNet(transaction, voucher, discount);
|
|
397
|
+
const voucherForBirDiscount = -format2(isNonVat ? voucher : voucher / 1.12);
|
|
411
398
|
const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
|
|
412
|
-
const otherDiscountAdjustment = -format2(Math.abs(otherDiscount * 0.12));
|
|
399
|
+
const otherDiscountAdjustment = isNonVat ? 0 : -format2(Math.abs(otherDiscount * 0.12));
|
|
413
400
|
const storedVat = Math.abs(toMoneyNumber(transaction.vat_amount));
|
|
414
401
|
const storedVatSales = toMoneyNumber(transaction.vat_sales);
|
|
415
402
|
const storedVatExemptSales = toMoneyNumber(transaction.vat_exempt_sales);
|
|
@@ -435,8 +422,8 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
435
422
|
totalDeductions: 0
|
|
436
423
|
};
|
|
437
424
|
deductions.totalDeductions = Object.values(deductions).reduce((total, amount) => total + amount, 0);
|
|
438
|
-
const vatExemptSales = isSuccessful ? storedVatExemptSales : 0;
|
|
439
|
-
const allocatedVatAdjustment = allocate(vatExemptSales * 0.12, {
|
|
425
|
+
const vatExemptSales = isSuccessful ? isNonVat ? format2(storedVatSales + storedVatExemptSales + storedNonTaxableSales + voucher) : storedVatExemptSales : 0;
|
|
426
|
+
const allocatedVatAdjustment = allocate((isNonVat ? 0 : vatExemptSales) * 0.12, {
|
|
440
427
|
...vatExemptWeights ?? counts,
|
|
441
428
|
naac: 0,
|
|
442
429
|
solo: 0,
|
|
@@ -454,12 +441,12 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
454
441
|
others: 0,
|
|
455
442
|
totalAdjustments: 0
|
|
456
443
|
};
|
|
457
|
-
const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
444
|
+
const regularVat = isNonVat ? 0 : storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
|
|
458
445
|
let vatAmount = format2(
|
|
459
|
-
isSuccessful ? voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsVoidedVoucherSale ? gross - netOfVat : netOfVat * 0.12
|
|
446
|
+
isSuccessful ? isNonVat ? 0 : voucher > 0 ? Math.abs(scopedVoucherVatNet * 0.12) : regularVat : options.isVatRegistered === false ? 0 : reconstructsVoidedVoucherSale ? gross - netOfVat : netOfVat * 0.12
|
|
460
447
|
);
|
|
461
448
|
const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
|
|
462
|
-
if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
|
|
449
|
+
if (!isNonVat && (hasVoucherAndDiscount || hasMixedStatutoryTax)) {
|
|
463
450
|
vatAmount = format2(
|
|
464
451
|
storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
|
|
465
452
|
);
|
|
@@ -467,10 +454,10 @@ function buildTransactionProjection(transaction, options = {}) {
|
|
|
467
454
|
adjustments.vatOnReturns = returned ? -vatAmount : 0;
|
|
468
455
|
adjustments.vatOnCancelled = cancelled ? -vatAmount : 0;
|
|
469
456
|
adjustments.totalAdjustments = Object.values(adjustments).reduce((total, amount) => total + amount, 0);
|
|
470
|
-
const vatableSales = isSuccessful ? hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : netOfVat;
|
|
457
|
+
const vatableSales = isSuccessful ? isNonVat ? 0 : hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : netOfVat;
|
|
471
458
|
const zeroRatedSales = isSuccessful ? storedZeroRatedSales : 0;
|
|
472
459
|
const netSales = isSuccessful ? format2(
|
|
473
|
-
vatableSales + vatExemptSales + zeroRatedSales + storedNonTaxableSales + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
|
|
460
|
+
vatableSales + vatExemptSales + zeroRatedSales + (isNonVat ? 0 : storedNonTaxableSales) + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
|
|
474
461
|
) : 0;
|
|
475
462
|
const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
|
|
476
463
|
return {
|