@managesome/eposmatic-toolkit 0.2.674 → 0.2.675

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.
@@ -459,8 +459,59 @@ function getReceiptBody({ orderItems, currency_symbol, show_modifiers, display_m
459
459
  return items;
460
460
  }
461
461
  // =========================><=========================
462
+ /**
463
+ * For a SPECIAL / HALF_HALF order item (a deal or half-half pizza), the
464
+ * top-level modifiers hold the real constituent items as options: each
465
+ * `option.ref` is an item `_id` that may live in any category.
466
+ *
467
+ * In partial printing these composite products must not be printed blindly:
468
+ * - an option whose item is not selected in ANY included category is dropped;
469
+ * - a modifier left with no options is dropped;
470
+ * - if every modifier is dropped the whole item is dropped as well.
471
+ *
472
+ * Returns a shallow-cloned item with the trimmed modifiers, or null when
473
+ * nothing survives the filter.
474
+ */
475
+ function getPartiallyIncludedCompositeItem(item, includedItemIds) {
476
+ const trimmedModifiers = [];
477
+ const itemModifiers = item.modifiers ?? [];
478
+ for (let i = 0; i < itemModifiers.length; i++) {
479
+ const modifier = itemModifiers[i];
480
+ // option.ref acts as a real item _id; keep the option only when that item
481
+ // is part of the partial menu in any of its categories.
482
+ const keptOptions = modifier.options.filter((option) => includedItemIds.has(option.ref));
483
+ if (keptOptions.length === 0)
484
+ continue;
485
+ trimmedModifiers.push({
486
+ ...modifier,
487
+ options: keptOptions,
488
+ });
489
+ }
490
+ if (trimmedModifiers.length === 0)
491
+ return null;
492
+ return {
493
+ ...item,
494
+ modifiers: trimmedModifiers,
495
+ };
496
+ }
462
497
  const getPartialItems = (categories = [], included_categories_map, filterEmpty) => {
463
498
  const partialCategories = [];
499
+ // Union of every included item id across all categories. Built lazily and
500
+ // only when a composite item (deal / half-half) actually needs it, so plain
501
+ // orders don't pay for it.
502
+ let allIncludedItemIds = null;
503
+ const getAllIncludedItemIds = () => {
504
+ if (allIncludedItemIds == null) {
505
+ allIncludedItemIds = new Set();
506
+ for (const categoryId in included_categories_map) {
507
+ const includedItems = included_categories_map[categoryId].includedItemsMap;
508
+ for (const itemId in includedItems) {
509
+ allIncludedItemIds.add(itemId);
510
+ }
511
+ }
512
+ }
513
+ return allIncludedItemIds;
514
+ };
464
515
  for (let i = 0; i < categories.length; i++) {
465
516
  const category = categories[i];
466
517
  const includedCategory = included_categories_map[category.category_id];
@@ -470,8 +521,20 @@ const getPartialItems = (categories = [], included_categories_map, filterEmpty)
470
521
  for (let j = 0; j < category.items.length; j++) {
471
522
  const item = category.items[j];
472
523
  const includedItem = includedCategory.includedItemsMap[item.item_id];
524
+ // A composite item (deal / half-half) is still gated by its own item_id
525
+ // exactly like any other item; only once included do we trim its parts.
473
526
  if (!includedItem)
474
527
  continue;
528
+ if ([constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL, constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF].includes(item.item_type)) {
529
+ const partialItem = getPartiallyIncludedCompositeItem(item, getAllIncludedItemIds());
530
+ if (partialItem == null)
531
+ continue;
532
+ partialItems.push({
533
+ sortId: includedItem.sortId,
534
+ item: partialItem,
535
+ });
536
+ continue;
537
+ }
475
538
  partialItems.push({
476
539
  sortId: includedItem.sortId,
477
540
  item,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.674",
3
+ "version": "0.2.675",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",