@ubnt/store.core 11.12.0-beta.1 → 11.12.0-beta.2

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.
Files changed (167) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/assets/ai-360.jpg +0 -0
  3. package/lib/assets/ai-3602.jpg +0 -0
  4. package/lib/assets/ai-lpr.jpg +0 -0
  5. package/lib/assets/ai-lpr2.jpg +0 -0
  6. package/lib/assets/ai-theta.jpg +0 -0
  7. package/lib/assets/ai-theta2.jpg +0 -0
  8. package/lib/assets/attention.svg +1 -1
  9. package/lib/assets/attention2.svg +1 -1
  10. package/lib/assets/door-hub-mini.jpg +0 -0
  11. package/lib/assets/door-hub-mini2.jpg +0 -0
  12. package/lib/assets/g2-reader-pro.jpg +0 -0
  13. package/lib/assets/g2-reader-pro2.jpg +0 -0
  14. package/lib/assets/g3-reader-flex.jpg +0 -0
  15. package/lib/assets/g3-reader-flex2.jpg +0 -0
  16. package/lib/assets/g3-reader-pro.jpg +0 -0
  17. package/lib/assets/g3-reader-pro2.jpg +0 -0
  18. package/lib/assets/g3-reader.jpg +0 -0
  19. package/lib/assets/g3-reader2.jpg +0 -0
  20. package/lib/assets/g3-starter-kit-pro.jpg +0 -0
  21. package/lib/assets/g3-starter-kit-pro2.jpg +0 -0
  22. package/lib/assets/g5-dome.jpg +0 -0
  23. package/lib/assets/g5-dome2.jpg +0 -0
  24. package/lib/assets/g5-flex.jpg +0 -0
  25. package/lib/assets/g5-flex2.jpg +0 -0
  26. package/lib/assets/g5-turret-ultra.jpg +0 -0
  27. package/lib/assets/g5-turret-ultra2.jpg +0 -0
  28. package/lib/assets/intercom.jpg +0 -0
  29. package/lib/assets/intercom2.jpg +0 -0
  30. package/lib/assets/interior-design.svg +1 -1
  31. package/lib/assets/interior-design2.svg +1 -1
  32. package/lib/assets/minus4.svg +1 -1
  33. package/lib/assets/minus5.svg +1 -1
  34. package/lib/assets/plus4.svg +1 -1
  35. package/lib/assets/plus5.svg +1 -1
  36. package/lib/assets/ptz2.svg +1 -1
  37. package/lib/assets/ptz3.svg +1 -1
  38. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.js +1 -1
  39. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputCard.mjs +1 -1
  40. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.js +2 -2
  41. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/InputSections/CounterSection.mjs +2 -2
  42. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.js +1 -1
  43. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/attention.svg.mjs +2 -2
  44. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.js +1 -1
  45. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/minus.svg.mjs +2 -2
  46. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.js +1 -1
  47. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/InputCard/assets/plus.svg.mjs +2 -2
  48. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.js +1 -1
  49. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/ProgressBarChart.mjs +1 -1
  50. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.js +1 -1
  51. package/lib/components/ResourceCalculatorV1/ComputeResourceCalculator/components/ProgressBarChart/assets/attention.svg.mjs +2 -2
  52. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.js +2 -2
  53. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/PoeConsumerSelectModal/PoeConsumerSelectModal.mjs +2 -2
  54. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.js +1 -1
  55. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/minus.svg.mjs +2 -2
  56. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.js +1 -1
  57. package/lib/components/ResourceCalculatorV1/PoeCalculator/components/PoeConsumerConfigurator/assets/plus.svg.mjs +2 -2
  58. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.js +1 -1
  59. package/lib/constants/modelCompareData/assets/Bullet/ai-lpr.jpg.mjs +2 -2
  60. package/lib/constants/modelCompareData/assets/Compact/g5-flex.jpg.js +1 -1
  61. package/lib/constants/modelCompareData/assets/Compact/g5-flex.jpg.mjs +2 -2
  62. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.js +1 -1
  63. package/lib/constants/modelCompareData/assets/DomeTurret/ai-360.jpg.mjs +2 -2
  64. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.js +1 -1
  65. package/lib/constants/modelCompareData/assets/DomeTurret/g5-dome.jpg.mjs +2 -2
  66. package/lib/constants/modelCompareData/assets/DomeTurret/g5-turret-ultra.jpg.js +1 -1
  67. package/lib/constants/modelCompareData/assets/DomeTurret/g5-turret-ultra.jpg.mjs +2 -2
  68. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.js +1 -1
  69. package/lib/constants/modelCompareData/assets/DoorAccess/door-hub-mini.jpg.mjs +2 -2
  70. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.js +1 -1
  71. package/lib/constants/modelCompareData/assets/DoorAccess/g2-reader-pro.jpg.mjs +2 -2
  72. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.js +1 -1
  73. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-flex.jpg.mjs +2 -2
  74. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.js +1 -1
  75. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader-pro.jpg.mjs +2 -2
  76. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader.jpg.js +1 -1
  77. package/lib/constants/modelCompareData/assets/DoorAccess/g3-reader.jpg.mjs +2 -2
  78. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.js +1 -1
  79. package/lib/constants/modelCompareData/assets/DoorAccess/g3-starter-kit-pro.jpg.mjs +2 -2
  80. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.js +1 -1
  81. package/lib/constants/modelCompareData/assets/DoorAccess/intercom.jpg.mjs +2 -2
  82. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.js +1 -1
  83. package/lib/constants/modelCompareData/assets/Interior/ai-theta.jpg.mjs +2 -2
  84. package/lib/constants/modelCompareData/assets/interior-design.svg.js +1 -1
  85. package/lib/constants/modelCompareData/assets/interior-design.svg.mjs +2 -2
  86. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.js +1 -1
  87. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/bullet/ai-lpr.jpg.mjs +2 -2
  88. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g5-flex.jpg.js +1 -1
  89. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/compact/g5-flex.jpg.mjs +2 -2
  90. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.js +1 -1
  91. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/ai-360.jpg.mjs +2 -2
  92. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.js +1 -1
  93. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-dome.jpg.mjs +2 -2
  94. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-turret-ultra.jpg.js +1 -1
  95. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/dome-and-turret/g5-turret-ultra.jpg.mjs +2 -2
  96. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.js +1 -1
  97. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/door-hub-mini.jpg.mjs +2 -2
  98. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.js +1 -1
  99. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g2-reader-pro.jpg.mjs +2 -2
  100. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.js +1 -1
  101. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-flex.jpg.mjs +2 -2
  102. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.js +1 -1
  103. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader-pro.jpg.mjs +2 -2
  104. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader.jpg.js +1 -1
  105. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-reader.jpg.mjs +2 -2
  106. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.js +1 -1
  107. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/g3-starter-kit-pro.jpg.mjs +2 -2
  108. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.js +1 -1
  109. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/door-access/intercom.jpg.mjs +2 -2
  110. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.js +1 -1
  111. package/lib/constants/modelCompareData/assets/product-list-assets/cameras/interior-design/ai-theta.jpg.mjs +2 -2
  112. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.js +1 -1
  113. package/lib/constants/modelCompareData/assets/product-list-assets/interior-design.svg.mjs +2 -2
  114. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.js +1 -1
  115. package/lib/constants/modelCompareData/assets/product-list-assets/ptz.svg.mjs +2 -2
  116. package/lib/constants/modelCompareData/assets/ptz.svg.js +1 -1
  117. package/lib/constants/modelCompareData/assets/ptz.svg.mjs +2 -2
  118. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.js +1 -1
  119. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/InteriorDesign.mjs +1 -1
  120. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.js +1 -1
  121. package/lib/constants/modelCompareData/data/product-groups/cameraSecurity/Ptz.mjs +1 -1
  122. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.js +1 -1
  123. package/lib/constants/modelCompareData/data/product-list-groups/interiorDesign.mjs +1 -1
  124. package/lib/constants/modelCompareData/data/product-list-groups/ptz.js +1 -1
  125. package/lib/constants/modelCompareData/data/product-list-groups/ptz.mjs +1 -1
  126. package/lib/constants/modelCompareData/data/products/ai360.js +2 -2
  127. package/lib/constants/modelCompareData/data/products/ai360.mjs +2 -2
  128. package/lib/constants/modelCompareData/data/products/aiLpr.js +2 -2
  129. package/lib/constants/modelCompareData/data/products/aiLpr.mjs +2 -2
  130. package/lib/constants/modelCompareData/data/products/doorHubMini.js +2 -2
  131. package/lib/constants/modelCompareData/data/products/doorHubMini.mjs +2 -2
  132. package/lib/constants/modelCompareData/data/products/g2ReaderPro.js +2 -2
  133. package/lib/constants/modelCompareData/data/products/g2ReaderPro.mjs +2 -2
  134. package/lib/constants/modelCompareData/data/products/g3Reader.js +2 -2
  135. package/lib/constants/modelCompareData/data/products/g3Reader.mjs +2 -2
  136. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.js +2 -2
  137. package/lib/constants/modelCompareData/data/products/g3ReaderFlex.mjs +2 -2
  138. package/lib/constants/modelCompareData/data/products/g3ReaderPro.js +2 -2
  139. package/lib/constants/modelCompareData/data/products/g3ReaderPro.mjs +2 -2
  140. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.js +2 -2
  141. package/lib/constants/modelCompareData/data/products/g3StarterKitPro.mjs +2 -2
  142. package/lib/constants/modelCompareData/data/products/g5Dome.js +2 -2
  143. package/lib/constants/modelCompareData/data/products/g5Dome.mjs +2 -2
  144. package/lib/constants/modelCompareData/data/products/g5Flex.js +2 -2
  145. package/lib/constants/modelCompareData/data/products/g5Flex.mjs +2 -2
  146. package/lib/constants/modelCompareData/data/products/g5TurretUltra.js +2 -2
  147. package/lib/constants/modelCompareData/data/products/g5TurretUltra.mjs +2 -2
  148. package/lib/constants/modelCompareData/data/products/intercom.js +2 -2
  149. package/lib/constants/modelCompareData/data/products/intercom.mjs +2 -2
  150. package/lib/constants/modelCompareData/data/products/theta.js +2 -2
  151. package/lib/constants/modelCompareData/data/products/theta.mjs +2 -2
  152. package/lib/utils/money/constants.d.ts +5 -0
  153. package/lib/utils/money/constants.js +6 -1
  154. package/lib/utils/money/constants.js.map +1 -1
  155. package/lib/utils/money/constants.mjs +7 -2
  156. package/lib/utils/money/constants.mjs.map +1 -1
  157. package/lib/utils/money/tax.d.ts +1 -1
  158. package/lib/utils/money/tax.js +6 -1
  159. package/lib/utils/money/tax.js.map +1 -1
  160. package/lib/utils/money/tax.mjs +8 -3
  161. package/lib/utils/money/tax.mjs.map +1 -1
  162. package/lib/utils/money/tax.private.d.ts +2 -2
  163. package/lib/utils/money/tax.private.js +3 -3
  164. package/lib/utils/money/tax.private.js.map +1 -1
  165. package/lib/utils/money/tax.private.mjs +3 -3
  166. package/lib/utils/money/tax.private.mjs.map +1 -1
  167. package/package.json +1 -1
