@etohq/utils 1.0.0 → 1.2.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.
Files changed (262) hide show
  1. package/dist/auth/token.d.ts +1 -1
  2. package/dist/auth/token.d.ts.map +1 -1
  3. package/dist/bundles.d.ts +0 -8
  4. package/dist/bundles.d.ts.map +1 -1
  5. package/dist/bundles.js +1 -9
  6. package/dist/bundles.js.map +1 -1
  7. package/dist/common/big-number.d.ts +39 -0
  8. package/dist/common/big-number.d.ts.map +1 -0
  9. package/dist/{totals → common}/big-number.js +20 -3
  10. package/dist/common/big-number.js.map +1 -0
  11. package/dist/common/container.d.ts +0 -7
  12. package/dist/common/container.d.ts.map +1 -1
  13. package/dist/common/container.js +0 -7
  14. package/dist/common/container.js.map +1 -1
  15. package/dist/{totals → common}/create-raw-properties-from-bignumber.d.ts.map +1 -1
  16. package/dist/{totals → common}/create-raw-properties-from-bignumber.js +4 -4
  17. package/dist/common/create-raw-properties-from-bignumber.js.map +1 -0
  18. package/dist/common/define-config.d.ts +14 -3
  19. package/dist/common/define-config.d.ts.map +1 -1
  20. package/dist/common/define-config.js +97 -132
  21. package/dist/common/define-config.js.map +1 -1
  22. package/dist/common/index.d.ts +5 -1
  23. package/dist/common/index.d.ts.map +1 -1
  24. package/dist/common/index.js +5 -1
  25. package/dist/common/index.js.map +1 -1
  26. package/dist/{totals → common}/math.d.ts +1 -1
  27. package/dist/common/math.d.ts.map +1 -0
  28. package/dist/{totals → common}/math.js +3 -3
  29. package/dist/{totals → common}/math.js.map +1 -1
  30. package/dist/common/merge-plugin-modules.js +8 -8
  31. package/dist/common/merge-plugin-modules.js.map +1 -1
  32. package/dist/{totals → common}/transform-properties-to-bignumber.d.ts.map +1 -1
  33. package/dist/{totals → common}/transform-properties-to-bignumber.js.map +1 -1
  34. package/dist/core-flows/events.d.ts +0 -76
  35. package/dist/core-flows/events.d.ts.map +1 -1
  36. package/dist/core-flows/events.js +8 -77
  37. package/dist/core-flows/events.js.map +1 -1
  38. package/dist/dal/mikro-orm/big-number-field.js +1 -1
  39. package/dist/dal/mikro-orm/big-number-field.js.map +1 -1
  40. package/dist/dal/mikro-orm/mikro-orm-create-connection.d.ts +2 -2
  41. package/dist/dal/mikro-orm/mikro-orm-create-connection.d.ts.map +1 -1
  42. package/dist/dal/mikro-orm/mikro-orm-create-connection.js +7 -5
  43. package/dist/dal/mikro-orm/mikro-orm-create-connection.js.map +1 -1
  44. package/dist/dal/mikro-orm/sql-migration-generator.d.ts +29 -0
  45. package/dist/dal/mikro-orm/sql-migration-generator.d.ts.map +1 -0
  46. package/dist/dal/mikro-orm/sql-migration-generator.js +106 -0
  47. package/dist/dal/mikro-orm/sql-migration-generator.js.map +1 -0
  48. package/dist/dml/entity-builder.d.ts +53 -3
  49. package/dist/dml/entity-builder.d.ts.map +1 -1
  50. package/dist/dml/entity-builder.js +95 -2
  51. package/dist/dml/entity-builder.js.map +1 -1
  52. package/dist/dml/helpers/entity-builder/define-property.d.ts.map +1 -1
  53. package/dist/dml/helpers/entity-builder/define-property.js +30 -4
  54. package/dist/dml/helpers/entity-builder/define-property.js.map +1 -1
  55. package/dist/dml/properties/base.d.ts +1 -0
  56. package/dist/dml/properties/base.d.ts.map +1 -1
  57. package/dist/dml/properties/base.js +7 -0
  58. package/dist/dml/properties/base.js.map +1 -1
  59. package/dist/dml/properties/enum.d.ts +1 -0
  60. package/dist/dml/properties/enum.d.ts.map +1 -1
  61. package/dist/dml/properties/enum.js +4 -0
  62. package/dist/dml/properties/enum.js.map +1 -1
  63. package/dist/dml/properties/index.d.ts +1 -0
  64. package/dist/dml/properties/index.d.ts.map +1 -1
  65. package/dist/dml/properties/index.js +1 -0
  66. package/dist/dml/properties/index.js.map +1 -1
  67. package/dist/dml/properties/vector.d.ts +31 -0
  68. package/dist/dml/properties/vector.d.ts.map +1 -0
  69. package/dist/dml/properties/vector.js +40 -0
  70. package/dist/dml/properties/vector.js.map +1 -0
  71. package/dist/feature-flags/index.d.ts +0 -6
  72. package/dist/feature-flags/index.d.ts.map +1 -1
  73. package/dist/feature-flags/index.js +0 -6
  74. package/dist/feature-flags/index.js.map +1 -1
  75. package/dist/index.d.ts +1 -10
  76. package/dist/index.d.ts.map +1 -1
  77. package/dist/index.js +1 -10
  78. package/dist/index.js.map +1 -1
  79. package/dist/link/index.d.ts +0 -1
  80. package/dist/link/index.d.ts.map +1 -1
  81. package/dist/link/index.js +0 -1
  82. package/dist/link/index.js.map +1 -1
  83. package/dist/modules-sdk/definition.d.ts +0 -42
  84. package/dist/modules-sdk/definition.d.ts.map +1 -1
  85. package/dist/modules-sdk/definition.js +3 -35
  86. package/dist/modules-sdk/definition.js.map +1 -1
  87. package/dist/modules-sdk/eto-internal-service.d.ts.map +1 -1
  88. package/dist/modules-sdk/eto-internal-service.js +1 -1
  89. package/dist/modules-sdk/eto-internal-service.js.map +1 -1
  90. package/dist/modules-sdk/joiner-config-builder.js +1 -1
  91. package/dist/modules-sdk/joiner-config-builder.js.map +1 -1
  92. package/dist/modules-sdk/loaders/mikro-orm-connection-loader.d.ts.map +1 -1
  93. package/dist/modules-sdk/loaders/mikro-orm-connection-loader.js.map +1 -1
  94. package/dist/modules-sdk/mikro-orm-cli-config-builder.js +1 -1
  95. package/dist/modules-sdk/mikro-orm-cli-config-builder.js.map +1 -1
  96. package/dist/modules-sdk/modules-to-container-types.js +1 -1
  97. package/dist/payment/abstract-payment-provider.d.ts +1 -1
  98. package/dist/payment/abstract-payment-provider.js +1 -1
  99. package/dist/payment/get-smallest-unit.d.ts +17 -0
  100. package/dist/payment/get-smallest-unit.d.ts.map +1 -0
  101. package/dist/payment/get-smallest-unit.js +68 -0
  102. package/dist/payment/get-smallest-unit.js.map +1 -0
  103. package/dist/payment/index.d.ts +1 -0
  104. package/dist/payment/index.d.ts.map +1 -1
  105. package/dist/payment/index.js +1 -0
  106. package/dist/payment/index.js.map +1 -1
  107. package/dist/pg/index.d.ts +1 -1
  108. package/dist/pg/index.d.ts.map +1 -1
  109. package/dist/tsconfig.tsbuildinfo +1 -1
  110. package/package.json +2 -5
  111. package/dist/common/wrap-handler.d.ts +0 -19
  112. package/dist/common/wrap-handler.d.ts.map +0 -1
  113. package/dist/common/wrap-handler.js +0 -36
  114. package/dist/common/wrap-handler.js.map +0 -1
  115. package/dist/feature-flags/eto-v2.d.ts +0 -3
  116. package/dist/feature-flags/eto-v2.d.ts.map +0 -1
  117. package/dist/feature-flags/eto-v2.js +0 -10
  118. package/dist/feature-flags/eto-v2.js.map +0 -1
  119. package/dist/feature-flags/many-to-many-inventory.d.ts +0 -3
  120. package/dist/feature-flags/many-to-many-inventory.d.ts.map +0 -1
  121. package/dist/feature-flags/many-to-many-inventory.js +0 -10
  122. package/dist/feature-flags/many-to-many-inventory.js.map +0 -1
  123. package/dist/feature-flags/order-editing.d.ts +0 -3
  124. package/dist/feature-flags/order-editing.d.ts.map +0 -1
  125. package/dist/feature-flags/order-editing.js +0 -10
  126. package/dist/feature-flags/order-editing.js.map +0 -1
  127. package/dist/feature-flags/product-categories.d.ts +0 -3
  128. package/dist/feature-flags/product-categories.d.ts.map +0 -1
  129. package/dist/feature-flags/product-categories.js +0 -10
  130. package/dist/feature-flags/product-categories.js.map +0 -1
  131. package/dist/feature-flags/sales-channels.d.ts +0 -3
  132. package/dist/feature-flags/sales-channels.d.ts.map +0 -1
  133. package/dist/feature-flags/sales-channels.js +0 -10
  134. package/dist/feature-flags/sales-channels.js.map +0 -1
  135. package/dist/feature-flags/tax-inclusive-pricing.d.ts +0 -3
  136. package/dist/feature-flags/tax-inclusive-pricing.d.ts.map +0 -1
  137. package/dist/feature-flags/tax-inclusive-pricing.js +0 -10
  138. package/dist/feature-flags/tax-inclusive-pricing.js.map +0 -1
  139. package/dist/fulfillment/events.d.ts +0 -71
  140. package/dist/fulfillment/events.d.ts.map +0 -1
  141. package/dist/fulfillment/events.js +0 -24
  142. package/dist/fulfillment/events.js.map +0 -1
  143. package/dist/fulfillment/geo-zone.d.ts +0 -7
  144. package/dist/fulfillment/geo-zone.d.ts.map +0 -1
  145. package/dist/fulfillment/geo-zone.js +0 -11
  146. package/dist/fulfillment/geo-zone.js.map +0 -1
  147. package/dist/fulfillment/index.d.ts +0 -5
  148. package/dist/fulfillment/index.d.ts.map +0 -1
  149. package/dist/fulfillment/index.js +0 -21
  150. package/dist/fulfillment/index.js.map +0 -1
  151. package/dist/fulfillment/provider.d.ts +0 -394
  152. package/dist/fulfillment/provider.d.ts.map +0 -1
  153. package/dist/fulfillment/provider.js +0 -412
  154. package/dist/fulfillment/provider.js.map +0 -1
  155. package/dist/fulfillment/shipping-options.d.ts +0 -5
  156. package/dist/fulfillment/shipping-options.d.ts.map +0 -1
  157. package/dist/fulfillment/shipping-options.js +0 -9
  158. package/dist/fulfillment/shipping-options.js.map +0 -1
  159. package/dist/inventory/events.d.ts +0 -26
  160. package/dist/inventory/events.d.ts.map +0 -1
  161. package/dist/inventory/events.js +0 -12
  162. package/dist/inventory/events.js.map +0 -1
  163. package/dist/inventory/index.d.ts +0 -2
  164. package/dist/inventory/index.d.ts.map +0 -1
  165. package/dist/inventory/index.js +0 -18
  166. package/dist/inventory/index.js.map +0 -1
  167. package/dist/link/links.d.ts +0 -22
  168. package/dist/link/links.d.ts.map +0 -1
  169. package/dist/link/links.js +0 -27
  170. package/dist/link/links.js.map +0 -1
  171. package/dist/order/index.d.ts +0 -4
  172. package/dist/order/index.d.ts.map +0 -1
  173. package/dist/order/index.js +0 -20
  174. package/dist/order/index.js.map +0 -1
  175. package/dist/order/order-change-action.d.ts +0 -21
  176. package/dist/order/order-change-action.d.ts.map +0 -1
  177. package/dist/order/order-change-action.js +0 -25
  178. package/dist/order/order-change-action.js.map +0 -1
  179. package/dist/order/order-change.d.ts +0 -31
  180. package/dist/order/order-change.d.ts.map +0 -1
  181. package/dist/order/order-change.js +0 -36
  182. package/dist/order/order-change.js.map +0 -1
  183. package/dist/order/status.d.ts +0 -85
  184. package/dist/order/status.d.ts.map +0 -1
  185. package/dist/order/status.js +0 -92
  186. package/dist/order/status.js.map +0 -1
  187. package/dist/pricing/builders.d.ts +0 -10
  188. package/dist/pricing/builders.d.ts.map +0 -1
  189. package/dist/pricing/builders.js +0 -53
  190. package/dist/pricing/builders.js.map +0 -1
  191. package/dist/pricing/enums.d.ts +0 -8
  192. package/dist/pricing/enums.d.ts.map +0 -1
  193. package/dist/pricing/enums.js +0 -12
  194. package/dist/pricing/enums.js.map +0 -1
  195. package/dist/pricing/events.d.ts +0 -38
  196. package/dist/pricing/events.d.ts.map +0 -1
  197. package/dist/pricing/events.js +0 -8
  198. package/dist/pricing/events.js.map +0 -1
  199. package/dist/pricing/index.d.ts +0 -5
  200. package/dist/pricing/index.d.ts.map +0 -1
  201. package/dist/pricing/index.js +0 -21
  202. package/dist/pricing/index.js.map +0 -1
  203. package/dist/pricing/price-list.d.ts +0 -9
  204. package/dist/pricing/price-list.d.ts.map +0 -1
  205. package/dist/pricing/price-list.js +0 -14
  206. package/dist/pricing/price-list.js.map +0 -1
  207. package/dist/product/events.d.ts +0 -50
  208. package/dist/product/events.d.ts.map +0 -1
  209. package/dist/product/events.js +0 -16
  210. package/dist/product/events.js.map +0 -1
  211. package/dist/product/get-variant-availability.d.ts +0 -48
  212. package/dist/product/get-variant-availability.d.ts.map +0 -1
  213. package/dist/product/get-variant-availability.js +0 -100
  214. package/dist/product/get-variant-availability.js.map +0 -1
  215. package/dist/product/index.d.ts +0 -9
  216. package/dist/product/index.d.ts.map +0 -1
  217. package/dist/product/index.js +0 -27
  218. package/dist/product/index.js.map +0 -1
  219. package/dist/promotion/index.d.ts +0 -48
  220. package/dist/promotion/index.d.ts.map +0 -1
  221. package/dist/promotion/index.js +0 -60
  222. package/dist/promotion/index.js.map +0 -1
  223. package/dist/shipping/index.d.ts +0 -6
  224. package/dist/shipping/index.d.ts.map +0 -1
  225. package/dist/shipping/index.js +0 -10
  226. package/dist/shipping/index.js.map +0 -1
  227. package/dist/totals/adjustment/index.d.ts +0 -11
  228. package/dist/totals/adjustment/index.d.ts.map +0 -1
  229. package/dist/totals/adjustment/index.js +0 -43
  230. package/dist/totals/adjustment/index.js.map +0 -1
  231. package/dist/totals/big-number.d.ts +0 -23
  232. package/dist/totals/big-number.d.ts.map +0 -1
  233. package/dist/totals/big-number.js.map +0 -1
  234. package/dist/totals/cart/index.d.ts +0 -35
  235. package/dist/totals/cart/index.d.ts.map +0 -1
  236. package/dist/totals/cart/index.js +0 -132
  237. package/dist/totals/cart/index.js.map +0 -1
  238. package/dist/totals/create-raw-properties-from-bignumber.js.map +0 -1
  239. package/dist/totals/index.d.ts +0 -9
  240. package/dist/totals/index.d.ts.map +0 -1
  241. package/dist/totals/index.js +0 -25
  242. package/dist/totals/index.js.map +0 -1
  243. package/dist/totals/line-item/index.d.ts +0 -46
  244. package/dist/totals/line-item/index.d.ts.map +0 -1
  245. package/dist/totals/line-item/index.js +0 -97
  246. package/dist/totals/line-item/index.js.map +0 -1
  247. package/dist/totals/math.d.ts.map +0 -1
  248. package/dist/totals/promotion/index.d.ts +0 -5
  249. package/dist/totals/promotion/index.d.ts.map +0 -1
  250. package/dist/totals/promotion/index.js +0 -42
  251. package/dist/totals/promotion/index.js.map +0 -1
  252. package/dist/totals/shipping-method/index.d.ts +0 -27
  253. package/dist/totals/shipping-method/index.d.ts.map +0 -1
  254. package/dist/totals/shipping-method/index.js +0 -57
  255. package/dist/totals/shipping-method/index.js.map +0 -1
  256. package/dist/totals/tax/index.d.ts +0 -15
  257. package/dist/totals/tax/index.d.ts.map +0 -1
  258. package/dist/totals/tax/index.js +0 -37
  259. package/dist/totals/tax/index.js.map +0 -1
  260. /package/dist/{totals → common}/create-raw-properties-from-bignumber.d.ts +0 -0
  261. /package/dist/{totals → common}/transform-properties-to-bignumber.d.ts +0 -0
  262. /package/dist/{totals → common}/transform-properties-to-bignumber.js +0 -0
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./cart"), exports);
18
- __exportStar(require("./create-raw-properties-from-bignumber"), exports);
19
- __exportStar(require("./line-item"), exports);
20
- __exportStar(require("./math"), exports);
21
- __exportStar(require("./tax"), exports);
22
- __exportStar(require("./promotion"), exports);
23
- __exportStar(require("./shipping-method"), exports);
24
- __exportStar(require("./transform-properties-to-bignumber"), exports);
25
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/totals/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAsB;AACtB,yEAAsD;AACtD,8CAA2B;AAC3B,yCAAsB;AACtB,wCAAqB;AACrB,8CAA2B;AAC3B,oDAAiC;AACjC,sEAAmD"}
@@ -1,46 +0,0 @@
1
- import { AdjustmentLineDTO, TaxLineDTO } from "@etohq/types";
2
- import { BigNumber } from "../big-number";
3
- interface GetLineItemsTotalsContext {
4
- includeTax?: boolean;
5
- extraQuantityFields?: Record<string, string>;
6
- }
7
- export interface GetItemTotalInput {
8
- id: string;
9
- unit_price: BigNumber;
10
- quantity: BigNumber;
11
- is_tax_inclusive?: boolean;
12
- tax_lines?: Pick<TaxLineDTO, "rate">[];
13
- adjustments?: Pick<AdjustmentLineDTO, "amount">[];
14
- detail?: {
15
- fulfilled_quantity: BigNumber;
16
- delivered_quantity: BigNumber;
17
- shipped_quantity: BigNumber;
18
- return_requested_quantity: BigNumber;
19
- return_received_quantity: BigNumber;
20
- return_dismissed_quantity: BigNumber;
21
- written_off_quantity: BigNumber;
22
- };
23
- }
24
- export interface GetItemTotalOutput {
25
- quantity: BigNumber;
26
- unit_price: BigNumber;
27
- subtotal: BigNumber;
28
- total: BigNumber;
29
- original_total: BigNumber;
30
- discount_total: BigNumber;
31
- discount_subtotal: BigNumber;
32
- discount_tax_total: BigNumber;
33
- refundable_total?: BigNumber;
34
- refundable_total_per_unit?: BigNumber;
35
- tax_total: BigNumber;
36
- original_tax_total: BigNumber;
37
- fulfilled_total?: BigNumber;
38
- shipped_total?: BigNumber;
39
- return_requested_total?: BigNumber;
40
- return_received_total?: BigNumber;
41
- return_dismissed_total?: BigNumber;
42
- write_off_total?: BigNumber;
43
- }
44
- export declare function getLineItemsTotals(items: GetItemTotalInput[], context: GetLineItemsTotalsContext): {};
45
- export {};
46
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/totals/line-item/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkB,UAAU,EAAE,MAAM,cAAc,CAAA;AAG5E,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAIzC,UAAU,yBAAyB;IACjC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC7C;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,SAAS,CAAA;IACrB,QAAQ,EAAE,SAAS,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,SAAS,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,CAAA;IACtC,WAAW,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CAAA;IACjD,MAAM,CAAC,EAAE;QACP,kBAAkB,EAAE,SAAS,CAAA;QAC7B,kBAAkB,EAAE,SAAS,CAAA;QAC7B,gBAAgB,EAAE,SAAS,CAAA;QAC3B,yBAAyB,EAAE,SAAS,CAAA;QACpC,wBAAwB,EAAE,SAAS,CAAA;QACnC,yBAAyB,EAAE,SAAS,CAAA;QACpC,oBAAoB,EAAE,SAAS,CAAA;KAChC,CAAA;CACF;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAA;IACnB,UAAU,EAAE,SAAS,CAAA;IAErB,QAAQ,EAAE,SAAS,CAAA;IAEnB,KAAK,EAAE,SAAS,CAAA;IAChB,cAAc,EAAE,SAAS,CAAA;IAEzB,cAAc,EAAE,SAAS,CAAA;IACzB,iBAAiB,EAAE,SAAS,CAAA;IAC5B,kBAAkB,EAAE,SAAS,CAAA;IAE7B,gBAAgB,CAAC,EAAE,SAAS,CAAA;IAC5B,yBAAyB,CAAC,EAAE,SAAS,CAAA;IAErC,SAAS,EAAE,SAAS,CAAA;IACpB,kBAAkB,EAAE,SAAS,CAAA;IAE7B,eAAe,CAAC,EAAE,SAAS,CAAA;IAC3B,aAAa,CAAC,EAAE,SAAS,CAAA;IACzB,sBAAsB,CAAC,EAAE,SAAS,CAAA;IAClC,qBAAqB,CAAC,EAAE,SAAS,CAAA;IACjC,sBAAsB,CAAC,EAAE,SAAS,CAAA;IAClC,eAAe,CAAC,EAAE,SAAS,CAAA;CAC5B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,iBAAiB,EAAE,EAC1B,OAAO,EAAE,yBAAyB,MAcnC"}
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLineItemsTotals = getLineItemsTotals;
4
- const common_1 = require("../../common");
5
- const adjustment_1 = require("../adjustment");
6
- const big_number_1 = require("../big-number");
7
- const math_1 = require("../math");
8
- const tax_1 = require("../tax");
9
- function getLineItemsTotals(items, context) {
10
- const itemsTotals = {};
11
- let index = 0;
12
- for (const item of items) {
13
- itemsTotals[item.id ?? index] = getLineItemTotals(item, {
14
- includeTax: context.includeTax || item.is_tax_inclusive,
15
- extraQuantityFields: context.extraQuantityFields,
16
- });
17
- index++;
18
- }
19
- return itemsTotals;
20
- }
21
- function setRefundableTotal(item, discountsTotal, totals, context) {
22
- const itemDetail = item.detail;
23
- const totalReturnedQuantity = math_1.MathBN.sum(itemDetail.return_requested_quantity ?? 0, itemDetail.return_received_quantity ?? 0, itemDetail.return_dismissed_quantity ?? 0);
24
- const currentQuantity = math_1.MathBN.sub(item.quantity, totalReturnedQuantity);
25
- const discountPerUnit = math_1.MathBN.div(discountsTotal, item.quantity);
26
- const refundableSubTotal = math_1.MathBN.sub(math_1.MathBN.mult(currentQuantity, item.unit_price), math_1.MathBN.mult(currentQuantity, discountPerUnit));
27
- const taxTotal = (0, tax_1.calculateTaxTotal)({
28
- taxLines: item.tax_lines || [],
29
- taxableAmount: refundableSubTotal,
30
- });
31
- const refundableTotal = math_1.MathBN.add(refundableSubTotal, taxTotal);
32
- totals.refundable_total_per_unit = new big_number_1.BigNumber(math_1.MathBN.eq(currentQuantity, 0)
33
- ? 0
34
- : math_1.MathBN.div(refundableTotal, currentQuantity));
35
- totals.refundable_total = new big_number_1.BigNumber(refundableTotal);
36
- }
37
- function getLineItemTotals(item, context) {
38
- const isTaxInclusive = item.is_tax_inclusive ?? context.includeTax;
39
- const sumTax = math_1.MathBN.sum(...((item.tax_lines ?? []).map((taxLine) => taxLine.rate) ?? []));
40
- const sumTaxRate = math_1.MathBN.div(sumTax, 100);
41
- const totalItemPrice = math_1.MathBN.mult(item.unit_price, item.quantity);
42
- /*
43
- If the price is inclusive of tax, we need to remove the taxed amount from the subtotal
44
- Original Price = Total Price / (1 + Tax Rate)
45
- */
46
- const subtotal = isTaxInclusive
47
- ? math_1.MathBN.div(totalItemPrice, math_1.MathBN.add(1, sumTaxRate))
48
- : totalItemPrice;
49
- const { adjustmentsTotal: discountsTotal, adjustmentsSubtotal: discountsSubtotal, adjustmentsTaxTotal: discountTaxTotal, } = (0, adjustment_1.calculateAdjustmentTotal)({
50
- adjustments: item.adjustments || [],
51
- includesTax: isTaxInclusive,
52
- taxRate: sumTaxRate,
53
- });
54
- const taxTotal = (0, tax_1.calculateTaxTotal)({
55
- taxLines: item.tax_lines || [],
56
- taxableAmount: math_1.MathBN.sub(subtotal, discountsSubtotal),
57
- setTotalField: "total",
58
- });
59
- const originalTaxTotal = (0, tax_1.calculateTaxTotal)({
60
- taxLines: item.tax_lines || [],
61
- taxableAmount: subtotal,
62
- setTotalField: "subtotal",
63
- });
64
- const totals = {
65
- quantity: item.quantity,
66
- unit_price: item.unit_price,
67
- subtotal: new big_number_1.BigNumber(subtotal),
68
- total: new big_number_1.BigNumber(math_1.MathBN.sum(math_1.MathBN.sub(subtotal, discountsSubtotal), taxTotal)),
69
- original_total: new big_number_1.BigNumber(isTaxInclusive ? totalItemPrice : math_1.MathBN.add(subtotal, originalTaxTotal)),
70
- discount_total: new big_number_1.BigNumber(discountsTotal),
71
- discount_subtotal: new big_number_1.BigNumber(discountsSubtotal),
72
- discount_tax_total: new big_number_1.BigNumber(discountTaxTotal),
73
- tax_total: new big_number_1.BigNumber(taxTotal),
74
- original_tax_total: new big_number_1.BigNumber(originalTaxTotal),
75
- };
76
- if ((0, common_1.isDefined)(item.detail?.return_requested_quantity)) {
77
- setRefundableTotal(item, discountsTotal, totals, context);
78
- }
79
- const div = math_1.MathBN.eq(item.quantity, 0) ? 1 : item.quantity;
80
- const totalPerUnit = math_1.MathBN.div(totals.total, div);
81
- const optionalFields = {
82
- ...(context.extraQuantityFields ?? {}),
83
- };
84
- for (const field in optionalFields) {
85
- const totalField = optionalFields[field];
86
- let target = item[totalField];
87
- if (field.includes(".")) {
88
- target = (0, common_1.pickValueFromObject)(field, item);
89
- }
90
- if (!(0, common_1.isDefined)(target)) {
91
- continue;
92
- }
93
- totals[totalField] = new big_number_1.BigNumber(math_1.MathBN.mult(totalPerUnit, target));
94
- }
95
- return totals;
96
- }
97
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/totals/line-item/index.ts"],"names":[],"mappings":";;AAyDA,gDAgBC;AAxED,yCAA6D;AAC7D,8CAAwD;AACxD,8CAAyC;AACzC,kCAAgC;AAChC,gCAA0C;AAoD1C,SAAgB,kBAAkB,CAChC,KAA0B,EAC1B,OAAkC;IAElC,MAAM,WAAW,GAAG,EAAE,CAAA;IAEtB,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,WAAW,CAAC,IAAI,CAAC,EAAE,IAAI,KAAK,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE;YACtD,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,IAAI,CAAC,gBAAgB;YACvD,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;SACjD,CAAC,CAAA;QACF,KAAK,EAAE,CAAA;IACT,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,SAAS,kBAAkB,CACzB,IAAuB,EACvB,cAA8B,EAC9B,MAA0B,EAC1B,OAAkC;IAElC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAO,CAAA;IAC/B,MAAM,qBAAqB,GAAG,aAAM,CAAC,GAAG,CACtC,UAAU,CAAC,yBAAyB,IAAI,CAAC,EACzC,UAAU,CAAC,wBAAwB,IAAI,CAAC,EACxC,UAAU,CAAC,yBAAyB,IAAI,CAAC,CAC1C,CAAA;IACD,MAAM,eAAe,GAAG,aAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC,CAAA;IACxE,MAAM,eAAe,GAAG,aAAM,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAA;IAEjE,MAAM,kBAAkB,GAA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AE,EAAE,OAAO,GAAG,OAAO;IAM5C,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO;IAM7C,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO;IAM5C,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO;IAM7C,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,OAAO;CAK7C"}
@@ -1,5 +0,0 @@
1
- import { BigNumberInput } from "@etohq/types";
2
- export declare function getPromotionValue(promotion: any, lineItemTotal: any, lineItemsTotal: any): any;
3
- export declare function getApplicableQuantity(lineItem: any, maxQuantity: any): any;
4
- export declare function calculateAdjustmentAmountFromPromotion(lineItem: any, promotion: any, lineItemsTotal?: BigNumberInput): import("bignumber.js").BigNumber;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/totals/promotion/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAsB7C,wBAAgB,iBAAiB,CAAC,SAAS,KAAA,EAAE,aAAa,KAAA,EAAE,cAAc,KAAA,OAMzE;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,KAAA,EAAE,WAAW,KAAA,OAM1D;AAMD,wBAAgB,sCAAsC,CACpD,QAAQ,KAAA,EACR,SAAS,KAAA,EACT,cAAc,GAAE,cAAkB,oCAiBnC"}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPromotionValue = getPromotionValue;
4
- exports.getApplicableQuantity = getApplicableQuantity;
5
- exports.calculateAdjustmentAmountFromPromotion = calculateAdjustmentAmountFromPromotion;
6
- const promotion_1 = require("../../promotion");
7
- const math_1 = require("../math");
8
- function getPromotionValueForPercentage(promotion, lineItemTotal) {
9
- return math_1.MathBN.mult(math_1.MathBN.div(promotion.value, 100), lineItemTotal);
10
- }
11
- function getPromotionValueForFixed(promotion, lineItemTotal, lineItemsTotal) {
12
- if (promotion.allocation === promotion_1.ApplicationMethodAllocation.ACROSS) {
13
- return math_1.MathBN.mult(math_1.MathBN.div(lineItemTotal, lineItemsTotal), promotion.value);
14
- }
15
- return promotion.value;
16
- }
17
- function getPromotionValue(promotion, lineItemTotal, lineItemsTotal) {
18
- if (promotion.type === promotion_1.ApplicationMethodType.PERCENTAGE) {
19
- return getPromotionValueForPercentage(promotion, lineItemTotal);
20
- }
21
- return getPromotionValueForFixed(promotion, lineItemTotal, lineItemsTotal);
22
- }
23
- function getApplicableQuantity(lineItem, maxQuantity) {
24
- if (maxQuantity && lineItem.quantity) {
25
- return math_1.MathBN.min(lineItem.quantity, maxQuantity);
26
- }
27
- return lineItem.quantity;
28
- }
29
- function getLineItemUnitPrice(lineItem) {
30
- return math_1.MathBN.div(lineItem.subtotal, lineItem.quantity);
31
- }
32
- function calculateAdjustmentAmountFromPromotion(lineItem, promotion, lineItemsTotal = 0) {
33
- const quantity = getApplicableQuantity(lineItem, promotion.max_quantity);
34
- const lineItemTotal = math_1.MathBN.mult(getLineItemUnitPrice(lineItem), quantity);
35
- const applicableTotal = math_1.MathBN.sub(lineItemTotal, promotion.applied_value);
36
- if (math_1.MathBN.lte(applicableTotal, 0)) {
37
- return applicableTotal;
38
- }
39
- const promotionValue = getPromotionValue(promotion, applicableTotal, lineItemsTotal);
40
- return math_1.MathBN.min(promotionValue, applicableTotal);
41
- }
42
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/totals/promotion/index.ts"],"names":[],"mappings":";;AAsBA,8CAMC;AAED,sDAMC;AAMD,wFAoBC;AA7DD,+CAGwB;AACxB,kCAAgC;AAEhC,SAAS,8BAA8B,CA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,SAAS,CAAC,YAAY,CAAC,CAAA;IACxE,MAAM,aAAa,GAAG,aAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAA;IAC3E,MAAM,eAAe,GAAG,aAAM,CAAC,GAAG,CAAC,aAAa,EAAE,SAAS,CAAC,aAAa,CAAC,CAAA;IAE1E,IAAI,aAAM,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC;QACnC,OAAO,eAAe,CAAA;IACxB,CAAC;IAED,MAAM,cAAc,GAAG,iBAAiB,CACtC,SAAS,EACT,eAAe,EACf,cAAc,CACf,CAAA;IAED,OAAO,aAAM,CAAC,GAAG,CAAC,cAAc,EAAE,eAAe,CAAC,CAAA;AACpD,CAAC"}
@@ -1,27 +0,0 @@
1
- import { AdjustmentLineDTO, TaxLineDTO } from "@etohq/types";
2
- import { BigNumber } from "../big-number";
3
- interface GetShippingMethodsTotalsContext {
4
- includeTax?: boolean;
5
- }
6
- export interface GetShippingMethodTotalInput {
7
- id: string;
8
- amount: BigNumber;
9
- is_tax_inclusive?: boolean;
10
- tax_lines?: TaxLineDTO[];
11
- adjustments?: Pick<AdjustmentLineDTO, "amount">[];
12
- }
13
- export interface GetShippingMethodTotalOutput {
14
- amount: BigNumber;
15
- subtotal: BigNumber;
16
- total: BigNumber;
17
- original_total: BigNumber;
18
- discount_total: BigNumber;
19
- discount_subtotal: BigNumber;
20
- discount_tax_total: BigNumber;
21
- tax_total: BigNumber;
22
- original_tax_total: BigNumber;
23
- }
24
- export declare function getShippingMethodsTotals(shippingMethods: GetShippingMethodTotalInput[], context: GetShippingMethodsTotalsContext): Record<string, GetShippingMethodTotalOutput>;
25
- export declare function getShippingMethodTotals(shippingMethod: GetShippingMethodTotalInput, context: GetShippingMethodsTotalsContext): GetShippingMethodTotalOutput;
26
- export {};
27
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/totals/shipping-method/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAIzC,UAAU,+BAA+B;IACvC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED,MAAM,WAAW,2BAA2B;IAC1C,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,SAAS,CAAA;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,SAAS,CAAC,EAAE,UAAU,EAAE,CAAA;IACxB,WAAW,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,EAAE,CAAA;CAClD;AAED,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,SAAS,CAAA;IAEjB,QAAQ,EAAE,SAAS,CAAA;IAEnB,KAAK,EAAE,SAAS,CAAA;IAChB,cAAc,EAAE,SAAS,CAAA;IAEzB,cAAc,EAAE,SAAS,CAAA;IACzB,iBAAiB,EAAE,SAAS,CAAA;IAC5B,kBAAkB,EAAE,SAAS,CAAA;IAE7B,SAAS,EAAE,SAAS,CAAA;IACpB,kBAAkB,EAAE,SAAS,CAAA;CAC9B;AAED,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,2BAA2B,EAAE,EAC9C,OAAO,EAAE,+BAA+B,GACvC,MAAM,CAAC,MAAM,EAAE,4BAA4B,CAAC,CAa9C;AAED,wBAAgB,uBAAuB,CACrC,cAAc,EAAE,2BAA2B,EAC3C,OAAO,EAAE,+BAA+B,gCA4DzC"}
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getShippingMethodsTotals = getShippingMethodsTotals;
4
- exports.getShippingMethodTotals = getShippingMethodTotals;
5
- const adjustment_1 = require("../adjustment");
6
- const big_number_1 = require("../big-number");
7
- const math_1 = require("../math");
8
- const tax_1 = require("../tax");
9
- function getShippingMethodsTotals(shippingMethods, context) {
10
- const shippingMethodsTotals = {};
11
- let index = 0;
12
- for (const shippingMethod of shippingMethods) {
13
- shippingMethodsTotals[shippingMethod.id ?? index] = getShippingMethodTotals(shippingMethod, context);
14
- index++;
15
- }
16
- return shippingMethodsTotals;
17
- }
18
- function getShippingMethodTotals(shippingMethod, context) {
19
- const isTaxInclusive = shippingMethod.is_tax_inclusive ?? context.includeTax;
20
- const shippingMethodAmount = math_1.MathBN.convert(shippingMethod.amount);
21
- const sumTax = math_1.MathBN.sum(...(shippingMethod.tax_lines?.map((taxLine) => taxLine.rate) ?? []));
22
- const sumTaxRate = math_1.MathBN.div(sumTax, 100);
23
- const subtotal = isTaxInclusive
24
- ? math_1.MathBN.div(shippingMethodAmount, math_1.MathBN.add(1, sumTaxRate))
25
- : shippingMethodAmount;
26
- const { adjustmentsTotal: discountsTotal, adjustmentsSubtotal: discountsSubtotal, adjustmentsTaxTotal: discountsTaxTotal, } = (0, adjustment_1.calculateAdjustmentTotal)({
27
- adjustments: shippingMethod.adjustments || [],
28
- includesTax: isTaxInclusive,
29
- taxRate: sumTaxRate,
30
- });
31
- const taxLines = shippingMethod.tax_lines || [];
32
- const taxTotal = (0, tax_1.calculateTaxTotal)({
33
- taxLines,
34
- taxableAmount: math_1.MathBN.sub(subtotal, discountsSubtotal),
35
- setTotalField: "total",
36
- });
37
- const originalTaxTotal = (0, tax_1.calculateTaxTotal)({
38
- taxLines,
39
- taxableAmount: subtotal,
40
- setTotalField: "subtotal",
41
- });
42
- const totals = {
43
- amount: new big_number_1.BigNumber(shippingMethodAmount),
44
- subtotal: new big_number_1.BigNumber(subtotal),
45
- total: new big_number_1.BigNumber(math_1.MathBN.sum(math_1.MathBN.sub(subtotal, discountsSubtotal), taxTotal)),
46
- original_total: new big_number_1.BigNumber(isTaxInclusive
47
- ? shippingMethodAmount
48
- : math_1.MathBN.add(subtotal, originalTaxTotal)),
49
- discount_total: new big_number_1.BigNumber(discountsTotal),
50
- discount_subtotal: new big_number_1.BigNumber(discountsSubtotal),
51
- discount_tax_total: new big_number_1.BigNumber(discountsTaxTotal),
52
- tax_total: new big_number_1.BigNumber(taxTotal),
53
- original_tax_total: new big_number_1.BigNumber(originalTaxTotal),
54
- };
55
- return totals;
56
- }
57
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/totals/shipping-method/index.ts"],"names":[],"mappings":";;AAkCA,4DAgBC;AAED,0DA8DC;AAjHD,8CAAwD;AACxD,8CAAyC;AACzC,kCAAgC;AAChC,gCAA0C;AA8B1C,SAAgB,wBAAwB,CACtC,eAA8C,EAC9C,OAAwC;IAExC,MAAM,qBAAqB,GAAG,EAAE,CAAA;IAEhC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,qBAAqB,CAAC,cAAc,CAAC,EAAE,IAAI,KAAK,CAAC,GAAG,uBAAuB,CACzE,cAAc,EACd,OAAO,CACR,CAAA;QACD,KAAK,EAAE,CAAA;IACT,CAAC;IAED,OAAO,qBAAqB,CAAA;AAC9B,CAAC;AAED,SAAgB,uBAAuB,CACrC,cAA2C,EAC3C,OAAwC;IAExC,MAAM,cAAc,GAAG,cAAc,CAAC,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAA;IAE5E,MAAM,oBAAoB,GAAG,aAAM,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;IAClE,MAAM,MAAM,GAAG,aAAM,CAAC,GAAG,CACvB,GAAG,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CACpE,CAAA;IACD,MAAM,UAAU,GAAG,aAAM,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAE1C,MAAM,QAAQ,GAAG,cAAc;QAC7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E,IAAI,sBAAS,CAAC,iBAAiB,CAAC;QACnD,kBAAkB,EAAE,IAAI,sBAAS,CAAC,iBAAiB,CAAC;QAEpD,SAAS,EAAE,IAAI,sBAAS,CAAC,QAAQ,CAAC;QAClC,kBAAkB,EAAE,IAAI,sBAAS,CAAC,gBAAgB,CAAC;KACpD,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
@@ -1,15 +0,0 @@
1
- import { BigNumberInput, TaxLineDTO } from "@etohq/types";
2
- export declare function calculateTaxTotal({ taxLines, taxableAmount, setTotalField, }: {
3
- taxLines: Pick<TaxLineDTO, "rate">[];
4
- taxableAmount: BigNumberInput;
5
- setTotalField?: string;
6
- }): import("bignumber.js").BigNumber;
7
- export declare function calculateAmountsWithTax({ taxLines, amount, includesTax, }: {
8
- taxLines: Pick<TaxLineDTO, "rate">[];
9
- amount: number;
10
- includesTax?: boolean;
11
- }): {
12
- priceWithTax: number;
13
- priceWithoutTax: number;
14
- };
15
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/totals/tax/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAIzD,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,aAAa,EACb,aAAa,GACd,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,CAAA;IACpC,aAAa,EAAE,cAAc,CAAA;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,oCAmBA;AAED,wBAAgB,uBAAuB,CAAC,EACtC,QAAQ,EACR,MAAM,EACN,WAAW,GACZ,EAAE;IACD,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;;;EAmBA"}
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateTaxTotal = calculateTaxTotal;
4
- exports.calculateAmountsWithTax = calculateAmountsWithTax;
5
- const big_number_1 = require("../big-number");
6
- const math_1 = require("../math");
7
- function calculateTaxTotal({ taxLines, taxableAmount, setTotalField, }) {
8
- if (math_1.MathBN.lte(taxableAmount, 0)) {
9
- return math_1.MathBN.convert(0);
10
- }
11
- let taxTotal = math_1.MathBN.convert(0);
12
- for (const taxLine of taxLines) {
13
- const rate = math_1.MathBN.div(taxLine.rate, 100);
14
- let taxAmount = math_1.MathBN.mult(taxableAmount, rate);
15
- if (setTotalField) {
16
- ;
17
- taxLine[setTotalField] = new big_number_1.BigNumber(taxAmount);
18
- }
19
- taxTotal = math_1.MathBN.add(taxTotal, taxAmount);
20
- }
21
- return taxTotal;
22
- }
23
- function calculateAmountsWithTax({ taxLines, amount, includesTax, }) {
24
- const sumTaxRate = math_1.MathBN.div(math_1.MathBN.sum(...((taxLines ?? []).map((taxLine) => taxLine.rate) ?? [])), 100);
25
- const taxableAmount = includesTax
26
- ? math_1.MathBN.div(amount, math_1.MathBN.add(1, sumTaxRate))
27
- : amount;
28
- const tax = calculateTaxTotal({
29
- taxLines,
30
- taxableAmount,
31
- });
32
- return {
33
- priceWithTax: includesTax ? amount : math_1.MathBN.add(tax, amount).toNumber(),
34
- priceWithoutTax: includesTax ? math_1.MathBN.sub(amount, tax).toNumber() : amount,
35
- };
36
- }
37
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/totals/tax/index.ts"],"names":[],"mappings":";;AAIA,8CA2BC;AAED,0DA2BC;AA3DD,8CAAyC;AACzC,kCAAgC;AAEhC,SAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,aAAa,EACb,aAAa,GAKd;IACC,IAAI,aAAM,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,EAAE,CA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