@managesome/eposmatic-toolkit 0.4.37 → 0.4.39

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 (57) hide show
  1. package/esm/constants/accounting-templates.js +431 -0
  2. package/esm/constants/index.js +1 -0
  3. package/esm/helpers/store/cart-actions.js +54 -6
  4. package/esm/helpers/utils/cart-helpers.js +19 -5
  5. package/esm/helpers/utils/common.js +18 -1
  6. package/esm/helpers/utils/offer-apply-helpers.js +5 -3
  7. package/esm/helpers/utils/offers-helpers.js +92 -63
  8. package/lib/constants/accounting-templates.d.ts +8 -0
  9. package/lib/constants/accounting-templates.js +434 -0
  10. package/lib/constants/index.d.ts +1 -0
  11. package/lib/constants/index.js +1 -0
  12. package/lib/helpers/store/cart-actions.js +54 -6
  13. package/lib/helpers/utils/cart-helpers.js +19 -5
  14. package/lib/helpers/utils/common.d.ts +15 -0
  15. package/lib/helpers/utils/common.js +19 -1
  16. package/lib/helpers/utils/offer-apply-helpers.js +5 -3
  17. package/lib/helpers/utils/offers-helpers.d.ts +15 -4
  18. package/lib/helpers/utils/offers-helpers.js +92 -62
  19. package/lib/schemas/models/expense_categories.d.ts +3 -3
  20. package/lib/schemas/models/expense_details.d.ts +3 -3
  21. package/lib/schemas/models/gift_cards.d.ts +3 -3
  22. package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
  23. package/lib/schemas/models/internal_invoices.d.ts +3 -3
  24. package/lib/schemas/models/items.d.ts +12 -12
  25. package/lib/schemas/models/marketing_fingerprints.d.ts +3 -3
  26. package/lib/schemas/models/modifier_extras.d.ts +3 -3
  27. package/lib/schemas/models/offers.d.ts +3 -3
  28. package/lib/schemas/models/public_holidays.d.ts +3 -3
  29. package/lib/schemas/models/specials.d.ts +3 -3
  30. package/lib/schemas/models/tenant_chart_of_accounts.d.ts +3 -3
  31. package/lib/schemas/models/tenant_hr_departments.d.ts +3 -3
  32. package/lib/schemas/models/tenant_hr_documents.d.ts +3 -3
  33. package/lib/schemas/models/tenant_hr_policies.d.ts +3 -3
  34. package/lib/schemas/models/tenant_hr_positions.d.ts +3 -3
  35. package/lib/schemas/models/tenant_journal_entries.d.ts +3 -3
  36. package/lib/schemas/models/void_order_items.d.ts +3 -3
  37. package/lib/schemas/models/vouchers.d.ts +3 -3
  38. package/lib/schemas/models/warehouse_communications.d.ts +3 -3
  39. package/lib/schemas/models/warehouse_items.d.ts +3 -3
  40. package/lib/schemas/models/warehouse_void_purchase_order_items.d.ts +3 -3
  41. package/lib/schemas/models/warehouse_void_sale_order_items.d.ts +3 -3
  42. package/lib/schemas/types/tenant_chart_of_accounts.d.ts +7 -0
  43. package/lib/tests/cart-helpers-edit-item-refs.test.d.ts +1 -0
  44. package/lib/tests/cart-helpers-edit-item-refs.test.js +99 -0
  45. package/lib/tests/code-redemption-helpers.test.d.ts +1 -0
  46. package/lib/tests/code-redemption-helpers.test.js +246 -0
  47. package/lib/tests/gift-card-helpers.test.d.ts +1 -0
  48. package/lib/tests/gift-card-helpers.test.js +100 -0
  49. package/lib/tests/offer-claim-regressions.test.d.ts +1 -0
  50. package/lib/tests/offer-claim-regressions.test.js +367 -0
  51. package/lib/tests/offers-helpers.test.js +24 -4
  52. package/lib/tests/offers-matrix.test.js +248 -20
  53. package/lib/tests/ref-exclusion-matching.test.d.ts +1 -0
  54. package/lib/tests/ref-exclusion-matching.test.js +168 -0
  55. package/lib/tests/wallet-cashback-helpers.test.d.ts +1 -0
  56. package/lib/tests/wallet-cashback-helpers.test.js +108 -0
  57. package/package.json +1 -1