@@ -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 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,CAIM,KAAA;EACG,OAAAC,wBAAA,CAAyBC,GAAI,CAAAF,OAAO,CACvC,GAAAG,0BAAA,CAA2BL,aAAaC,OAAO,CAAA,GAC/CK,4BAA6B,CAAAN,WAAA,EAAaC,OAAO,CAAA;AACvD,CAAA;AAEa,MAAAM,eAAA,GAAkBA,CAC7BC,oBAAA,EACAP,OACG,KAAA;EACG,MAAAQ,QAAA,GAAWC,WAAWF,oBAAoB,CAAA;EAGhD,MAAMG,YAAYC,KAAM,CAAAC,SAAA,CACtBJ,QAAS,CAAAK,MAAA,GAASL,QAAS,CAAAK,MAAA,IAAU,CAAI,GAAAb,OAAA,CAC3C,CAAA;EAEA,OAAOc,MAAO,CAAA;IACZ,GAAGN,QAAA;IACHK,MAAA,EAAQL,SAASK,MAAS,GAAAH;EAAA,CAC3B,CAAA;AACH,CAAA;AAWa,MAAAK,iCAAA,GACXf,OACW,IAAA;EACL,MAAAgB,SAAA,GAAYC,uBAAuBjB,OAAO,CAAA;EAC1C,MAAAkB,CAAA,GAAIC,QAAS,CAAAH,SAAA,EAAW,GAAG,CAAA;EACjC,OAAOI,OAAOF,CAAG,EAAA;IACfG,QAAQC,wBAAyB,CAAAC,QAAA;IACjCC,KAAO,EAAAC;EAAA,CACR,CAAA;AACH,CAAA;AAEa,MAAAR,sBAAA,GAA0BjB,OAAmC,IAAA;EACxE,MAAM0B,eACJ,OAAO1B,OAAA,KAAY,WAAWA,OAAU,GAAA2B,MAAA,CAAOC,WAAW5B,OAAO,CAAA;EACnE6B,OAAA,CAAQH,YAAY,CAAA;EAEpB,MAAMI,kBAAkBH,MAAO,CAAAI,QAAA,CAE3B,CAAAL,YAAA,GACAM,KAAKC,GAAI,CAAAX,wBAAA,CAAyBY,MAAMZ,wBAAyB,CAAAC,QAAQ,CACzE,EAAAY,OAAA,CAAQ,CAAC,CACb,CAAA;EACA,OAAOrB,MAAO,CAAA;IACZD,MAAQ,EAAAiB,eAAA;IACRM,QAAU,EAAAd;EAAA,CACX,CAAA;AACH,CAAA;AAWa,MAAAe,oBAAA,GACXrC,OACiB,IAAA;EACV,OAAA,GAAGe,iCAAkC,CAAAf,OAAO,CAAC,GAAA;AACtD,CAAA;AAEa,MAAAsC,oBAAA,GAAwBC,IACnC,IAAAC,WAAA,CAAY,CAACD,IAAM,EAAAjB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAM/C,MAAAkB,qBAAA,GAAyBC,KAA4B,IAAA;EAC1D,MAAAC,OAAA,GAAUD,MAAME,MAAO,CAAA,CAACC,KAAKN,IAAS,KAAAM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAS,GAAAN,WAAA,CAAYG,OAAS,EAAArB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EACpEwB,MAAA,CAAAD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EACxCC,MAAA,CAAAD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EAC1C,OAAAA,MAAA;AACT,CAAA;"}
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 { 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 // TODO: NEP-4834 Talk with @renarsvilnis about this approach:\n // Search by `NEP-4834`\n if (storeId === StoreId.Cn) {\n return calculateWholeQtyLineItemTax(itemSummary, taxRate, Round.ChinaRound);\n }\n\n return storesWithPerItemTaxRate.has(storeId)\n ? calculatePerQtyLineItemTax(itemSummary, taxRate)\n : calculateWholeQtyLineItemTax(itemSummary, taxRate, Round.Financial);\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","StoreId","Cn","calculateWholeQtyLineItemTax","Round","ChinaRound","storesWithPerItemTaxRate","has","calculatePerQtyLineItemTax","Financial","removeTaxAmount","baseAmountWithTaxObj","snapshot","toSnapshot","taxAmount","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,CAA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,YAAA,GACAM,KAAKC,GAAI,CAAAX,wBAAA,CAAyBY,MAAMZ,wBAAyB,CAAAC,QAAQ,CACzE,EAAAY,OAAA,CAAQ,CAAC,CACb,CAAA;EACA,OAAOrB,MAAO,CAAA;IACZD,MAAQ,EAAAiB,eAAA;IACRM,QAAU,EAAAd;EAAA,CACX,CAAA;AACH,CAAA;AAWa,MAAAe,oBAAA,GACXxC,OACiB,IAAA;EACV,OAAA,GAAGkB,iCAAkC,CAAAlB,OAAO,CAAC,GAAA;AACtD,CAAA;AAEa,MAAAyC,oBAAA,GAAwBC,IACnC,IAAAC,WAAA,CAAY,CAACD,IAAM,EAAAjB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;AAM/C,MAAAkB,qBAAA,GAAyBC,KAA4B,IAAA;EAC1D,MAAAC,OAAA,GAAUD,MAAME,MAAO,CAAA,CAACC,KAAKN,IAAS,KAAAM,GAAA,GAAMN,MAAM,CAAC,CAAA;EACzD,MAAMO,MAAS,GAAAN,WAAA,CAAYG,OAAS,EAAArB,wBAAA,CAAyBC,UAAU,IAAI,CAAA;EACpEwB,MAAA,CAAAD,MAAA,IAAU,GAAG,2BAA2B,CAAA;EACxCC,MAAA,CAAAD,MAAA,GAAS,GAAG,8BAA8B,CAAA;EAC1C,OAAAA,MAAA;AACT,CAAA;"}
@@ -1,8 +1,8 @@
1
- import type { Dino, LineItemSummary, SingleLineItemSummary, TaxRate } from "./types";
1
+ import type { Dino, LineItemSummary, RoundingFn, SingleLineItemSummary, TaxRate } from "./types";
2
2
  /**
3
3
  * Reverse engineer the taxable amount from "whole item" taxable amount into "per item" taxable amount for custom tax
4
4
  * rate calculations
5
5
  */
6
6
  export declare const allocatePerItemTaxableAmount: (itemSummary: LineItemSummary) => SingleLineItemSummary[];
7
- export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
7
+ export declare const calculateWholeQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate, rounding: RoundingFn) => Dino;
8
8
  export declare const calculatePerQtyLineItemTax: (itemSummary: LineItemSummary, taxRate: TaxRate) => Dino;
