@qrwise/pos-calculations 0.0.25 → 0.0.27

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
@@ -423,12 +423,13 @@ function buildTransactionProjection(transaction, options = {}) {
423
423
  const gross = toMoneyNumber(transaction.gross_amount);
424
424
  const discount = Math.abs(toMoneyNumber(transaction.discount_amount));
425
425
  const voucher = Math.abs(toMoneyNumber(transaction.voucher_discount_amount));
426
+ const isNonVat = options.isVatRegistered === false;
426
427
  const hasVoucher = voucher > 0;
427
428
  const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
428
- const scopedVoucherVatNet = voucherVatNet(transaction, voucher, discount);
429
- const voucherForBirDiscount = -format2(voucher / 1.12);
429
+ const scopedVoucherVatNet = isNonVat ? 0 : voucherVatNet(transaction, voucher, discount);
430
+ const voucherForBirDiscount = -format2(isNonVat ? voucher : voucher / 1.12);
430
431
  const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
431
- const otherDiscountAdjustment = -format2(Math.abs(otherDiscount * 0.12));
432
+ const otherDiscountAdjustment = isNonVat ? 0 : -format2(Math.abs(otherDiscount * 0.12));
432
433
  const storedVat = Math.abs(toMoneyNumber(transaction.vat_amount));
433
434
  const storedVatSales = toMoneyNumber(transaction.vat_sales);
434
435
  const storedVatExemptSales = toMoneyNumber(transaction.vat_exempt_sales);
@@ -454,8 +455,8 @@ function buildTransactionProjection(transaction, options = {}) {
454
455
  totalDeductions: 0
455
456
  };
456
457
  deductions.totalDeductions = Object.values(deductions).reduce((total, amount) => total + amount, 0);
457
- const vatExemptSales = isSuccessful ? storedVatExemptSales : 0;
458
- const allocatedVatAdjustment = allocate(vatExemptSales * 0.12, {
458
+ const vatExemptSales = isSuccessful ? isNonVat ? format2(storedVatSales + storedVatExemptSales + storedNonTaxableSales + voucher) : storedVatExemptSales : isNonVat ? netOfVat : 0;
459
+ const allocatedVatAdjustment = allocate((isNonVat ? 0 : vatExemptSales) * 0.12, {
459
460
  ...vatExemptWeights ?? counts,
460
461
  naac: 0,
461
462
  solo: 0,
@@ -473,12 +474,12 @@ function buildTransactionProjection(transaction, options = {}) {
473
474
  others: 0,
474
475
  totalAdjustments: 0
475
476
  };
476
- const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
477
+ const regularVat = isNonVat ? 0 : storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
477
478
  let vatAmount = format2(
478
- 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
479
480
  );
480
481
  const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
481
- if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
482
+ if (!isNonVat && (hasVoucherAndDiscount || hasMixedStatutoryTax)) {
482
483
  vatAmount = format2(
483
484
  storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
484
485
  );
@@ -486,10 +487,10 @@ function buildTransactionProjection(transaction, options = {}) {
486
487
  adjustments.vatOnReturns = returned ? -vatAmount : 0;
487
488
  adjustments.vatOnCancelled = cancelled ? -vatAmount : 0;
488
489
  adjustments.totalAdjustments = Object.values(adjustments).reduce((total, amount) => total + amount, 0);
489
- 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 : isNonVat ? 0 : netOfVat;
490
491
  const zeroRatedSales = isSuccessful ? storedZeroRatedSales : 0;
491
492
  const netSales = isSuccessful ? format2(
492
- 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
493
494
  ) : 0;
494
495
  const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
495
496
  return {
package/dist/index.d.cts CHANGED
@@ -122,6 +122,7 @@ interface FinancialTransactionInput {
122
122
  discount_id?: string | null;
123
123
  discount_name?: string | null;
124
124
  discount_rate?: number | string | null;
125
+ discount_rate_type?: "percentage" | "fixed" | string | null;
125
126
  }> | null;
126
127
  transaction_items?: Array<{
127
128
  id?: string;
package/dist/index.d.ts CHANGED
@@ -122,6 +122,7 @@ interface FinancialTransactionInput {
122
122
  discount_id?: string | null;
123
123
  discount_name?: string | null;
124
124
  discount_rate?: number | string | null;
125
+ discount_rate_type?: "percentage" | "fixed" | string | null;
125
126
  }> | null;
126
127
  transaction_items?: Array<{
127
128
  id?: string;
package/dist/index.js CHANGED
@@ -390,12 +390,13 @@ function buildTransactionProjection(transaction, options = {}) {
390
390
  const gross = toMoneyNumber(transaction.gross_amount);
391
391
  const discount = Math.abs(toMoneyNumber(transaction.discount_amount));
392
392
  const voucher = Math.abs(toMoneyNumber(transaction.voucher_discount_amount));
393
+ const isNonVat = options.isVatRegistered === false;
393
394
  const hasVoucher = voucher > 0;
394
395
  const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
395
- const scopedVoucherVatNet = voucherVatNet(transaction, voucher, discount);
396
- const voucherForBirDiscount = -format2(voucher / 1.12);
396
+ const scopedVoucherVatNet = isNonVat ? 0 : voucherVatNet(transaction, voucher, discount);
397
+ const voucherForBirDiscount = -format2(isNonVat ? voucher : voucher / 1.12);
397
398
  const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
398
- const otherDiscountAdjustment = -format2(Math.abs(otherDiscount * 0.12));
399
+ const otherDiscountAdjustment = isNonVat ? 0 : -format2(Math.abs(otherDiscount * 0.12));
399
400
  const storedVat = Math.abs(toMoneyNumber(transaction.vat_amount));
400
401
  const storedVatSales = toMoneyNumber(transaction.vat_sales);
401
402
  const storedVatExemptSales = toMoneyNumber(transaction.vat_exempt_sales);
@@ -421,8 +422,8 @@ function buildTransactionProjection(transaction, options = {}) {
421
422
  totalDeductions: 0
422
423
  };
423
424
  deductions.totalDeductions = Object.values(deductions).reduce((total, amount) => total + amount, 0);
424
- const vatExemptSales = isSuccessful ? storedVatExemptSales : 0;
425
- const allocatedVatAdjustment = allocate(vatExemptSales * 0.12, {
425
+ const vatExemptSales = isSuccessful ? isNonVat ? format2(storedVatSales + storedVatExemptSales + storedNonTaxableSales + voucher) : storedVatExemptSales : isNonVat ? netOfVat : 0;
426
+ const allocatedVatAdjustment = allocate((isNonVat ? 0 : vatExemptSales) * 0.12, {
426
427
  ...vatExemptWeights ?? counts,
427
428
  naac: 0,
428
429
  solo: 0,
@@ -440,12 +441,12 @@ function buildTransactionProjection(transaction, options = {}) {
440
441
  others: 0,
441
442
  totalAdjustments: 0
442
443
  };
443
- const regularVat = storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
444
+ const regularVat = isNonVat ? 0 : storedVat || format2(Math.abs(storedVatExemptSales * 0.12));
444
445
  let vatAmount = format2(
445
- 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
446
447
  );
447
448
  const hasMixedStatutoryTax = isSuccessful && discount > 0 && storedVat > 0 && storedVatSales > 0 && storedVatExemptSales > 0;
448
- if (hasVoucherAndDiscount || hasMixedStatutoryTax) {
449
+ if (!isNonVat && (hasVoucherAndDiscount || hasMixedStatutoryTax)) {
449
450
  vatAmount = format2(
450
451
  storedVat + Math.abs(adjustments.scDiscountAdjustment) + Math.abs(adjustments.pwdDiscountAdjustment) + Math.abs(adjustments.otherDiscountAdjustment)
451
452
  );
@@ -453,10 +454,10 @@ function buildTransactionProjection(transaction, options = {}) {
453
454
  adjustments.vatOnReturns = returned ? -vatAmount : 0;
454
455
  adjustments.vatOnCancelled = cancelled ? -vatAmount : 0;
455
456
  adjustments.totalAdjustments = Object.values(adjustments).reduce((total, amount) => total + amount, 0);
456
- 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 : isNonVat ? 0 : netOfVat;
457
458
  const zeroRatedSales = isSuccessful ? storedZeroRatedSales : 0;
458
459
  const netSales = isSuccessful ? format2(
459
- 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
460
461
  ) : 0;
461
462
  const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
462
463
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrwise/pos-calculations",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "description": "Shared POS calculations for QR Wise POS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",