@ubnt/store.core 11.28.0-custom-tax.1 → 11.28.0
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/CHANGELOG.md +7 -0
- package/lib/_virtual/_virtual_multi-entry.js +6 -2
- package/lib/_virtual/_virtual_multi-entry.js.map +1 -1
- package/lib/_virtual/_virtual_multi-entry.mjs +6 -2
- package/lib/_virtual/_virtual_multi-entry.mjs.map +1 -1
- package/lib/assets/ai-360.jpg +0 -0
- package/lib/assets/ai-3602.jpg +0 -0
- package/lib/assets/ai-dslr.jpg +0 -0
- package/lib/assets/ai-dslr2.jpg +0 -0
- package/lib/assets/attention.svg +1 -1
- package/lib/assets/attention2.svg +1 -1
- package/lib/assets/compact.svg +1 -1
- package/lib/assets/compact2.svg +1 -1
- package/lib/assets/compact3.svg +1 -0
- package/lib/assets/door-hub-mini.jpg +0 -0
- package/lib/assets/door-hub-mini2.jpg +0 -0
- package/lib/assets/floodlight.svg +1 -1
- package/lib/assets/floodlight2.svg +1 -1
- package/lib/assets/g2-reader.jpg +0 -0
- package/lib/assets/g2-reader2.jpg +0 -0
- package/lib/assets/g3-reader.jpg +0 -0
- package/lib/assets/g3-reader2.jpg +0 -0
- package/lib/assets/g3-starter-kit-pro.jpg +0 -0
- package/lib/assets/g3-starter-kit-pro2.jpg +0 -0
- package/lib/assets/g3-starter-kit.jpg +0 -0
- package/lib/assets/g3-starter-kit2.jpg +0 -0
- package/lib/assets/g4-ptz.jpg +0 -0
- package/lib/assets/g4-ptz2.jpg +0 -0
- package/lib/assets/g5-dome.jpg +0 -0
- package/lib/assets/g5-dome2.jpg +0 -0
- package/lib/assets/g5-ptz.jpg +0 -0
- package/lib/assets/g5-ptz2.jpg +0 -0
- package/lib/assets/globe.svg +1 -1
- package/lib/assets/globe2.svg +1 -1
- package/lib/assets/interior-design.svg +1 -1
- package/lib/assets/interior-design2.svg +1 -1
- package/lib/assets/power.svg +1 -1
- package/lib/assets/power2.svg +1 -1
- package/lib/assets/rack.svg +1 -1
- package/lib/assets/rack2.svg +1 -1
- package/lib/components/Header/Header.js +1 -1
- package/lib/components/Header/Header.mjs +1 -1
- package/lib/components/Header/ProHeader/ProHeader.js +1 -1
- package/lib/components/Header/ProHeader/ProHeader.mjs +1 -1
- package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.js +1 -1
- package/lib/components/MicrositeHeader/components/HeaderContent/HeaderContent.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
- package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
- package/lib/constants/icons/header/globe.svg.js +1 -1
- package/lib/constants/icons/header/globe.svg.mjs +2 -2
- package/lib/constants/icons/header/index.js +1 -1
- package/lib/constants/icons/header/index.mjs +1 -1
- package/lib/constants/icons/menu/floodlight.svg.js +5 -5
- package/lib/constants/icons/menu/floodlight.svg.mjs +2 -2
- package/lib/constants/icons/menu/index.js +9 -9
- package/lib/constants/icons/menu/index.mjs +3 -3
- package/lib/constants/icons/menu/power.svg.js +5 -5
- package/lib/constants/icons/menu/power.svg.mjs +2 -2
- package/lib/constants/icons/menu/rack.svg.js +5 -5
- package/lib/constants/icons/menu/rack.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/Bullet/ai-dslr.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/PTZ/g4-ptz.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/PTZ/g5-ptz.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/PTZ/g5-ptz.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/compact.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/compact.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/floodlight.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/floodlight.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/globe.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/globe.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/interior-design.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/interior-design.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/power.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/power.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-dslr.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g4-ptz.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g5-ptz.jpg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/cameras/ptz/g5-ptz.jpg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/compact.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/compact2.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/compact2.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.mjs +2 -2
- package/lib/constants/modelCompareData/assets/rack.svg.js +1 -1
- package/lib/constants/modelCompareData/assets/rack.svg.mjs +2 -2
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.js +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Compact.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.js +1 -1
- package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/compact.js +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/compact.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.js +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.mjs +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/productListSwitchingCompact.js +1 -1
- package/lib/constants/modelCompareData/data/product-list-groups/productListSwitchingCompact.mjs +1 -1
- package/lib/constants/modelCompareData/data/products/ai360.js +2 -2
- package/lib/constants/modelCompareData/data/products/ai360.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/aiDslr.js +2 -2
- package/lib/constants/modelCompareData/data/products/aiDslr.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/doorHubMini.js +2 -2
- package/lib/constants/modelCompareData/data/products/doorHubMini.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g2Reader.js +2 -2
- package/lib/constants/modelCompareData/data/products/g2Reader.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g3Reader.js +2 -2
- package/lib/constants/modelCompareData/data/products/g3Reader.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKit.js +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKit.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKitPro.js +2 -2
- package/lib/constants/modelCompareData/data/products/g3StarterKitPro.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g4Ptz.js +2 -2
- package/lib/constants/modelCompareData/data/products/g4Ptz.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g5Dome.js +2 -2
- package/lib/constants/modelCompareData/data/products/g5Dome.mjs +2 -2
- package/lib/constants/modelCompareData/data/products/g5Ptz.js +2 -2
- package/lib/constants/modelCompareData/data/products/g5Ptz.mjs +2 -2
- package/lib/constants/modelCompareData/data/properties/accessPowerMethod.js +1 -1
- package/lib/constants/modelCompareData/data/properties/accessPowerMethod.mjs +1 -1
- package/lib/constants/modelCompareData/data/properties/availability.js +1 -1
- package/lib/constants/modelCompareData/data/properties/availability.mjs +1 -1
- package/lib/constants/modelCompareData/data/properties/builtInFloodlight.js +1 -1
- package/lib/constants/modelCompareData/data/properties/builtInFloodlight.mjs +1 -1
- package/lib/constants/modelCompareData/data/properties/dcPowerOutput.js +1 -1
- package/lib/constants/modelCompareData/data/properties/dcPowerOutput.mjs +1 -1
- package/lib/constants/modelCompareData/data/properties/mounting.js +1 -1
- package/lib/constants/modelCompareData/data/properties/mounting.mjs +1 -1
- package/lib/constants/modelCompareData/data/properties/unasPowerMethod.js +1 -1
- package/lib/constants/modelCompareData/data/properties/unasPowerMethod.mjs +1 -1
- package/lib/constants/modelCompareData/data/properties/webMode.js +1 -1
- package/lib/constants/modelCompareData/data/properties/webMode.mjs +1 -1
- package/lib/contexts/MenuContext/mapping.js +3 -3
- package/lib/contexts/MenuContext/mapping.mjs +2 -2
- package/lib/contexts/MicrositeMenuContext/mapping.js +3 -3
- package/lib/contexts/MicrositeMenuContext/mapping.mjs +2 -2
- package/lib/utils/{map.js → KeyMap.js} +1 -1
- package/lib/utils/KeyMap.js.map +1 -0
- package/lib/utils/{map.mjs → KeyMap.mjs} +1 -1
- package/lib/utils/KeyMap.mjs.map +1 -0
- package/lib/utils/index.d.ts +3 -1
- package/lib/utils/index.js +6 -2
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/index.mjs +6 -2
- package/lib/utils/index.mjs.map +1 -1
- package/lib/utils/makeMap.d.ts +44 -0
- package/lib/utils/makeMap.js +28 -0
- package/lib/utils/makeMap.js.map +1 -0
- package/lib/utils/makeMap.mjs +25 -0
- package/lib/utils/makeMap.mjs.map +1 -0
- package/lib/utils/makeSet.d.ts +14 -0
- package/lib/utils/makeSet.js +8 -0
- package/lib/utils/makeSet.js.map +1 -0
- package/lib/utils/makeSet.mjs +7 -0
- package/lib/utils/makeSet.mjs.map +1 -0
- package/lib/utils/makeSet.test.d.ts +1 -0
- package/lib/utils/money/index.d.ts +0 -1
- package/lib/utils/money/index.js +0 -2
- package/lib/utils/money/index.js.map +1 -1
- package/lib/utils/money/index.mjs +0 -1
- package/lib/utils/money/index.mjs.map +1 -1
- package/lib/utils/money/tax.d.ts +3 -6
- package/lib/utils/money/tax.js +10 -3
- package/lib/utils/money/tax.js.map +1 -1
- package/lib/utils/money/tax.mjs +13 -6
- package/lib/utils/money/tax.mjs.map +1 -1
- package/lib/utils/money/tax.private.d.ts +2 -7
- package/lib/utils/money/tax.private.js +6 -21
- package/lib/utils/money/tax.private.js.map +1 -1
- package/lib/utils/money/tax.private.mjs +8 -22
- package/lib/utils/money/tax.private.mjs.map +1 -1
- package/package.json +1 -1
- package/lib/assets/compact22.svg +0 -1
- package/lib/utils/map.js.map +0 -1
- package/lib/utils/map.mjs.map +0 -1
- package/lib/utils/money/allocators/totalAmount.d.ts +0 -17
- package/lib/utils/money/allocators/totalAmount.js +0 -40
- package/lib/utils/money/allocators/totalAmount.js.map +0 -1
- package/lib/utils/money/allocators/totalAmount.mjs +0 -38
- package/lib/utils/money/allocators/totalAmount.mjs.map +0 -1
- /package/lib/utils/{map.d.ts → KeyMap.d.ts} +0 -0
- /package/lib/utils/{map.test.d.ts → KeyMap.test.d.ts} +0 -0
- /package/lib/utils/{money/allocators/totalAmount.test.d.ts → makeMap.test.d.ts} +0 -0
package/lib/utils/money/tax.mjs
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toSnapshot, dinero, multiply, toUnit, halfEven } from 'dinero.js';
|
|
2
2
|
import { assert } from '../errors.mjs';
|
|
3
3
|
import { isFloat, toFixedRate } from '../number.mjs';
|
|
4
|
-
import { storesWithPerItemTaxRate, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
|
|
5
|
-
import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax
|
|
4
|
+
import { storesWithPerItemTaxRate, Round, TAX_RATE_DINERO_CURRENCY } from './constants.mjs';
|
|
5
|
+
import { calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax } from './tax.private.mjs';
|
|
6
6
|
"use strict";
|
|
7
7
|
const calculateLineItemTax = ({
|
|
8
8
|
itemSummary,
|
|
9
9
|
taxRate,
|
|
10
|
-
|
|
10
|
+
storeId
|
|
11
11
|
}) => {
|
|
12
|
-
return storesWithPerItemTaxRate.has(
|
|
12
|
+
return storesWithPerItemTaxRate.has(storeId) ? calculatePerQtyLineItemTax(itemSummary, taxRate) : calculateWholeQtyLineItemTax(itemSummary, taxRate);
|
|
13
|
+
};
|
|
14
|
+
const removeTaxAmount = (baseAmountWithTaxObj, taxRate) => {
|
|
15
|
+
const snapshot = toSnapshot(baseAmountWithTaxObj);
|
|
16
|
+
const taxAmount = Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
|
|
17
|
+
return dinero({
|
|
18
|
+
...snapshot,
|
|
19
|
+
amount: snapshot.amount - taxAmount
|
|
20
|
+
});
|
|
13
21
|
};
|
|
14
|
-
const removeTaxAmount = (amountWithTax, taxRate) => subtract(amountWithTax, getTaxFromFinalAmount(amountWithTax, taxRate));
|
|
15
22
|
const convertDecimalTaxRateToPercentage = taxRate => {
|
|
16
23
|
const dineroObj = decimalTaxRateToDinero(taxRate);
|
|
17
24
|
const t = multiply(dineroObj, 100);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n dinero,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n
|
|
1
|
+
{"version":3,"file":"tax.mjs","sources":["../../../src/utils/money/tax.ts"],"sourcesContent":["import {\n dinero,\n // FIXME: move usage to rounding\n halfEven,\n multiply,\n toSnapshot,\n toUnit,\n} from \"dinero.js\";\n\nimport type { StoreId } from \"../../types\";\nimport { assert } from \"../errors\";\nimport { isFloat, toFixedRate } from \"../number\";\nimport {\n Round,\n storesWithPerItemTaxRate,\n TAX_RATE_DINERO_CURRENCY,\n} from \"./constants\";\nimport {\n calculatePerQtyLineItemTax,\n calculateWholeQtyLineItemTax,\n} from \"./tax.private\";\nimport type { Dino, LineItemSummary, TaxRate } from \"./types\";\n\n/**\n * Function to calculate the tax amount for a given line item depending on the store's tax rate calculation strategy\n */\nexport const calculateLineItemTax = ({\n itemSummary,\n taxRate,\n storeId,\n}: {\n itemSummary: LineItemSummary;\n taxRate: TaxRate;\n storeId: StoreId;\n}) => {\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate);\n};\n\nexport const removeTaxAmount = (\n baseAmountWithTaxObj: Dino,\n taxRate: TaxRate,\n) => {\n const snapshot = toSnapshot(baseAmountWithTaxObj);\n\n // Calculate the tax amount and apply rounding on it so that behavior for reverse process is consistent\n const taxAmount = Round.Financial(\n snapshot.amount - snapshot.amount / (1 + taxRate),\n );\n\n return dinero({\n ...snapshot,\n amount: snapshot.amount - taxAmount,\n });\n};\n\n/**\n * Will return a percentage tax rate from a decimal tax rate (usually returned by DB)\n *\n * Use for math-related calculations ONLY! Use `formatDecimalTaxRate` for display purposes e.g. invoices.\n *\n * @example convertDecimalTaxRateToPercentage(\"0.01\") // 1\n * @example convertDecimalTaxRateToPercentage(\"0.1023\") // 10.23\n * @example convertDecimalTaxRateToPercentage(\"0.12345678\") // 12.345678\n */\nexport const convertDecimalTaxRateToPercentage = (\n taxRate: string | number,\n): number => {\n const dineroObj = decimalTaxRateToDinero(taxRate);\n const t = multiply(dineroObj, 100);\n return toUnit(t, {\n digits: TAX_RATE_DINERO_CURRENCY.exponent,\n round: halfEven,\n });\n};\n\nexport const decimalTaxRateToDinero = (taxRate: string | number): Dino => {\n const parsedNumber =\n typeof taxRate === \"number\" ? taxRate : Number.parseFloat(taxRate);\n isFloat(parsedNumber);\n\n const parsedNumberInt = Number.parseInt(\n (\n parsedNumber *\n Math.pow(TAX_RATE_DINERO_CURRENCY.base, TAX_RATE_DINERO_CURRENCY.exponent)\n ).toFixed(0),\n );\n return dinero({\n amount: parsedNumberInt,\n currency: TAX_RATE_DINERO_CURRENCY,\n });\n};\n\n/**\n * Will return a percentage string from a decimal tax rate (usually returned by DB).\n *\n * Use for display purposes e.g. invoices.\n *\n * @example formatDecimalTaxRate(\"0.01\") // \"1%\"\n * @example formatDecimalTaxRate(\"0.1023\") // \"10.23%\"\n * @example formatDecimalTaxRate(\"0.12345678\") // \"12.345678%\"\n */\nexport const formatDecimalTaxRate = <TaxRateFloat extends string | number>(\n taxRate: TaxRateFloat,\n): `${number}%` => {\n return `${convertDecimalTaxRateToPercentage(taxRate)}%`;\n};\n\nexport const stringTaxRateToFloat = (rate: string): number =>\n toFixedRate(+rate, TAX_RATE_DINERO_CURRENCY.exponent, true);\n\n/**\n * Calculate total Tax(LV: \"PVN\") for country, which consists of multiple tax entries\n * Returning fixed to ${TAX_RATE_DINERO_CURRENCY.exponent} 4 decimal places, to for example 0.2100 represent 21.00%\n */\nexport const calculateTotalTaxRate = (rates: number[]): number => {\n const rateSum = rates.reduce((sum, rate) => sum + rate, 0);\n const result = toFixedRate(rateSum, TAX_RATE_DINERO_CURRENCY.exponent, true);\n assert(result >= 0, \"Tax rate must be positive\");\n assert(result < 1, \"Tax rate must be less than 1\");\n return result;\n};\n"],"names":["calculateLineItemTax","itemSummary","taxRate","storeId","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","calculateWholeQtyLineItemTax","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","taxAmount","Round","Financial","amount","dinero","convertDecimalTaxRateToPercentage","dineroObj","decimalTaxRateToDinero","t","multiply","toUnit","digits","TAX_RATE_DINERO_CURRENCY","exponent","round","halfEven","parsedNumber","Number","parseFloat","isFloat","parsedNumberInt","parseInt","Math","pow","base","toFixed","currency","formatDecimalTaxRate","stringTaxRateToFloat","rate","toFixedRate","calculateTotalTaxRate","rates","rateSum","reduce","sum","result","assert"],"mappings":";;;;;;AA0BO,MAAMA,uBAAuBA,CAAC;EACnCC,WAAA;EACAC,OAAA;EACAC;AACF,CAAA,KAIM;EACJ,OAAOC,wBAAA,CAAyBC,GAAA,CAAIF,OAAO,CAAA,GACvCG,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,4BAAA,CAA6BN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEO,MAAMM,eAAA,GAAkBA,CAC7BC,oBAAA,EACAP,OAAA,KACG;EACH,MAAMQ,QAAA,GAAWC,WAAWF,oBAAoB,CAAA;EAGhD,MAAMG,YAAYC,KA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,CAAO,CAACC,KAAKN,IAAA,KAASM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAA,GAASN,WAAA,CAAYG,OAAA,EAASrB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EAC3EwB,MAAA,CAAOD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EAC/CC,MAAA,CAAOD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EACjD,OAAOA,MAAA;AACT,CAAA;"}
|
|
@@ -4,10 +4,5 @@ import type { Dino, LineItemSummary, SingleLineItemSummary, TaxRate } from "./ty
|
|
|
4
4
|
* rate calculations
|
|
5
5
|
*/
|
|
6
6
|
export declare const allocatePerItemTaxableAmount: (itemSummary: LineItemSummary) => SingleLineItemSummary[];
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
hasTaxIncludedPrice: boolean;
|
|
10
|
-
}) => Dino;
|
|
11
|
-
export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate, options: {
|
|
12
|
-
hasTaxIncludedPrice: boolean;
|
|
13
|
-
}) => Dino;
|
|
7
|
+
export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
|
|
8
|
+
export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
|
|
@@ -29,37 +29,23 @@ const allocatePerItemTaxableAmount = itemSummary => {
|
|
|
29
29
|
};
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
|
|
33
|
+
if (taxRate === 0) {
|
|
34
|
+
return misc.getDinero(0, itemSummary.currency);
|
|
35
|
+
}
|
|
33
36
|
return dinero_js.dinero({
|
|
34
37
|
amount: constants.Round.Financial(itemSummary.taxableAmount * taxRate),
|
|
35
38
|
currency: misc.getDineroCurrency(itemSummary.currency)
|
|
36
39
|
});
|
|
37
40
|
};
|
|
38
|
-
const
|
|
39
|
-
const snapshot = dinero_js.toSnapshot(amountWithTax);
|
|
40
|
-
const taxAmount = constants.Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
|
|
41
|
-
return dinero_js.dinero({
|
|
42
|
-
...snapshot,
|
|
43
|
-
amount: taxAmount
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
const calculateTaxFromTaxIncludedPrice = (itemSummary, taxRate) => {
|
|
47
|
-
return getTaxFromFinalAmount(misc.getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRate);
|
|
48
|
-
};
|
|
49
|
-
const calculateWholeQtyLineItemTax = (itemSummary, taxRate, options) => {
|
|
50
|
-
if (taxRate === 0) {
|
|
51
|
-
return misc.getDinero(0, itemSummary.currency);
|
|
52
|
-
}
|
|
53
|
-
return options.hasTaxIncludedPrice ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate) : calculateTaxOnTaxableAmount(itemSummary, taxRate);
|
|
54
|
-
};
|
|
55
|
-
const calculatePerQtyLineItemTax = (itemSummary, taxRate, options) => {
|
|
41
|
+
const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
|
|
56
42
|
if (taxRate === 0) {
|
|
57
43
|
return misc.getDinero(0, itemSummary.currency);
|
|
58
44
|
}
|
|
59
45
|
const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
|
|
60
46
|
let totalTaxAmount = misc.getDinero(0, itemSummary.currency);
|
|
61
47
|
singleItemSummaries.forEach(itemSummary2 => {
|
|
62
|
-
const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate
|
|
48
|
+
const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
|
|
63
49
|
totalTaxAmount = dinero_js.add(totalTaxAmount, taxAmount);
|
|
64
50
|
});
|
|
65
51
|
return totalTaxAmount;
|
|
@@ -67,5 +53,4 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate, options) => {
|
|
|
67
53
|
exports.allocatePerItemTaxableAmount = allocatePerItemTaxableAmount;
|
|
68
54
|
exports.calculatePerQtyLineItemTax = calculatePerQtyLineItemTax;
|
|
69
55
|
exports.calculateWholeQtyLineItemTax = calculateWholeQtyLineItemTax;
|
|
70
|
-
exports.getTaxFromFinalAmount = getTaxFromFinalAmount;
|
|
71
56
|
//# sourceMappingURL=tax.private.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract
|
|
1
|
+
{"version":3,"file":"tax.private.js","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItem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,WAAA,EACAqB,OAAA,KACS;EAET,IAAIA,YAAY,CAAA,EAAG;IACjB,OAAOjB,cAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAMA,OAAOgB,gBAAA,CAAO;IACZV,MAAA,EAAQW,SAAAA,CAAAA,KAAA,CAAMC,SAAA,CAAUxB,WAAA,CAAYK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,IAAAA,CAAAA,iBAAA,CAAkBzB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEO,MAAMoB,0BAAA,GAA6BA,CACxC1B,WAAA,EACAqB,OAAA,KACS;EAET,IAAIA,YAAY,CAAA,EAAG;IACjB,OAAOjB,cAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAMqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAA,GAAiBxB,IAAAA,CAAAA,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtDqB,mBAAA,CAAoBE,OAAA,CAAS7B,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYV,4BAAA,CAA6BpB,YAAAA,EAAaqB,OAAO,CAAA;IACnEO,cAAA,GAAiBzB,SAAAA,CAAAA,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOF,cAAA;AACT,CAAA;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { add, subtract, dinero
|
|
1
|
+
import { add, subtract, dinero } from 'dinero.js';
|
|
2
2
|
import { FixedAmountAllocator } from './allocators/fixedAmount.mjs';
|
|
3
3
|
import { Round } from './constants.mjs';
|
|
4
4
|
import { getDinero, amount, getDineroCurrency } from './misc.mjs';
|
|
@@ -27,40 +27,26 @@ const allocatePerItemTaxableAmount = itemSummary => {
|
|
|
27
27
|
};
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
-
const
|
|
30
|
+
const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
|
|
31
|
+
if (taxRate === 0) {
|
|
32
|
+
return getDinero(0, itemSummary.currency);
|
|
33
|
+
}
|
|
31
34
|
return dinero({
|
|
32
35
|
amount: Round.Financial(itemSummary.taxableAmount * taxRate),
|
|
33
36
|
currency: getDineroCurrency(itemSummary.currency)
|
|
34
37
|
});
|
|
35
38
|
};
|
|
36
|
-
const
|
|
37
|
-
const snapshot = toSnapshot(amountWithTax);
|
|
38
|
-
const taxAmount = Round.Financial(snapshot.amount - snapshot.amount / (1 + taxRate));
|
|
39
|
-
return dinero({
|
|
40
|
-
...snapshot,
|
|
41
|
-
amount: taxAmount
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
const calculateTaxFromTaxIncludedPrice = (itemSummary, taxRate) => {
|
|
45
|
-
return getTaxFromFinalAmount(getDinero(itemSummary.taxableAmount, itemSummary.currency), taxRate);
|
|
46
|
-
};
|
|
47
|
-
const calculateWholeQtyLineItemTax = (itemSummary, taxRate, options) => {
|
|
48
|
-
if (taxRate === 0) {
|
|
49
|
-
return getDinero(0, itemSummary.currency);
|
|
50
|
-
}
|
|
51
|
-
return options.hasTaxIncludedPrice ? calculateTaxFromTaxIncludedPrice(itemSummary, taxRate) : calculateTaxOnTaxableAmount(itemSummary, taxRate);
|
|
52
|
-
};
|
|
53
|
-
const calculatePerQtyLineItemTax = (itemSummary, taxRate, options) => {
|
|
39
|
+
const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
|
|
54
40
|
if (taxRate === 0) {
|
|
55
41
|
return getDinero(0, itemSummary.currency);
|
|
56
42
|
}
|
|
57
43
|
const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
|
|
58
44
|
let totalTaxAmount = getDinero(0, itemSummary.currency);
|
|
59
45
|
singleItemSummaries.forEach(itemSummary2 => {
|
|
60
|
-
const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate
|
|
46
|
+
const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
|
|
61
47
|
totalTaxAmount = add(totalTaxAmount, taxAmount);
|
|
62
48
|
});
|
|
63
49
|
return totalTaxAmount;
|
|
64
50
|
};
|
|
65
|
-
export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax
|
|
51
|
+
export { allocatePerItemTaxableAmount, calculatePerQtyLineItemTax, calculateWholeQtyLineItemTax };
|
|
66
52
|
//# sourceMappingURL=tax.private.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract
|
|
1
|
+
{"version":3,"file":"tax.private.mjs","sources":["../../../src/utils/money/tax.private.ts"],"sourcesContent":["// #############################################################################\n// Internal helper functions not for consumption outside of store.core!\n// Wrote as separate files so that they can be easily unit tested without exposing them\n// #############################################################################\nimport { add, dinero, subtract } from \"dinero.js\";\n\nimport { FixedAmountAllocator } from \"./allocators/fixedAmount\";\nimport { Round } from \"./constants\";\nimport { amount, getDinero, getDineroCurrency } from \"./misc\";\nimport type {\n Dino,\n LineItemSummary,\n SingleLineItemSummary,\n TaxRate,\n} from \"./types\";\n\n/**\n * Reverse engineer the taxable amount from \"whole item\" taxable amount into \"per item\" taxable amount for custom tax\n * rate calculations\n */\nexport const allocatePerItemTaxableAmount = (\n itemSummary: LineItemSummary,\n): SingleLineItemSummary[] => {\n /**\n * If the item quantity is 1, we can just return the item summary as is\n */\n if (itemSummary.quantity === 1) {\n return [itemSummary as SingleLineItemSummary];\n }\n\n // Reverse engineer price before discount\n const preDiscountAmount = add(\n getDinero(itemSummary.taxableAmount, itemSummary.currency),\n getDinero(itemSummary.discountAmount, itemSummary.currency),\n );\n\n const allocator = new FixedAmountAllocator({\n initialAllocateAmount: itemSummary.discountAmount,\n initialTotalAmount: amount(preDiscountAmount),\n currency: itemSummary.currency,\n });\n\n // Iterate over the amount of qty to reverse engineer the discount price\n return Array.from({ length: itemSummary.quantity }, () => {\n const discountAllocatedAmount = allocator.allocate(\n itemSummary.itemPrice,\n itemSummary.currency,\n );\n\n const taxableAmount = subtract(\n getDinero(itemSummary.itemPrice, itemSummary.currency),\n discountAllocatedAmount,\n );\n\n return {\n itemPrice: itemSummary.itemPrice,\n taxableAmount: amount(taxableAmount),\n discountAmount: amount(discountAllocatedAmount),\n currency: itemSummary.currency,\n quantity: 1,\n } as SingleLineItemSummary;\n });\n};\n\nexport const calculateWholeQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n /**\n * Historically we calculate the tax by using dinero allocation, but we did not have control over how we round things.\n * So instead as we are already working with currency in cents we can multiply and round it ourselves.\n */\n return dinero({\n amount: Round.Financial(itemSummary.taxableAmount * taxRate),\n currency: getDineroCurrency(itemSummary.currency),\n });\n};\n\nexport const calculatePerQtyLineItemTax = (\n itemSummary: LineItemSummary,\n taxRate: TaxRate,\n): Dino => {\n // Nothing to calculate\n if (taxRate === 0) {\n return getDinero(0, itemSummary.currency);\n }\n\n // Split the item summary into per individual item qty summaries\n const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);\n\n // Calculate individual item qty tax and sum them up\n let totalTaxAmount = getDinero(0, itemSummary.currency);\n\n singleItemSummaries.forEach((itemSummary) => {\n // Probably a bit confusing at first, but calling the whole qty tax calculation function here as we can safely use\n // it as item summary is always a single item summary here\n const taxAmount = calculateWholeQtyLineItemTax(itemSummary, taxRate);\n totalTaxAmount = add(totalTaxAmount, taxAmount);\n });\n\n return totalTaxAmount;\n};\n"],"names":["allocatePerItemTaxableAmount","itemSummary","quantity","preDiscountAmount","add","getDinero","taxableAmount","currency","discountAmount","allocator","FixedAmountAllocator","initialAllocateAmount","initialTotalAmount","amount","Array","from","length","discountAllocatedAmount","allocate","itemPrice","subtract","calculateWholeQtyLineItemTax","taxRate","dinero","Round","Financial","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount"],"mappings":";;;;;AAoBO,MAAMA,4BAAA,GACXC,WAAA,IAC4B;EAI5B,IAAIA,WAAA,CAAYC,aAAa,CAAA,EAAG;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAC9C;EAGA,MAAME,iBAAA,GAAoBC,GAAA,CACxBC,SAAA,CAAUJ,WAAA,CAAYK,aAAA,EAAeL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAA,CAAUJ,WAAA,CAAYO,cAAA,EAAgBP,WAAA,CAAYM,QAAQ,CAAA,CAC5D;EAEA,MAAME,SAAA,GAAY,IAAIC,oBAAA,CAAqB;IACzCC,uBAAuBV,WAAA,CAAYO,cAAA;IACnCI,kBAAA,EAAoBC,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAA,CAAYM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAA,CAAK;IAAEC,QAAQf,WAAA,CAAYC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAA,CAAUS,QAAA,CACxCjB,WAAA,CAAYkB,SAAA,EACZlB,WAAA,CAAYM,QAAA,CACd;IAEA,MAAMD,aAAA,GAAgBc,QAAA,CACpBf,SAAA,CAAUJ,WAAA,CAAYkB,SAAA,EAAWlB,WAAA,CAAYM,QAAQ,CAAA,EACrDU,uBAAA,CACF;IAEA,OAAO;MACLE,WAAWlB,WAAA,CAAYkB,SAAA;MACvBb,aAAA,EAAeO,OAAOP,aAAa,CAAA;MACnCE,cAAA,EAAgBK,OAAOI,uBAAuB,CAAA;MAC9CV,UAAUN,WAAA,CAAYM,QAAA;MACtBL,QAAA,EAAU;IAAA,CACZ;EACF,CAAC,CAAA;AACH,CAAA;AAEO,MAAMmB,4BAAA,GAA+BA,CAC1CpB,WAAA,EACAqB,OAAA,KACS;EAET,IAAIA,YAAY,CAAA,EAAG;IACjB,OAAOjB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAMA,OAAOgB,MAAA,CAAO;IACZV,MAAA,EAAQW,KAAA,CAAMC,SAAA,CAAUxB,WAAA,CAAYK,gBAAgBgB,OAAO,CAAA;IAC3Df,QAAA,EAAUmB,iBAAA,CAAkBzB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEO,MAAMoB,0BAAA,GAA6BA,CACxC1B,WAAA,EACAqB,OAAA,KACS;EAET,IAAIA,YAAY,CAAA,EAAG;IACjB,OAAOjB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAC1C;EAGA,MAAMqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAA,GAAiBxB,SAAA,CAAU,CAAA,EAAGJ,WAAA,CAAYM,QAAQ,CAAA;EAEtDqB,mBAAA,CAAoBE,OAAA,CAAS7B,YAAAA,IAAgB;IAG3C,MAAM8B,SAAA,GAAYV,4BAAA,CAA6BpB,YAAAA,EAAaqB,OAAO,CAAA;IACnEO,cAAA,GAAiBzB,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAChD,CAAC,CAAA;EAED,OAAOF,cAAA;AACT,CAAA;"}
|
package/package.json
CHANGED
package/lib/assets/compact22.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 20 20"><path fill="#808893" fill-rule="evenodd" d="M2.008 12.973q0-.134.017-.263a2 2 0 0 1 1.983-1.737h12A2 2 0 0 1 17.99 12.7v.007q.018.13.018.266v1a2 2 0 0 1-2 2h-12a2 2 0 0 1-2-2zM5 13h1v1H5zm3 0h1v1H8zm4 0h-1v1h1zm2 0h1v1h-1z" clip-rule="evenodd"/><path fill="#808893" d="M4.008 9.973c-.572 0-1.108.16-1.563.439l.833-4.38A2.5 2.5 0 0 1 5.734 4h8.532a2.5 2.5 0 0 1 2.455 2.033l.831 4.367a3 3 0 0 0-1.544-.427z"/></svg>
|
package/lib/utils/map.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map.js","sources":["../../src/utils/map.ts"],"sourcesContent":["import { createArrayFromInterfaceKeys } from \"./array\";\n\n/**\n * Type-safe key parser that ensures all properties of the key are used\n */\nexport type KeyParser<Key> = (key: Key) => string;\n\n/**\n * Type-safe KeyMap implementation with compile-time validation\n */\nexport class KeyMap<Key, Value> {\n #map: Map<string, Value>;\n #keyParser: KeyParser<Key>;\n #keyValidator: (key: Key) => void;\n\n constructor(\n parser: KeyParser<Key>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n validator?: (key: Key) => void,\n ) {\n this.#keyParser = parser;\n this.#keyValidator = validator || (() => {});\n this.#map = Array.isArray(entries)\n ? new Map(\n entries.map(([key, value]) => {\n this.#keyValidator(key);\n return [this.#keyParser(key), value];\n }),\n )\n : new Map();\n }\n\n /**\n * Get a value by key with runtime validation\n */\n get(key: Key): Value | undefined {\n this.#keyValidator(key);\n return this.#map.get(this.#keyParser(key));\n }\n\n /**\n * Set a value by key with runtime validation\n */\n set(key: Key, value: Value): void {\n this.#keyValidator(key);\n this.#map.set(this.#keyParser(key), value);\n }\n\n /**\n * Check if a key exists with runtime validation\n */\n has(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.has(this.#keyParser(key));\n }\n\n /**\n * Get all values\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Get all keys (returns stringified keys)\n */\n keys(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n /**\n * Get all entries (returns stringified keys)\n */\n entries(): IterableIterator<[string, Value]> {\n return this.#map.entries();\n }\n\n /**\n * Get the size of the map\n */\n get size(): number {\n return this.#map.size;\n }\n\n /**\n * Clear all entries\n */\n clear(): void {\n this.#map.clear();\n }\n\n /**\n * Delete an entry by key\n */\n delete(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.delete(this.#keyParser(key));\n }\n\n /**\n * Create a KeyMap for database composite keys with automatic validation\n */\n static createForCompositeKey<\n Key extends Record<string, string | number>,\n Value,\n >(\n keyFieldObject: Record<keyof Key, true>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n ): KeyMap<Key, Value> {\n const keyFields = createArrayFromInterfaceKeys(keyFieldObject);\n\n const parser: KeyParser<Key> = (key) => {\n return keyFields.map((field) => String(key[field])).join(\"_\");\n };\n\n const validator = (key: Key) => {\n for (const field of keyFields) {\n if (!(field in key)) {\n throw new Error(`Missing required key field: ${String(field)}`);\n }\n if (key[field] == null) {\n throw new Error(\n `Key field ${String(field)} cannot be null or undefined`,\n );\n }\n }\n };\n\n return new KeyMap(parser, entries, validator);\n }\n}\n"],"names":["KeyMap","map","keyParser","keyValidator","constructor","parser","entries","validator","Array","isArray","Map","key","value","get","set","has","values","keys","size","clear","delete","createForCompositeKey","keyFieldObject","keyFields","createArrayFromInterfaceKeys","field","String","join","Error"],"mappings":";;;;AAUO,MAAMA,MAAA,CAAmB;EAC9B,CAAAC,GAAA;EACA,CAAAC,SAAA;EACA,CAAAC,YAAA;EAEAC,WAAAA,CACEC,MAAA,EACAC,OAAA,EACAC,SAAA,EACA;IACA,IAAA,CAAK,CAAAL,SAAA,GAAaG,MAAA;IAClB,IAAA,CAAK,CAAAF,YAAA,GAAgBI,cAAc,MAAM,CAAC,CAAA,CAAA;IAC1C,IAAA,CAAK,CAAAN,GAAA,GAAOO,KAAA,CAAMC,OAAA,CAAQH,OAAO,IAC7B,IAAII,GAAA,CACFJ,QAAQL,GAAA,CAAI,CAAC,CAACU,GAAA,EAAKC,KAAK,CAAA,KAAM;MAC5B,IAAA,CAAK,CAAAT,aAAcQ,GAAG,CAAA;MACtB,OAAO,CAAC,IAAA,CAAK,CAAAT,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KAAA,CAAA,CAAM;EAClB;EAAA;AAAA;AAAA;EAKAC,OAAOT,GAAA,EAAmB;IACxB,IAAA,CAAK,CAAAR,aAAcQ,GAAG,CAAA;IACtB,OAAO,KAAK,CAAAV,GAAA,CAAKmB,MAAA,CAAO,IAAA,CAAK,CAAAlB,SAAA,CAAWS,GAAG,CAAC,CAAA;EAC9C;EAAA;AAAA;AAAA;EAKA,OAAOU,qBAAAA,CAILC,cAAA,EACAhB,OAAA,EACoB;IACpB,MAAMiB,SAAA,GAAYC,KAAAA,CAAAA,6BAA6BF,cAAc,CAAA;IAE7D,MAAMjB,MAAA,GAA0BM,GAAA,IAAQ;MACtC,OAAOY,SAAA,CAAUtB,GAAA,CAAKwB,KAAA,IAAUC,MAAA,CAAOf,GAAA,CAAIc,KAAK,CAAC,CAAC,CAAA,CAAEE,IAAA,CAAK,GAAG,CAAA;IAC9D,CAAA;IAEA,MAAMpB,SAAA,GAAaI,GAAA,IAAa;MAC9B,KAAA,MAAWc,SAASF,SAAA,EAAW;QAC7B,IAAI,EAAEE,SAASd,GAAA,CAAA,EAAM;UACnB,MAAM,IAAIiB,KAAA,CAAM,+BAA+BF,MAAA,CAAOD,KAAK,CAAC,EAAE,CAAA;QAChE;QACA,IAAId,GAAA,CAAIc,KAAK,CAAA,IAAK,IAAA,EAAM;UACtB,MAAM,IAAIG,KAAA,CACR,aAAaF,MAAA,CAAOD,KAAK,CAAC,8BAAA,CAC5B;QACF;MACF;IACF,CAAA;IAEA,OAAO,IAAIzB,MAAA,CAAOK,MAAA,EAAQC,OAAA,EAASC,SAAS,CAAA;EAC9C;AACF;"}
|
package/lib/utils/map.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"map.mjs","sources":["../../src/utils/map.ts"],"sourcesContent":["import { createArrayFromInterfaceKeys } from \"./array\";\n\n/**\n * Type-safe key parser that ensures all properties of the key are used\n */\nexport type KeyParser<Key> = (key: Key) => string;\n\n/**\n * Type-safe KeyMap implementation with compile-time validation\n */\nexport class KeyMap<Key, Value> {\n #map: Map<string, Value>;\n #keyParser: KeyParser<Key>;\n #keyValidator: (key: Key) => void;\n\n constructor(\n parser: KeyParser<Key>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n validator?: (key: Key) => void,\n ) {\n this.#keyParser = parser;\n this.#keyValidator = validator || (() => {});\n this.#map = Array.isArray(entries)\n ? new Map(\n entries.map(([key, value]) => {\n this.#keyValidator(key);\n return [this.#keyParser(key), value];\n }),\n )\n : new Map();\n }\n\n /**\n * Get a value by key with runtime validation\n */\n get(key: Key): Value | undefined {\n this.#keyValidator(key);\n return this.#map.get(this.#keyParser(key));\n }\n\n /**\n * Set a value by key with runtime validation\n */\n set(key: Key, value: Value): void {\n this.#keyValidator(key);\n this.#map.set(this.#keyParser(key), value);\n }\n\n /**\n * Check if a key exists with runtime validation\n */\n has(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.has(this.#keyParser(key));\n }\n\n /**\n * Get all values\n */\n values(): IterableIterator<Value> {\n return this.#map.values();\n }\n\n /**\n * Get all keys (returns stringified keys)\n */\n keys(): IterableIterator<string> {\n return this.#map.keys();\n }\n\n /**\n * Get all entries (returns stringified keys)\n */\n entries(): IterableIterator<[string, Value]> {\n return this.#map.entries();\n }\n\n /**\n * Get the size of the map\n */\n get size(): number {\n return this.#map.size;\n }\n\n /**\n * Clear all entries\n */\n clear(): void {\n this.#map.clear();\n }\n\n /**\n * Delete an entry by key\n */\n delete(key: Key): boolean {\n this.#keyValidator(key);\n return this.#map.delete(this.#keyParser(key));\n }\n\n /**\n * Create a KeyMap for database composite keys with automatic validation\n */\n static createForCompositeKey<\n Key extends Record<string, string | number>,\n Value,\n >(\n keyFieldObject: Record<keyof Key, true>,\n entries?: readonly (readonly [Key, Value])[] | null | undefined,\n ): KeyMap<Key, Value> {\n const keyFields = createArrayFromInterfaceKeys(keyFieldObject);\n\n const parser: KeyParser<Key> = (key) => {\n return keyFields.map((field) => String(key[field])).join(\"_\");\n };\n\n const validator = (key: Key) => {\n for (const field of keyFields) {\n if (!(field in key)) {\n throw new Error(`Missing required key field: ${String(field)}`);\n }\n if (key[field] == null) {\n throw new Error(\n `Key field ${String(field)} cannot be null or undefined`,\n );\n }\n }\n };\n\n return new KeyMap(parser, entries, validator);\n }\n}\n"],"names":["KeyMap","map","keyParser","keyValidator","constructor","parser","entries","validator","Array","isArray","Map","key","value","get","set","has","values","keys","size","clear","delete","createForCompositeKey","keyFieldObject","keyFields","createArrayFromInterfaceKeys","field","String","join","Error"],"mappings":";;AAUO,MAAMA,MAAA,CAAmB;EAC9B,CAAAC,GAAA;EACA,CAAAC,SAAA;EACA,CAAAC,YAAA;EAEAC,WAAAA,CACEC,MAAA,EACAC,OAAA,EACAC,SAAA,EACA;IACA,IAAA,CAAK,CAAAL,SAAA,GAAaG,MAAA;IAClB,IAAA,CAAK,CAAAF,YAAA,GAAgBI,cAAc,MAAM,CAAC,CAAA,CAAA;IAC1C,IAAA,CAAK,CAAAN,GAAA,GAAOO,KAAA,CAAMC,OAAA,CAAQH,OAAO,IAC7B,IAAII,GAAA,CACFJ,QAAQL,GAAA,CAAI,CAAC,CAACU,GAAA,EAAKC,KAAK,CAAA,KAAM;MAC5B,IAAA,CAAK,CAAAT,aAAcQ,GAAG,CAAA;MACtB,OAAO,CAAC,IAAA,CAAK,CAAAT,SAAA,CAAWS,GAAG,GAAGC,KAAK,CAAA;IACrC,CAAC,CAAA,CACH,GAAA,mBACIF,GAAA,CAAA,CAAI;EACd;EAAA;AAAA;AAAA;EAKAG,IAAIF,GAAA,EAA6B;IAC/B,IAAA,CAAK,CAAAR,aAAcQ,GAAG,CAAA;IACtB,OAAO,KAAK,CAAAV,GAAA,CAAKY,GAAA,CAAI,IAAA,CAAK,CAAAX,SAAA,CAAWS,GAAG,CAAC,CAAA;EAC3C;EAAA;AAAA;AAAA;EAKAG,GAAAA,CAAIH,KAAUC,KAAA,EAAoB;IAChC,IAAA,CAAK,CAAAT,aAAcQ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ACtC,OAAOY,SAAA,CAAUtB,GAAA,CAAKwB,KAAA,IAAUC,MAAA,CAAOf,GAAA,CAAIc,KAAK,CAAC,CAAC,CAAA,CAAEE,IAAA,CAAK,GAAG,CAAA;IAC9D,CAAA;IAEA,MAAMpB,SAAA,GAAaI,GAAA,IAAa;MAC9B,KAAA,MAAWc,SAASF,SAAA,EAAW;QAC7B,IAAI,EAAEE,SAASd,GAAA,CAAA,EAAM;UACnB,MAAM,IAAIiB,KAAA,CAAM,+BAA+BF,MAAA,CAAOD,KAAK,CAAC,EAAE,CAAA;QAChE;QACA,IAAId,GAAA,CAAIc,KAAK,CAAA,IAAK,IAAA,EAAM;UACtB,MAAM,IAAIG,KAAA,CACR,aAAaF,MAAA,CAAOD,KAAK,CAAC,8BAAA,CAC5B;QACF;MACF;IACF,CAAA;IAEA,OAAO,IAAIzB,MAAA,CAAOK,MAAA,EAAQC,OAAA,EAASC,SAAS,CAAA;EAC9C;AACF;"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Currency } from "../../../types";
|
|
2
|
-
import type { Cents, Dino } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* Helper class to distribute a total amount across a quantity of items.
|
|
5
|
-
*/
|
|
6
|
-
export declare class TotalAmountAllocator {
|
|
7
|
-
#private;
|
|
8
|
-
constructor({ amount, quantity, currency, }: {
|
|
9
|
-
quantity: number;
|
|
10
|
-
amount: Cents;
|
|
11
|
-
currency: Currency;
|
|
12
|
-
});
|
|
13
|
-
allocate(quantity: number): {
|
|
14
|
-
qtyAllocated: number;
|
|
15
|
-
amount: Dino;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var dinero_js = require('dinero.js');
|
|
4
|
-
var errors = require('../../errors.js');
|
|
5
|
-
var misc = require('../misc.js');
|
|
6
|
-
"use strict";
|
|
7
|
-
class TotalAmountAllocator {
|
|
8
|
-
#remainingAmount;
|
|
9
|
-
#remainingQuantity;
|
|
10
|
-
#currency;
|
|
11
|
-
constructor({
|
|
12
|
-
amount,
|
|
13
|
-
quantity,
|
|
14
|
-
currency
|
|
15
|
-
}) {
|
|
16
|
-
this.#remainingAmount = misc.getDinero(amount, currency);
|
|
17
|
-
this.#remainingQuantity = quantity;
|
|
18
|
-
this.#currency = currency;
|
|
19
|
-
}
|
|
20
|
-
allocate(quantity) {
|
|
21
|
-
const quantityToAllocate = Math.min(quantity, this.#remainingQuantity);
|
|
22
|
-
if (quantityToAllocate === 0) {
|
|
23
|
-
return {
|
|
24
|
-
qtyAllocated: 0,
|
|
25
|
-
amount: misc.getDinero(0, this.#currency)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
const [allocated, newRemainingAmount] = dinero_js.allocate(this.#remainingAmount, [quantityToAllocate, this.#remainingQuantity - quantityToAllocate]);
|
|
29
|
-
errors.assert(!!allocated, "Couldn't allocate amount");
|
|
30
|
-
errors.assert(!!newRemainingAmount, "Couldn't retrieve remaining amount");
|
|
31
|
-
this.#remainingAmount = newRemainingAmount;
|
|
32
|
-
this.#remainingQuantity -= quantityToAllocate;
|
|
33
|
-
return {
|
|
34
|
-
qtyAllocated: quantityToAllocate,
|
|
35
|
-
amount: allocated
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.TotalAmountAllocator = TotalAmountAllocator;
|
|
40
|
-
//# sourceMappingURL=totalAmount.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"totalAmount.js","sources":["../../../../src/utils/money/allocators/totalAmount.ts"],"sourcesContent":["import { allocate } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { getDinero } from \"../misc\";\nimport type { Cents, Dino } from \"../types\";\n\n/**\n * Helper class to distribute a total amount across a quantity of items.\n */\nexport class TotalAmountAllocator {\n #remainingAmount: Dino;\n #remainingQuantity: number;\n #currency: Currency;\n\n constructor({\n amount,\n quantity,\n currency,\n }: {\n quantity: number;\n amount: Cents;\n currency: Currency;\n }) {\n this.#remainingAmount = getDinero(amount, currency);\n this.#remainingQuantity = quantity;\n this.#currency = currency;\n }\n\n allocate(quantity: number): { qtyAllocated: number; amount: Dino } {\n // Normalize quantity to not exceed remaining\n const quantityToAllocate = Math.min(quantity, this.#remainingQuantity);\n\n if (quantityToAllocate === 0) {\n return { qtyAllocated: 0, amount: getDinero(0, this.#currency) };\n }\n\n const [allocated, newRemainingAmount] = allocate(this.#remainingAmount, [\n quantityToAllocate,\n this.#remainingQuantity - quantityToAllocate,\n ]);\n\n assert(!!allocated, \"Couldn't allocate amount\");\n assert(!!newRemainingAmount, \"Couldn't retrieve remaining amount\");\n\n // Update remaining amounts\n this.#remainingAmount = newRemainingAmount;\n this.#remainingQuantity -= quantityToAllocate;\n\n return { qtyAllocated: quantityToAllocate, amount: allocated };\n }\n}\n"],"names":["TotalAmountAllocator","remainingAmount","remainingQuantity","currency","constructor","amount","quantity","getDinero","allocate","quantityToAllocate","Math","min","qtyAllocated","allocated","newRemainingAmount","assert"],"mappings":";;;;;;AAUO,MAAMA,oBAAA,CAAqB;EAChC,CAAAC,eAAA;EACA,CAAAC,iBAAA;EACA,CAAAC,QAAA;EAEAC,WAAAA,CAAY;IACVC,MAAA;IACAC,QAAA;IACAH;EAAA,CACF,EAIG;IACD,IAAA,CAAK,CAAAF,eAAA,GAAmBM,cAAA,CAAUF,MAAA,EAAQF,QAAQ,CAAA;IAClD,IAAA,CAAK,CAAAD,iBAAA,GAAqBI,QAAA;IAC1B,IAAA,CAAK,CAAAH,QAAA,GAAYA,QAAA;EACnB;EAEAK,SAASF,QAAA,EAA0D;IAEjE,MAAMG,kBAAA,GAAqBC,IAAA,CAAKC,GAAA,CAAIL,QAAA,EAAU,KAAK,CAAAJ,iBAAkB,CAAA;IAErE,IAAIO,uBAAuB,CAAA,EAAG;MAC5B,OAAO;QAAEG,cAAc,CAAA;QAAGP,MAAA,EAAQE,IAAAA,CAAAA,UAAU,CAAA,EAAG,IAAA,CAAK,CAAAJ,QAAS;MAAA,CAAE;IACjE;IAEA,MAAM,CAACU,SAAA,EAAWC,kBAAkB,CAAA,GAAIN,SAAAA,CAAAA,QAAA,CAAS,KAAK,CAAAP,eAAA,EAAkB,CACtEQ,kBAAA,EACA,KAAK,CAAAP,iBAAA,GAAqBO,kBAAA,CAC3B,CAAA;IAEDM,aAAA,CAAO,CAAC,CAACF,SAAA,EAAW,0BAA0B,CAAA;IAC9CE,aAAA,CAAO,CAAC,CAACD,kBAAA,EAAoB,oCAAoC,CAAA;IAGjE,IAAA,CAAK,CAAAb,eAAA,GAAmBa,kBAAA;IACxB,IAAA,CAAK,CAAAZ,iBAAA,IAAsBO,kBAAA;IAE3B,OAAO;MAAEG,YAAA,EAAcH,kBAAA;MAAoBJ,MAAA,EAAQQ;IAAA,CAAU;EAC/D;AACF;"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { allocate } from 'dinero.js';
|
|
2
|
-
import { assert } from '../../errors.mjs';
|
|
3
|
-
import { getDinero } from '../misc.mjs';
|
|
4
|
-
"use strict";
|
|
5
|
-
class TotalAmountAllocator {
|
|
6
|
-
#remainingAmount;
|
|
7
|
-
#remainingQuantity;
|
|
8
|
-
#currency;
|
|
9
|
-
constructor({
|
|
10
|
-
amount,
|
|
11
|
-
quantity,
|
|
12
|
-
currency
|
|
13
|
-
}) {
|
|
14
|
-
this.#remainingAmount = getDinero(amount, currency);
|
|
15
|
-
this.#remainingQuantity = quantity;
|
|
16
|
-
this.#currency = currency;
|
|
17
|
-
}
|
|
18
|
-
allocate(quantity) {
|
|
19
|
-
const quantityToAllocate = Math.min(quantity, this.#remainingQuantity);
|
|
20
|
-
if (quantityToAllocate === 0) {
|
|
21
|
-
return {
|
|
22
|
-
qtyAllocated: 0,
|
|
23
|
-
amount: getDinero(0, this.#currency)
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const [allocated, newRemainingAmount] = allocate(this.#remainingAmount, [quantityToAllocate, this.#remainingQuantity - quantityToAllocate]);
|
|
27
|
-
assert(!!allocated, "Couldn't allocate amount");
|
|
28
|
-
assert(!!newRemainingAmount, "Couldn't retrieve remaining amount");
|
|
29
|
-
this.#remainingAmount = newRemainingAmount;
|
|
30
|
-
this.#remainingQuantity -= quantityToAllocate;
|
|
31
|
-
return {
|
|
32
|
-
qtyAllocated: quantityToAllocate,
|
|
33
|
-
amount: allocated
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
export { TotalAmountAllocator };
|
|
38
|
-
//# sourceMappingURL=totalAmount.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"totalAmount.mjs","sources":["../../../../src/utils/money/allocators/totalAmount.ts"],"sourcesContent":["import { allocate } from \"dinero.js\";\n\nimport type { Currency } from \"../../../types\";\nimport { assert } from \"../../errors\";\nimport { getDinero } from \"../misc\";\nimport type { Cents, Dino } from \"../types\";\n\n/**\n * Helper class to distribute a total amount across a quantity of items.\n */\nexport class TotalAmountAllocator {\n #remainingAmount: Dino;\n #remainingQuantity: number;\n #currency: Currency;\n\n constructor({\n amount,\n quantity,\n currency,\n }: {\n quantity: number;\n amount: Cents;\n currency: Currency;\n }) {\n this.#remainingAmount = getDinero(amount, currency);\n this.#remainingQuantity = quantity;\n this.#currency = currency;\n }\n\n allocate(quantity: number): { qtyAllocated: number; amount: Dino } {\n // Normalize quantity to not exceed remaining\n const quantityToAllocate = Math.min(quantity, this.#remainingQuantity);\n\n if (quantityToAllocate === 0) {\n return { qtyAllocated: 0, amount: getDinero(0, this.#currency) };\n }\n\n const [allocated, newRemainingAmount] = allocate(this.#remainingAmount, [\n quantityToAllocate,\n this.#remainingQuantity - quantityToAllocate,\n ]);\n\n assert(!!allocated, \"Couldn't allocate amount\");\n assert(!!newRemainingAmount, \"Couldn't retrieve remaining amount\");\n\n // Update remaining amounts\n this.#remainingAmount = newRemainingAmount;\n this.#remainingQuantity -= quantityToAllocate;\n\n return { qtyAllocated: quantityToAllocate, amount: allocated };\n }\n}\n"],"names":["TotalAmountAllocator","remainingAmount","remainingQuantity","currency","constructor","amount","quantity","getDinero","allocate","quantityToAllocate","Math","min","qtyAllocated","allocated","newRemainingAmount","assert"],"mappings":";;;;AAUO,MAAMA,oBAAA,CAAqB;EAChC,CAAAC,eAAA;EACA,CAAAC,iBAAA;EACA,CAAAC,QAAA;EAEAC,WAAAA,CAAY;IACVC,MAAA;IACAC,QAAA;IACAH;EAAA,CACF,EAIG;IACD,IAAA,CAAK,CAAAF,eAAA,GAAmBM,SAAA,CAAUF,MAAA,EAAQF,QAAQ,CAAA;IAClD,IAAA,CAAK,CAAAD,iBAAA,GAAqBI,QAAA;IAC1B,IAAA,CAAK,CAAAH,QAAA,GAAYA,QAAA;EACnB;EAEAK,SAASF,QAAA,EAA0D;IAEjE,MAAMG,kBAAA,GAAqBC,IAAA,CAAKC,GAAA,CAAIL,QAAA,EAAU,KAAK,CAAAJ,iBAAkB,CAAA;IAErE,IAAIO,uBAAuB,CAAA,EAAG;MAC5B,OAAO;QAAEG,cAAc,CAAA;QAAGP,MAAA,EAAQE,UAAU,CAAA,EAAG,IAAA,CAAK,CAAAJ,QAAS;MAAA,CAAE;IACjE;IAEA,MAAM,CAACU,SAAA,EAAWC,kBAAkB,CAAA,GAAIN,QAAA,CAAS,KAAK,CAAAP,eAAA,EAAkB,CACtEQ,kBAAA,EACA,KAAK,CAAAP,iBAAA,GAAqBO,kBAAA,CAC3B,CAAA;IAEDM,MAAA,CAAO,CAAC,CAACF,SAAA,EAAW,0BAA0B,CAAA;IAC9CE,MAAA,CAAO,CAAC,CAACD,kBAAA,EAAoB,oCAAoC,CAAA;IAGjE,IAAA,CAAK,CAAAb,eAAA,GAAmBa,kBAAA;IACxB,IAAA,CAAK,CAAAZ,iBAAA,IAAsBO,kBAAA;IAE3B,OAAO;MAAEG,YAAA,EAAcH,kBAAA;MAAoBJ,MAAA,EAAQQ;IAAA,CAAU;EAC/D;AACF;"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|