@@ -29,12 +29,12 @@ const allocatePerItemTaxableAmount = itemSummary => {
29
29
  };
30
30
  });
31
31
  };
32
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
32
+ const calculateWholeQtyLineItemTax = (itemSummary, taxRate, rounding) => {
33
33
  if (taxRate === 0) {
34
34
  return misc.getDinero(0, itemSummary.currency);
35
35
  }
36
36
  return dinero_js.dinero({
37
- amount: constants.Round.Financial(itemSummary.taxableAmount * taxRate),
37
+ amount: rounding(itemSummary.taxableAmount * taxRate),
38
38
  currency: misc.getDineroCurrency(itemSummary.currency)
39
39
  });
40
40
  };
@@ -45,7 +45,7 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
45
45
  const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
46
46
  let totalTaxAmount = misc.getDinero(0, itemSummary.currency);
47
47
  singleItemSummaries.forEach(itemSummary2 => {
48
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
48
+ const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate, constants.Round.Financial);
49
49
  totalTaxAmount = dinero_js.add(totalTaxAmount, taxAmount);
50
50
  });
51
51
  return totalTaxAmount;
@@ -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 } 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":";;;;;;;AAoBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAAA;EAI9C,MAAME,iBAAoB,GAAAC,SAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,IAAAA,CAAAA,SAAU,CAAAJ,WAAA,CAAYO,cAAgB,EAAAP,WAAA,CAAYM,QAAQ,CAC5D,CAAA;EAEM,MAAAE,SAAA,GAAY,IAAIC,gCAAqB,CAAA;IACzCC,uBAAuBV,WAAY,CAAAO,cAAA;IACnCI,kBAAA,EAAoBC,YAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAY,CAAAM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAK,CAAA;IAAEC,QAAQf,WAAY,CAAAC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAU,CAAAS,QAAA,CACxCjB,WAAY,CAAAkB,SAAA,EACZlB,WAAY,CAAAM,QACd,CAAA;IAEA,MAAMD,aAAgB,GAAAc,SAAA,CAAAA,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AAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,cAAA;AACT,CAAA;;;"}
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 RoundingFn,\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 // TODO: Search by NEP-4834\n rounding: RoundingFn,\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: rounding(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(\n itemSummary,\n taxRate,\n Round.Financial,\n );\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","rounding","dinero","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount","Round","Financial"],"mappings":";;;;;;;AAqBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAAA;EAI9C,MAAME,iBAAoB,GAAAC,SAAA,CAAAA,GAAA,CACxBC,IAAAA,CAAAA,SAAU,CAAA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AAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEa,MAAAmB,0BAAA,GAA6BA,CACxCzB,WAAA,EACAqB,OACS,KAAA;EAET,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAjB,cAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAAA;EAIpC,MAAAoB,mBAAA,GAAsB3B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI2B,cAAiB,GAAAvB,IAAA,CAAAA,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCoB,mBAAA,CAAAE,OAAA,CAAS5B,YAAgB,IAAA;IAG3C,MAAM6B,SAAY,GAAAT,4BAAA,CAChBpB,YAAAA,EACAqB,OAAA,EACAS,eAAM,CAAAC,SACR,CAAA;IACiBJ,cAAA,GAAAxB,SAAAA,CAAAA,GAAA,CAAIwB,gBAAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,cAAA;AACT,CAAA;;;"}
@@ -27,12 +27,12 @@ const allocatePerItemTaxableAmount = itemSummary => {
27
27
  };