@@ -0,0 +1,434 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESTAURANT_ACCOUNTS_TEMPLATE = void 0;
4
+ const accounting_1 = require("./enums/accounting");
5
+ /**
6
+ * Default restaurant chart of accounts (Pakistan-first, PKR) — the seed used by
7
+ * `POST /tenant-chart-of-accounts/seed-template` and the admin panel's
8
+ * "Load Restaurant Template" action. Entries are flat posting accounts; tenants
9
+ * nest their own sub-accounts afterwards, and seeding never overwrites existing codes.
10
+ */
11
+ exports.RESTAURANT_ACCOUNTS_TEMPLATE = [
12
+ // ===================== Assets =====================
13
+ {
14
+ code: '1001',
15
+ name: 'Cash on Hand',
16
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
17
+ description: 'Physical cash held in cash drawers.',
18
+ },
19
+ {
20
+ code: '1011',
21
+ name: 'Bank – Main Operating Account',
22
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
23
+ },
24
+ {
25
+ code: '1012',
26
+ name: 'Bank – Payouts / Settlement Account',
27
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
28
+ },
29
+ {
30
+ code: '1021',
31
+ name: 'Card Settlement Clearing',
32
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
33
+ },
34
+ {
35
+ code: '1022',
36
+ name: 'JazzCash Clearing',
37
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
38
+ },
39
+ {
40
+ code: '1023',
41
+ name: 'EasyPaisa Clearing',
42
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
43
+ },
44
+ {
45
+ code: '1024',
46
+ name: 'Raast Clearing',
47
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
48
+ },
49
+ {
50
+ code: '1025',
51
+ name: 'Terminal Devices Clearing',
52
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
53
+ },
54
+ {
55
+ code: '1031',
56
+ name: 'Foodpanda Receivable',
57
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
58
+ },
59
+ {
60
+ code: '1032',
61
+ name: 'Own App / Web Receivable',
62
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
63
+ },
64
+ {
65
+ code: '1040',
66
+ name: 'Accounts Receivable – Customers',
67
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
68
+ description: 'Credit bills / pay-later orders and B2B clients.',
69
+ },
70
+ {
71
+ code: '1051',
72
+ name: 'Inventory – Raw Materials',
73
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
74
+ },
75
+ {
76
+ code: '1052',
77
+ name: 'Inventory – Packed / Retail Items',
78
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
79
+ },
80
+ {
81
+ code: '1053',
82
+ name: 'Inventory – Packaging & Consumables',
83
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
84
+ },
85
+ {
86
+ code: '1060',
87
+ name: 'Input Tax Receivable (GST)',
88
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
89
+ description: 'GST paid on purchases, claimable as credit.',
90
+ },
91
+ {
92
+ code: '1070',
93
+ name: 'Prepaid Expenses',
94
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
95
+ },
96
+ {
97
+ code: '1081',
98
+ name: 'Kitchen Equipment',
99
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
100
+ },
101
+ {
102
+ code: '1082',
103
+ name: 'Furniture & Fittings',
104
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
105
+ },
106
+ {
107
+ code: '1083',
108
+ name: 'Computers & POS Hardware',
109
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
110
+ },
111
+ {
112
+ code: '1085',
113
+ name: 'Accumulated Depreciation',
114
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
115
+ description: 'Depreciation charged to date (a contra-asset account).',
116
+ },
117
+ {
118
+ code: '1090',
119
+ name: 'Security Deposits',
120
+ type: accounting_1.ACCOUNT_TYPE_ENUM.ASSET,
121
+ },
122
+ // ===================== Liabilities =====================
123
+ {
124
+ code: '2001',
125
+ name: 'Accounts Payable – Vendors',
126
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
127
+ },
128
+ {
129
+ code: '2011',
130
+ name: 'Accrued Salaries & Wages',
131
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
132
+ },
133
+ {
134
+ code: '2012',
135
+ name: 'Accrued Utilities',
136
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
137
+ },
138
+ {
139
+ code: '2021',
140
+ name: 'Net Wages Payable',
141
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
142
+ },
143
+ {
144
+ code: '2022',
145
+ name: 'Salary Tax Withheld Payable',
146
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
147
+ },
148
+ {
149
+ code: '2023',
150
+ name: 'EOBI / Social Security Payable',
151
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
152
+ },
153
+ {
154
+ code: '2030',
155
+ name: 'Tips Payable',
156
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
157
+ description: 'Tips collected but not yet distributed to staff.',
158
+ },
159
+ {
160
+ code: '2041',
161
+ name: 'GST Payable – Card Sales',
162
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
163
+ },
164
+ {
165
+ code: '2042',
166
+ name: 'GST Payable – Cash Sales',
167
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
168
+ },
169
+ {
170
+ code: '2043',
171
+ name: 'Provincial Services Tax Payable',
172
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
173
+ description: 'PRA / SRB / KPRA services tax collected.',
174
+ },
175
+ {
176
+ code: '2044',
177
+ name: 'FBR POS Invoice Tax Payable',
178
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
179
+ },
180
+ {
181
+ code: '2050',
182
+ name: 'Gift Card & Voucher Liability',
183
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
184
+ description: 'Prepaid gift cards / vouchers not yet redeemed.',
185
+ },
186
+ {
187
+ code: '2060',
188
+ name: 'Customer Advances / Deposits',
189
+ type: accounting_1.ACCOUNT_TYPE_ENUM.LIABILITY,
190
+ },
191
+ // ===================== Equity =====================
192
+ {
193
+ code: '3001',
194
+ name: "Owner's Capital",
195
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EQUITY,
196
+ },
197
+ {
198
+ code: '3002',
199
+ name: "Owner's Drawings",
200
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EQUITY,
201
+ },
202
+ {
203
+ code: '3003',
204
+ name: 'Retained Earnings',
205
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EQUITY,
206
+ },
207
+ {
208
+ code: '3099',
209
+ name: 'Opening Balance Equity',
210
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EQUITY,
211
+ description: 'Balancing account used by opening balances entry.',
212
+ },
213
+ // ===================== Revenue =====================
214
+ {
215
+ code: '4001',
216
+ name: 'Food Sales',
217
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
218
+ },
219
+ {
220
+ code: '4002',
221
+ name: 'Beverage Sales',
222
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
223
+ },
224
+ {
225
+ code: '4003',
226
+ name: 'Delivery Sales – Own',
227
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
228
+ },
229
+ {
230
+ code: '4004',
231
+ name: 'Delivery Sales – Platforms',
232
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
233
+ },
234
+ {
235
+ code: '4005',
236
+ name: 'Catering & Events Sales',
237
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
238
+ },
239
+ {
240
+ code: '4010',
241
+ name: 'Service Fee Income',
242
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
243
+ },
244
+ {
245
+ code: '4011',
246
+ name: 'Delivery & Rider Income',
247
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
248
+ },
249
+ {
250
+ code: '4012',
251
+ name: 'Surcharge Income',
252
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
253
+ },
254
+ {
255
+ code: '4090',
256
+ name: 'Sales Discounts',
257
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
258
+ description: 'Discounts given — a contra-revenue account.',
259
+ },
260
+ {
261
+ code: '4091',
262
+ name: 'Complimentary / Comps',
263
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
264
+ description: 'Complimentary meals — a contra-revenue account.',
265
+ },
266
+ {
267
+ code: '4092',
268
+ name: 'Sales Returns & Refunds',
269
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
270
+ description: 'Refunds and returns — a contra-revenue account.',
271
+ },
272
+ // ===================== Cost of Sales =====================
273
+ {
274
+ code: '5001',
275
+ name: 'Food Cost',
276
+ type: accounting_1.ACCOUNT_TYPE_ENUM.COGS,
277
+ },
278
+ {
279
+ code: '5002',
280
+ name: 'Beverage Cost',
281
+ type: accounting_1.ACCOUNT_TYPE_ENUM.COGS,
282
+ },
283
+ {
284
+ code: '5003',
285
+ name: 'Packaging Cost',
286
+ type: accounting_1.ACCOUNT_TYPE_ENUM.COGS,
287
+ },
288
+ {
289
+ code: '5010',
290
+ name: 'Inventory Wastage & Spoilage',
291
+ type: accounting_1.ACCOUNT_TYPE_ENUM.COGS,
292
+ },
293
+ {
294
+ code: '5011',
295
+ name: 'Inventory Shrinkage',
296
+ type: accounting_1.ACCOUNT_TYPE_ENUM.COGS,
297
+ },
298
+ {
299
+ code: '5012',
300
+ name: 'Inventory Adjustment Gain / Loss',
301
+ type: accounting_1.ACCOUNT_TYPE_ENUM.COGS,
302
+ },
303
+ // ===================== Expenses =====================
304
+ {
305
+ code: '6001',
306
+ name: 'Salaries & Wages',
307
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
308
+ },
309
+ {
310
+ code: '6002',
311
+ name: 'Overtime',
312
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
313
+ },
314
+ {
315
+ code: '6003',
316
+ name: 'Staff Meals & Amenities',
317
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
318
+ },
319
+ {
320
+ code: '6010',
321
+ name: 'Rent & Rentals',
322
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
323
+ },
324
+ {
325
+ code: '6020',
326
+ name: 'Utilities',
327
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
328
+ description: 'Electricity, gas, water, internet.',
329
+ },
330
+ {
331
+ code: '6031',
332
+ name: 'Platform Commissions',
333
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
334
+ description: 'Commissions deducted by delivery platforms.',
335
+ },
336
+ {
337
+ code: '6032',
338
+ name: 'Ads & Social Media',
339
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
340
+ },
341
+ {
342
+ code: '6033',
343
+ name: 'Promotions & Campaigns',
344
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
345
+ },
346
+ {
347
+ code: '6034',
348
+ name: 'Loyalty & Rewards Cost',
349
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
350
+ },
351
+ {
352
+ code: '6041',
353
+ name: 'Rider Payouts',
354
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
355
+ },
356
+ {
357
+ code: '6042',
358
+ name: 'Fuel & Vehicle',
359
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
360
+ },
361
+ {
362
+ code: '6050',
363
+ name: 'Repairs & Maintenance',
364
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
365
+ },
366
+ {
367
+ code: '6060',
368
+ name: 'Cleaning & Housekeeping Supplies',
369
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
370
+ },
371
+ {
372
+ code: '6070',
373
+ name: 'Licenses, Permits & Government Fees',
374
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
375
+ },
376
+ {
377
+ code: '6080',
378
+ name: 'Insurance',
379
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
380
+ },
381
+ {
382
+ code: '6091',
383
+ name: 'Payment Processing Fees',
384
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
385
+ },
386
+ {
387
+ code: '6092',
388
+ name: 'Bank Charges',
389
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
390
+ },
391
+ {
392
+ code: '6100',
393
+ name: 'Software & Subscriptions',
394
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
395
+ },
396
+ {
397
+ code: '6110',
398
+ name: 'Professional Fees',
399
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
400
+ description: 'Accounting, legal and consultancy fees.',
401
+ },
402
+ {
403
+ code: '6120',
404
+ name: 'Training & Recruitment',
405
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
406
+ },
407
+ {
408
+ code: '6130',
409
+ name: 'Office & Miscellaneous Expenses',
410
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
411
+ },
412
+ {
413
+ code: '6140',
414
+ name: 'Depreciation Expense',
415
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
416
+ },
417
+ // ================ Other Income & Expenses ================
418
+ {
419
+ code: '7001',
420
+ name: 'Cash Over / Short',
421
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
422
+ description: 'Day-close cash drawer variances.',
423
+ },
424
+ {
425
+ code: '7002',
426
+ name: 'Interest Expense',
427
+ type: accounting_1.ACCOUNT_TYPE_ENUM.EXPENSE,
428
+ },
429
+ {
430
+ code: '7003',
431
+ name: 'Other Income',
432
+ type: accounting_1.ACCOUNT_TYPE_ENUM.INCOME,
433
+ },
434
+ ];
@@ -1,3 +1,4 @@
1
+ export * from './accounting-templates';
1
2
  export * from './ANALYTICS';
