@qrwise/pos-calculations 0.0.20 → 0.0.21

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
@@ -416,6 +416,17 @@ 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
+ }
419
430
  function buildTransactionProjection(transaction, options = {}) {
420
431
  const status = `${transaction.status} ${transaction.payment_status}`.toLowerCase();
421
432
  const state = status.includes("refund") || status.includes("return") ? "RETURNED" : status.includes("cancel") || status.includes("void") ? "CANCELLED" : "SUCCESS";
@@ -424,10 +435,10 @@ function buildTransactionProjection(transaction, options = {}) {
424
435
  const discount = Math.abs(toMoneyNumber(transaction.discount_amount));
425
436
  const voucher = Math.abs(toMoneyNumber(transaction.voucher_discount_amount));
426
437
  const voucherRate = toMoneyNumber(transaction.voucher_rate);
427
- const hasVoucher = voucherRate > 0;
438
+ const hasVoucher = voucher > 0;
428
439
  const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
429
440
  const scopedVoucherVatNet = voucherVatNet(transaction, voucher, discount);
430
- const voucherForBirDiscount = -format2(
441
+ const voucherForBirDiscount = itemizedVoucherCount(transaction) > 1 ? -format2(voucher / 1.12) : -format2(
431
442
  transaction.voucher_type?.toLowerCase() === "fixed" ? scopedVoucherVatNet - format2(voucherRate) : scopedVoucherVatNet * format2(voucherRate / 100)
432
443
  );
433
444
  const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
@@ -491,7 +502,6 @@ function buildTransactionProjection(transaction, options = {}) {
491
502
  vatableSales + vatExemptSales + zeroRatedSales + storedNonTaxableSales + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
492
503
  ) : 0;
493
504
  const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
494
- const takeoutCharge = toMoneyNumber(transaction.takeout_charge_amount);
495
505
  return {
496
506
  state,
497
507
  receipt: {
@@ -510,7 +520,6 @@ function buildTransactionProjection(transaction, options = {}) {
510
520
  storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales + storedVat
511
521
  ),
512
522
  serviceCharge,
513
- takeoutCharge,
514
523
  amountPayable: toMoneyNumber(transaction.amount_payable)
515
524
  },
516
525
  report: {
@@ -522,7 +531,6 @@ function buildTransactionProjection(transaction, options = {}) {
522
531
  zeroRatedSales,
523
532
  deductions,
524
533
  serviceCharge,
525
- takeoutCharge,
526
534
  adjustments,
527
535
  vatPayable: isSuccessful ? Math.max(0, format2(vatAmount - Math.abs(adjustments.totalAdjustments))) : 0,
528
536
  netSales,
package/dist/index.d.cts CHANGED
@@ -118,7 +118,6 @@ interface FinancialTransactionInput {
118
118
  zero_rated_sales?: number | string | null;
119
119
  non_taxable_sales?: number | string | null;
120
120
  service_charge_amount?: number | string | null;
121
- takeout_charge_amount?: number | string | null;
122
121
  discount_customers?: Array<{
123
122
  discount_id?: string | null;
124
123
  discount_name?: string | null;
@@ -156,7 +155,6 @@ declare function buildTransactionProjection(transaction: FinancialTransactionInp
156
155
  vatAmount: number;
157
156
  totalSales: number;
158
157
  serviceCharge: number;
159
- takeoutCharge: number;
160
158
  amountPayable: number;
161
159
  };
162
160
  report: {
@@ -178,7 +176,6 @@ declare function buildTransactionProjection(transaction: FinancialTransactionInp
178
176
  totalDeductions: number;
179
177
  };
180
178
  serviceCharge: number;
181
- takeoutCharge: number;
182
179
  adjustments: {
183
180
  scDiscountAdjustment: number;
184
181
  pwdDiscountAdjustment: number;
package/dist/index.d.ts CHANGED
@@ -118,7 +118,6 @@ interface FinancialTransactionInput {
118
118
  zero_rated_sales?: number | string | null;
119
119
  non_taxable_sales?: number | string | null;
120
120
  service_charge_amount?: number | string | null;
121
- takeout_charge_amount?: number | string | null;
122
121
  discount_customers?: Array<{
123
122
  discount_id?: string | null;
124
123
  discount_name?: string | null;
@@ -156,7 +155,6 @@ declare function buildTransactionProjection(transaction: FinancialTransactionInp
156
155
  vatAmount: number;
157
156
  totalSales: number;
158
157
  serviceCharge: number;
159
- takeoutCharge: number;
160
158
  amountPayable: number;
161
159
  };
162
160
  report: {
@@ -178,7 +176,6 @@ declare function buildTransactionProjection(transaction: FinancialTransactionInp
178
176
  totalDeductions: number;
179
177
  };
180
178
  serviceCharge: number;
181
- takeoutCharge: number;
182
179
  adjustments: {
183
180
  scDiscountAdjustment: number;
184
181
  pwdDiscountAdjustment: number;
package/dist/index.js CHANGED
@@ -383,6 +383,17 @@ 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
+ }
386
397
  function buildTransactionProjection(transaction, options = {}) {
387
398
  const status = `${transaction.status} ${transaction.payment_status}`.toLowerCase();
388
399
  const state = status.includes("refund") || status.includes("return") ? "RETURNED" : status.includes("cancel") || status.includes("void") ? "CANCELLED" : "SUCCESS";
@@ -391,10 +402,10 @@ function buildTransactionProjection(transaction, options = {}) {
391
402
  const discount = Math.abs(toMoneyNumber(transaction.discount_amount));
392
403
  const voucher = Math.abs(toMoneyNumber(transaction.voucher_discount_amount));
393
404
  const voucherRate = toMoneyNumber(transaction.voucher_rate);
394
- const hasVoucher = voucherRate > 0;
405
+ const hasVoucher = voucher > 0;
395
406
  const hasVoucherAndDiscount = isSuccessful && voucher > 0 && discount > 0;
396
407
  const scopedVoucherVatNet = voucherVatNet(transaction, voucher, discount);
397
- const voucherForBirDiscount = -format2(
408
+ const voucherForBirDiscount = itemizedVoucherCount(transaction) > 1 ? -format2(voucher / 1.12) : -format2(
398
409
  transaction.voucher_type?.toLowerCase() === "fixed" ? scopedVoucherVatNet - format2(voucherRate) : scopedVoucherVatNet * format2(voucherRate / 100)
399
410
  );
400
411
  const otherDiscount = isSuccessful && hasVoucher ? format2(voucherForBirDiscount) : 0;
@@ -458,7 +469,6 @@ function buildTransactionProjection(transaction, options = {}) {
458
469
  vatableSales + vatExemptSales + zeroRatedSales + storedNonTaxableSales + deductions.scDiscount + deductions.pwdDiscount + deductions.naacDiscount + deductions.soloDiscount + deductions.movDiscount + deductions.otherDiscount
459
470
  ) : 0;
460
471
  const serviceCharge = toMoneyNumber(transaction.service_charge_amount);
461
- const takeoutCharge = toMoneyNumber(transaction.takeout_charge_amount);
462
472
  return {
463
473
  state,
464
474
  receipt: {
@@ -477,7 +487,6 @@ function buildTransactionProjection(transaction, options = {}) {
477
487
  storedVatSales + storedVatExemptSales + storedZeroRatedSales + storedNonTaxableSales + storedVat
478
488
  ),
479
489
  serviceCharge,
480
- takeoutCharge,
481
490
  amountPayable: toMoneyNumber(transaction.amount_payable)
482
491
  },
483
492
  report: {
@@ -489,7 +498,6 @@ function buildTransactionProjection(transaction, options = {}) {
489
498
  zeroRatedSales,
490
499
  deductions,
491
500
  serviceCharge,
492
- takeoutCharge,
493
501
  adjustments,
494
502
  vatPayable: isSuccessful ? Math.max(0, format2(vatAmount - Math.abs(adjustments.totalAdjustments))) : 0,
495
503
  netSales,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrwise/pos-calculations",
3
- "version": "0.0.20",
3
+ "version": "0.0.21",
4
4
  "description": "Shared POS calculations for QR Wise POS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",