28
28
  });
29
29
  };
30
- const calculateWholeQtyLineItemTax = (itemSummary, taxRate) => {
30
+ const calculateWholeQtyLineItemTax = (itemSummary, taxRate, rounding) => {
31
31
  if (taxRate === 0) {
32
32
  return getDinero(0, itemSummary.currency);
33
33
  }
34
34
  return dinero({
35
- amount: Round.Financial(itemSummary.taxableAmount * taxRate),
35
+ amount: rounding(itemSummary.taxableAmount * taxRate),
36
36
  currency: getDineroCurrency(itemSummary.currency)
37
37
  });
38
38
  };
@@ -43,7 +43,7 @@ const calculatePerQtyLineItemTax = (itemSummary, taxRate) => {
43
43
  const singleItemSummaries = allocatePerItemTaxableAmount(itemSummary);
44
44
  let totalTaxAmount = getDinero(0, itemSummary.currency);
45
45
  singleItemSummaries.forEach(itemSummary2 => {
46
- const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate);
46
+ const taxAmount = calculateWholeQtyLineItemTax(itemSummary2, taxRate, Round.Financial);
47
47
  totalTaxAmount = add(totalTaxAmount, taxAmount);
48
48
  });
49
49
  return totalTaxAmount;
@@ -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 } 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":";;;;;AAoBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAAA;EAI9C,MAAME,iBAAoB,GAAAC,GAAA,CACxBC,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAA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IA,YAAY,CAAG,EAAA;IACV,OAAAjB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAAA;EAIpC,MAAAqB,mBAAA,GAAsB5B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI4B,cAAiB,GAAAxB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCqB,mBAAA,CAAAE,OAAA,CAAS7B,YAAgB,IAAA;IAGrC,MAAA8B,SAAA,GAAYV,4BAA6BpB,CAAAA,YAAAA,EAAaqB,OAAO,CAAA;IAClDO,cAAA,GAAAzB,GAAA,CAAIyB,gBAAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,cAAA;AACT,CAAA;"}
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 RoundingFn,\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 // TODO: Search by NEP-4834\n rounding: RoundingFn,\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: rounding(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(\n itemSummary,\n taxRate,\n Round.Financial,\n );\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","rounding","dinero","getDineroCurrency","calculatePerQtyLineItemTax","singleItemSummaries","totalTaxAmount","forEach","taxAmount","Round","Financial"],"mappings":";;;;;AAqBa,MAAAA,4BAAA,GACXC,WAC4B,IAAA;EAIxB,IAAAA,WAAA,CAAYC,aAAa,CAAG,EAAA;IAC9B,OAAO,CAACD,WAAoC,CAAA;EAAA;EAI9C,MAAME,iBAAoB,GAAAC,GAAA,CACxBC,SAAU,CAAAJ,WAAA,CAAYK,aAAe,EAAAL,WAAA,CAAYM,QAAQ,CAAA,EACzDF,SAAU,CAAAJ,WAAA,CAAYO,cAAgB,EAAAP,WAAA,CAAYM,QAAQ,CAC5D,CAAA;EAEM,MAAAE,SAAA,GAAY,IAAIC,oBAAqB,CAAA;IACzCC,uBAAuBV,WAAY,CAAAO,cAAA;IACnCI,kBAAA,EAAoBC,OAAOV,iBAAiB,CAAA;IAC5CI,UAAUN,WAAY,CAAAM;EAAA,CACvB,CAAA;EAGD,OAAOO,MAAMC,IAAK,CAAA;IAAEC,QAAQf,WAAY,CAAAC;EAAA,GAAY,MAAM;IACxD,MAAMe,0BAA0BR,SAAU,CAAAS,QAAA,CACxCjB,WAAY,CAAAkB,SAAA,EACZlB,WAAY,CAAAM,QACd,CAAA;IAEA,MAAMD,aAAgB,GAAAc,QAAA,CACpBf,SAAU,CAAAJ,WAAA,CAAYkB,SAAW,EAAAlB,WAAA,CAAYM,QAAQ,CAAA,EACrDU,uBACF,CAAA;IAEO,OAAA;MACLE,WAAWlB,WAAY,CAAAkB,SAAA;MACvBb,aAAA,EAAeO,OAAOP,aAAa,CAAA;MACnCE,cAAA,EAAgBK,OAAOI,uBAAuB,CAAA;MAC9CV,UAAUN,WAAY,CAAAM,QAAA;MACtBL,QAAU,EAAA;IACZ,CAAA;EAAA,CACD,CAAA;AACH,CAAA;AAEO,MAAMmB,4BAA+B,GAAAA,CAC1CpB,WACA,EAAAqB,OAAA,EAEAC,QACS,KAAA;EAET,IAAID,YAAY,CAAG,EAAA;IACV,OAAAjB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAAA;EAO1C,OAAOiB,MAAO,CAAA;IACZX,MAAQ,EAAAU,QAAA,CAAStB,WAAY,CAAAK,aAAA,GAAgBgB,OAAO,CAAA;IACpDf,QAAA,EAAUkB,iBAAkB,CAAAxB,WAAA,CAAYM,QAAQ;EAAA,CACjD,CAAA;AACH,CAAA;AAEa,MAAAmB,0BAAA,GAA6BA,CACxCzB,WAAA,EACAqB,OACS,KAAA;EAET,IAAIA,YAAY,CAAG,EAAA;IACV,OAAAjB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAAA;EAIpC,MAAAoB,mBAAA,GAAsB3B,6BAA6BC,WAAW,CAAA;EAGpE,IAAI2B,cAAiB,GAAAvB,SAAA,CAAU,CAAG,EAAAJ,WAAA,CAAYM,QAAQ,CAAA;EAElCoB,mBAAA,CAAAE,OAAA,CAAS5B,YAAgB,IAAA;IAG3C,MAAM6B,SAAY,GAAAT,4BAAA,CAChBpB,YAAAA,EACAqB,OAAA,EACAS,KAAM,CAAAC,SACR,CAAA;IACiBJ,cAAA,GAAAxB,GAAA,CAAIwB,gBAAgBE,SAAS,CAAA;EAAA,CAC/C,CAAA;EAEM,OAAAF,cAAA;AACT,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubnt/store.core",
3
- "version": "11.12.0-beta.1",
3
+ "version": "11.12.0-beta.2",
4
4
  "description": "",
5
5
  "sideEffects": false,
6
6
  "scripts": {