2
3
  export * from './API_ERRORS';
3
4
  export * from './COMMON';
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./accounting-templates"), exports);
17
18
  __exportStar(require("./ANALYTICS"), exports);
18
19
  __exportStar(require("./API_ERRORS"), exports);
19
20
  __exportStar(require("./COMMON"), exports);
@@ -1021,7 +1021,12 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
1021
1021
  subtotal: orderLevelDiscountBaseAmount,
1022
1022
  hasExcludedRefs: false,
1023
1023
  };
1024
- if (hasExcludedRefs && !is_discount_percentage) {
1024
+ // A fixed discount with exclusions is legitimate: the builder already
1025
+ // normalized it against the eligible subtotal. Only clear when there
1026
+ // is nothing left to discount - the capping branch below re-derives
1027
+ // the amount from the same base. (The voucher copy never had this
1028
+ // early clear, which is why the two drifted.)
1029
+ if (hasExcludedRefs && !is_discount_percentage && eligibleSubtotal <= 0) {
1025
1030
  clearOrderLevelDiscount('loyalty');
1026
1031
  }
1027
1032
  else {
@@ -1034,10 +1039,7 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
1034
1039
  Number.isFinite(max_discount_amount) &&
1035
1040
  max_discount_amount >= 0;
1036
1041
  const hasFlatMaxPercentage = !is_discount_percentage && hasRelevantPercentageCap;
1037
- if (hasExcludedRefs && !is_discount_percentage && !hasFlatMaxPercentage) {
1038
- clearOrderLevelDiscount('loyalty');
1039
- }
1040
- else if (hasExcludedRefs) {
1042
+ if (hasExcludedRefs) {
1041
1043
  // Excluded items present: must apply percentage against eligible subtotal only.
1042
1044
  const eligibleBase = hasFlatMaxPercentage
1043
1045
  ? (0, utils_1.parseNum)((0, utils_1.getNetItemsValueAfterItemDiscount)({
@@ -1165,7 +1167,10 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
1165
1167
  Number.isFinite(max_discount_amount) &&
1166
1168
  max_discount_amount >= 0;
1167
1169
  const hasFlatMaxPercentage = !is_discount_percentage && hasRelevantPercentageCap;
1168
- if (hasExcludedRefs && !is_discount_percentage && !hasFlatMaxPercentage) {
1170
+ // Same rule as the loyalty slot: a fixed discount with exclusions is
1171
+ // valid (the builder already normalized it against the eligible
1172
+ // subtotal), so only clear when nothing is left to discount.
1173
+ if (hasExcludedRefs && !is_discount_percentage && eligibleSubtotal <= 0) {
1169
1174
  clearOrderLevelDiscount('voucher');
1170
1175
  }
1171
1176
  else if (hasExcludedRefs) {
@@ -2517,6 +2522,7 @@ function getUpdateItemInCartData(data, payload, courses, listnerSettings, applie
2517
2522
  ...data,
2518
2523
  ...(iterations.length > 0 && { iterations }),
2519
2524
  categories,
2525
+ ...getItemRemovalRedeemedOffersPatch({ data, categories, removedItemId: payload._id }),
2520
2526
  };
2521
2527
  const synced = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
2522
2528
  if (appliedCustomDiscounts && appliedCustomDiscounts.length > 0) {
@@ -2569,6 +2575,47 @@ function getUpdateCartInfoData(data, payload, courses, listnerSettings, syncCont
2569
2575
  };
2570
2576
  }
2571
2577
  /* ======================><====================== */
2578
+ /**
2579
+ * Drop the claim for any offer whose last stamped item was just removed.
2580
+ *
2581
+ * An item reward lives both in `redeemed_offers` and on the item's own
2582
+ * `item_discount_details`. The offers sync is parked while an order is edited, so
2583
+ * removing a reward item used to leave its claim behind: the order could still be
2584
+ * settled against a reward that is no longer in it. This reconciles the one case
2585
+ * that needs no offer definition - nothing stamped is left.
2586
+ */
2587
+ function getItemRemovalRedeemedOffersPatch({ data, categories, removedItemId, }) {
2588
+ if (removedItemId == null)
2589
+ return {};
2590
+ const removedOfferIds = [];
2591
+ for (let i = 0; i < (data.categories ?? []).length; i++) {
2592
+ const items = data.categories?.[i].items ?? [];
2593
+ for (let j = 0; j < items.length; j++) {
2594
+ if (items[j]._id !== removedItemId)
2595
+ continue;
2596
+ const discountDetails = items[j].item_discount_details;
2597
+ const offerId = discountDetails?.loyalty_discount_id ?? discountDetails?.voucher_discount_id;
2598
+ if (offerId != null)
2599
+ removedOfferIds.push(offerId);
2600
+ }
2601
+ }
2602
+ if (removedOfferIds.length === 0)
2603
+ return {};
2604
+ const nextRedeemedOffers = { ...(getRedeemedOffersMap(data.redeemed_offers) ?? {}) };
2605
+ for (let i = 0; i < removedOfferIds.length; i++) {
2606
+ const offerId = getNormalizedOfferId(removedOfferIds[i]);
2607
+ if (offerId == null)
2608
+ continue;
2609
+ const stillStamped = (categories ?? []).some((category) => (category.items ?? []).some((item) => {
2610
+ const details = item.item_discount_details;
2611
+ return (getNormalizedOfferId(details?.loyalty_discount_id) === offerId ||
2612
+ getNormalizedOfferId(details?.voucher_discount_id) === offerId);
2613
+ }));
2614
+ if (!stillStamped)
2615
+ delete nextRedeemedOffers[offerId];
2616
+ }
2617
+ return { redeemed_offers: getRedeemedOffersMap(nextRedeemedOffers) };
2618
+ }
2572
2619
  function getRemoveItemFromCartData(data, payload, courses, listnerSettings, appliedCustomDiscounts) {
2573
2620
  const orderItemIdsMap = {};
2574
2621
  let categories;
@@ -2647,6 +2694,7 @@ function getRemoveItemFromCartData(data, payload, courses, listnerSettings, appl
2647
2694
  ...data,
2648
2695
  ...(iterations.length > 0 && { iterations }),
2649
2696
  categories,
2697
+ ...getItemRemovalRedeemedOffersPatch({ data, categories, removedItemId: payload._id }),
2650
2698
  };
2651
2699
  const synced = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
2652
2700
  if (appliedCustomDiscounts && appliedCustomDiscounts.length > 0) {
@@ -51,7 +51,11 @@ function getEditItemProps({ item, orderItemCategoryId, orderItem, offers, isLoya
51
51
  return;
52
52
  let applyLoyalty;
53
53
  let applyVoucher;
54
- const excludeRefs = undefined;
54
+ // "hide these options" and "this option is not discountable" are two different
55
+ // lists and were previously crossed here: the hide list was never populated and
56
+ // the no-discount slot received the hide list, so editing a reward item hid
57
+ // nothing and price-protected the wrong options.
58
+ let excludeRefs = undefined;
55
59
  let excludedDiscountRefs = undefined;
56
60
  const zeroPriceRefs = undefined;
57
61
  // Step 1: Check if loyalty discount or voucher discount is applied
@@ -61,20 +65,24 @@ function getEditItemProps({ item, orderItemCategoryId, orderItem, offers, isLoya
61
65
  return;
62
66
  // const rewardItems = offer?.reward_items;
63
67
  let refs = [];
68
+ let offerHideRefs = [];
64
69
  let offerExcludedDiscountRefs = [];
65
70
  let applicable_quantity = 1;
66
71
  if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS) {
67
72
  if (offer.reward_items == null)
68
73
  return;
69
74
  refs = offer.reward_items.exclusive_refs.concat(item._id) ?? [];
70
- offerExcludedDiscountRefs = offer.reward_items.excluded_refs;
75
+ // excluded_refs hides options; exclusive_refs marks options as not discountable.
76
+ offerHideRefs = offer.reward_items.excluded_refs;
77
+ offerExcludedDiscountRefs = offer.reward_items.exclusive_refs;
71
78
  applicable_quantity = offer.reward_items.num_of_items || 1;
72
79
  }
73
80
  else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
74
81
  if (offer.reward_discount_items == null)
75
82
  return;
76
83
  refs = offer.reward_discount_items.exclusive_refs.concat(item._id) ?? [];
77
- offerExcludedDiscountRefs = offer.reward_discount_items.excluded_refs;
84
+ offerHideRefs = offer.reward_discount_items.excluded_refs;
85
+ offerExcludedDiscountRefs = offer.reward_discount_items.exclusive_refs;
78
86
  applicable_quantity = offer.reward_discount_items.num_of_items || 1;
79
87
  }
80
88
  let discount_details = null;
@@ -93,6 +101,7 @@ function getEditItemProps({ item, orderItemCategoryId, orderItem, offers, isLoya
93
101
  discount_details,
94
102
  applicable_quantity,
95
103
  };
104
+ excludeRefs = offerHideRefs;
96
105
  excludedDiscountRefs = offerExcludedDiscountRefs;
97
106
  }
98
107
  if (isVoucherDiscountApplied) {
@@ -101,20 +110,24 @@ function getEditItemProps({ item, orderItemCategoryId, orderItem, offers, isLoya
101
110
  return;
102
111
  // const rewardItems = offer?.reward_items;
103
112
  let refs = [];
113
+ let offerHideRefs = [];
104
114
  let offerExcludedDiscountRefs = [];
105
115
  let applicable_quantity = 1;
106
116
  if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.ITEMS) {
107
117
  if (offer.reward_items == null)
108
118
  return;
109
119
  refs = offer.reward_items.exclusive_refs.concat(item._id) ?? [];
110
- offerExcludedDiscountRefs = offer.reward_items.excluded_refs;
120
+ // excluded_refs hides options; exclusive_refs marks options as not discountable.
121
+ offerHideRefs = offer.reward_items.excluded_refs;
122
+ offerExcludedDiscountRefs = offer.reward_items.exclusive_refs;
111
123
  applicable_quantity = offer.reward_items.num_of_items || 1;
112
124
  }
113
125
  else if (offer.reward_type === constants_1.OFFER_REWARD_TYPE_ENUM.DISCOUNT_ITEMS) {
114
126
  if (offer.reward_discount_items == null)
115
127
  return;
116
128
  refs = offer.reward_discount_items.exclusive_refs.concat(item._id) ?? [];
117
- offerExcludedDiscountRefs = offer.reward_discount_items.excluded_refs;
129
+ offerHideRefs = offer.reward_discount_items.excluded_refs;
130
+ offerExcludedDiscountRefs = offer.reward_discount_items.exclusive_refs;
118
131
  applicable_quantity = offer.reward_discount_items.num_of_items || 1;
119
132
  }
120
133
  let discount_details = null;
@@ -133,6 +146,7 @@ function getEditItemProps({ item, orderItemCategoryId, orderItem, offers, isLoya
133
146
  discount_details,
134
147
  applicable_quantity,
135
148
  };
149
+ excludeRefs = offerHideRefs;
136
150
  excludedDiscountRefs = offerExcludedDiscountRefs;
137
151
  }
138
152
  // TODO: We need to add use case for HalfHalf and Specials
@@ -38,11 +38,26 @@ interface IGetCappedOfferDiscountAmount {
38
38
  maxDiscountPercentage?: number | null;
39
39
  }
40
40
  export declare function getCappedOfferDiscountAmount({ baseAmount, discountValue, isDiscountPercentage, maxDiscountAmount, maxDiscountPercentage, }: IGetCappedOfferDiscountAmount): number;
41
+ /**
42
+ * Does this order line match any of the given refs?
43
+ *
44
+ * A ref is an **item-level** id: an item id, and - because a SPECIAL or
45
+ * HALF_HALF order line stores its own document id in `item_id` - a special or
46
+ * half-half id too. Modifier/option refs never appear here: those belong to the
47
+ * reward's "Hide Options" / "Discount Not Applicable" lists, which act on the
48
+ * modifier tree at selection time, not on spend qualification.
49
+ */
50
+ export declare function doesOrderItemMatchRefs(item: {
51
+ item_id?: string | null;
52
+ }, refs: string[]): boolean;
41
53
  /**
42
54
  * Calculate the eligible subtotal by excluding items/categories in excluded_refs.
43
55
  *
44
56
  * Shared by the cart engine (discount application/re-sync) and the offer-stats
45
57
  * engine (spend qualification) so both use the exact same exclusion math.
58
+ *
59
+ * A ref matches a whole category (`category_id`) or an item - where "item" means
60
+ * the item id, one of its modifier refs, or one of its option refs.
46
61
  */
47
62
  export declare function calculateEligibleOfferDiscountDetails(categories: IOrderCategory[] | undefined, excluded_refs: string[]): {
48
63
  subtotal: number;