@parv0888/scheme-engine 0.1.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 (175) hide show
  1. package/dist/calculators/discount-application.d.ts +44 -0
  2. package/dist/calculators/discount-application.d.ts.map +1 -0
  3. package/dist/calculators/discount-application.js +174 -0
  4. package/dist/calculators/discount-application.js.map +1 -0
  5. package/dist/calculators/index.d.ts +65 -0
  6. package/dist/calculators/index.d.ts.map +1 -0
  7. package/dist/calculators/index.js +196 -0
  8. package/dist/calculators/index.js.map +1 -0
  9. package/dist/calculators/payout-types/article.d.ts +23 -0
  10. package/dist/calculators/payout-types/article.d.ts.map +1 -0
  11. package/dist/calculators/payout-types/article.js +73 -0
  12. package/dist/calculators/payout-types/article.js.map +1 -0
  13. package/dist/calculators/payout-types/basket.d.ts +49 -0
  14. package/dist/calculators/payout-types/basket.d.ts.map +1 -0
  15. package/dist/calculators/payout-types/basket.js +108 -0
  16. package/dist/calculators/payout-types/basket.js.map +1 -0
  17. package/dist/calculators/payout-types/coupon.d.ts +23 -0
  18. package/dist/calculators/payout-types/coupon.d.ts.map +1 -0
  19. package/dist/calculators/payout-types/coupon.js +74 -0
  20. package/dist/calculators/payout-types/coupon.js.map +1 -0
  21. package/dist/calculators/payout-types/discount.d.ts +21 -0
  22. package/dist/calculators/payout-types/discount.d.ts.map +1 -0
  23. package/dist/calculators/payout-types/discount.js +110 -0
  24. package/dist/calculators/payout-types/discount.js.map +1 -0
  25. package/dist/calculators/payout-types/fixed-discount.d.ts +31 -0
  26. package/dist/calculators/payout-types/fixed-discount.d.ts.map +1 -0
  27. package/dist/calculators/payout-types/fixed-discount.js +65 -0
  28. package/dist/calculators/payout-types/fixed-discount.js.map +1 -0
  29. package/dist/calculators/payout-types/foc.d.ts +30 -0
  30. package/dist/calculators/payout-types/foc.d.ts.map +1 -0
  31. package/dist/calculators/payout-types/foc.js +130 -0
  32. package/dist/calculators/payout-types/foc.js.map +1 -0
  33. package/dist/calculators/payout-types/mrp-percentage.d.ts +34 -0
  34. package/dist/calculators/payout-types/mrp-percentage.d.ts.map +1 -0
  35. package/dist/calculators/payout-types/mrp-percentage.js +77 -0
  36. package/dist/calculators/payout-types/mrp-percentage.js.map +1 -0
  37. package/dist/calculators/payout-types/nlp.d.ts +22 -0
  38. package/dist/calculators/payout-types/nlp.d.ts.map +1 -0
  39. package/dist/calculators/payout-types/nlp.js +59 -0
  40. package/dist/calculators/payout-types/nlp.js.map +1 -0
  41. package/dist/calculators/payout-types/per-unit.d.ts +32 -0
  42. package/dist/calculators/payout-types/per-unit.d.ts.map +1 -0
  43. package/dist/calculators/payout-types/per-unit.js +94 -0
  44. package/dist/calculators/payout-types/per-unit.js.map +1 -0
  45. package/dist/calculators/payout-types/product-new.d.ts +27 -0
  46. package/dist/calculators/payout-types/product-new.d.ts.map +1 -0
  47. package/dist/calculators/payout-types/product-new.js +85 -0
  48. package/dist/calculators/payout-types/product-new.js.map +1 -0
  49. package/dist/calculators/payout-types/product.d.ts +31 -0
  50. package/dist/calculators/payout-types/product.d.ts.map +1 -0
  51. package/dist/calculators/payout-types/product.js +73 -0
  52. package/dist/calculators/payout-types/product.js.map +1 -0
  53. package/dist/calculators/payout-types/topup.d.ts +19 -0
  54. package/dist/calculators/payout-types/topup.d.ts.map +1 -0
  55. package/dist/calculators/payout-types/topup.js +46 -0
  56. package/dist/calculators/payout-types/topup.js.map +1 -0
  57. package/dist/calculators/slab-matcher.d.ts +41 -0
  58. package/dist/calculators/slab-matcher.d.ts.map +1 -0
  59. package/dist/calculators/slab-matcher.js +68 -0
  60. package/dist/calculators/slab-matcher.js.map +1 -0
  61. package/dist/esm/calculators/discount-application.js +170 -0
  62. package/dist/esm/calculators/discount-application.js.map +1 -0
  63. package/dist/esm/calculators/index.js +176 -0
  64. package/dist/esm/calculators/index.js.map +1 -0
  65. package/dist/esm/calculators/payout-types/article.js +70 -0
  66. package/dist/esm/calculators/payout-types/article.js.map +1 -0
  67. package/dist/esm/calculators/payout-types/basket.js +105 -0
  68. package/dist/esm/calculators/payout-types/basket.js.map +1 -0
  69. package/dist/esm/calculators/payout-types/coupon.js +71 -0
  70. package/dist/esm/calculators/payout-types/coupon.js.map +1 -0
  71. package/dist/esm/calculators/payout-types/discount.js +107 -0
  72. package/dist/esm/calculators/payout-types/discount.js.map +1 -0
  73. package/dist/esm/calculators/payout-types/fixed-discount.js +62 -0
  74. package/dist/esm/calculators/payout-types/fixed-discount.js.map +1 -0
  75. package/dist/esm/calculators/payout-types/foc.js +127 -0
  76. package/dist/esm/calculators/payout-types/foc.js.map +1 -0
  77. package/dist/esm/calculators/payout-types/mrp-percentage.js +74 -0
  78. package/dist/esm/calculators/payout-types/mrp-percentage.js.map +1 -0
  79. package/dist/esm/calculators/payout-types/nlp.js +56 -0
  80. package/dist/esm/calculators/payout-types/nlp.js.map +1 -0
  81. package/dist/esm/calculators/payout-types/per-unit.js +91 -0
  82. package/dist/esm/calculators/payout-types/per-unit.js.map +1 -0
  83. package/dist/esm/calculators/payout-types/product-new.js +82 -0
  84. package/dist/esm/calculators/payout-types/product-new.js.map +1 -0
  85. package/dist/esm/calculators/payout-types/product.js +70 -0
  86. package/dist/esm/calculators/payout-types/product.js.map +1 -0
  87. package/dist/esm/calculators/payout-types/topup.js +43 -0
  88. package/dist/esm/calculators/payout-types/topup.js.map +1 -0
  89. package/dist/esm/calculators/slab-matcher.js +64 -0
  90. package/dist/esm/calculators/slab-matcher.js.map +1 -0
  91. package/dist/esm/helpers/calc-type-checks.js +30 -0
  92. package/dist/esm/helpers/calc-type-checks.js.map +1 -0
  93. package/dist/esm/helpers/compare-value.js +109 -0
  94. package/dist/esm/helpers/compare-value.js.map +1 -0
  95. package/dist/esm/helpers/constraint-checks.js +67 -0
  96. package/dist/esm/helpers/constraint-checks.js.map +1 -0
  97. package/dist/esm/helpers/index.js +8 -0
  98. package/dist/esm/helpers/index.js.map +1 -0
  99. package/dist/esm/helpers/math.js +84 -0
  100. package/dist/esm/helpers/math.js.map +1 -0
  101. package/dist/esm/helpers/payout-type-checks.js +29 -0
  102. package/dist/esm/helpers/payout-type-checks.js.map +1 -0
  103. package/dist/esm/helpers/qualifier-checks.js +188 -0
  104. package/dist/esm/helpers/qualifier-checks.js.map +1 -0
  105. package/dist/esm/helpers/scheme-applicability.js +93 -0
  106. package/dist/esm/helpers/scheme-applicability.js.map +1 -0
  107. package/dist/esm/index.js +10 -0
  108. package/dist/esm/index.js.map +1 -0
  109. package/dist/esm/types/applied-scheme.js +19 -0
  110. package/dist/esm/types/applied-scheme.js.map +1 -0
  111. package/dist/esm/types/enums.js +115 -0
  112. package/dist/esm/types/enums.js.map +1 -0
  113. package/dist/esm/types/index.js +5 -0
  114. package/dist/esm/types/index.js.map +1 -0
  115. package/dist/esm/types/item-props.js +2 -0
  116. package/dist/esm/types/item-props.js.map +1 -0
  117. package/dist/esm/types/scheme.js +2 -0
  118. package/dist/esm/types/scheme.js.map +1 -0
  119. package/dist/helpers/calc-type-checks.d.ts +21 -0
  120. package/dist/helpers/calc-type-checks.d.ts.map +1 -0
  121. package/dist/helpers/calc-type-checks.js +36 -0
  122. package/dist/helpers/calc-type-checks.js.map +1 -0
  123. package/dist/helpers/compare-value.d.ts +40 -0
  124. package/dist/helpers/compare-value.d.ts.map +1 -0
  125. package/dist/helpers/compare-value.js +120 -0
  126. package/dist/helpers/compare-value.js.map +1 -0
  127. package/dist/helpers/constraint-checks.d.ts +30 -0
  128. package/dist/helpers/constraint-checks.d.ts.map +1 -0
  129. package/dist/helpers/constraint-checks.js +73 -0
  130. package/dist/helpers/constraint-checks.js.map +1 -0
  131. package/dist/helpers/index.d.ts +8 -0
  132. package/dist/helpers/index.d.ts.map +1 -0
  133. package/dist/helpers/index.js +24 -0
  134. package/dist/helpers/index.js.map +1 -0
  135. package/dist/helpers/math.d.ts +50 -0
  136. package/dist/helpers/math.d.ts.map +1 -0
  137. package/dist/helpers/math.js +96 -0
  138. package/dist/helpers/math.js.map +1 -0
  139. package/dist/helpers/payout-type-checks.d.ts +17 -0
  140. package/dist/helpers/payout-type-checks.d.ts.map +1 -0
  141. package/dist/helpers/payout-type-checks.js +34 -0
  142. package/dist/helpers/payout-type-checks.js.map +1 -0
  143. package/dist/helpers/qualifier-checks.d.ts +62 -0
  144. package/dist/helpers/qualifier-checks.d.ts.map +1 -0
  145. package/dist/helpers/qualifier-checks.js +194 -0
  146. package/dist/helpers/qualifier-checks.js.map +1 -0
  147. package/dist/helpers/scheme-applicability.d.ts +40 -0
  148. package/dist/helpers/scheme-applicability.d.ts.map +1 -0
  149. package/dist/helpers/scheme-applicability.js +99 -0
  150. package/dist/helpers/scheme-applicability.js.map +1 -0
  151. package/dist/index.d.ts +4 -0
  152. package/dist/index.d.ts.map +1 -0
  153. package/dist/index.js +26 -0
  154. package/dist/index.js.map +1 -0
  155. package/dist/types/applied-scheme.d.ts +157 -0
  156. package/dist/types/applied-scheme.d.ts.map +1 -0
  157. package/dist/types/applied-scheme.js +22 -0
  158. package/dist/types/applied-scheme.js.map +1 -0
  159. package/dist/types/enums.d.ts +91 -0
  160. package/dist/types/enums.d.ts.map +1 -0
  161. package/dist/types/enums.js +118 -0
  162. package/dist/types/enums.js.map +1 -0
  163. package/dist/types/index.d.ts +5 -0
  164. package/dist/types/index.d.ts.map +1 -0
  165. package/dist/types/index.js +21 -0
  166. package/dist/types/index.js.map +1 -0
  167. package/dist/types/item-props.d.ts +103 -0
  168. package/dist/types/item-props.d.ts.map +1 -0
  169. package/dist/types/item-props.js +3 -0
  170. package/dist/types/item-props.js.map +1 -0
  171. package/dist/types/scheme.d.ts +172 -0
  172. package/dist/types/scheme.d.ts.map +1 -0
  173. package/dist/types/scheme.js +3 -0
  174. package/dist/types/scheme.js.map +1 -0
  175. package/package.json +29 -0
