@managesome/eposmatic-toolkit 0.2.721 → 0.2.733
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers/types/order-engine.d.ts +17 -2
- package/lib/helpers/utils/cart-helpers.d.ts +2 -0
- package/lib/helpers/utils/halfhalf-setup-helpers.js +47 -27
- package/lib/helpers/utils/order-engine.d.ts +56 -15
- package/lib/helpers/utils/order-engine.js +240 -130
- package/lib/schemas/models/index.d.ts +1 -0
- package/lib/schemas/models/index.js +1 -0
- package/lib/schemas/models/inventory_entries.d.ts +152 -0
- package/lib/schemas/models/inventory_entries.js +142 -0
- package/lib/schemas/types/index.d.ts +1 -0
- package/lib/schemas/types/index.js +1 -0
- package/lib/schemas/types/inventory_entries.d.ts +41 -0
- package/lib/schemas/types/inventory_entries.js +2 -0
- package/lib/tests/choose-expensive-edge-cases.test.d.ts +1 -0
- package/lib/tests/choose-expensive-edge-cases.test.js +966 -0
- package/lib/tests/choose-expensive-flow-verification.test.d.ts +1 -0
- package/lib/tests/choose-expensive-flow-verification.test.js +702 -0
- package/lib/tests/halfhalf-selection-rules.test.d.ts +1 -0
- package/lib/tests/halfhalf-selection-rules.test.js +200 -0
- package/lib/tests/segment-price-floor.test.d.ts +1 -0
- package/lib/tests/segment-price-floor.test.js +143 -0
- package/lib/tests/specials-halfhalf-pricing.test.js +40 -19
- package/package.json +1 -1
|
@@ -8,9 +8,12 @@ exports.syncOrderEngineItem = syncOrderEngineItem;
|
|
|
8
8
|
exports.checkIfModifiersExist = checkIfModifiersExist;
|
|
9
9
|
exports.makeSpaceForFreeOptions = makeSpaceForFreeOptions;
|
|
10
10
|
exports.applyChooseExpensiveSegmentPrice = applyChooseExpensiveSegmentPrice;
|
|
11
|
-
exports.
|
|
11
|
+
exports.getOrderEngineOptionSegmentValue = getOrderEngineOptionSegmentValue;
|
|
12
12
|
exports.hasFlaggedHalfHalfOption = hasFlaggedHalfHalfOption;
|
|
13
|
+
exports.getBlockedHalfHalfOptionPaths = getBlockedHalfHalfOptionPaths;
|
|
14
|
+
exports.getHalfHalfBlockedItemIds = getHalfHalfBlockedItemIds;
|
|
13
15
|
exports.applyNestedChooseExpensiveSegmentPrice = applyNestedChooseExpensiveSegmentPrice;
|
|
16
|
+
exports.applySegmentPriceFloor = applySegmentPriceFloor;
|
|
14
17
|
exports.convertOrderEngineItemToOrderItem = convertOrderEngineItemToOrderItem;
|
|
15
18
|
exports.convertItemDiscountToOrderItemDiscount = convertItemDiscountToOrderItemDiscount;
|
|
16
19
|
exports.convertCatalogItemToOrderEngineItem = convertCatalogItemToOrderEngineItem;
|
|
@@ -163,6 +166,11 @@ function syncOrderEngineItem(orderEngineItem) {
|
|
|
163
166
|
const option = modifier.options[j];
|
|
164
167
|
if (!option.default)
|
|
165
168
|
continue;
|
|
169
|
+
// `is_free` means NOT charged (the cart math —
|
|
170
|
+
// `calculateItemModifiersPrice` — skips them too): free options keep
|
|
171
|
+
// their price for reference but must never add to the totals.
|
|
172
|
+
if (option.is_free)
|
|
173
|
+
continue;
|
|
166
174
|
const quantity = option.quantity || 1;
|
|
167
175
|
// Add option price to total
|
|
168
176
|
total += (option.price || 0) * quantity;
|
|
@@ -303,11 +311,16 @@ function makeSpaceForFreeOptions(options, num_free_options) {
|
|
|
303
311
|
* baked into the option price at conversion. choose_expensive compares every
|
|
304
312
|
* segment option (option price + required/price-defining modifier prices —
|
|
305
313
|
* e.g. a "Pizza Size" group whose Small/Large/X-Large options are part of the
|
|
306
|
-
* item's price) and levels the cheaper
|
|
314
|
+
* item's price) and levels the cheaper PICK to the most expensive SELECTED
|
|
307
315
|
* half — `A($5)+B($5)` charges 5+5, `B($5)+C($6)` charges 6+6, and switching
|
|
308
|
-
* `C+D -> A+B` lowers them again.
|
|
309
|
-
*
|
|
310
|
-
*
|
|
316
|
+
* `C+D -> A+B` lowers them again. Every option is levelled to `max(own value,
|
|
317
|
+
* the max of the OTHER segments' selected values)` — the level its OWN pick
|
|
318
|
+
* would produce: choosing an unselected sibling REPLACES its segment's
|
|
319
|
+
* current pick, so that pick never inflates its own siblings' prices (a
|
|
320
|
+
* segment holding the expensive half keeps its other options at their own
|
|
321
|
+
* prices — you can only pick the next half from the NEXT segment), while a
|
|
322
|
+
* segment with no pick yet previews the full level. Unselected options never
|
|
323
|
+
* contribute to totals. The raise is applied to the FIRST
|
|
311
324
|
* PRICED element along the segment's price chain: the segment option's own
|
|
312
325
|
* price when non-zero, else the first priced required leaf ("First Half ->
|
|
313
326
|
* ROMA -> Pizza Size -> Large 13"") — see `findRaiseTarget`. Optional/upsell
|
|
@@ -346,26 +359,6 @@ function applyChooseExpensiveSegmentPrice(orderEngineItem, options) {
|
|
|
346
359
|
* (ids are BSON ObjectIds so `_` is unambiguous).
|
|
347
360
|
*/
|
|
348
361
|
const buildOptionPath = (modifierPath, optionId) => `${modifierPath}_${optionId}`;
|
|
349
|
-
/**
|
|
350
|
-
* Records the ORIGINAL price of every option in the engine tree, keyed by its
|
|
351
|
-
* option path (see `TOrderEnginePriceReferences`). One walk, no copies — the
|
|
352
|
-
* map is the engine's memory for reversible price normalization.
|
|
353
|
-
*/
|
|
354
|
-
function getOrderEnginePriceReferences(orderEngineItem) {
|
|
355
|
-
const references = {};
|
|
356
|
-
const walk = (modifiers, parentPath) => {
|
|
357
|
-
modifiers.forEach((modifier) => {
|
|
358
|
-
const modifierPath = parentPath ? `${parentPath}_${modifier._id}` : modifier._id;
|
|
359
|
-
(modifier.options ?? []).forEach((option) => {
|
|
360
|
-
const optionPath = buildOptionPath(modifierPath, option._id);
|
|
361
|
-
references[optionPath] = option.price ?? 0;
|
|
362
|
-
walk(option.modifiers ?? [], optionPath);
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
};
|
|
366
|
-
walk(orderEngineItem.modifiers ?? [], '');
|
|
367
|
-
return references;
|
|
368
|
-
}
|
|
369
362
|
/**
|
|
370
363
|
* Re-bases engine option prices from `references` (option path -> original
|
|
371
364
|
* price). The scope decides WHICH options are re-based:
|
|
@@ -408,6 +401,73 @@ function rebaseEngineOptionPrices(modifiers, references, parentPath, scope, insi
|
|
|
408
401
|
});
|
|
409
402
|
return treeChanged ? nextModifiers : modifiers;
|
|
410
403
|
}
|
|
404
|
+
/**
|
|
405
|
+
* The option a required (price-defining) group contributes to the segment
|
|
406
|
+
* value: the SELECTED (default) one for a multi-option group, or the only
|
|
407
|
+
* option of a single-option group — never an unselected sibling.
|
|
408
|
+
*/
|
|
409
|
+
function getSelectedRequiredOption(modifier) {
|
|
410
|
+
const options = modifier.options ?? [];
|
|
411
|
+
return options.find((option) => option.default) ?? (options.length === 1 ? options[0] : null);
|
|
412
|
+
}
|
|
413
|
+
/** Required (price-defining) group: at least one selection is mandatory. */
|
|
414
|
+
function isRequiredModifierGroup(modifier) {
|
|
415
|
+
return ((modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
416
|
+
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0));
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Value of the SELECTED option of every required (price-defining) modifier
|
|
420
|
+
* group, at any depth — e.g. "Pizza Size" -> "Large 13"" is part of the
|
|
421
|
+
* item's price whichever size is picked, and only the picked size is charged.
|
|
422
|
+
* Optional/upsell groups, unselected siblings and the add-ons chosen on top of
|
|
423
|
+
* the item are excluded: they must not influence the comparison.
|
|
424
|
+
*/
|
|
425
|
+
function getRequiredOptionPrices(modifiers) {
|
|
426
|
+
let total = 0;
|
|
427
|
+
(modifiers ?? []).forEach((modifier) => {
|
|
428
|
+
if (!isRequiredModifierGroup(modifier))
|
|
429
|
+
return;
|
|
430
|
+
const selected = getSelectedRequiredOption(modifier);
|
|
431
|
+
if (selected == null)
|
|
432
|
+
return;
|
|
433
|
+
total += (selected.price ?? 0) * (selected.quantity || 1);
|
|
434
|
+
total += getRequiredOptionPrices(selected.modifiers);
|
|
435
|
+
});
|
|
436
|
+
return total;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Value `choose_expensive_segment_price` compares and levels: the option price
|
|
440
|
+
* (base + item/option level upsell, merged at conversion) + the prices of its
|
|
441
|
+
* SELECTED required (price-defining) options. Exposed so callers that show a
|
|
442
|
+
* price for a single segment (e.g. the segment customization drawer) use the
|
|
443
|
+
* SAME math.
|
|
444
|
+
*/
|
|
445
|
+
function getOrderEngineOptionSegmentValue(option) {
|
|
446
|
+
return (option.price ?? 0) + getRequiredOptionPrices(option.modifiers);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* First priced required leaf reachable from `modifiers` (direct children):
|
|
450
|
+
* the single option of a single-option required group (its price is fixed —
|
|
451
|
+
* e.g. "ROMA -> Pizza Size -> Large 13""), or the selected/default option
|
|
452
|
+
* of a multi-option required group (never an unselected sibling).
|
|
453
|
+
*/
|
|
454
|
+
function findPricedRequiredLeaf(modifiers) {
|
|
455
|
+
for (const modifier of modifiers ?? []) {
|
|
456
|
+
if (!isRequiredModifierGroup(modifier))
|
|
457
|
+
continue;
|
|
458
|
+
const candidate = getSelectedRequiredOption(modifier);
|
|
459
|
+
if (candidate != null && (candidate.price ?? 0) > 0)
|
|
460
|
+
return candidate;
|
|
461
|
+
}
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
/** Raises the option `targetId` inside its (direct) modifier group by `delta`. */
|
|
465
|
+
function raiseOptionPriceInModifiers(modifiers, targetId, delta) {
|
|
466
|
+
return modifiers.map((modifier) => ({
|
|
467
|
+
...modifier,
|
|
468
|
+
options: modifier.options.map((option) => option._id === targetId ? { ...option, price: (option.price ?? 0) + delta } : option),
|
|
469
|
+
}));
|
|
470
|
+
}
|
|
411
471
|
/**
|
|
412
472
|
* Core `choose_expensive_segment_price` normalization over a list of segment
|
|
413
473
|
* groups (single-select: one option per group). Used for standalone HALF_HALF
|
|
@@ -418,57 +478,14 @@ function rebaseEngineOptionPrices(modifiers, references, parentPath, scope, insi
|
|
|
418
478
|
* segment), otherwise the raised segment groups.
|
|
419
479
|
*/
|
|
420
480
|
function applyChooseExpensiveSegmentPriceToModifiers(segmentGroups) {
|
|
421
|
-
// Prices of ALL options of required (price-defining) modifier groups, at
|
|
422
|
-
// any depth — e.g. "Pizza Size" -> "Large 13"" is part of the item's price
|
|
423
|
-
// whichever size is picked (mirrors `getSegmentItemTotalPrice` used by the
|
|
424
|
-
// modern workable converter). Optional/upsell modifier groups are excluded:
|
|
425
|
-
// they add on top and must not influence the comparison.
|
|
426
|
-
const getRequiredOptionPrices = (modifiers) => {
|
|
427
|
-
let total = 0;
|
|
428
|
-
(modifiers ?? []).forEach((modifier) => {
|
|
429
|
-
const isRequired = (modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
430
|
-
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0);
|
|
431
|
-
if (!isRequired)
|
|
432
|
-
return;
|
|
433
|
-
(modifier.options ?? []).forEach((option) => {
|
|
434
|
-
total += (option.price ?? 0) * (option.quantity || 1);
|
|
435
|
-
total += getRequiredOptionPrices(option.modifiers);
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
return total;
|
|
439
|
-
};
|
|
440
|
-
// Segment price = option price (base + item/option level upsell, already
|
|
441
|
-
// merged at conversion) + required (price-defining) modifier prices.
|
|
442
|
-
const getSegmentTotal = (option) => (option.price ?? 0) + getRequiredOptionPrices(option.modifiers);
|
|
443
481
|
// One selected option per segment group (segments are single-select).
|
|
444
|
-
const selections = [];
|
|
445
|
-
|
|
446
|
-
const options = segmentGroups[g].options ?? [];
|
|
447
|
-
for (let o = 0; o < options.length; o++) {
|
|
448
|
-
const option = options[o];
|
|
449
|
-
if (!option.default || option.is_free)
|
|
450
|
-
continue;
|
|
451
|
-
selections.push({ groupIndex: g, optionIndex: o });
|
|
452
|
-
break; // single-select: at most one selected option
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
if (selections.length === 0)
|
|
482
|
+
const selections = segmentGroups.map((group) => (group.options ?? []).find((option) => option.default && !option.is_free) ?? null);
|
|
483
|
+
if (selections.every((selection) => selection == null))
|
|
456
484
|
return null;
|
|
457
|
-
//
|
|
458
|
-
//
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
let maxSegmentValue = 0;
|
|
462
|
-
for (const selection of selections) {
|
|
463
|
-
const option = segmentGroups[selection.groupIndex].options[selection.optionIndex];
|
|
464
|
-
if (option.is_free)
|
|
465
|
-
continue;
|
|
466
|
-
const segmentValue = getSegmentTotal(option);
|
|
467
|
-
if (segmentValue > maxSegmentValue) {
|
|
468
|
-
maxSegmentValue = segmentValue;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
if (maxSegmentValue <= 0)
|
|
485
|
+
// Value of every segment's SELECTED option — only picks are charged, and
|
|
486
|
+
// only picks drive the level.
|
|
487
|
+
const selectedValues = selections.map((selection) => selection == null ? 0 : getOrderEngineOptionSegmentValue(selection));
|
|
488
|
+
if (Math.max(...selectedValues, 0) <= 0)
|
|
472
489
|
return null;
|
|
473
490
|
// RULE for where the raise lands: on the FIRST PRICED element along the
|
|
474
491
|
// segment's price chain —
|
|
@@ -481,54 +498,43 @@ function applyChooseExpensiveSegmentPriceToModifiers(segmentGroups) {
|
|
|
481
498
|
// 3. otherwise, the segment option's own price (even when 0).
|
|
482
499
|
// This keeps the raise where the price actually lives and never invents a
|
|
483
500
|
// price on an empty slot or an unselected option.
|
|
484
|
-
const findRaiseTarget = (option) =>
|
|
485
|
-
if ((option.price ?? 0) > 0)
|
|
486
|
-
return option;
|
|
487
|
-
for (const modifier of option.modifiers ?? []) {
|
|
488
|
-
const isRequired = (modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
489
|
-
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0);
|
|
490
|
-
if (!isRequired)
|
|
491
|
-
continue;
|
|
492
|
-
const options = modifier.options ?? [];
|
|
493
|
-
const candidate = options.length === 1 ? options[0] : (options.find((opt) => opt.default) ?? null);
|
|
494
|
-
if (candidate != null && (candidate.price ?? 0) > 0)
|
|
495
|
-
return candidate;
|
|
496
|
-
}
|
|
497
|
-
return null;
|
|
498
|
-
};
|
|
501
|
+
const findRaiseTarget = (option) => (option.price ?? 0) > 0 ? option : findPricedRequiredLeaf(option.modifiers);
|
|
499
502
|
const raiseSegmentOption = (option, delta) => {
|
|
500
503
|
const target = findRaiseTarget(option);
|
|
501
504
|
if (target == null || target._id === option._id) {
|
|
502
505
|
return { ...option, price: (option.price ?? 0) + delta };
|
|
503
506
|
}
|
|
507
|
+
return { ...option, modifiers: raiseOptionPriceInModifiers(option.modifiers, target._id, delta) };
|
|
508
|
+
};
|
|
509
|
+
// Every option is levelled to `max(own value, the max of the OTHER
|
|
510
|
+
// segments' selected values)` — the level its OWN pick would produce:
|
|
511
|
+
// - the selected option of a segment is CHARGED that way (the most
|
|
512
|
+
// expensive selected half drives every pick),
|
|
513
|
+
// - an unselected SIBLING replaces its segment's current pick when
|
|
514
|
+
// chosen, so that pick must not inflate the sibling's price (the
|
|
515
|
+
// expensive half's own list keeps its other options at their prices),
|
|
516
|
+
// - every option of a segment with no pick yet previews the full level
|
|
517
|
+
// (what picking it right now would cost).
|
|
518
|
+
// Free (`is_free`) options never drive the comparison and are never raised.
|
|
519
|
+
return segmentGroups.map((modifier, groupIndex) => {
|
|
520
|
+
const otherSegmentsMax = Math.max(...selectedValues.filter((_, index) => index !== groupIndex), 0);
|
|
504
521
|
return {
|
|
505
|
-
...
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
522
|
+
...modifier,
|
|
523
|
+
options: (modifier.options ?? []).map((option) => {
|
|
524
|
+
if (option.is_free)
|
|
525
|
+
return option;
|
|
526
|
+
const segmentValue = getOrderEngineOptionSegmentValue(option);
|
|
527
|
+
const target = Math.max(segmentValue, otherSegmentsMax);
|
|
528
|
+
if (target <= segmentValue)
|
|
529
|
+
return option;
|
|
530
|
+
// Level by the difference so the option's final segment value
|
|
531
|
+
// (base + upsell + required modifiers) equals the target — applied
|
|
532
|
+
// to the priced leaf when available (see `raiseSegmentOption`). The
|
|
533
|
+
// IHalfHalfSetup upsell (item price) is untouched.
|
|
534
|
+
return raiseSegmentOption(option, target - segmentValue);
|
|
535
|
+
}),
|
|
510
536
|
};
|
|
511
|
-
};
|
|
512
|
-
// Every option whose segment price is below that max is levelled to it:
|
|
513
|
-
// selected halves are CHARGED that way, unselected ones SHOW what they would
|
|
514
|
-
// cost if picked (they never contribute to totals while unselected), and
|
|
515
|
-
// free options are never raised.
|
|
516
|
-
return segmentGroups.map((modifier) => ({
|
|
517
|
-
...modifier,
|
|
518
|
-
options: (modifier.options ?? []).map((option) => {
|
|
519
|
-
if (option.is_free)
|
|
520
|
-
return option;
|
|
521
|
-
const segmentValue = getSegmentTotal(option);
|
|
522
|
-
// Already at (or above) the most expensive selected segment: keep as is.
|
|
523
|
-
if (segmentValue >= maxSegmentValue)
|
|
524
|
-
return option;
|
|
525
|
-
// Level by the difference so the segment's final price (base + upsell +
|
|
526
|
-
// required modifiers) equals the expensive selected half — applied to
|
|
527
|
-
// the priced leaf when available (see `raiseSegmentOption`). The
|
|
528
|
-
// IHalfHalfSetup upsell (item price) is untouched.
|
|
529
|
-
return raiseSegmentOption(option, maxSegmentValue - segmentValue);
|
|
530
|
-
}),
|
|
531
|
-
}));
|
|
537
|
+
});
|
|
532
538
|
}
|
|
533
539
|
/**
|
|
534
540
|
* True when the item has a top-level modifier group option that is a nested
|
|
@@ -537,6 +543,84 @@ function applyChooseExpensiveSegmentPriceToModifiers(segmentGroups) {
|
|
|
537
543
|
function hasFlaggedHalfHalfOption(orderEngineItem) {
|
|
538
544
|
return (orderEngineItem.modifiers ?? []).some((modifier) => (modifier.options ?? []).some((option) => option.ref_type === constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF && option.choose_expensive_segment_price === true));
|
|
539
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* Half-half selection rule: an item may fill at most `segments - 1` halves —
|
|
548
|
+
* it may never make ALL sides of the half-half (otherwise it is not a half-half
|
|
549
|
+
* anymore). Returns the option PATHS that would complete "all sides" when
|
|
550
|
+
* selected, formatted exactly like `setCheckFieldInOrderEngineItem`
|
|
551
|
+
* identifiers (`seg-2_roma`, `mod-pizza_halfhalf-1_seg-2_milan`), so callers
|
|
552
|
+
* can block, guard and label them.
|
|
553
|
+
*
|
|
554
|
+
* Handles both shapes:
|
|
555
|
+
* - a HALF_HALF item (its top-level groups are the segments — pass
|
|
556
|
+
* `isHalfHalfSegmentItem: false`),
|
|
557
|
+
* - a flagged half-half option nested in a SPECIAL (its own modifier groups
|
|
558
|
+
* are the segments).
|
|
559
|
+
* A drawer opened for a single half-half SEGMENT passes
|
|
560
|
+
* `isHalfHalfSegmentItem: true` so the item's own option groups are never
|
|
561
|
+
* treated as segments.
|
|
562
|
+
*/
|
|
563
|
+
function getBlockedHalfHalfOptionPaths(orderEngineItem, isHalfHalfSegmentItem = false) {
|
|
564
|
+
const blocked = new Set();
|
|
565
|
+
const blockSegments = (segments, segmentsPath) => {
|
|
566
|
+
const total = segments.length;
|
|
567
|
+
if (total < 2)
|
|
568
|
+
return;
|
|
569
|
+
const selectedBySegment = segments.map((segment) => segment.options.find((option) => option.default) ?? null);
|
|
570
|
+
segments.forEach((segment, index) => {
|
|
571
|
+
const segmentPath = segmentsPath ? `${segmentsPath}_${segment._id}` : segment._id;
|
|
572
|
+
segment.options.forEach((option) => {
|
|
573
|
+
const others = selectedBySegment.filter((selected, otherIndex) => otherIndex !== index && selected != null && selected._id === option._id).length;
|
|
574
|
+
if (others >= total - 1) {
|
|
575
|
+
blocked.add(`${segmentPath}_${option._id}`);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
};
|
|
580
|
+
const walkNestedHalfHalf = (modifiers, parentPath) => {
|
|
581
|
+
modifiers.forEach((modifier) => {
|
|
582
|
+
const modifierPath = parentPath ? `${parentPath}_${modifier._id}` : modifier._id;
|
|
583
|
+
modifier.options.forEach((option) => {
|
|
584
|
+
const optionPath = `${modifierPath}_${option._id}`;
|
|
585
|
+
if (option.ref_type === constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF &&
|
|
586
|
+
option.choose_expensive_segment_price === true) {
|
|
587
|
+
blockSegments(option.modifiers ?? [], optionPath);
|
|
588
|
+
}
|
|
589
|
+
walkNestedHalfHalf(option.modifiers ?? [], optionPath);
|
|
590
|
+
});
|
|
591
|
+
});
|
|
592
|
+
};
|
|
593
|
+
if (orderEngineItem.item_type === constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF && !isHalfHalfSegmentItem) {
|
|
594
|
+
blockSegments((orderEngineItem.modifiers ?? []).filter((modifier) => modifier.depth === 0), '');
|
|
595
|
+
}
|
|
596
|
+
walkNestedHalfHalf(orderEngineItem.modifiers ?? [], '');
|
|
597
|
+
return blocked;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Same half-half selection rule for the MODERN selection list (no engine tree
|
|
601
|
+
* yet): the item ids that cannot be picked for `segmentIndex` because doing so
|
|
602
|
+
* would make them occupy every segment. `segmentIndex` is the segment being
|
|
603
|
+
* picked/edited (its own current item does not count against itself).
|
|
604
|
+
*/
|
|
605
|
+
function getHalfHalfBlockedItemIds(orderItems, segmentIndex) {
|
|
606
|
+
if (segmentIndex == null)
|
|
607
|
+
return [];
|
|
608
|
+
const totalSegments = orderItems.length;
|
|
609
|
+
if (totalSegments < 2)
|
|
610
|
+
return [];
|
|
611
|
+
const blocked = [];
|
|
612
|
+
const checked = new Set();
|
|
613
|
+
orderItems.forEach((orderItem) => {
|
|
614
|
+
if (orderItem == null || checked.has(orderItem.item_id))
|
|
615
|
+
return;
|
|
616
|
+
checked.add(orderItem.item_id);
|
|
617
|
+
const others = orderItems.filter((other, index) => index !== segmentIndex && other != null && other.item_id === orderItem.item_id).length;
|
|
618
|
+
if (others >= totalSegments - 1) {
|
|
619
|
+
blocked.push(orderItem.item_id);
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
return blocked;
|
|
623
|
+
}
|
|
540
624
|
/**
|
|
541
625
|
* `choose_expensive_segment_price` for a half-half option nested in a special:
|
|
542
626
|
* the option's own top-level modifiers are its segment groups, so they get the
|
|
@@ -571,6 +655,37 @@ function applyNestedChooseExpensiveSegmentPrice(orderEngineItem, options) {
|
|
|
571
655
|
}));
|
|
572
656
|
return syncOrderEngineItem({ ...rebased, modifiers });
|
|
573
657
|
}
|
|
658
|
+
/**
|
|
659
|
+
* Levels the item's segment VALUE (item price + required option prices — the
|
|
660
|
+
* value `getOrderEngineOptionSegmentValue` / `applyChooseExpensiveSegmentPrice`
|
|
661
|
+
* compare) UP to `floorPrice`, using the same raise mechanics as the rule: the
|
|
662
|
+
* raise lands on the FIRST PRICED element — the item price when non-zero,
|
|
663
|
+
* otherwise the first priced required leaf, otherwise the item price.
|
|
664
|
+
*
|
|
665
|
+
* Used by the drawer that edits a SINGLE half-half segment: the half-half
|
|
666
|
+
* screen passes the max value of the OTHER selected halves as the floor, so
|
|
667
|
+
* the drawer shows the amount this segment is actually charged once the
|
|
668
|
+
* choose_expensive rule levels it. It never lowers.
|
|
669
|
+
*/
|
|
670
|
+
function applySegmentPriceFloor(orderEngineItem, floorPrice) {
|
|
671
|
+
if (!(floorPrice > 0))
|
|
672
|
+
return orderEngineItem;
|
|
673
|
+
const currentValue = (orderEngineItem.price ?? 0) + getRequiredOptionPrices(orderEngineItem.modifiers);
|
|
674
|
+
const delta = floorPrice - currentValue;
|
|
675
|
+
if (delta <= 0)
|
|
676
|
+
return orderEngineItem;
|
|
677
|
+
if ((orderEngineItem.price ?? 0) > 0) {
|
|
678
|
+
return syncOrderEngineItem({ ...orderEngineItem, price: orderEngineItem.price + delta });
|
|
679
|
+
}
|
|
680
|
+
const target = findPricedRequiredLeaf(orderEngineItem.modifiers);
|
|
681
|
+
if (target == null) {
|
|
682
|
+
return syncOrderEngineItem({ ...orderEngineItem, price: (orderEngineItem.price ?? 0) + delta });
|
|
683
|
+
}
|
|
684
|
+
return syncOrderEngineItem({
|
|
685
|
+
...orderEngineItem,
|
|
686
|
+
modifiers: raiseOptionPriceInModifiers(orderEngineItem.modifiers, target._id, delta),
|
|
687
|
+
});
|
|
688
|
+
}
|
|
574
689
|
function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderItemModifiers, platform, tenantId, excludeRefs, zeroPriceRefs, loyaltyRefs, voucherRefs, keepOptionalModifiersAtBottom, soldoutModifiers, depth = 0, priceReferences, parentPath, }) {
|
|
575
690
|
function getSortedModifiers(modifiers = []) {
|
|
576
691
|
const sortedModifiers = modifiers.sort((a, b) => a.sort_id - b.sort_id);
|
|
@@ -673,6 +788,10 @@ function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderI
|
|
|
673
788
|
price: optionPrice,
|
|
674
789
|
quantity: qty,
|
|
675
790
|
modifiers: newModifiers,
|
|
791
|
+
// `zeroPriceRefs` (half-half `exclusive_refs`) mutate the PRICE only
|
|
792
|
+
// (`optionPrice` above) — they must never set `is_free`: the "Free"
|
|
793
|
+
// tag belongs exclusively to `num_free_options` options
|
|
794
|
+
// (`makeSpaceForFreeOptions`).
|
|
676
795
|
is_free,
|
|
677
796
|
loyalty_applied: false,
|
|
678
797
|
voucher_applied: false,
|
|
@@ -1130,21 +1249,12 @@ function setCheckFieldInOrderEngineItem(orderEngineItem, identifier, shouldCheck
|
|
|
1130
1249
|
const allIds = identifier.split('_').filter((id) => id.trim() !== '');
|
|
1131
1250
|
const modifiers = setUpdateModifiers(orderEngineItem.modifiers, allIds, 0);
|
|
1132
1251
|
const updatedOrderEngineItem = syncOrderEngineItem({ ...orderEngineItem, modifiers });
|
|
1133
|
-
//
|
|
1134
|
-
//
|
|
1135
|
-
// `
|
|
1136
|
-
//
|
|
1137
|
-
//
|
|
1138
|
-
|
|
1139
|
-
// segment. Idempotent: it never lowers a price, so re-running is safe.
|
|
1140
|
-
if (orderEngineItem.item_type === constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF && chooseExpensiveSegmentPrice === true) {
|
|
1141
|
-
return applyChooseExpensiveSegmentPrice(updatedOrderEngineItem);
|
|
1142
|
-
}
|
|
1143
|
-
// Half-half option nested in a special: normalize its own segment groups
|
|
1144
|
-
// (the option's top-level modifiers) whenever it carries the setup flag.
|
|
1145
|
-
if (orderEngineItem.item_type === constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL && hasFlaggedHalfHalfOption(updatedOrderEngineItem)) {
|
|
1146
|
-
return applyNestedChooseExpensiveSegmentPrice(updatedOrderEngineItem);
|
|
1147
|
-
}
|
|
1252
|
+
// `choose_expensive_segment_price` is NOT applied here: price normalization
|
|
1253
|
+
// has a single entry point (`applyChooseExpensiveSegmentPrice` /
|
|
1254
|
+
// `applyNestedChooseExpensiveSegmentPrice`, called with the original price
|
|
1255
|
+
// references by the drawer after this mutation). The flag parameter is kept
|
|
1256
|
+
// for API compatibility and ignored.
|
|
1257
|
+
void chooseExpensiveSegmentPrice;
|
|
1148
1258
|
return updatedOrderEngineItem;
|
|
1149
1259
|
}
|
|
1150
1260
|
function setIncrementOrderEngineItemQuantity(orderEngineItem, increment) {
|
|
@@ -23,6 +23,7 @@ export * from './internal_operational_roles';
|
|
|
23
23
|
export * from './internal_staffs';
|
|
24
24
|
export * from './inventories';
|
|
25
25
|
export * from './inventory_categories';
|
|
26
|
+
export * from './inventory_entries';
|
|
26
27
|
export * from './inventory_transactions';
|
|
27
28
|
export * from './item_transactions';
|
|
28
29
|
export * from './items';
|
|
@@ -39,6 +39,7 @@ __exportStar(require("./internal_operational_roles"), exports);
|
|
|
39
39
|
__exportStar(require("./internal_staffs"), exports);
|
|
40
40
|
__exportStar(require("./inventories"), exports);
|
|
41
41
|
__exportStar(require("./inventory_categories"), exports);
|
|
42
|
+
__exportStar(require("./inventory_entries"), exports);
|
|
42
43
|
__exportStar(require("./inventory_transactions"), exports);
|
|
43
44
|
__exportStar(require("./item_transactions"), exports);
|
|
44
45
|
__exportStar(require("./items"), exports);
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
export declare const InventoryEntrySchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
3
|
+
timestamps: true;
|
|
4
|
+
versionKey: false;
|
|
5
|
+
minimize: false;
|
|
6
|
+
}, {
|
|
7
|
+
createdAt: NativeDate;
|
|
8
|
+
updatedAt: NativeDate;
|
|
9
|
+
} & {
|
|
10
|
+
_id: import("mongoose").Types.ObjectId;
|
|
11
|
+
createdAt: NativeDate;
|
|
12
|
+
updatedAt: NativeDate;
|
|
13
|
+
items: import("mongoose").Types.DocumentArray<{
|
|
14
|
+
_id: import("mongoose").Types.ObjectId;
|
|
15
|
+
inventory_code: string;
|
|
16
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
17
|
+
transaction_quantity: number;
|
|
18
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
19
|
+
inventory_name: string;
|
|
20
|
+
stock_price?: number | null | undefined;
|
|
21
|
+
preparation?: any;
|
|
22
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
23
|
+
_id: import("mongoose").Types.ObjectId;
|
|
24
|
+
inventory_code: string;
|
|
25
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
26
|
+
transaction_quantity: number;
|
|
27
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
28
|
+
inventory_name: string;
|
|
29
|
+
stock_price?: number | null | undefined;
|
|
30
|
+
preparation?: any;
|
|
31
|
+
}> & {
|
|
32
|
+
_id: import("mongoose").Types.ObjectId;
|
|
33
|
+
inventory_code: string;
|
|
34
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
35
|
+
transaction_quantity: number;
|
|
36
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
37
|
+
inventory_name: string;
|
|
38
|
+
stock_price?: number | null | undefined;
|
|
39
|
+
preparation?: any;
|
|
40
|
+
}>;
|
|
41
|
+
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
42
|
+
ref_id: string;
|
|
43
|
+
created_by: {
|
|
44
|
+
_id: string;
|
|
45
|
+
name: string;
|
|
46
|
+
};
|
|
47
|
+
doc_number: string;
|
|
48
|
+
total_items: number;
|
|
49
|
+
transaction_category: import("../../constants").INVENTORY_TRANSACTION_CATEGORY_ENUM;
|
|
50
|
+
total_stock_price: number;
|
|
51
|
+
description?: string | null | undefined;
|
|
52
|
+
department_code?: string | null | undefined;
|
|
53
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
54
|
+
createdAt: NativeDate;
|
|
55
|
+
updatedAt: NativeDate;
|
|
56
|
+
} & {
|
|
57
|
+
_id: import("mongoose").Types.ObjectId;
|
|
58
|
+
createdAt: NativeDate;
|
|
59
|
+
updatedAt: NativeDate;
|
|
60
|
+
items: import("mongoose").Types.DocumentArray<{
|
|
61
|
+
_id: import("mongoose").Types.ObjectId;
|
|
62
|
+
inventory_code: string;
|
|
63
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
64
|
+
transaction_quantity: number;
|
|
65
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
66
|
+
inventory_name: string;
|
|
67
|
+
stock_price?: number | null | undefined;
|
|
68
|
+
preparation?: any;
|
|
69
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
70
|
+
_id: import("mongoose").Types.ObjectId;
|
|
71
|
+
inventory_code: string;
|
|
72
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
73
|
+
transaction_quantity: number;
|
|
74
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
75
|
+
inventory_name: string;
|
|
76
|
+
stock_price?: number | null | undefined;
|
|
77
|
+
preparation?: any;
|
|
78
|
+
}> & {
|
|
79
|
+
_id: import("mongoose").Types.ObjectId;
|
|
80
|
+
inventory_code: string;
|
|
81
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
82
|
+
transaction_quantity: number;
|
|
83
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
84
|
+
inventory_name: string;
|
|
85
|
+
stock_price?: number | null | undefined;
|
|
86
|
+
preparation?: any;
|
|
87
|
+
}>;
|
|
88
|
+
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
89
|
+
ref_id: string;
|
|
90
|
+
created_by: {
|
|
91
|
+
_id: string;
|
|
92
|
+
name: string;
|
|
93
|
+
};
|
|
94
|
+
doc_number: string;
|
|
95
|
+
total_items: number;
|
|
96
|
+
transaction_category: import("../../constants").INVENTORY_TRANSACTION_CATEGORY_ENUM;
|
|
97
|
+
total_stock_price: number;
|
|
98
|
+
description?: string | null | undefined;
|
|
99
|
+
department_code?: string | null | undefined;
|
|
100
|
+
}>> & import("mongoose").FlatRecord<{
|
|
101
|
+
createdAt: NativeDate;
|
|
102
|
+
updatedAt: NativeDate;
|
|
103
|
+
} & {
|
|
104
|
+
_id: import("mongoose").Types.ObjectId;
|
|
105
|
+
createdAt: NativeDate;
|
|
106
|
+
updatedAt: NativeDate;
|
|
107
|
+
items: import("mongoose").Types.DocumentArray<{
|
|
108
|
+
_id: import("mongoose").Types.ObjectId;
|
|
109
|
+
inventory_code: string;
|
|
110
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
111
|
+
transaction_quantity: number;
|
|
112
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
113
|
+
inventory_name: string;
|
|
114
|
+
stock_price?: number | null | undefined;
|
|
115
|
+
preparation?: any;
|
|
116
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
117
|
+
_id: import("mongoose").Types.ObjectId;
|
|
118
|
+
inventory_code: string;
|
|
119
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
120
|
+
transaction_quantity: number;
|
|
121
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
122
|
+
inventory_name: string;
|
|
123
|
+
stock_price?: number | null | undefined;
|
|
124
|
+
preparation?: any;
|
|
125
|
+
}> & {
|
|
126
|
+
_id: import("mongoose").Types.ObjectId;
|
|
127
|
+
inventory_code: string;
|
|
128
|
+
unit: import("../../constants").INVENTORY_ITEM_UNIT_ENUM;
|
|
129
|
+
transaction_quantity: number;
|
|
130
|
+
transaction_type: import("../../constants").INVENTORY_TRANSACTION_TYPE_ENUM;
|
|
131
|
+
inventory_name: string;
|
|
132
|
+
stock_price?: number | null | undefined;
|
|
133
|
+
preparation?: any;
|
|
134
|
+
}>;
|
|
135
|
+
ref_type: import("../../constants").WAREHOUSE_REF_TYPE_ENUM;
|
|
136
|
+
ref_id: string;
|
|
137
|
+
created_by: {
|
|
138
|
+
_id: string;
|
|
139
|
+
name: string;
|
|
140
|
+
};
|
|
141
|
+
doc_number: string;
|
|
142
|
+
total_items: number;
|
|
143
|
+
transaction_category: import("../../constants").INVENTORY_TRANSACTION_CATEGORY_ENUM;
|
|
144
|
+
total_stock_price: number;
|
|
145
|
+
description?: string | null | undefined;
|
|
146
|
+
department_code?: string | null | undefined;
|
|
147
|
+
}> & Required<{
|
|
148
|
+
_id: import("mongoose").Types.ObjectId;
|
|
149
|
+
}> & {
|
|
150
|
+
__v: number;
|
|
151
|
+
}>;
|
|
152
|
+
export declare const INVENTORY_ENTRIES_COLLECTION_NAME = "inventory_entries";
|