@qrwise/pos-calculations 0.0.27 → 0.0.28

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
@@ -436,6 +436,7 @@ function buildTransactionProjection(transaction, options = {}) {
436
436
  const storedZeroRatedSales = toMoneyNumber(transaction.zero_rated_sales);
437
437
  const storedNonTaxableSales = toMoneyNumber(transaction.non_taxable_sales);
438
438
  const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
439
+ const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
439
440
  const reconstructsVoidedVoucherSale = !isSuccessful && hasVoucher && gross > 0 && options.isVatRegistered !== void 0;
440
441
  const voidedVoucherNet = reconstructsVoidedVoucherSale ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
441
442
  const netOfVat = voidedVoucherNet || storedNetOfVat || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
@@ -487,12 +488,25 @@ function buildTransactionProjection(transaction, options = {}) {
487
488
  adjustments.vatOnReturns = returned ? -vatAmount : 0;
488
489
  adjustments.vatOnCancelled = cancelled ? -vatAmount : 0;
489
490
  adjustments.totalAdjustments = Object.values(adjustments).reduce((total, amount) => total + amount, 0);
490
- const vatableSales = isSuccessful ? isNonVat ? 0 : hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : isNonVat ? 0 : netOfVat;
491
+ let vatableSales = isSuccessful ? isNonVat ? 0 : hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : isNonVat ? 0 : netOfVat;
492
+ const projectedGross = format2(vatableSales + vatAmount + vatExemptSales + storedZeroRatedSales);
493
+ const unclassifiedDiscountGross = format2(gross - projectedGross);
494
+ const storedComponentPayable = format2(storedNetOfVat + storedVat - discount + serviceCharge);
495
+ const hasHistoricalUnclassifiedDiscount = isSuccessful && !isNonVat && !hasVoucher && storedNonTaxableSales === 0 && unclassifiedDiscountGross > 0.02 && Math.abs(format2(toMoneyNumber(transaction.amount_payable) - storedComponentPayable)) <= 0.02;
496
+ if (hasHistoricalUnclassifiedDiscount) {
497
+ const inferredDiscountNet = format2(unclassifiedDiscountGross / 1.12);
498
+ const inferredDiscountVat = format2(unclassifiedDiscountGross - inferredDiscountNet);
499
+ vatableSales = format2(vatableSales + inferredDiscountNet);
500
+ vatAmount = format2(vatAmount + inferredDiscountVat);
501
+ deductions.otherDiscount = -inferredDiscountNet;
502
+ deductions.totalDeductions = format2(deductions.totalDeductions - inferredDiscountNet);
503
+ adjustments.otherDiscountAdjustment = -inferredDiscountVat;
504
+ adjustments.totalAdjustments = format2(adjustments.totalAdjustments - inferredDiscountVat);
505
+ }
491
506
  const zeroRatedSales = isSuccessful ? storedZeroRatedSales : 0;
492
507
  const netSales = isSuccessful ? format2(
493
508
  vatableSales + vatExemptSales + zeroRatedSales + (isNonVat ? 0 : storedNonTaxableSales) + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
494
509
  ) : 0;
495
- const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
496
510
  return {
497
511
  state,
498
512
  receipt: {
package/dist/index.js CHANGED
@@ -403,6 +403,7 @@ function buildTransactionProjection(transaction, options = {}) {
403
403
  const storedZeroRatedSales = toMoneyNumber(transaction.zero_rated_sales);
404
404
  const storedNonTaxableSales = toMoneyNumber(transaction.non_taxable_sales);
405
405
  const storedNetOfVat = storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales;
406
+ const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
406
407
  const reconstructsVoidedVoucherSale = !isSuccessful && hasVoucher && gross > 0 && options.isVatRegistered !== void 0;
407
408
  const voidedVoucherNet = reconstructsVoidedVoucherSale ? format2(gross / (options.isVatRegistered ? 1.12 : 1)) : 0;
408
409
  const netOfVat = voidedVoucherNet || storedNetOfVat || Math.max(0, toMoneyNumber(transaction.amount_payable) - storedVat);
@@ -454,12 +455,25 @@ function buildTransactionProjection(transaction, options = {}) {
454
455
  adjustments.vatOnReturns = returned ? -vatAmount : 0;
455
456
  adjustments.vatOnCancelled = cancelled ? -vatAmount : 0;
456
457
  adjustments.totalAdjustments = Object.values(adjustments).reduce((total, amount) => total + amount, 0);
457
- const vatableSales = isSuccessful ? isNonVat ? 0 : hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : isNonVat ? 0 : netOfVat;
458
+ let vatableSales = isSuccessful ? isNonVat ? 0 : hasVoucherAndDiscount ? format2(storedVatSales + Math.abs(otherDiscount)) : voucher > 0 ? scopedVoucherVatNet : storedVatSales : isNonVat ? 0 : netOfVat;
459
+ const projectedGross = format2(vatableSales + vatAmount + vatExemptSales + storedZeroRatedSales);
460
+ const unclassifiedDiscountGross = format2(gross - projectedGross);
461
+ const storedComponentPayable = format2(storedNetOfVat + storedVat - discount + serviceCharge);
462
+ const hasHistoricalUnclassifiedDiscount = isSuccessful && !isNonVat && !hasVoucher && storedNonTaxableSales === 0 && unclassifiedDiscountGross > 0.02 && Math.abs(format2(toMoneyNumber(transaction.amount_payable) - storedComponentPayable)) <= 0.02;
463
+ if (hasHistoricalUnclassifiedDiscount) {
464
+ const inferredDiscountNet = format2(unclassifiedDiscountGross / 1.12);
465
+ const inferredDiscountVat = format2(unclassifiedDiscountGross - inferredDiscountNet);
466
+ vatableSales = format2(vatableSales + inferredDiscountNet);
467
+ vatAmount = format2(vatAmount + inferredDiscountVat);
468
+ deductions.otherDiscount = -inferredDiscountNet;
469
+ deductions.totalDeductions = format2(deductions.totalDeductions - inferredDiscountNet);
470
+ adjustments.otherDiscountAdjustment = -inferredDiscountVat;
471
+ adjustments.totalAdjustments = format2(adjustments.totalAdjustments - inferredDiscountVat);
472
+ }
458
473
  const zeroRatedSales = isSuccessful ? storedZeroRatedSales : 0;
459
474
  const netSales = isSuccessful ? format2(
460
475
  vatableSales + vatExemptSales + zeroRatedSales + (isNonVat ? 0 : storedNonTaxableSales) + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
461
476
  ) : 0;
462
- const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
463
477
  return {
464
478
  state,
465
479
  receipt: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrwise/pos-calculations",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "Shared POS calculations for QR Wise POS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",