@@ -0,0 +1,176 @@
1
+ import { SchemePayoutType, SchemeSubType, SchemeSubType2, SchemePayoutCalculationType } from "../types/enums";
2
+ import { createEmptySlabResult } from "../types/applied-scheme";
3
+ import { calculateDiscountPayout } from "./payout-types/discount";
4
+ import { calculateMrpPercentageDiscountPayout } from "./payout-types/mrp-percentage";
5
+ import { calculatePerUnitPayout } from "./payout-types/per-unit";
6
+ import { calculateFixedDiscountPayout } from "./payout-types/fixed-discount";
7
+ import { calculateFocPayout } from "./payout-types/foc";
8
+ import { calculateProductPayout } from "./payout-types/product";
9
+ import { calculateProductSchemeNewPayout } from "./payout-types/product-new";
10
+ import { calculateBasketPayout } from "./payout-types/basket";
11
+ import { calculateCouponPayout } from "./payout-types/coupon";
12
+ import { calculateTopupPayout } from "./payout-types/topup";
13
+ import { calculateArticlePayout } from "./payout-types/article";
14
+ import { calculateNlpPayout } from "./payout-types/nlp";
15
+ /**
16
+ * Detects if a scheme is a GST Claim scheme based on naming conventions.
17
+ */
18
+ function isGstClaimScheme(scheme) {
19
+ const GSTSchemeName = "GST Claim";
20
+ const hasGstBase = scheme.name.toLowerCase().trim() === GSTSchemeName.toLowerCase().trim() &&
21
+ (scheme.schemeSubType2 || "").toLowerCase().trim() ===
22
+ SchemeSubType2.NON_CLAIMABLE.toLowerCase().trim() &&
23
+ scheme.payoutCalculationType.toLowerCase().trim() ===
24
+ SchemePayoutCalculationType.CONTINUOUS &&
25
+ scheme.payoutType.toLowerCase().trim() ===
26
+ SchemePayoutType.DISCOUNT.toLowerCase().trim();
27
+ const isPrimaryGstScheme = scheme.category === "Primary" &&
28
+ scheme.schemeSubType.toLowerCase().trim() ===
29
+ SchemeSubType.NON_EXTENDABLE.toLowerCase().trim();
30
+ const isSecondaryGstScheme = scheme.category === "Secondary" &&
31
+ scheme.schemeSubType.toLowerCase().trim() ===
32
+ SchemeSubType.EXTENDABLE.toLowerCase().trim();
33
+ return hasGstBase && (isPrimaryGstScheme || isSecondaryGstScheme);
34
+ }
35
+ /**
36
+ * Master dispatcher: routes to the correct payout-type calculator.
37
+ *
38
+ * This is the primary public API for scheme calculation. Given a scheme
39
+ * and pre-computed aggregates, it returns a pure SchemeSlabResult that
40
+ * the caller can use to update item state.
41
+ */
42
+ export function calculateSchemeSlabResult(input) {
43
+ const { scheme } = input;
44
+ const payoutType = scheme.payoutType;
45
+ switch (payoutType) {
46
+ case SchemePayoutType.DISCOUNT:
47
+ return calculateDiscountPayout({
48
+ scheme,
49
+ compareValue: input.compareValue,
50
+ applicableProducts: input.applicableProducts,
51
+ isMrpBilling: input.isMrpBilling,
52
+ isGstClaimScheme: isGstClaimScheme(scheme),
53
+ });
54
+ case SchemePayoutType.PERCENTAGE_DISCOUNT_ON_MRP:
55
+ return calculateMrpPercentageDiscountPayout({
56
+ scheme,
57
+ compareValue: input.compareValue,
58
+ applicableProducts: input.applicableProducts,
59
+ isMrpBilling: input.isMrpBilling,
60
+ productMrp: input.productMrp,
61
+ productPtr: input.productPtr,
62
+ totalTaxPercentage: input.totalTaxPercentage,
63
+ });
64
+ case SchemePayoutType.PERUNIT:
65
+ return calculatePerUnitPayout({
66
+ scheme,
67
+ compareValue: input.compareValue,
68
+ applicableProducts: input.applicableProducts,
69
+ isMrpBilling: input.isMrpBilling,
70
+ totalTaxPercentage: input.totalTaxPercentage,
71
+ perUnitPrices: input.perUnitPrices,
72
+ });
73
+ case SchemePayoutType.FIXED_DISCOUNT:
74
+ return calculateFixedDiscountPayout({
75
+ scheme,
76
+ compareValue: input.compareValue,
77
+ totalAmount: input.totalAmount,
78
+ applicableProducts: input.applicableProducts,
79
+ isMrpBilling: input.isMrpBilling,
80
+ itemBaseValues: [],
81
+ });
82
+ case SchemePayoutType.FOC:
83
+ case SchemePayoutType.FOC_SLAB:
84
+ return calculateFocPayout({
85
+ scheme,
86
+ compareValue: input.compareValue,
87
+ applicableProducts: input.applicableProducts,
88
+ isMrpBilling: input.isMrpBilling,
89
+ companyUsesStepfocSchemeInDms: input.companyUsesStepfocSchemeInDms,
90
+ applyContinuousSchemeLogic: input.applyContinuousSchemeLogic,
91
+ applyStepMultiplierSchemeLogic: input.applyStepMultiplierSchemeLogic,
92
+ });
93
+ case SchemePayoutType.PRODUCT:
94
+ return calculateProductPayout({
95
+ scheme,
96
+ compareValue: input.compareValue,
97
+ totalAmount: input.totalAmount,
98
+ applicableProducts: input.applicableProducts,
99
+ isMrpBilling: input.isMrpBilling,
100
+ focProductPrice: input.focProductPrice,
101
+ companyUsesUnitaryProductScheme: input.companyUsesUnitaryProductScheme,
102
+ });
103
+ case SchemePayoutType.PRODUCT_SCHEME_NEW:
104
+ return calculateProductSchemeNewPayout({
105
+ scheme,
106
+ compareValue: input.compareValue,
107
+ totalAmount: input.totalAmount,
108
+ applicableProducts: input.applicableProducts,
109
+ isMrpBilling: input.isMrpBilling,
110
+ focProductPrice: input.focProductPrice,
111
+ companyUsesUnitaryProductScheme: input.companyUsesUnitaryProductScheme,
112
+ });
113
+ case SchemePayoutType.BASKET:
114
+ return calculateBasketPayout({
115
+ scheme,
116
+ compareValue: input.compareValue,
117
+ applicableProducts: input.applicableProducts,
118
+ baskets: input.baskets || [],
119
+ selectedItems: input.selectedItems || [],
120
+ isMrpBilling: input.isMrpBilling,
121
+ });
122
+ case SchemePayoutType.COUPON:
123
+ return calculateCouponPayout({
124
+ scheme,
125
+ compareValue: input.compareValue,
126
+ totalAmount: input.totalAmount,
127
+ applicableProducts: input.applicableProducts,
128
+ isMrpBilling: input.isMrpBilling,
129
+ });
130
+ case SchemePayoutType.TOPUP:
131
+ return calculateTopupPayout({
132
+ scheme,
133
+ compareValue: input.compareValue,
134
+ applicableProducts: input.applicableProducts,
135
+ isMrpBilling: input.isMrpBilling,
136
+ });
137
+ case SchemePayoutType.ARTICLE:
138
+ return calculateArticlePayout({
139
+ scheme,
140
+ compareValue: input.compareValue,
141
+ totalAmount: input.totalAmount,
142
+ applicableProducts: input.applicableProducts,
143
+ isMrpBilling: input.isMrpBilling,
144
+ });
145
+ case SchemePayoutType.NLP:
146
+ return calculateNlpPayout({
147
+ scheme,
148
+ compareValue: input.compareValue,
149
+ totalAmount: input.totalAmount,
150
+ applicableProducts: input.applicableProducts,
151
+ isMrpBilling: input.isMrpBilling,
152
+ productPtr: input.productPtr,
153
+ });
154
+ default: {
155
+ const result = createEmptySlabResult(payoutType);
156
+ result.warnings.push(`Payout type not matching: ${payoutType}`);
157
+ return result;
158
+ }
159
+ }
160
+ }
161
+ // ─── Re-exports ─────────────────────────────────────────────────
162
+ export { calculateDiscountPayout } from "./payout-types/discount";
163
+ export { calculateMrpPercentageDiscountPayout } from "./payout-types/mrp-percentage";
164
+ export { calculatePerUnitPayout } from "./payout-types/per-unit";
165
+ export { calculateFixedDiscountPayout } from "./payout-types/fixed-discount";
166
+ export { calculateFocPayout } from "./payout-types/foc";
167
+ export { calculateProductPayout } from "./payout-types/product";
168
+ export { calculateProductSchemeNewPayout } from "./payout-types/product-new";
169
+ export { calculateBasketPayout } from "./payout-types/basket";
170
+ export { calculateCouponPayout } from "./payout-types/coupon";
171
+ export { calculateTopupPayout } from "./payout-types/topup";
172
+ export { calculateArticlePayout } from "./payout-types/article";
173
+ export { calculateNlpPayout } from "./payout-types/nlp";
174
+ export { findMatchingSlab, findInterpolationSlabs } from "./slab-matcher";
175
+ export { calculateAppliedDiscountValues, recalculateSchemePercentage } from "./discount-application";
176
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/calculators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,cAAc,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAG9G,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAMhE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,oCAAoC,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACx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import { isPayoutCalcTypeContinuous, isPayoutCalcTypeStep } from "../../helpers/calc-type-checks";
4
+ import { isValidConstraintType } from "../../helpers/constraint-checks";
5
+ import { findMatchingSlab } from "../slab-matcher";
6
+ export function calculateArticlePayout(input) {
7
+ if (!input) {
8
+ const result = createEmptySlabResult(SchemePayoutType.ARTICLE);
9
+ result.warnings.push("Article payout type is not yet implemented");
10
+ return result;
11
+ }
12
+ const { scheme, compareValue, totalAmount, applicableProducts } = input;
13
+ const result = createEmptySlabResult(SchemePayoutType.ARTICLE);
14
+ if (!isValidConstraintType(scheme.constraintType)) {
15
+ result.warnings.push(`Invalid constraint type: ${scheme.constraintType}`);
16
+ return result;
17
+ }
18
+ const slabs = [...scheme.slabs].sort((a, b) => b.constraint - a.constraint);
19
+ if (slabs.length === 0) {
20
+ result.warnings.push("Slab list is empty");
21
+ return result;
22
+ }
23
+ const matcherParams = {
24
+ slabs,
25
+ compareValue,
26
+ applicableProducts,
27
+ payoutType: SchemePayoutType.ARTICLE,
28
+ discountOn: scheme.discountOn ?? null,
29
+ };
30
+ const payoutCalcType = scheme.payoutCalculationType;
31
+ if (isPayoutCalcTypeStep(payoutCalcType)) {
32
+ const match = findMatchingSlab(matcherParams);
33
+ if (!match)
34
+ return result;
35
+ const { slab } = match;
36
+ let stepMultiplier = 0;
37
+ if (slab.constraint > 0) {
38
+ stepMultiplier = Math.floor(compareValue / slab.constraint);
39
+ }
40
+ const discountValue = slab.payout * slab.constraint * stepMultiplier;
41
+ let effectivePercent = 0;
42
+ if (totalAmount > 0) {
43
+ effectivePercent = (discountValue / totalAmount) * 100;
44
+ }
45
+ result.matched = true;
46
+ result.matchedSlabId = slab.id;
47
+ result.discountPercent = effectivePercent;
48
+ result.targetMethod = "setDiscountScheme";
49
+ return result;
50
+ }
51
+ if (isPayoutCalcTypeContinuous(payoutCalcType)) {
52
+ const match = findMatchingSlab(matcherParams);
53
+ if (!match)
54
+ return result;
55
+ const { slab } = match;
56
+ const discountValue = slab.payout * compareValue;
57
+ let effectivePercent = 0;
58
+ if (totalAmount > 0) {
59
+ effectivePercent = (discountValue / totalAmount) * 100;
60
+ }
61
+ result.matched = true;
62
+ result.matchedSlabId = slab.id;
63
+ result.discountPercent = effectivePercent;
64
+ result.targetMethod = "setDiscountScheme";
65
+ return result;
66
+ }
67
+ result.warnings.push(`No matching calculation type found: ${payoutCalcType}`);
68
+ return result;
69
+ }
70
+ //# sourceMappingURL=article.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"article.js","sourceRoot":"","sources":["../../../../src/calculators/payout-types/article.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAA0B,MAAM,iBAAiB,CAAC;AAuB3E,MAAM,UAAU,sBAAsB,CAAC,KAA8B;IACnE,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,MAAM,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAC/D,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;QACnE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC;IACxE,MAAM,MAAM,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAE/D,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC;QAClD,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,4BAA4B,MAAM,CAAC,cAAc,EAAE,CAAC,CAAC;QAC1E,OAAO,MAAM,C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AAC;QACtB,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,eAAe,GAAG,gBAAgB,CAAC;QAC1C,MAAM,CAAC,YAAY,GAAG,mBAAmB,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAI,0BAA0B,CAAC,cAAc,CAAC,EAAE,CAAC;QAC/C,MAAM,KAAK,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAC9C,IAAI,CAAC,KAAK;YAAE,OAAO,MAAM,CAAC;QAE1B,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;QACvB,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;QACjD,IAAI,gBAAgB,GAAG,CAAC,CAAC;QACzB,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;YACpB,gBAAgB,GAAG,CAAC,aAAa,GAAG,WAAW,CAAC,GAAG,GAAG,CAAC;QACzD,CAAC;QAED,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,MAAM,CAAC,aAAa,GAAG,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,eAAe,GAAG,gBAAgB,CAAC;QAC1C,MAAM,CAAC,YAAY,GAAG,mBAAmB,CAAC;QAC1C,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,uCAAuC,cAAc,EAAE,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,105 @@
1
+ import { SchemePayoutType, SchemeConstraintType } from "../../types/enums";
2
+ import { createEmptySlabResult } from "../../types/applied-scheme";
3
+ import { isPayoutCalcTypeContinuous } from "../../helpers/calc-type-checks";
4
+ import { isValidConstraintType } from "../../helpers/constraint-checks";
5
+ import { checkIfSecondaryCategoryFilterPassed } from "../../helpers/qualifier-checks";
6
+ /**
7
+ * Calculate payout for BASKET payout type.
8
+ *
9
+ * Slabs sorted by id desc.
10
+ * Validates mandatory baskets pass constraint (qty or amount).
11
+ * itemDiscountPercent = slab.basketInvoicePayout
12
+ * Only applies to basket product items.
13
+ */
14
+ export function calculateBasketPayout(input) {
15
+ const { scheme, compareValue, applicableProducts, baskets, selectedItems, isMrpBilling } = input;
16
+ const result = {
17
+ ...createEmptySlabResult(SchemePayoutType.BASKET),
18
+ applicableProductIds: [],
19
+ };
20
+ if (!isValidConstraintType(scheme.constraintType)) {
21
+ result.warnings.push(`Invalid constraint type: ${scheme.constraintType}`);
22
+ return result;
23
+ }
24
+ if (!isPayoutCalcTypeContinuous(scheme.payoutCalculationType)) {
25
+ result.warnings.push(`No matching calculation type found: ${scheme.payoutCalculationType}`);
26
+ return result;
27
+ }
28
+ const slabs = [...scheme.slabs].sort((a, b) => b.id - a.id);
29
+ if (slabs.length === 0) {
30
+ result.warnings.push("Slab list is empty");
31
+ return result;
32
+ }
33
+ for (const slab of slabs) {
34
+ // Check qualifiers
35
+ const qualifierParams = {
36
+ secondQualifier: slab.secondQualifier,
37
+ secondQualifierType: slab.secondQualifierType,
38
+ discountOn: scheme.discountOn ?? null,
39
+ firstQualifier: slab.firstQualifier,
40
+ thirdQualifier: slab.thirdQualifier,
41
+ thirdQualifierType: slab.thirdQualifierType,
42
+ slabConstraint: slab.constraint,
43
+ };
44
+ if (!checkIfSecondaryCategoryFilterPassed(qualifierParams, applicableProducts)) {
45
+ continue;
46
+ }
47
+ // Get all basket product IDs for this slab
48
+ const slabBasketIds = slab.qualifierSchemeSlabs.map((v) => v.basketId);
49
+ const slabBaskets = baskets.filter((v) => slabBasketIds.includes(+v.id));
50
+ const allBasketProductIds = slabBaskets.map((v) => v.productIds).flat();
51
+ const allBasketSelectedItems = selectedItems.filter((v) => allBasketProductIds.includes(v.productId));
52
+ // Check slab constraint against basket items total
53
+ const basketTotalAmount = allBasketSelectedItems.reduce((acc, v) => acc + v.quantity * v.price, 0);
54
+ if (basketTotalAmount < slab.constraint) {
55
+ continue;
56
+ }
57
+ // Check mandatory baskets
58
+ const mandatoryBasketSlabs = slab.qualifierSchemeSlabs.filter((v) => v.isBasketMandatory);
59
+ let basketsConstraintPassed = mandatoryBasketSlabs.length === 0 ? false : true;
60
+ for (const basketSlab of mandatoryBasketSlabs) {
61
+ const basket = baskets.find((v) => v.id == basketSlab.basketId);
62
+ if (!basket) {
63
+ result.warnings.push(`Basket not found: ${basketSlab.basketId}`);
64
+ basketsConstraintPassed = false;
65
+ break;
66
+ }
67
+ const basketProductIds = basket.productIds;
68
+ const basketSelectedItems = selectedItems.filter((v) => basketProductIds?.includes(v.productId));
69
+ const constraint = basketSlab.quantity;
70
+ let basketCompareValue;
71
+ if (scheme.constraintType === SchemeConstraintType.QUANTITY) {
72
+ basketCompareValue = basketSelectedItems.reduce((acc, v) => acc + v.quantity, 0);
73
+ }
74
+ else if (scheme.constraintType === SchemeConstraintType.AMOUNT) {
75
+ basketCompareValue = basketSelectedItems.reduce((acc, v) => acc + v.quantity * v.price, 0);
76
+ }
77
+ else {
78
+ result.warnings.push(`Basket scheme: Invalid constraint type: ${scheme.constraintType}`);
79
+ basketCompareValue = -1;
80
+ }
81
+ if (basketCompareValue >= constraint) {
82
+ basketsConstraintPassed = true;
83
+ }
84
+ else {
85
+ basketsConstraintPassed = false;
86
+ break;
87
+ }
88
+ }
89
+ if (basketsConstraintPassed) {
90
+ // Get applicable basket product IDs
91
+ const basketIds = slab.qualifierSchemeSlabs.map((v) => v.basketId.toString());
92
+ const applicableBasketProductIds = baskets
93
+ .filter((v) => basketIds.includes(v.id.toString()))
94
+ .reduce((acc, v) => acc.concat(v.productIds), []);
95
+ result.matched = true;
96
+ result.matchedSlabId = slab.id;
97
+ result.discountPercent = slab.basketInvoicePayout;
98
+ result.applicableProductIds = applicableBasketProductIds;
99
+ result.targetMethod = "setDiscountScheme";
100
+ return result;
101
+ }
102
+ }
103
+ return result;
104
+ }
105
+ //# sourceMappingURL=basket.js.map
@@ -0,0 +1 @@
1
+ {"version":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EAAE,CAAC;YAC/B,MAAM,CAAC,eAAe,GAAG,IAAI,CAAC,mBAAmB,CAAC;YAClD,MAAM,CAAC,oBAAoB,GAAG,0BAA0B,CAAC;YACzD,MAAM,CAAC,YAAY,GAAG,mBAAmB,CAAC;YAC1C,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { SchemePayoutType } from "../../types/enums";
2
+ import { createEmptySlabResult } from "../../types/applied-scheme";
3
+ import { isPayoutCalcTypeContinuous, isPayoutCalcTypeStep } from "../../helpers/calc-type-checks";
4
+ import { isValidConstraintType } from "../../helpers/constraint-checks";
5
+ import { findMatchingSlab } from "../slab-matcher";
6
+ /**
7
+ * Calculate payout for COUPON payout type.
8
+ *
9
+ * Continuous: placeholder discount (totalCouponValue = 0) + addProduct
10
+ * Step: addProduct with slab.payout qty
11
+ */
12
+ export function calculateCouponPayout(input) {
13
+ const { scheme, compareValue, totalAmount, applicableProducts, isMrpBilling } = input;
14
+ const result = createEmptySlabResult(SchemePayoutType.COUPON);
15
+ if (!isValidConstraintType(scheme.constraintType)) {
16
+ result.warnings.push(`Invalid constraint type: ${scheme.constraintType}`);
17
+ return result;
18
+ }
19
+ const slabs = [...scheme.slabs].sort((a, b) => (a.constraint < b.constraint ? 1 : -1));
20
+ if (slabs.length === 0) {
21
+ result.warnings.push("Slab list is empty");
22
+ return result;
23
+ }
24
+ const payoutCalcType = scheme.payoutCalculationType;
25
+ const matcherParams = {
26
+ slabs,
27
+ compareValue,
28
+ applicableProducts,
29
+ payoutType: SchemePayoutType.COUPON,
30
+ discountOn: scheme.discountOn ?? null,
31
+ };
32
+ // ─── Continuous ────────────────────────────────────────────────
33
+ if (isPayoutCalcTypeContinuous(payoutCalcType)) {
34
+ const match = findMatchingSlab(matcherParams);
35
+ if (!match)
36
+ return result;
37
+ const { slab } = match;
38
+ // Placeholder: coupon value not yet implemented
39
+ const totalCouponValue = 0;
40
+ const itemDiscountPercent = totalAmount > 0 ? totalCouponValue / totalAmount : 0;
41
+ const payoutProductId = slab.productId;
42
+ const factor = Math.floor(compareValue / slab.constraint);
43
+ const payoutQty = (isMrpBilling ? slab.mrpPayout : slab.payout) * factor;
44
+ result.matched = true;
45
+ result.matchedSlabId = slab.id;
46
+ result.discountPercent = itemDiscountPercent;
47
+ result.freeQty = payoutQty;
48
+ result.productToAdd = { productId: payoutProductId, quantity: payoutQty };
49
+ // Multiple target methods: setDiscountScheme for discount + addProduct for free item
50
+ result.targetMethod = "addProduct";
51
+ return result;
52
+ }
53
+ // ─── Step ──────────────────────────────────────────────────────
54
+ if (isPayoutCalcTypeStep(payoutCalcType)) {
55
+ const match = findMatchingSlab(matcherParams);
56
+ if (!match)
57
+ return result;
58
+ const { slab } = match;
59
+ const payoutProductId = slab.productId;
60
+ const payoutQty = isMrpBilling ? slab.mrpPayout : slab.payout;
61
+ result.matched = true;
62
+ result.matchedSlabId = slab.id;
63
+ result.freeQty = payoutQty;
64
+ result.productToAdd = { productId: payoutProductId, quantity: payoutQty };
65
+ result.targetMethod = "addProduct";
66
+ return result;
67
+ }
68
+ result.warnings.push(`No matching calculation type found: ${payoutCalcType}`);
69
+ return result;
70
+ }
71
+ //# sourceMappingURL=coupon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"coupon.js","sourceRoot":"","sources":["../../../../src/calculators/payout-types/coupon.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAClG,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAA0B,MAAM,iBAAiB,CAAC;AAgB3E;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAA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CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;QAC3B,MAAM,CAAC,YAAY,GAAG,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;QAC1E,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;QACnC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,uCAAuC,cAAc,EAAE,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,107 @@
1
+ import { SchemePayoutType } from "../../types/enums";
2
+ import { createEmptySlabResult } from "../../types/applied-scheme";
3
+ import { isPayoutCalcTypeStep, isPayoutCalcTypeContinuous, isPayoutCalcTypeProrata } from "../../helpers/calc-type-checks";
4
+ import { isValidConstraintType } from "../../helpers/constraint-checks";
5
+ import { findMatchingSlab } from "../slab-matcher";
6
+ import { SchemeConstraintType } from "../../types/enums";
7
+ /**
8
+ * Calculate discount payout for DISCOUNT payout type.
9
+ * Supports: Step, Continuous, Prorata (Bug 9 fix).
10
+ */
11
+ export function calculateDiscountPayout(input) {
12
+ const { scheme, compareValue, applicableProducts, isMrpBilling, isGstClaimScheme } = input;
13
+ const result = createEmptySlabResult(SchemePayoutType.DISCOUNT);
14
+ if (!isValidConstraintType(scheme.constraintType)) {
15
+ result.warnings.push(`Invalid constraint type: ${scheme.constraintType}`);
16
+ return result;
17
+ }
18
+ const slabs = [...scheme.slabs].sort((a, b) => (a.constraint < b.constraint ? 1 : -1));
19
+ if (slabs.length === 0) {
20
+ result.warnings.push("Slab list is empty");
21
+ return result;
22
+ }
23
+ const matcherParams = {
24
+ slabs,
25
+ compareValue,
26
+ applicableProducts,
27
+ payoutType: SchemePayoutType.DISCOUNT,
28
+ discountOn: scheme.discountOn ?? null,
29
+ };
30
+ const payoutCalcType = scheme.payoutCalculationType;
31
+ // ─── Step ──────────────────────────────────────────────────────
32
+ if (isPayoutCalcTypeStep(payoutCalcType)) {
33
+ const match = findMatchingSlab(matcherParams);
34
+ if (match) {
35
+ const { slab } = match;
36
+ const stepDiscountPercent = isMrpBilling ? slab.mrpPayout : slab.payout;
37
+ // Client-validated semantics: STEP applies once on the matched slab constraint,
38
+ // not multiplied by floor(compareValue / slab.constraint).
39
+ const discountAmountTotal = (stepDiscountPercent * slab.constraint) / 100;
40
+ const itemDiscountPercent = ((discountAmountTotal || 0) * 100) / (compareValue || 1);
41
+ result.matched = true;
42
+ result.matchedSlabId = slab.id;
43
+ result.discountPercent = itemDiscountPercent;
44
+ result.targetMethod = isGstClaimScheme ? "setGstDiscountScheme" : "setDiscountScheme";
45
+ result.isGstReform = isGstClaimScheme;
46
+ if (isGstClaimScheme) {
47
+ result.additionalDiscountPercent_1 = itemDiscountPercent;
48
+ result.discountPercent = 0;
49
+ }
50
+ }
51
+ return result;
52
+ }
53
+ // ─── Continuous ────────────────────────────────────────────────
54
+ if (isPayoutCalcTypeContinuous(payoutCalcType)) {
55
+ const match = findMatchingSlab(matcherParams);
56
+ if (match) {
57
+ const { slab } = match;
58
+ const itemDiscountPercent = isMrpBilling ? slab.mrpPayout : slab.payout;
59
+ result.matched = true;
60
+ result.matchedSlabId = slab.id;
61
+ result.discountPercent = itemDiscountPercent;
62
+ result.targetMethod = isGstClaimScheme ? "setGstDiscountScheme" : "setDiscountScheme";
63
+ result.isGstReform = isGstClaimScheme;
64
+ if (isGstClaimScheme) {
65
+ result.additionalDiscountPercent_1 = itemDiscountPercent;
66
+ result.discountPercent = 0;
67
+ }
68
+ }
69
+ return result;
70
+ }
71
+ // ─── Prorata (Bug 9 fix — new calculation type) ────────────────
72
+ if (isPayoutCalcTypeProrata(payoutCalcType)) {
73
+ const ascSlabs = [...scheme.slabs].sort((a, b) => a.constraint - b.constraint);
74
+ // FieldAssist Prorata (doc): slabs act like stepped bands where each slab's payout applies
75
+ // from its own constraint up to (nextConstraint - 1). The final reached slab applies from
76
+ // its constraint up to compareValue (inclusive), which is why e.g. qty=50 gives "5% of 1".
77
+ if (compareValue < ascSlabs[0].constraint)
78
+ return result;
79
+ let totalDiscount = 0;
80
+ for (let i = 0; i < ascSlabs.length; i++) {
81
+ const slab = ascSlabs[i];
82
+ const next = ascSlabs[i + 1] ?? null;
83
+ const payout = isMrpBilling ? slab.mrpPayout : slab.payout;
84
+ const bandQty = next && compareValue >= next.constraint
85
+ ? Math.max(0, scheme.constraintType === SchemeConstraintType.AMOUNT
86
+ ? next.constraint - slab.constraint - 1
87
+ : next.constraint - slab.constraint)
88
+ : Math.max(0, compareValue - slab.constraint + 1);
89
+ if (bandQty > 0) {
90
+ totalDiscount += (bandQty * payout) / 100;
91
+ }
92
+ // If we haven't reached the next slab threshold, this is the final band.
93
+ if (!next || compareValue < next.constraint)
94
+ break;
95
+ }
96
+ const effectivePercent = compareValue > 0 ? (totalDiscount / compareValue) * 100 : 0;
97
+ result.matched = true;
98
+ result.matchedSlabId = ascSlabs[ascSlabs.length - 1]?.id ?? null;
99
+ result.discountPercent = effectivePercent;
100
+ result.targetMethod = isGstClaimScheme ? "setGstDiscountScheme" : "setDiscountScheme";
101
+ result.isGstReform = isGstClaimScheme;
102
+ return result;
103
+ }
104
+ result.warnings.push(`No matching calculation type found: ${payoutCalcType}`);
105
+ return result;
106
+ }
107
+ //# sourceMappingURL=discount.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discount.js","sourceRoot":"","sources":["../../../../src/calculators/payout-types/discount.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC3H,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAkD,MAAM,iBAAiB,CAAC;AAEnG,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ePayoutType } from "../../types/enums";
2
+ import { createEmptySlabResult } from "../../types/applied-scheme";
3
+ import { SchemePayoutCalculationType } from "../../types/enums";
4
+ import { isValidConstraintType } from "../../helpers/constraint-checks";
5
+ import { findMatchingSlab } from "../slab-matcher";
6
+ /**
7
+ * Calculate payout for FixedValueDiscount payout type.
8
+ *
9
+ * discountAmountTotal = slab.payout (flat value, not percentage)
10
+ * itemDiscountPercent = discountAmountTotal × 100 / totalAmount
11
+ * itemDiscountValue = itemDiscountPercent × itemBaseValue / 100
12
+ *
13
+ * Budget capping: if remainingBudget < discountValue, adjusts both.
14
+ */
15
+ export function calculateFixedDiscountPayout(input) {
16
+ const { scheme, compareValue, totalAmount, applicableProducts, isMrpBilling } = input;
17
+ const result = createEmptySlabResult(SchemePayoutType.FIXED_DISCOUNT);
18
+ if (!isValidConstraintType(scheme.constraintType)) {
19
+ result.warnings.push(`Invalid constraint type: ${scheme.constraintType}`);
20
+ return result;
21
+ }
22
+ if (!scheme.payoutCalculationType) {
23
+ result.warnings.push(`No matching calculation type found: ${scheme.payoutCalculationType}`);
24
+ return result;
25
+ }
26
+ const slabs = [...scheme.slabs].sort((a, b) => (a.constraint < b.constraint ? 1 : -1));
27
+ if (slabs.length === 0) {
28
+ result.warnings.push("Slab list is empty");
29
+ return result;
30
+ }
31
+ const matcherParams = {
32
+ slabs,
33
+ compareValue,
34
+ applicableProducts,
35
+ payoutType: SchemePayoutType.FIXED_DISCOUNT,
36
+ discountOn: scheme.discountOn ?? null,
37
+ };
38
+ const match = findMatchingSlab(matcherParams);
39
+ if (!match)
40
+ return result;
41
+ const { slab } = match;
42
+ const payoutBase = isMrpBilling ? slab.mrpPayout : slab.payout;
43
+ const payoutCalcType = scheme.payoutCalculationType?.toLowerCase()?.trim() ?? "";
44
+ const isStepLike = payoutCalcType === SchemePayoutCalculationType.STEP ||
45
+ payoutCalcType === SchemePayoutCalculationType.STEP_MULTIPLIER;
46
+ const factor = isStepLike && slab.constraint > 0 ? Math.floor(compareValue / slab.constraint) : 1;
47
+ let discountAmountTotal = payoutBase * Math.max(0, factor || 0);
48
+ // Use remaining budget as a generic max-capping value for fixed payouts
49
+ // (matches how many client validations are modeled: cap total fixed discount).
50
+ const maxCapping = scheme.employeeWiseRemainingBudget;
51
+ if (typeof maxCapping === "number" && maxCapping >= 0) {
52
+ discountAmountTotal = Math.min(discountAmountTotal, maxCapping);
53
+ }
54
+ const itemDiscountPercent = ((discountAmountTotal || 0) * 100) / (totalAmount || 1);
55
+ result.matched = true;
56
+ result.matchedSlabId = slab.id;
57
+ result.discountPercent = itemDiscountPercent;
58
+ result.discountValue = discountAmountTotal;
59
+ result.targetMethod = "setDiscountAndValueScheme";
60
+ return result;
61
+ }
62
+ //# sourceMappingURL=fixed-discount.js.map