@qrwise/pos-calculations 0.0.28 → 0.0.29

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
@@ -27,6 +27,8 @@ __export(index_exports, {
27
27
  getDiscountBreakdown: () => getDiscountBreakdown,
28
28
  isAddVatAfterDiscount: () => isAddVatAfterDiscount,
29
29
  isVatExemptDiscount: () => isVatExemptDiscount,
30
+ subscriptionTaxFromBase: () => subscriptionTaxFromBase,
31
+ subscriptionTaxFromTotal: () => subscriptionTaxFromTotal,
30
32
  toMoneyNumber: () => toMoneyNumber
31
33
  });
32
34
  module.exports = __toCommonJS(index_exports);
@@ -544,6 +546,41 @@ function buildTransactionProjection(transaction, options = {}) {
544
546
  discountCounts: counts
545
547
  };
546
548
  }
549
+
550
+ // src/subscription-tax.ts
551
+ function cents(amount) {
552
+ const value = Number(amount);
553
+ const result = Math.round(value * 100);
554
+ if (!Number.isFinite(value) || value < 0 || !Number.isSafeInteger(result) || Math.abs(value * 100 - result) > 1e-4)
555
+ throw new Error("Invalid subscription amount");
556
+ return result;
557
+ }
558
+ function subscriptionTaxFromBase(amount) {
559
+ const base = cents(amount);
560
+ const vat = Math.round(base * 12 / 100);
561
+ if (!Number.isSafeInteger(base + vat)) throw new Error("Invalid subscription total");
562
+ return { base_price: base / 100, vat_amount: vat / 100, amount: (base + vat) / 100 };
563
+ }
564
+ function subscriptionTaxFromTotal(amount) {
565
+ const total = cents(amount);
566
+ const { vatNet } = calculateTotals({
567
+ quantity: 1,
568
+ discountableTotalAmount: total / 100,
569
+ nonDiscountableTotalAmount: 0,
570
+ serviceChargeableTotalAmount: 0,
571
+ togoableTotalAmount: 0,
572
+ voucherType: null,
573
+ voucherRate: 0,
574
+ discountType: null,
575
+ discountRate: 0,
576
+ vatRate: 112,
577
+ isVatRegistered: true,
578
+ serviceChargeRate: 0,
579
+ togoCharge: 0
580
+ });
581
+ const base = Math.round(vatNet * 100);
582
+ return { base_price: base / 100, vat_amount: (total - base) / 100, amount: total / 100 };
583
+ }
547
584
  // Annotate the CommonJS export names for ESM import in node:
548
585
  0 && (module.exports = {
549
586
  buildTransactionProjection,
@@ -553,5 +590,7 @@ function buildTransactionProjection(transaction, options = {}) {
553
590
  getDiscountBreakdown,
554
591
  isAddVatAfterDiscount,
555
592
  isVatExemptDiscount,
593
+ subscriptionTaxFromBase,
594
+ subscriptionTaxFromTotal,
556
595
  toMoneyNumber
557
596
  });
package/dist/index.d.cts CHANGED
@@ -197,4 +197,17 @@ declare function buildTransactionProjection(transaction: FinancialTransactionInp
197
197
  discountCounts: DiscountWeights;
198
198
  };
199
199
 
200
- export { type CalculateTotalsInput, type CalculateTotalsResult, type DiscountBreakdown, type DiscountRates, type DiscountType, type FinancialTransactionInput, type PaxDiscountCounts, type ReportDiscountCategory, type TransactionProjectionOptions, type VoucherType, buildTransactionProjection, calculateTotals, clamp, format2, getDiscountBreakdown, isAddVatAfterDiscount, isVatExemptDiscount, toMoneyNumber };
200
+ /** Catalog subscription prices exclude 12% VAT. Round VAT once per charge. */
201
+ declare function subscriptionTaxFromBase(amount: number | string): {
202
+ base_price: number;
203
+ vat_amount: number;
204
+ amount: number;
205
+ };
206
+ /** Preserve the actual total on legacy subscriptions and historical payments. */
207
+ declare function subscriptionTaxFromTotal(amount: number | string): {
208
+ base_price: number;
209
+ vat_amount: number;
210
+ amount: number;
211
+ };
212
+
213
+ export { type CalculateTotalsInput, type CalculateTotalsResult, type DiscountBreakdown, type DiscountRates, type DiscountType, type FinancialTransactionInput, type PaxDiscountCounts, type ReportDiscountCategory, type TransactionProjectionOptions, type VoucherType, buildTransactionProjection, calculateTotals, clamp, format2, getDiscountBreakdown, isAddVatAfterDiscount, isVatExemptDiscount, subscriptionTaxFromBase, subscriptionTaxFromTotal, toMoneyNumber };
package/dist/index.d.ts CHANGED
@@ -197,4 +197,17 @@ declare function buildTransactionProjection(transaction: FinancialTransactionInp
197
197
  discountCounts: DiscountWeights;
198
198
  };
199
199
 
200
- export { type CalculateTotalsInput, type CalculateTotalsResult, type DiscountBreakdown, type DiscountRates, type DiscountType, type FinancialTransactionInput, type PaxDiscountCounts, type ReportDiscountCategory, type TransactionProjectionOptions, type VoucherType, buildTransactionProjection, calculateTotals, clamp, format2, getDiscountBreakdown, isAddVatAfterDiscount, isVatExemptDiscount, toMoneyNumber };
200
+ /** Catalog subscription prices exclude 12% VAT. Round VAT once per charge. */
201
+ declare function subscriptionTaxFromBase(amount: number | string): {
202
+ base_price: number;
203
+ vat_amount: number;
204
+ amount: number;
205
+ };
206
+ /** Preserve the actual total on legacy subscriptions and historical payments. */
207
+ declare function subscriptionTaxFromTotal(amount: number | string): {
208
+ base_price: number;
209
+ vat_amount: number;
210
+ amount: number;
211
+ };
212
+
213
+ export { type CalculateTotalsInput, type CalculateTotalsResult, type DiscountBreakdown, type DiscountRates, type DiscountType, type FinancialTransactionInput, type PaxDiscountCounts, type ReportDiscountCategory, type TransactionProjectionOptions, type VoucherType, buildTransactionProjection, calculateTotals, clamp, format2, getDiscountBreakdown, isAddVatAfterDiscount, isVatExemptDiscount, subscriptionTaxFromBase, subscriptionTaxFromTotal, toMoneyNumber };
package/dist/index.js CHANGED
@@ -511,6 +511,41 @@ function buildTransactionProjection(transaction, options = {}) {
511
511
  discountCounts: counts
512
512
  };
513
513
  }
514
+
515
+ // src/subscription-tax.ts
516
+ function cents(amount) {
517
+ const value = Number(amount);
518
+ const result = Math.round(value * 100);
519
+ if (!Number.isFinite(value) || value < 0 || !Number.isSafeInteger(result) || Math.abs(value * 100 - result) > 1e-4)
520
+ throw new Error("Invalid subscription amount");
521
+ return result;
522
+ }
523
+ function subscriptionTaxFromBase(amount) {
524
+ const base = cents(amount);
525
+ const vat = Math.round(base * 12 / 100);
526
+ if (!Number.isSafeInteger(base + vat)) throw new Error("Invalid subscription total");
527
+ return { base_price: base / 100, vat_amount: vat / 100, amount: (base + vat) / 100 };
528
+ }
529
+ function subscriptionTaxFromTotal(amount) {
530
+ const total = cents(amount);
531
+ const { vatNet } = calculateTotals({
532
+ quantity: 1,
533
+ discountableTotalAmount: total / 100,
534
+ nonDiscountableTotalAmount: 0,
535
+ serviceChargeableTotalAmount: 0,
536
+ togoableTotalAmount: 0,
537
+ voucherType: null,
538
+ voucherRate: 0,
539
+ discountType: null,
540
+ discountRate: 0,
541
+ vatRate: 112,
542
+ isVatRegistered: true,
543
+ serviceChargeRate: 0,
544
+ togoCharge: 0
545
+ });
546
+ const base = Math.round(vatNet * 100);
547
+ return { base_price: base / 100, vat_amount: (total - base) / 100, amount: total / 100 };
548
+ }
514
549
  export {
515
550
  buildTransactionProjection,
516
551
  calculateTotals,
@@ -519,5 +554,7 @@ export {
519
554
  getDiscountBreakdown,
520
555
  isAddVatAfterDiscount,
521
556
  isVatExemptDiscount,
557
+ subscriptionTaxFromBase,
558
+ subscriptionTaxFromTotal,
522
559
  toMoneyNumber
523
560
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrwise/pos-calculations",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "description": "Shared POS calculations for QR Wise POS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",