@managesome/eposmatic-toolkit 0.3.8 → 0.3.10
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/esm/constants/ANALYTICS.js +146 -0
- package/esm/constants/API_ERRORS.js +6 -0
- package/esm/constants/COMMON.js +369 -0
- package/esm/constants/DELIVERY.js +45 -0
- package/esm/constants/DIALER_ENUMS.js +11 -0
- package/esm/constants/ENUMS.js +1988 -0
- package/esm/constants/FBR_ENUMS.js +18 -0
- package/esm/constants/HUBRISE_ENUMS.js +179 -0
- package/esm/constants/INTERNAL_ENUMS.js +49 -0
- package/esm/constants/NOTIFICATIONS.js +6 -0
- package/esm/constants/ORDER.js +251 -0
- package/esm/constants/PRA_ENUMS.js +18 -0
- package/esm/constants/REPORT_WEBVIEW.js +28 -0
- package/esm/constants/RFQ_GO.js +83 -0
- package/esm/constants/SMARTPAY_ENUMS.js +55 -0
- package/esm/constants/SOCKET.js +149 -0
- package/esm/constants/SRB_ENUMS.js +13 -0
- package/esm/constants/SWITCHPAY.js +28 -0
- package/esm/constants/TENANT_ENUMS.js +90 -0
- package/esm/constants/TENANT_PURCHASE_ORDER.js +91 -0
- package/esm/constants/WALLET.js +51 -0
- package/esm/constants/WAREHOUSE_ANALYTICS.js +28 -0
- package/esm/constants/WAREHOUSE_ENUMS.js +420 -0
- package/esm/constants/WAREHOUSE_PURCHASE_ORDER.js +97 -0
- package/esm/constants/WEBVIEW.js +43 -0
- package/esm/constants/WORKER_ENDPOINTS.js +79 -0
- package/esm/constants/index.js +27 -0
- package/esm/constants/types.js +2 -0
- package/esm/helpers/fbr/generate-invoice.js +94 -0
- package/esm/helpers/fbr/index.js +1 -0
- package/esm/helpers/hubrise/hubrise-catalog.js +304 -0
- package/esm/helpers/hubrise/index.js +1 -0
- package/esm/helpers/index.js +9 -0
- package/esm/helpers/kpra/generate-invoice.js +26 -0
- package/esm/helpers/kpra/index.js +1 -0
- package/esm/helpers/order/generate-order.js +508 -0
- package/esm/helpers/order/generate-warehouse-internal-movement.js +71 -0
- package/esm/helpers/order/generate-warehouse-purchase-order-rfq.js +176 -0
- package/esm/helpers/order/generate-warehouse-purchase-order.js +187 -0
- package/esm/helpers/order/generate-warehouse-sale-order-rfq.js +176 -0
- package/esm/helpers/order/generate-warehouse-sale-order.js +149 -0
- package/esm/helpers/order/index.js +6 -0
- package/esm/helpers/pra/generate-invoice.js +94 -0
- package/esm/helpers/pra/index.js +1 -0
- package/esm/helpers/srb/generate-invoice.js +68 -0
- package/esm/helpers/srb/index.js +1 -0
- package/esm/helpers/store/all-orders-actions.js +17 -0
- package/esm/helpers/store/all-tenant-purchase-orders-actions.js +45 -0
- package/esm/helpers/store/all-warehouse-purchase-order-rfqs-actions.js +66 -0
- package/esm/helpers/store/all-warehouse-purchase-order-vendor-return-actions.js +50 -0
- package/esm/helpers/store/all-warehouse-purchase-orders-actions.js +49 -0
- package/esm/helpers/store/all-warehouse-sale-order-invoices-actions.js +132 -0
- package/esm/helpers/store/all-warehouse-sale-order-rfqs-actions.js +66 -0
- package/esm/helpers/store/all-warehouse-sale-orders-actions.js +72 -0
- package/esm/helpers/store/cart-actions.js +3563 -0
- package/esm/helpers/store/catalog-actions.js +379 -0
- package/esm/helpers/store/common-order-actions.js +937 -0
- package/esm/helpers/store/common-tenant-purchase-order-actions.js +440 -0
- package/esm/helpers/store/common-warehouse-internal-movement-actions.js +95 -0
- package/esm/helpers/store/common-warehouse-purchase-order-actions.js +530 -0
- package/esm/helpers/store/common-warehouse-purchase-order-receipt-actions.js +33 -0
- package/esm/helpers/store/common-warehouse-purchase-order-rfq-actions.js +523 -0
- package/esm/helpers/store/common-warehouse-purchase-order-vendor-return-actions.js +25 -0
- package/esm/helpers/store/common-warehouse-sale-order-actions.js +483 -0
- package/esm/helpers/store/common-warehouse-sale-order-invoice-actions.js +54 -0
- package/esm/helpers/store/common-warehouse-sale-order-rfq-actions.js +523 -0
- package/esm/helpers/store/index.js +26 -0
- package/esm/helpers/store/offline-ordering.js +251 -0
- package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +379 -0
- package/esm/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +360 -0
- package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +470 -0
- package/esm/helpers/store/warehouse-sale-order-rfq-cart-actions.js +359 -0
- package/esm/helpers/store/warehouse-sale-orders-cart-actions.js +456 -0
- package/esm/helpers/types/api-types.js +1 -0
- package/esm/helpers/types/cart-actions.js +1 -0
- package/esm/helpers/types/cart-helpers.js +1 -0
- package/esm/helpers/types/catalog.js +1 -0
- package/esm/helpers/types/common.js +1 -0
- package/esm/helpers/types/deliverect_menu.js +1 -0
- package/esm/helpers/types/email-templates.js +1 -0
- package/esm/helpers/types/fbr-generate-invoice.js +1 -0
- package/esm/helpers/types/halfhalf.js +1 -0
- package/esm/helpers/types/hubrise_catalog.js +1 -0
- package/esm/helpers/types/hubrise_customers.js +1 -0
- package/esm/helpers/types/hubrise_deliveries.js +1 -0
- package/esm/helpers/types/hubrise_location.js +1 -0
- package/esm/helpers/types/hubrise_orders.js +1 -0
- package/esm/helpers/types/index.js +33 -0
- package/esm/helpers/types/internal-leads.js +1 -0
- package/esm/helpers/types/inventory-catalog.js +1 -0
- package/esm/helpers/types/kpra-generate-invoice.js +1 -0
- package/esm/helpers/types/marketing.js +1 -0
- package/esm/helpers/types/order-engine.js +1 -0
- package/esm/helpers/types/pra-generate-invoice.js +1 -0
- package/esm/helpers/types/report-webview.js +1 -0
- package/esm/helpers/types/reports.js +1 -0
- package/esm/helpers/types/smartpay-apis.js +2 -0
- package/esm/helpers/types/specials.js +1 -0
- package/esm/helpers/types/split_bill.js +1 -0
- package/esm/helpers/types/srb-generate-invoice.js +1 -0
- package/esm/helpers/types/switchpay.js +1 -0
- package/esm/helpers/types/tenant-purchase-order-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-catalog.js +1 -0
- package/esm/helpers/types/warehouse-purchase-order-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-purchase-order-rfq-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-sale-order-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-sale-order-rfq-cart-actions.js +1 -0
- package/esm/helpers/types/workers.js +1 -0
- package/esm/helpers/utils/asaanbill-identifier-helpers.js +31 -0
- package/esm/helpers/utils/business-day-helpers.js +201 -0
- package/esm/helpers/utils/cart-helpers.js +156 -0
- package/esm/helpers/utils/catalog-conversion.js +129 -0
- package/esm/helpers/utils/code-redemption-helpers.js +452 -0
- package/esm/helpers/utils/color-helpers.js +31 -0
- package/esm/helpers/utils/common.js +368 -0
- package/esm/helpers/utils/crypt.js +40 -0
- package/esm/helpers/utils/customers-helpers.js +15 -0
- package/esm/helpers/utils/delivery-area-helpers.js +42 -0
- package/esm/helpers/utils/delivery-helpers.js +87 -0
- package/esm/helpers/utils/denominations-helpers.js +53 -0
- package/esm/helpers/utils/dinein.js +39 -0
- package/esm/helpers/utils/discount-helpers.js +55 -0
- package/esm/helpers/utils/email-helpers.js +111 -0
- package/esm/helpers/utils/error-helpers.js +14 -0
- package/esm/helpers/utils/expense.js +26 -0
- package/esm/helpers/utils/getFormFieldsDiff.js +15 -0
- package/esm/helpers/utils/gift-card-helpers.js +258 -0
- package/esm/helpers/utils/halfhalf-setup-helpers.js +779 -0
- package/esm/helpers/utils/hourly-comparison-report-helpers.js +851 -0
- package/esm/helpers/utils/hr-helpers.js +62 -0
- package/esm/helpers/utils/hubrise-utils.js +32 -0
- package/esm/helpers/utils/image-helpers.js +95 -0
- package/esm/helpers/utils/image-url-helpers.js +96 -0
- package/esm/helpers/utils/index.js +96 -0
- package/esm/helpers/utils/ingredients.js +26 -0
- package/esm/helpers/utils/internal-amount-helpers.js +49 -0
- package/esm/helpers/utils/inventory.js +123 -0
- package/esm/helpers/utils/inventory_entries.js +91 -0
- package/esm/helpers/utils/inventory_transactions.js +91 -0
- package/esm/helpers/utils/item-report-helpers.js +2603 -0
- package/esm/helpers/utils/items-comparison-report-helpers.js +1057 -0
- package/esm/helpers/utils/kds-helpers.js +43 -0
- package/esm/helpers/utils/location-helpers.js +13 -0
- package/esm/helpers/utils/menu-helpers.js +44 -0
- package/esm/helpers/utils/minified-catalog.js +428 -0
- package/esm/helpers/utils/offer-apply-helpers.js +613 -0
- package/esm/helpers/utils/offers-helpers.js +3351 -0
- package/esm/helpers/utils/operational-roles-helpers.js +33 -0
- package/esm/helpers/utils/order-engine.js +1409 -0
- package/esm/helpers/utils/order-history.js +208 -0
- package/esm/helpers/utils/payment-comparison-report-helpers.js +873 -0
- package/esm/helpers/utils/payment-helpers.js +302 -0
- package/esm/helpers/utils/pdf-generator.js +110 -0
- package/esm/helpers/utils/platform-catalog.js +306 -0
- package/esm/helpers/utils/platform-num.js +188 -0
- package/esm/helpers/utils/platform-specific-tenant-shifts.js +19 -0
- package/esm/helpers/utils/price-conversion.js +24 -0
- package/esm/helpers/utils/printer-helpers.js +319 -0
- package/esm/helpers/utils/public-holidays-helpers.js +8 -0
- package/esm/helpers/utils/ratings-comparison-report-helpers.js +1187 -0
- package/esm/helpers/utils/receipt-engine.js +1050 -0
- package/esm/helpers/utils/review-helpers.js +391 -0
- package/esm/helpers/utils/rider-tracking.js +12 -0
- package/esm/helpers/utils/riders-report-helpers.js +1590 -0
- package/esm/helpers/utils/sales-comparison-report-helpers.js +1259 -0
- package/esm/helpers/utils/sales-comparitive-report-helpers.js +939 -0
- package/esm/helpers/utils/sales-overview-report-helpers.js +1046 -0
- package/esm/helpers/utils/sales-summary-report-helpers.js +877 -0
- package/esm/helpers/utils/scan-code-helpers.js +31 -0
- package/esm/helpers/utils/selection-model.js +68 -0
- package/esm/helpers/utils/shift-window-helpers.js +148 -0
- package/esm/helpers/utils/simplified-catalog.js +107 -0
- package/esm/helpers/utils/simplified-halfhalf.js +101 -0
- package/esm/helpers/utils/simplified-specials.js +107 -0
- package/esm/helpers/utils/simplified-tenant.js +411 -0
- package/esm/helpers/utils/specials-helpers.js +727 -0
- package/esm/helpers/utils/tenant-calendar-helpers.js +67 -0
- package/esm/helpers/utils/tenant-cash-drawer-sessions-helpers.js +248 -0
- package/esm/helpers/utils/tenant-cash-drawers-helpers.js +31 -0
- package/esm/helpers/utils/tenant-cash-in-out-helpers.js +47 -0
- package/esm/helpers/utils/tenant-day-sessions-helpers.js +167 -0
- package/esm/helpers/utils/tenant-instore-shift-sessions-helpers.js +227 -0
- package/esm/helpers/utils/tenant-staff-helpers.js +19 -0
- package/esm/helpers/utils/tenant_cash_in_hand_transactions.js +31 -0
- package/esm/helpers/utils/time-helpers.js +142 -0
- package/esm/helpers/utils/void-items-report-helpers.js +529 -0
- package/esm/helpers/utils/void-order-items-helpers.js +32 -0
- package/esm/helpers/utils/voidations-summary-report-helpers.js +800 -0
- package/esm/helpers/utils/wallet-helpers.js +22 -0
- package/esm/helpers/utils/wallet-redemption-helpers.js +46 -0
- package/esm/helpers/utils/warehouse-catalog-conversion.js +117 -0
- package/esm/helpers/utils/warehouse-inventory.js +59 -0
- package/esm/helpers/utils/warehouse-purchase-order-engine.js +27 -0
- package/esm/helpers/utils/warehouse-purchase-order-receipt-engine.js +205 -0
- package/esm/helpers/utils/warehouse-purchase-order-x-report-helpers.js +1432 -0
- package/esm/helpers/utils/warehouse-sale-order-engine.js +27 -0
- package/esm/helpers/utils/warehouse-sale-order-receipt-engine.js +207 -0
- package/esm/helpers/utils/warehouse-sale-order-x-report-helpers.js +1 -0
- package/esm/helpers/utils/warehouse-sale-x-report-helpers.js +1434 -0
- package/esm/helpers/utils/warehouse-settings-helpers.js +37 -0
- package/esm/helpers/utils/warehouse-void-purchase-order-items-helpers.js +34 -0
- package/esm/helpers/utils/warehouse-void-purchase-order-items-report-helpers.js +18 -0
- package/esm/helpers/utils/warehouse-void-sale-order-items-helpers.js +34 -0
- package/esm/helpers/utils/warehouse-void-sale-order-items-report-helpers.js +18 -0
- package/esm/helpers/utils/warehouse_inventory_transactions.js +91 -0
- package/esm/helpers/utils/x-report-helpers.js +1850 -0
- package/esm/index.js +3 -0
- package/esm/schemas/index.js +2 -0
- package/esm/schemas/models/app_configs.js +36 -0
- package/esm/schemas/models/applied_order_discounts.js +103 -0
- package/esm/schemas/models/brands.js +56 -0
- package/esm/schemas/models/categories.js +74 -0
- package/esm/schemas/models/close_dates.js +63 -0
- package/esm/schemas/models/common-models.js +449 -0
- package/esm/schemas/models/courses.js +62 -0
- package/esm/schemas/models/customer_redemptions.js +82 -0
- package/esm/schemas/models/customers.js +269 -0
- package/esm/schemas/models/deliveries.js +137 -0
- package/esm/schemas/models/delivery_areas.js +97 -0
- package/esm/schemas/models/dinein_floors.js +55 -0
- package/esm/schemas/models/dinein_tables.js +97 -0
- package/esm/schemas/models/dinein_tables_fingerprints.js +96 -0
- package/esm/schemas/models/discounts.js +87 -0
- package/esm/schemas/models/expense_categories.js +61 -0
- package/esm/schemas/models/expense_details.js +130 -0
- package/esm/schemas/models/gift_cards.js +342 -0
- package/esm/schemas/models/halfhalf_setup.js +142 -0
- package/esm/schemas/models/index.js +111 -0
- package/esm/schemas/models/internal_customers.js +139 -0
- package/esm/schemas/models/internal_invoices.js +119 -0
- package/esm/schemas/models/internal_leads.js +78 -0
- package/esm/schemas/models/internal_operational_roles.js +85 -0
- package/esm/schemas/models/internal_staffs.js +65 -0
- package/esm/schemas/models/inventories.js +103 -0
- package/esm/schemas/models/inventory_categories.js +52 -0
- package/esm/schemas/models/inventory_transactions.js +143 -0
- package/esm/schemas/models/item_transactions.js +117 -0
- package/esm/schemas/models/items.js +341 -0
- package/esm/schemas/models/marketing_fingerprints.js +92 -0
- package/esm/schemas/models/menus.js +66 -0
- package/esm/schemas/models/messaging_devices.js +99 -0
- package/esm/schemas/models/modifier_extras.js +120 -0
- package/esm/schemas/models/offers.js +470 -0
- package/esm/schemas/models/offers_fingerprints.js +61 -0
- package/esm/schemas/models/operational_roles.js +155 -0
- package/esm/schemas/models/orders.js +1051 -0
- package/esm/schemas/models/printer_settings.js +245 -0
- package/esm/schemas/models/public_holidays.js +58 -0
- package/esm/schemas/models/reservations.js +127 -0
- package/esm/schemas/models/reviews.js +145 -0
- package/esm/schemas/models/rewards_usage.js +61 -0
- package/esm/schemas/models/riders.js +75 -0
- package/esm/schemas/models/specials.js +169 -0
- package/esm/schemas/models/staff_shifts.js +66 -0
- package/esm/schemas/models/tenant-activity-logs.js +126 -0
- package/esm/schemas/models/tenant_active_jobs.js +77 -0
- package/esm/schemas/models/tenant_calendar.js +89 -0
- package/esm/schemas/models/tenant_cash_drawer_sessions.js +208 -0
- package/esm/schemas/models/tenant_cash_drawers.js +60 -0
- package/esm/schemas/models/tenant_cash_in_hand_transactions.js +69 -0
- package/esm/schemas/models/tenant_cash_in_out.js +104 -0
- package/esm/schemas/models/tenant_clients.js +66 -0
- package/esm/schemas/models/tenant_day_sessions.js +166 -0
- package/esm/schemas/models/tenant_hr_attendance_records.js +87 -0
- package/esm/schemas/models/tenant_hr_biometric_enrollments.js +69 -0
- package/esm/schemas/models/tenant_hr_departments.js +42 -0
- package/esm/schemas/models/tenant_hr_documents.js +71 -0
- package/esm/schemas/models/tenant_hr_employees.js +172 -0
- package/esm/schemas/models/tenant_hr_leave_requests.js +80 -0
- package/esm/schemas/models/tenant_hr_payrolls.js +131 -0
- package/esm/schemas/models/tenant_hr_performance_reviews.js +58 -0
- package/esm/schemas/models/tenant_hr_policies.js +57 -0
- package/esm/schemas/models/tenant_hr_positions.js +48 -0
- package/esm/schemas/models/tenant_hr_shift_schedules.js +84 -0
- package/esm/schemas/models/tenant_hr_shifts.js +64 -0
- package/esm/schemas/models/tenant_instore_shift_sessions.js +204 -0
- package/esm/schemas/models/tenant_instore_shifts.js +63 -0
- package/esm/schemas/models/tenant_inventory_department_transactions.js +116 -0
- package/esm/schemas/models/tenant_inventory_department_utilities.js +85 -0
- package/esm/schemas/models/tenant_inventory_departments.js +55 -0
- package/esm/schemas/models/tenant_inventory_entries.js +131 -0
- package/esm/schemas/models/tenant_metadata.js +88 -0
- package/esm/schemas/models/tenant_order_item_instructions.js +66 -0
- package/esm/schemas/models/tenant_purchase_order_vendor_returns.js +80 -0
- package/esm/schemas/models/tenant_purchase_orders.js +158 -0
- package/esm/schemas/models/tenant_shifts.js +57 -0
- package/esm/schemas/models/tenant_staffs.js +129 -0
- package/esm/schemas/models/tenant_vendors.js +99 -0
- package/esm/schemas/models/tenants.js +811 -0
- package/esm/schemas/models/terminal_devices.js +63 -0
- package/esm/schemas/models/tokens.js +73 -0
- package/esm/schemas/models/track_order_numbers.js +42 -0
- package/esm/schemas/models/void_order_items.js +210 -0
- package/esm/schemas/models/vouchers.js +101 -0
- package/esm/schemas/models/wallet_transactions.js +128 -0
- package/esm/schemas/models/wallets.js +44 -0
- package/esm/schemas/models/warehouse-activity-logs.js +144 -0
- package/esm/schemas/models/warehouse_categories.js +83 -0
- package/esm/schemas/models/warehouse_clients.js +81 -0
- package/esm/schemas/models/warehouse_communications.js +226 -0
- package/esm/schemas/models/warehouse_internal_movements.js +463 -0
- package/esm/schemas/models/warehouse_inventory_entries.js +125 -0
- package/esm/schemas/models/warehouse_inventory_lot_serial_numbers.js +188 -0
- package/esm/schemas/models/warehouse_inventory_transactions.js +133 -0
- package/esm/schemas/models/warehouse_item_transactions.js +97 -0
- package/esm/schemas/models/warehouse_items.js +173 -0
- package/esm/schemas/models/warehouse_operational_roles.js +87 -0
- package/esm/schemas/models/warehouse_purchase_order_receipts.js +163 -0
- package/esm/schemas/models/warehouse_purchase_order_rfqs.js +339 -0
- package/esm/schemas/models/warehouse_purchase_order_vendor_returns.js +199 -0
- package/esm/schemas/models/warehouse_purchase_orders.js +334 -0
- package/esm/schemas/models/warehouse_sale_deliveries.js +155 -0
- package/esm/schemas/models/warehouse_sale_invoices.js +229 -0
- package/esm/schemas/models/warehouse_sale_order_rfqs.js +340 -0
- package/esm/schemas/models/warehouse_sale_orders.js +322 -0
- package/esm/schemas/models/warehouse_staffs.js +104 -0
- package/esm/schemas/models/warehouse_track_order_numbers.js +73 -0
- package/esm/schemas/models/warehouse_vendors.js +99 -0
- package/esm/schemas/models/warehouse_void_purchase_order_items.js +174 -0
- package/esm/schemas/models/warehouse_void_sale_order_items.js +174 -0
- package/esm/schemas/models/warehouses.js +253 -0
- package/esm/schemas/types/app_configs.js +1 -0
- package/esm/schemas/types/applied_order_discounts.js +1 -0
- package/esm/schemas/types/brands.js +1 -0
- package/esm/schemas/types/categories.js +1 -0
- package/esm/schemas/types/close_dates.js +1 -0
- package/esm/schemas/types/common.js +1 -0
- package/esm/schemas/types/courses.js +1 -0
- package/esm/schemas/types/customer_redemptions.js +1 -0
- package/esm/schemas/types/customers.js +1 -0
- package/esm/schemas/types/deliveries.js +1 -0
- package/esm/schemas/types/delivery_areas.js +1 -0
- package/esm/schemas/types/dinein_floors.js +1 -0
- package/esm/schemas/types/dinein_tables.js +1 -0
- package/esm/schemas/types/dinein_tables_fingerprints.js +1 -0
- package/esm/schemas/types/discounts.js +1 -0
- package/esm/schemas/types/expense_categories.js +1 -0
- package/esm/schemas/types/expense_details.js +1 -0
- package/esm/schemas/types/gift_cards.js +1 -0
- package/esm/schemas/types/halfhalf_setup.js +1 -0
- package/esm/schemas/types/index.js +113 -0
- package/esm/schemas/types/internal_customers.js +1 -0
- package/esm/schemas/types/internal_invoices.js +1 -0
- package/esm/schemas/types/internal_leads.js +1 -0
- package/esm/schemas/types/internal_operational_roles.js +16 -0
- package/esm/schemas/types/internal_staffs.js +1 -0
- package/esm/schemas/types/inventories.js +1 -0
- package/esm/schemas/types/inventory_categories.js +1 -0
- package/esm/schemas/types/inventory_department_transactions.js +1 -0
- package/esm/schemas/types/inventory_department_utilities.js +1 -0
- package/esm/schemas/types/inventory_departments.js +1 -0
- package/esm/schemas/types/inventory_transactions.js +1 -0
- package/esm/schemas/types/item_transactions.js +1 -0
- package/esm/schemas/types/items.js +1 -0
- package/esm/schemas/types/marketing_fingerprints.js +1 -0
- package/esm/schemas/types/menus.js +1 -0
- package/esm/schemas/types/messaging_devices.js +1 -0
- package/esm/schemas/types/modifier_extras.js +1 -0
- package/esm/schemas/types/multi_tenants.js +1 -0
- package/esm/schemas/types/offers.js +1 -0
- package/esm/schemas/types/offers_fingerprints.js +1 -0
- package/esm/schemas/types/operational_roles.js +15 -0
- package/esm/schemas/types/orders.js +1 -0
- package/esm/schemas/types/printer_settings.js +1 -0
- package/esm/schemas/types/public_holidays.js +1 -0
- package/esm/schemas/types/reservations.js +1 -0
- package/esm/schemas/types/reviews.js +1 -0
- package/esm/schemas/types/rewards_usage.js +1 -0
- package/esm/schemas/types/riders.js +1 -0
- package/esm/schemas/types/specials.js +1 -0
- package/esm/schemas/types/staff_shifts.js +1 -0
- package/esm/schemas/types/tenant-activity-logs.js +1 -0
- package/esm/schemas/types/tenant_active_jobs.js +1 -0
- package/esm/schemas/types/tenant_calendar.js +1 -0
- package/esm/schemas/types/tenant_cash_drawer_sessions.js +1 -0
- package/esm/schemas/types/tenant_cash_drawers.js +1 -0
- package/esm/schemas/types/tenant_cash_in_hand_transactions.js +1 -0
- package/esm/schemas/types/tenant_cash_in_out.js +1 -0
- package/esm/schemas/types/tenant_clients.js +1 -0
- package/esm/schemas/types/tenant_day_sessions.js +1 -0
- package/esm/schemas/types/tenant_hr_attendance_records.js +1 -0
- package/esm/schemas/types/tenant_hr_biometric_enrollments.js +1 -0
- package/esm/schemas/types/tenant_hr_departments.js +1 -0
- package/esm/schemas/types/tenant_hr_documents.js +1 -0
- package/esm/schemas/types/tenant_hr_employees.js +1 -0
- package/esm/schemas/types/tenant_hr_leave_requests.js +1 -0
- package/esm/schemas/types/tenant_hr_payrolls.js +1 -0
- package/esm/schemas/types/tenant_hr_performance_reviews.js +1 -0
- package/esm/schemas/types/tenant_hr_policies.js +1 -0
- package/esm/schemas/types/tenant_hr_positions.js +1 -0
- package/esm/schemas/types/tenant_hr_shift_schedules.js +1 -0
- package/esm/schemas/types/tenant_hr_shifts.js +1 -0
- package/esm/schemas/types/tenant_instore_shift_sessions.js +1 -0
- package/esm/schemas/types/tenant_instore_shifts.js +1 -0
- package/esm/schemas/types/tenant_inventory_entries.js +1 -0
- package/esm/schemas/types/tenant_metadata.js +1 -0
- package/esm/schemas/types/tenant_order_item_instructions.js +1 -0
- package/esm/schemas/types/tenant_purchase_order_vendor_returns.js +1 -0
- package/esm/schemas/types/tenant_purchase_orders.js +1 -0
- package/esm/schemas/types/tenant_shifts.js +1 -0
- package/esm/schemas/types/tenant_staffs.js +1 -0
- package/esm/schemas/types/tenant_vendors.js +1 -0
- package/esm/schemas/types/tenants.js +1 -0
- package/esm/schemas/types/terminal_devices.js +1 -0
- package/esm/schemas/types/tokens.js +1 -0
- package/esm/schemas/types/track_order_numbers.js +1 -0
- package/esm/schemas/types/void_order_items.js +1 -0
- package/esm/schemas/types/vouchers.js +1 -0
- package/esm/schemas/types/wallet_transactions.js +1 -0
- package/esm/schemas/types/wallets.js +1 -0
- package/esm/schemas/types/warehouse-activity-logs.js +1 -0
- package/esm/schemas/types/warehouse_categories.js +1 -0
- package/esm/schemas/types/warehouse_clients.js +1 -0
- package/esm/schemas/types/warehouse_communications.js +1 -0
- package/esm/schemas/types/warehouse_internal_movements.js +1 -0
- package/esm/schemas/types/warehouse_inventory_entries.js +1 -0
- package/esm/schemas/types/warehouse_inventory_lot_serial_numbers.js +1 -0
- package/esm/schemas/types/warehouse_inventory_transactions.js +1 -0
- package/esm/schemas/types/warehouse_item_transactions.js +1 -0
- package/esm/schemas/types/warehouse_items.js +1 -0
- package/esm/schemas/types/warehouse_operational_roles.js +15 -0
- package/esm/schemas/types/warehouse_purchase_order_receipts.js +18 -0
- package/esm/schemas/types/warehouse_purchase_order_rfqs.js +1 -0
- package/esm/schemas/types/warehouse_purchase_order_vendor_returns.js +1 -0
- package/esm/schemas/types/warehouse_purchase_orders.js +1 -0
- package/esm/schemas/types/warehouse_sale_deliveries.js +1 -0
- package/esm/schemas/types/warehouse_sale_invoices.js +1 -0
- package/esm/schemas/types/warehouse_sale_order_rfqs.js +1 -0
- package/esm/schemas/types/warehouse_sale_orders.js +1 -0
- package/esm/schemas/types/warehouse_staffs.js +1 -0
- package/esm/schemas/types/warehouse_track_order_numbers.js +1 -0
- package/esm/schemas/types/warehouse_vendors.js +1 -0
- package/esm/schemas/types/warehouse_void_purchase_order_items.js +1 -0
- package/esm/schemas/types/warehouse_void_sale_order_items.js +1 -0
- package/esm/schemas/types/warehouses.js +1 -0
- package/lib/helpers/types/api-types.d.ts +37 -0
- package/package.json +6 -3
|
@@ -0,0 +1,727 @@
|
|
|
1
|
+
import ObjectID from 'bson-objectid';
|
|
2
|
+
import { isEqual } from 'lodash';
|
|
3
|
+
import { MODIFIER_OPTION_REF_TYPE_ENUM, ORDER_ITEM_TYPE_ENUM } from '../../constants';
|
|
4
|
+
import { calculateItemTotalWithTax, getComparableOrderItem } from '../store';
|
|
5
|
+
import { convertHalfHalfToItem } from './halfhalf-setup-helpers';
|
|
6
|
+
import { convertItemDiscountToOrderItemDiscount } from './order-engine';
|
|
7
|
+
import { convertItemToWorkableItem, findApplicableSchedule, getExcludedPlatformsFromIncludedPlatforms, getPriceEnum, } from './platform-catalog';
|
|
8
|
+
import { convertPriceObjFromCents, convertPriceObjToCents, convertSpecialHoursFromCents, convertSpecialHoursToCents, mergePriceObjs, } from './platform-num';
|
|
9
|
+
import { convertPriceFromCents, convertPriceToCents } from './price-conversion';
|
|
10
|
+
import { buildSelectionRefQueues, buildStoredFromSelection, consumeSelectionMatch, } from './selection-model';
|
|
11
|
+
export function getSpecialsPostedData(data, payload) {
|
|
12
|
+
return data.some((special) => special._id === payload._id)
|
|
13
|
+
? data
|
|
14
|
+
: data.concat(getSpecialWithPrice(payload)).sort((a, b) => a.sort_id - b.sort_id);
|
|
15
|
+
}
|
|
16
|
+
export function renderBulkSpecialsUpdate(data, payload) {
|
|
17
|
+
return data
|
|
18
|
+
.map((special) => {
|
|
19
|
+
const updatedSpecial = payload.find((c) => c._id === special._id);
|
|
20
|
+
return updatedSpecial
|
|
21
|
+
? { ...special, ...(updatedSpecial != null ? getSpecialWithPrice(updatedSpecial) : {}) }
|
|
22
|
+
: special;
|
|
23
|
+
})
|
|
24
|
+
.sort((a, b) => a.sort_id - b.sort_id);
|
|
25
|
+
}
|
|
26
|
+
export function getSpecialsUpdatedData(data, payload) {
|
|
27
|
+
return data
|
|
28
|
+
.map((special) => special._id === payload._id
|
|
29
|
+
? {
|
|
30
|
+
...special,
|
|
31
|
+
...getSpecialWithPrice(payload),
|
|
32
|
+
}
|
|
33
|
+
: special)
|
|
34
|
+
.sort((a, b) => a.sort_id - b.sort_id);
|
|
35
|
+
}
|
|
36
|
+
export function getSpecialsDeletedData(data, payload) {
|
|
37
|
+
return data.filter((special) => special._id !== payload).sort((a, b) => a.sort_id - b.sort_id);
|
|
38
|
+
}
|
|
39
|
+
// ====================================================================================================
|
|
40
|
+
export function getSpecialWithPrice(special, writeable) {
|
|
41
|
+
const convertToPrice = writeable ? convertPriceObjToCents : convertPriceObjFromCents;
|
|
42
|
+
const convertItemSpecialHours = writeable ? convertSpecialHoursToCents : convertSpecialHoursFromCents;
|
|
43
|
+
const convertNumPrice = writeable ? convertPriceToCents : convertPriceFromCents;
|
|
44
|
+
return {
|
|
45
|
+
...special,
|
|
46
|
+
...(special.price != null ? { price: convertToPrice(special.price) } : {}),
|
|
47
|
+
...(special.discount_amount != null ? { discount_amount: convertToPrice(special.discount_amount) } : {}),
|
|
48
|
+
...(special.display_price != null ? { display_price: convertNumPrice(special.display_price) } : {}),
|
|
49
|
+
...(special.item_special_hours != null
|
|
50
|
+
? {
|
|
51
|
+
item_special_hours: convertItemSpecialHours(special.item_special_hours),
|
|
52
|
+
}
|
|
53
|
+
: {}),
|
|
54
|
+
...(special.modifier_specials != null
|
|
55
|
+
? {
|
|
56
|
+
modifier_specials: special.modifier_specials.map((modifierSpecial) => ({
|
|
57
|
+
...modifierSpecial,
|
|
58
|
+
items: modifierSpecial.items.map((item) => ({
|
|
59
|
+
...item,
|
|
60
|
+
...(item.upsell_price != null ? { upsell_price: convertToPrice(item.upsell_price) } : {}),
|
|
61
|
+
})),
|
|
62
|
+
})),
|
|
63
|
+
}
|
|
64
|
+
: {}),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Applies a modifier-special group's reference rules to a constituent item's
|
|
69
|
+
* own modifiers:
|
|
70
|
+
* - excluded_refs: modifiers/options whose ref is listed are REMOVED.
|
|
71
|
+
* - exclusive_refs: modifiers/options whose ref is listed have their PRICE
|
|
72
|
+
* REMOVED (set to null → treated as free) but stay selectable.
|
|
73
|
+
*
|
|
74
|
+
* Returns null when nothing is left after exclusion.
|
|
75
|
+
*/
|
|
76
|
+
export function applyModifierSpecialRefRules(modifiers, exclusiveRefs, excludedRefs) {
|
|
77
|
+
if (!modifiers || modifiers.length === 0)
|
|
78
|
+
return null;
|
|
79
|
+
let result = modifiers.map((modifier) => {
|
|
80
|
+
const isModifierExclusive = exclusiveRefs.includes(modifier.ref);
|
|
81
|
+
const options = modifier.options.map((option) => {
|
|
82
|
+
// Recurse: modifiers -> options -> modifiers -> options ...
|
|
83
|
+
// (option-level modifiers carry their own nested modifier/option tree
|
|
84
|
+
// that must honor the same ref rules — e.g. half-half: segment -> item
|
|
85
|
+
// -> "Pizza Size" -> "Large 13" -> "Drinks".)
|
|
86
|
+
const nestedModifiers = applyModifierSpecialRefRules(option.modifiers, exclusiveRefs, excludedRefs);
|
|
87
|
+
const updatedOption = { ...option, modifiers: nestedModifiers };
|
|
88
|
+
if (isModifierExclusive || exclusiveRefs.includes(option.ref)) {
|
|
89
|
+
return { ...updatedOption, price: null };
|
|
90
|
+
}
|
|
91
|
+
return updatedOption;
|
|
92
|
+
});
|
|
93
|
+
return { ...modifier, options };
|
|
94
|
+
});
|
|
95
|
+
if (excludedRefs.length > 0) {
|
|
96
|
+
result = result
|
|
97
|
+
.filter((modifier) => !excludedRefs.includes(modifier.ref))
|
|
98
|
+
.map((modifier) => ({
|
|
99
|
+
...modifier,
|
|
100
|
+
options: modifier.options.filter((option) => !excludedRefs.includes(option.ref)),
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
const withOptions = result.filter((modifier) => modifier.options.length > 0);
|
|
104
|
+
return withOptions.length > 0 ? withOptions : null;
|
|
105
|
+
}
|
|
106
|
+
export function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_id, halfhalfSetups) {
|
|
107
|
+
if (!platform || !tenant_id)
|
|
108
|
+
return [];
|
|
109
|
+
const isSimple = typeof itemsMap[Object.keys(itemsMap)[0]]?.sold_out === 'boolean';
|
|
110
|
+
const workableSpecials = [...specials];
|
|
111
|
+
workableSpecials.sort((a, b) => a.sort_id - b.sort_id);
|
|
112
|
+
const specialsMenu = [];
|
|
113
|
+
for (let i = 0; i < workableSpecials.length; i++) {
|
|
114
|
+
const special = specials[i];
|
|
115
|
+
if (!special.active || !special.tenants.includes(tenant_id) || !special.included_platforms.includes(platform)) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const applicableSchedule = findApplicableSchedule(special.item_special_hours, platform);
|
|
119
|
+
// if there is no applicable schedule, we skip the special
|
|
120
|
+
if (applicableSchedule === false)
|
|
121
|
+
continue;
|
|
122
|
+
// we get the price of the special
|
|
123
|
+
let price = special.price;
|
|
124
|
+
if (applicableSchedule !== true && applicableSchedule.price) {
|
|
125
|
+
// if there is an applicable schedule, we use the price from the schedule
|
|
126
|
+
price = applicableSchedule.price;
|
|
127
|
+
}
|
|
128
|
+
// we get the discount_amount of the special
|
|
129
|
+
let discount_amount = special.discount_amount;
|
|
130
|
+
let is_discount_percentage = special.is_discount_percentage;
|
|
131
|
+
if (applicableSchedule !== true && applicableSchedule.discount_amount) {
|
|
132
|
+
// if there is an applicable schedule, we use the discount_amount from the schedule
|
|
133
|
+
discount_amount = applicableSchedule.discount_amount;
|
|
134
|
+
// the schedule also carries the percentage flag (same as IItem)
|
|
135
|
+
is_discount_percentage = applicableSchedule.is_discount_percentage;
|
|
136
|
+
}
|
|
137
|
+
const modifierSpecials = [];
|
|
138
|
+
let hasEmptyGroup = false;
|
|
139
|
+
for (let j = 0; j < special.modifier_specials.length; j++) {
|
|
140
|
+
const modifierSpecial = special.modifier_specials[j];
|
|
141
|
+
const omitItemLevelSchedule = modifierSpecial.omit_items_schedule;
|
|
142
|
+
const modifierSpecialItems = [...modifierSpecial.items];
|
|
143
|
+
modifierSpecialItems.sort((a, b) => a.sort_id - b.sort_id);
|
|
144
|
+
const items = [];
|
|
145
|
+
// A modifier group can list half-half setups instead of catalog items;
|
|
146
|
+
// they are rendered/selected through the classic preview separately, but
|
|
147
|
+
// they keep the group non-empty so the special stays selectable.
|
|
148
|
+
let hasHalfHalfRef = false;
|
|
149
|
+
// Items that exist for this platform but are outside their own schedule
|
|
150
|
+
// right now (only possible with `omit_items_schedule === false`). Item
|
|
151
|
+
// schedules filter the SELECTABLE options — they must not invalidate the
|
|
152
|
+
// special at menu level; the special's own schedule is that gate.
|
|
153
|
+
let hasScheduledOutItem = false;
|
|
154
|
+
for (let k = 0; k < modifierSpecialItems.length; k++) {
|
|
155
|
+
const item = modifierSpecial.items[k];
|
|
156
|
+
const catalogItem = itemsMap[item.item_id];
|
|
157
|
+
if (!catalogItem) {
|
|
158
|
+
if (halfhalfSetups != null && halfhalfSetups[item.item_id] != null) {
|
|
159
|
+
hasHalfHalfRef = true;
|
|
160
|
+
}
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
// Constituent items are NOT gated by platform membership (the last
|
|
164
|
+
// `true`): the special's own `included_platforms` is the platform gate,
|
|
165
|
+
// and a deal may legitimately feature items that don't belong to the
|
|
166
|
+
// current platform — they are shown and selectable anyway. Inactive
|
|
167
|
+
// items stay excluded here; when EVERY item of a group is inactive the
|
|
168
|
+
// group resolves empty and blocks the special (see `hasEmptyGroup`).
|
|
169
|
+
const workableItem = convertItemToWorkableItem(catalogItem, platform, tenant_id, omitItemLevelSchedule, true, true);
|
|
170
|
+
if (!workableItem) {
|
|
171
|
+
// The item failed ONLY its own schedule: probe without the schedule
|
|
172
|
+
// check to tell "scheduled out right now" apart from "structurally
|
|
173
|
+
// unavailable" (inactive / tenant filtered).
|
|
174
|
+
if (convertItemToWorkableItem(catalogItem, platform, tenant_id, true, true, true) != null) {
|
|
175
|
+
hasScheduledOutItem = true;
|
|
176
|
+
}
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
workableItem.discount_amount = null;
|
|
180
|
+
if (special.price != null) {
|
|
181
|
+
workableItem.price = null;
|
|
182
|
+
}
|
|
183
|
+
if (item.upsell_price != null) {
|
|
184
|
+
workableItem.price = mergePriceObjs(workableItem.price, item.upsell_price);
|
|
185
|
+
}
|
|
186
|
+
// Apply the group's reference rules to the item's own modifiers:
|
|
187
|
+
// excluded_refs removes modifiers/options, exclusive_refs removes their price.
|
|
188
|
+
workableItem.modifiers = applyModifierSpecialRefRules(workableItem.modifiers, modifierSpecial.exclusive_refs, modifierSpecial.excluded_refs);
|
|
189
|
+
items.push(workableItem);
|
|
190
|
+
}
|
|
191
|
+
// A modifier group with zero resolvable items makes the special invalid
|
|
192
|
+
// (cannot be completed) — unless it only references half-half setups
|
|
193
|
+
// (selectable via the classic preview, kept as a selectable group) or
|
|
194
|
+
// its items are merely outside their own schedule right now. Item
|
|
195
|
+
// schedules filter the selectable options at selection time; menu-level
|
|
196
|
+
// validity is governed by the special's own schedule.
|
|
197
|
+
//
|
|
198
|
+
// With platform membership no longer gating constituent items, a group
|
|
199
|
+
// only ends up here when NONE of its items are usable: they are all
|
|
200
|
+
// INACTIVE (product rule: all-inactive group blocks the deal), missing
|
|
201
|
+
// from the catalog, or belong to another tenant. Out-of-platform items
|
|
202
|
+
// are resolvable and are shown.
|
|
203
|
+
if (items.length === 0 && !hasHalfHalfRef && !hasScheduledOutItem) {
|
|
204
|
+
hasEmptyGroup = true;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
modifierSpecials.push({
|
|
208
|
+
_id: modifierSpecial._id,
|
|
209
|
+
name: modifierSpecial.name,
|
|
210
|
+
quantity: modifierSpecial.quantity,
|
|
211
|
+
num_free_items: modifierSpecial.num_free_items,
|
|
212
|
+
exclusive_refs: modifierSpecial.exclusive_refs,
|
|
213
|
+
excluded_refs: modifierSpecial.excluded_refs,
|
|
214
|
+
items,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// Not selectable if any modifier group is empty (or there are no groups).
|
|
218
|
+
if (hasEmptyGroup || modifierSpecials.length === 0)
|
|
219
|
+
continue;
|
|
220
|
+
const specialMenu = {
|
|
221
|
+
_id: special._id,
|
|
222
|
+
name: special.name,
|
|
223
|
+
description: special.description,
|
|
224
|
+
sold_out: isSimple ? special.sold_out.includes(tenant_id) : special.sold_out,
|
|
225
|
+
image_url: special.image_url,
|
|
226
|
+
category_id: special.category_id,
|
|
227
|
+
price,
|
|
228
|
+
discount_amount,
|
|
229
|
+
is_discount_percentage,
|
|
230
|
+
display_price: special.display_price,
|
|
231
|
+
show_starting_from: special.show_starting_from,
|
|
232
|
+
modifier_specials: modifierSpecials,
|
|
233
|
+
};
|
|
234
|
+
specialsMenu.push(specialMenu);
|
|
235
|
+
}
|
|
236
|
+
return specialsMenu;
|
|
237
|
+
}
|
|
238
|
+
export function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity, platform, existingOrderItem, orderItemId, }) {
|
|
239
|
+
const groups = [];
|
|
240
|
+
let menu_id;
|
|
241
|
+
for (let i = 0; i < modifierSpecials.length; i++) {
|
|
242
|
+
const modifierSpecial = modifierSpecials[i];
|
|
243
|
+
const originalModifierSpecial = specialItem.modifier_specials.find((ms) => ms._id === modifierSpecial._id);
|
|
244
|
+
if (!originalModifierSpecial)
|
|
245
|
+
continue;
|
|
246
|
+
// One entry per filled slot; `comparable` is the SAME "is this the same
|
|
247
|
+
// selection?" projection the cart-line merge uses (`getAddItemToCartData`
|
|
248
|
+
// -> `getComparableOrderItem`) — computed once per slot item.
|
|
249
|
+
const entries = [];
|
|
250
|
+
for (let j = 0; j < modifierSpecial.selectedItems.length; j++) {
|
|
251
|
+
const selectedItem = modifierSpecial.selectedItems[j];
|
|
252
|
+
if (!selectedItem)
|
|
253
|
+
continue;
|
|
254
|
+
// The selected menu id (each selection item carries it) — the special
|
|
255
|
+
// belongs to the selected menu; only its constituent items (modifiers)
|
|
256
|
+
// bypass the menu filter.
|
|
257
|
+
if (selectedItem.menu_id != null && menu_id == null) {
|
|
258
|
+
menu_id = selectedItem.menu_id;
|
|
259
|
+
}
|
|
260
|
+
// `_id` is the real catalog item `_id` (like an IItem option), so raw
|
|
261
|
+
// modifiers comparison works for merge and edits stay deterministic.
|
|
262
|
+
entries.push({
|
|
263
|
+
option: {
|
|
264
|
+
_id: selectedItem.item_id,
|
|
265
|
+
ref: selectedItem.item_id,
|
|
266
|
+
name: selectedItem.name,
|
|
267
|
+
price: selectedItem.price,
|
|
268
|
+
quantity: selectedItem.quantity,
|
|
269
|
+
modifiers: selectedItem.modifiers,
|
|
270
|
+
is_free: false,
|
|
271
|
+
// The option IS an item or a half-half — carry its kind.
|
|
272
|
+
ref_type: selectedItem.item_type === ORDER_ITEM_TYPE_ENUM.HALF_HALF
|
|
273
|
+
? MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF
|
|
274
|
+
: MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
275
|
+
},
|
|
276
|
+
comparable: getComparableOrderItem(selectedItem),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
// Mark the cheapest N selected items as free (num_free_items), same as the
|
|
280
|
+
// classic drawer flow (makeSpaceForFreeOptions semantics). Slot order kept.
|
|
281
|
+
const numFreeItems = originalModifierSpecial.num_free_items || 0;
|
|
282
|
+
if (numFreeItems > 0 && entries.length > 0) {
|
|
283
|
+
const freeIndexes = new Set(entries
|
|
284
|
+
.map((entry, index) => ({
|
|
285
|
+
index,
|
|
286
|
+
value: (entry.option.price || 0) * (entry.option.quantity || 1),
|
|
287
|
+
}))
|
|
288
|
+
.sort((a, b) => a.value - b.value)
|
|
289
|
+
.slice(0, numFreeItems)
|
|
290
|
+
.map((entry) => entry.index));
|
|
291
|
+
entries.forEach((entry, index) => {
|
|
292
|
+
if (freeIndexes.has(index)) {
|
|
293
|
+
entry.option.is_free = true;
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
// MERGE identical selections: choosing the same item with the same
|
|
298
|
+
// modifiers in several slots means N units of that option, not N options —
|
|
299
|
+
// the stored line carries ONE option whose `quantity` is the unit sum
|
|
300
|
+
// (mirrors the cart merging two identical lines into one with a summed
|
|
301
|
+
// quantity). Free marking ran per slot BEFORE this and `is_free` is part
|
|
302
|
+
// of the merge key, so free units keep the exact count they had per slot
|
|
303
|
+
// (a mixed group stays as a free option + a paid option).
|
|
304
|
+
const mergedEntries = [];
|
|
305
|
+
for (const entry of entries) {
|
|
306
|
+
const existing = mergedEntries.find((candidate) => candidate.option.is_free === entry.option.is_free && isEqual(candidate.comparable, entry.comparable));
|
|
307
|
+
if (existing != null) {
|
|
308
|
+
existing.option.quantity = (existing.option.quantity || 1) + (entry.option.quantity || 1);
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
mergedEntries.push(entry);
|
|
312
|
+
}
|
|
313
|
+
const options = mergedEntries.map((entry) => entry.option);
|
|
314
|
+
// Group id = the modifier-special `_id` (same as ref — deterministic).
|
|
315
|
+
groups.push({
|
|
316
|
+
ref: originalModifierSpecial._id,
|
|
317
|
+
_id: '',
|
|
318
|
+
name: originalModifierSpecial.name,
|
|
319
|
+
min: 0,
|
|
320
|
+
max: 0,
|
|
321
|
+
freeN: numFreeItems,
|
|
322
|
+
options: options.map((option) => ({
|
|
323
|
+
ref: option.ref,
|
|
324
|
+
_id: option._id,
|
|
325
|
+
name: option.name,
|
|
326
|
+
price: option.price,
|
|
327
|
+
quantity: option.quantity,
|
|
328
|
+
is_free: option.is_free,
|
|
329
|
+
...(option.ref_type != null ? { ref_type: option.ref_type } : {}),
|
|
330
|
+
modifiers: option.modifiers ?? null,
|
|
331
|
+
})),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
// Save direction of the selection model: `_id`s preserved when carried from
|
|
335
|
+
// the stored order item, fresh ObjectIds otherwise.
|
|
336
|
+
const modifiers = buildStoredFromSelection(groups);
|
|
337
|
+
const orderItem = {
|
|
338
|
+
item_discount_details: convertItemDiscountToOrderItemDiscount(specialItem.discount_amount, specialItem.is_discount_percentage, platform, specialItem._id),
|
|
339
|
+
special_instructions: '',
|
|
340
|
+
_net_amount: 0,
|
|
341
|
+
_gross_amount: 0,
|
|
342
|
+
_gst_amount: 0,
|
|
343
|
+
_discount_amount: 0,
|
|
344
|
+
...existingOrderItem,
|
|
345
|
+
// Keep the original order-item id on edit (otherwise getCartItemsObj would
|
|
346
|
+
// treat it as removed + new); generate a fresh ObjectId on create, same as
|
|
347
|
+
// regular items.
|
|
348
|
+
_id: existingOrderItem?._id ?? orderItemId ?? ObjectID().toHexString(),
|
|
349
|
+
item_id: specialItem._id,
|
|
350
|
+
// The special belongs to the selected menu; only its constituent items
|
|
351
|
+
// (modifiers) bypass the menu filter.
|
|
352
|
+
menu_id,
|
|
353
|
+
item_type: ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
354
|
+
/*
|
|
355
|
+
is_ready?: boolean;
|
|
356
|
+
void_reason?: string;
|
|
357
|
+
seat_number?: number;
|
|
358
|
+
is_split?: boolean;
|
|
359
|
+
*/
|
|
360
|
+
name: specialItem.name,
|
|
361
|
+
price: getPriceEnum(specialItem.price, platform),
|
|
362
|
+
subtotal: 0,
|
|
363
|
+
tax_rate: 0,
|
|
364
|
+
quantity,
|
|
365
|
+
modifiers,
|
|
366
|
+
};
|
|
367
|
+
const { itemSubtotal, item_discount_details } = calculateItemTotalWithTax(orderItem);
|
|
368
|
+
orderItem.subtotal = itemSubtotal;
|
|
369
|
+
orderItem.item_discount_details = item_discount_details;
|
|
370
|
+
return orderItem;
|
|
371
|
+
}
|
|
372
|
+
// ====================================================================================================
|
|
373
|
+
/**
|
|
374
|
+
* De-structures a special IOrderItem back into the legacy selection format
|
|
375
|
+
* used by the SpecialsScreen selection flow (edit without classic preview).
|
|
376
|
+
*
|
|
377
|
+
* Each modifier on the order item maps back to its `IModifierSpecial` group
|
|
378
|
+
* (matched by ref or _id). Options MERGE identical slot selections into one
|
|
379
|
+
* option with a summed `quantity` (see `convertSpecialItemToOrderItem`), so
|
|
380
|
+
* the reverse fill EXPANDS a quantity into that many slots (one unit per
|
|
381
|
+
* slot, up to modifier_special.quantity, at least one slot reserved per
|
|
382
|
+
* remaining option) — the modern view is refilled with the same number of
|
|
383
|
+
* filled slots the cashier originally picked.
|
|
384
|
+
*
|
|
385
|
+
* Returns null if the order item doesn't belong to the provided special.
|
|
386
|
+
*/
|
|
387
|
+
export function deStructureSpecialOrderItem(orderItem, specialItem) {
|
|
388
|
+
if (orderItem.item_id !== specialItem._id)
|
|
389
|
+
return null;
|
|
390
|
+
const orderModifiers = orderItem.modifiers ?? [];
|
|
391
|
+
const modifierSpecials = [];
|
|
392
|
+
// Ref-keyed FIFO queues: stored modifiers are consumed one-at-a-time so a
|
|
393
|
+
// modifier special that appears multiple times maps to distinct occurrences.
|
|
394
|
+
const orderModifierQueues = buildSelectionRefQueues(orderModifiers);
|
|
395
|
+
const consumedModifierIds = new Set();
|
|
396
|
+
for (let i = 0; i < specialItem.modifier_specials.length; i++) {
|
|
397
|
+
const modifierSpecial = specialItem.modifier_specials[i];
|
|
398
|
+
// exactId = the modifier-special `_id` (legacy orders stored `_id` = ref).
|
|
399
|
+
let orderModifier = consumeSelectionMatch(orderModifierQueues, modifierSpecial._id, modifierSpecial._id);
|
|
400
|
+
if (orderModifier == null) {
|
|
401
|
+
// Legacy pre-punched lines: stored modifier may carry only `_id` = the
|
|
402
|
+
// modifier-special `_id` (no ref) — match by exact `_id` as a fallback.
|
|
403
|
+
orderModifier = orderModifiers.find((storedModifier) => !consumedModifierIds.has(storedModifier._id) && storedModifier._id === modifierSpecial._id);
|
|
404
|
+
}
|
|
405
|
+
if (orderModifier != null)
|
|
406
|
+
consumedModifierIds.add(orderModifier._id);
|
|
407
|
+
const selectedItems = new Array(modifierSpecial.quantity).fill(null);
|
|
408
|
+
if (orderModifier != null) {
|
|
409
|
+
const buildSlotItem = (option, quantity) => ({
|
|
410
|
+
_id: option._id,
|
|
411
|
+
item_id: option.ref,
|
|
412
|
+
menu_id: orderItem.menu_id ?? null,
|
|
413
|
+
item_type: ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
414
|
+
name: option.name,
|
|
415
|
+
price: option.price,
|
|
416
|
+
subtotal: option.price,
|
|
417
|
+
tax_rate: 0,
|
|
418
|
+
quantity,
|
|
419
|
+
special_instructions: '',
|
|
420
|
+
item_discount_details: null,
|
|
421
|
+
modifiers: option.modifiers ?? null,
|
|
422
|
+
// These values will be auto calculated
|
|
423
|
+
_discount_amount: 0,
|
|
424
|
+
_gross_amount: 0,
|
|
425
|
+
_gst_amount: 0,
|
|
426
|
+
_net_amount: 0,
|
|
427
|
+
});
|
|
428
|
+
// Reverse fill (see the docblock): a merged option with quantity N is
|
|
429
|
+
// refilled as N slot selections (one unit per slot) where the slot
|
|
430
|
+
// budget allows. Every remaining option keeps at least one slot
|
|
431
|
+
// reserved so a merged quantity can never starve the others; when the
|
|
432
|
+
// slots run out the leftover units stay on a single slot (a
|
|
433
|
+
// drawer-stepped quantity keeps its legacy one-slot shape).
|
|
434
|
+
let freeSlots = selectedItems.filter((item) => item === null).length;
|
|
435
|
+
const storedOptions = orderModifier.options;
|
|
436
|
+
for (let j = 0; j < storedOptions.length; j++) {
|
|
437
|
+
if (freeSlots <= 0)
|
|
438
|
+
break;
|
|
439
|
+
const option = storedOptions[j];
|
|
440
|
+
const units = option.quantity > 0 ? option.quantity : 1;
|
|
441
|
+
const remainingOptions = storedOptions.length - j - 1;
|
|
442
|
+
const slotsForOption = Math.min(units, Math.max(1, freeSlots - remainingOptions));
|
|
443
|
+
const unitsPerSlot = Math.floor(units / slotsForOption);
|
|
444
|
+
const slotsWithExtraUnit = units % slotsForOption;
|
|
445
|
+
for (let k = 0; k < slotsForOption; k++) {
|
|
446
|
+
const slotIndex = selectedItems.findIndex((item) => item === null);
|
|
447
|
+
if (slotIndex === -1)
|
|
448
|
+
break;
|
|
449
|
+
selectedItems[slotIndex] = buildSlotItem(option, unitsPerSlot + (k < slotsWithExtraUnit ? 1 : 0));
|
|
450
|
+
freeSlots -= 1;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
modifierSpecials.push({ _id: modifierSpecial._id, selectedItems });
|
|
455
|
+
}
|
|
456
|
+
return { modifierSpecials, quantity: orderItem.quantity };
|
|
457
|
+
}
|
|
458
|
+
// ====================================================================================================
|
|
459
|
+
/**
|
|
460
|
+
* Converts an ISpecial into an IItem so it can flow through the standard
|
|
461
|
+
* catalog → drawer → cart pipeline just like a regular catalog item.
|
|
462
|
+
*
|
|
463
|
+
* Each `IModifierSpecial` becomes an `IModifier` on the item, and each
|
|
464
|
+
* item within a modifier special becomes an `IModifierOption`.
|
|
465
|
+
*
|
|
466
|
+
* PURE CONVERSION ONLY — no availability filtering (active / tenants /
|
|
467
|
+
* included_platforms) and no special-hours / platform-based price
|
|
468
|
+
* resolution happens here. Setup fields are copied through as-is:
|
|
469
|
+
* - `item_special_hours` is preserved on the output item,
|
|
470
|
+
* - ITEM options are platform-open (`excluded_platforms: []`): constituent
|
|
471
|
+
* items are shown even when they don't belong to the current platform (the
|
|
472
|
+
* special's own `included_platforms` is the platform gate — same rule as
|
|
473
|
+
* `convertSpecialsToWorkableSpecials`; the classic drawer engine and the
|
|
474
|
+
* `hasAllModifierOptionsAvailable` gates must not filter them),
|
|
475
|
+
* - HALF-HALF options keep the derived (complement) `excluded_platforms` from
|
|
476
|
+
* the converted half-half item, so the half-half setup's own platform gate
|
|
477
|
+
* still applies (the classic counterpart of the platform-filtered
|
|
478
|
+
* `visibleHalfHalfItems` in the modern flow).
|
|
479
|
+
*
|
|
480
|
+
* Availability-aware consumers compose this with `isSetupApplicable(...)`
|
|
481
|
+
* (and `convertItemToWorkableItem(...)` / `getPlatformModifiers(...)` for
|
|
482
|
+
* schedule/pricing).
|
|
483
|
+
*
|
|
484
|
+
* Pricing model (mirrors convertSpecialsToWorkableSpecials):
|
|
485
|
+
* - Special-level price overrides individual item prices (options get null price).
|
|
486
|
+
* - Upsell prices are merged on top.
|
|
487
|
+
* - num_free_items → num_free_options (drawer handles free vs paid).
|
|
488
|
+
* - Item modifiers are pre-filtered by excluded_refs / exclusive_refs.
|
|
489
|
+
*
|
|
490
|
+
* Returns null only when no option can be resolved from the items map.
|
|
491
|
+
*/
|
|
492
|
+
export function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
493
|
+
// Fields are carried through as-is (no schedule resolution here).
|
|
494
|
+
const price = special.price;
|
|
495
|
+
const discount_amount = special.discount_amount;
|
|
496
|
+
const is_discount_percentage = special.is_discount_percentage;
|
|
497
|
+
// ── Build modifiers from modifier_specials ─────────────────────
|
|
498
|
+
const modifiers = [];
|
|
499
|
+
const allKeywords = [];
|
|
500
|
+
const allCaveats = [];
|
|
501
|
+
const allDietaryPreferences = [];
|
|
502
|
+
for (let j = 0; j < special.modifier_specials.length; j++) {
|
|
503
|
+
const modifierSpecial = special.modifier_specials[j];
|
|
504
|
+
const modifierSpecialItems = [...modifierSpecial.items];
|
|
505
|
+
modifierSpecialItems.sort((a, b) => a.sort_id - b.sort_id);
|
|
506
|
+
const options = [];
|
|
507
|
+
for (let k = 0; k < modifierSpecialItems.length; k++) {
|
|
508
|
+
const specialItem = modifierSpecialItems[k];
|
|
509
|
+
let catalogItem = itemsMap[specialItem.item_id];
|
|
510
|
+
// A modifier_special item can reference a half-half setup instead of a
|
|
511
|
+
// regular catalog item: convert it to an IItem (each segment becomes a
|
|
512
|
+
// nested single-select modifier) so it flows like any other option.
|
|
513
|
+
let isHalfHalfOption = false;
|
|
514
|
+
let halfHalfChooseExpensive = false;
|
|
515
|
+
if (catalogItem == null && halfhalfSetups != null) {
|
|
516
|
+
const halfhalfSetup = halfhalfSetups[specialItem.item_id];
|
|
517
|
+
if (halfhalfSetup != null) {
|
|
518
|
+
// The special's own (non-half-half) items are the ONLY segment
|
|
519
|
+
// options of a half-half nested here — the half-half's original
|
|
520
|
+
// item list is ignored. Pricing comes from each item's special
|
|
521
|
+
// upsell (split per segment), so an upsell defined once in the
|
|
522
|
+
// special applies whether the item is picked directly or inside a
|
|
523
|
+
// half-half. Only `choose_expensive_segment_price` is taken from
|
|
524
|
+
// the setup.
|
|
525
|
+
const specialItems = [];
|
|
526
|
+
for (let m = 0; m < modifierSpecial.items.length; m++) {
|
|
527
|
+
const sibling = modifierSpecial.items[m];
|
|
528
|
+
if (sibling.item_id === specialItem.item_id)
|
|
529
|
+
continue;
|
|
530
|
+
const siblingIsHalfHalf = itemsMap[sibling.item_id] == null && halfhalfSetups?.[sibling.item_id] != null;
|
|
531
|
+
if (!siblingIsHalfHalf) {
|
|
532
|
+
specialItems.push({
|
|
533
|
+
item_id: sibling.item_id,
|
|
534
|
+
upsell_price: sibling.upsell_price ?? null,
|
|
535
|
+
sort_id: sibling.sort_id,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
const halfhalfItem = convertHalfHalfToItem(halfhalfSetup, itemsMap, {
|
|
540
|
+
specialItems,
|
|
541
|
+
// The half-half option's own price inside the special is the
|
|
542
|
+
// special's upsell for the half-half (NOT the setup's own).
|
|
543
|
+
specialHalfHalfUpsell: specialItem.upsell_price ?? null,
|
|
544
|
+
});
|
|
545
|
+
if (halfhalfItem != null) {
|
|
546
|
+
catalogItem = halfhalfItem;
|
|
547
|
+
isHalfHalfOption = true;
|
|
548
|
+
halfHalfChooseExpensive = halfhalfSetup.choose_expensive_segment_price === true;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (!catalogItem)
|
|
553
|
+
continue;
|
|
554
|
+
allKeywords.push(...(catalogItem.keywords ?? []));
|
|
555
|
+
allCaveats.push(...(catalogItem.caveats ?? []));
|
|
556
|
+
allDietaryPreferences.push(...(catalogItem.dietary_preferences ?? []));
|
|
557
|
+
// Determine option price:
|
|
558
|
+
// special has its own price → options carry null price
|
|
559
|
+
// (num_free_options in the drawer handles free-vs-paid)
|
|
560
|
+
// no special price → use item's own price
|
|
561
|
+
// upsell_price is always merged on top
|
|
562
|
+
// For a half-half option the converted item's price ALREADY is the
|
|
563
|
+
// special's upsell for the half-half (specialHalfHalfUpsell), so the
|
|
564
|
+
// upsell must not be merged again — a pass-through special (no special
|
|
565
|
+
// price) would otherwise double it. Regular items keep the standard
|
|
566
|
+
// rule: option = (special price ? null : item price) + special upsell.
|
|
567
|
+
let optionPrice;
|
|
568
|
+
if (isHalfHalfOption) {
|
|
569
|
+
optionPrice = special.price != null ? (specialItem.upsell_price ?? null) : catalogItem.price;
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
optionPrice = special.price != null ? null : catalogItem.price;
|
|
573
|
+
if (specialItem.upsell_price != null) {
|
|
574
|
+
optionPrice = mergePriceObjs(optionPrice, specialItem.upsell_price);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
// Apply the modifier-special group's ref rules to the source item's own
|
|
578
|
+
// modifiers (excluded_refs removes, exclusive_refs zeroes price).
|
|
579
|
+
const itemModifiers = applyModifierSpecialRefRules(catalogItem.modifiers, modifierSpecial.exclusive_refs, modifierSpecial.excluded_refs);
|
|
580
|
+
options.push({
|
|
581
|
+
// `_id` is the real item `_id` (like a catalog option id —
|
|
582
|
+
// deterministic, identical across lines of the same selection);
|
|
583
|
+
// `ref` points to the same actual item.
|
|
584
|
+
_id: catalogItem._id,
|
|
585
|
+
ref: catalogItem._id,
|
|
586
|
+
name: catalogItem.name,
|
|
587
|
+
active: catalogItem.active,
|
|
588
|
+
sold_out: catalogItem.sold_out,
|
|
589
|
+
sort_id: specialItem.sort_id,
|
|
590
|
+
// This option IS a menu item (or a half-half) — carry its kind so
|
|
591
|
+
// downstream order items can tell item/half-half options apart.
|
|
592
|
+
ref_type: isHalfHalfOption ? MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF : MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
593
|
+
// Only on a nested half-half: the setup flag so the engine normalizes
|
|
594
|
+
// the option's own segment groups at selection time.
|
|
595
|
+
...(isHalfHalfOption && halfHalfChooseExpensive ? { choose_expensive_segment_price: true } : {}),
|
|
596
|
+
// Constituent items are NOT platform-gated inside a special (same
|
|
597
|
+
// rule as the menu/list conversion): regular item options are
|
|
598
|
+
// platform-open so the drawer engine (`getPlatformModifiers`) and the
|
|
599
|
+
// availability gates (`hasAllModifierOptionsAvailable`) keep them.
|
|
600
|
+
// Half-half options keep the derived complement — the half-half
|
|
601
|
+
// setup's own platform gate still applies.
|
|
602
|
+
excluded_platforms: isHalfHalfOption
|
|
603
|
+
? getExcludedPlatformsFromIncludedPlatforms(catalogItem.included_platforms)
|
|
604
|
+
: [],
|
|
605
|
+
// Carry the source item's special hours so the filter layer can apply
|
|
606
|
+
// schedule AVAILABILITY (pure mapping, no resolution here). Item
|
|
607
|
+
// schedule-level PRICING/DISCOUNTS are ignored inside a special: they
|
|
608
|
+
// are stripped here so availability (days/time/date) is honored but
|
|
609
|
+
// the schedule can never re-price the option. `omit_items_schedule`
|
|
610
|
+
// drops the schedule entirely (availability too).
|
|
611
|
+
item_modifier_option_special_hours: modifierSpecial.omit_items_schedule
|
|
612
|
+
? null
|
|
613
|
+
: (catalogItem.item_special_hours ?? []).map((hour) => ({
|
|
614
|
+
...hour,
|
|
615
|
+
price: null,
|
|
616
|
+
discount_amount: null,
|
|
617
|
+
is_discount_percentage: false,
|
|
618
|
+
})),
|
|
619
|
+
price: optionPrice,
|
|
620
|
+
modifiers: itemModifiers,
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
// A modifier group with zero resolvable items makes the special invalid
|
|
624
|
+
// (cannot be completed) — the whole conversion fails.
|
|
625
|
+
if (options.length === 0)
|
|
626
|
+
return null;
|
|
627
|
+
// ── Selection shape — DERIVED from how the drawer + engine consume
|
|
628
|
+
// these fields, not set generically ─────────────────────────────────
|
|
629
|
+
//
|
|
630
|
+
// Engine/UI switches on the fields (order-engine + drawer components):
|
|
631
|
+
// - `max_num_options === 1` → RADIO rows (tick one, no steppers)
|
|
632
|
+
// - `*_option_choice_quantity` set → stepper rows; a click seeds the
|
|
633
|
+
// row at `min_option_choice_quantity`; stepping below it deselects;
|
|
634
|
+
// a lone required option is AUTO-SELECTED on open at that quantity
|
|
635
|
+
// - `min/max_aggregate_options_quantity` → the UNIT total validation,
|
|
636
|
+
// click bounce and drawer caps enforce against (sum of option
|
|
637
|
+
// quantities — repeats included)
|
|
638
|
+
//
|
|
639
|
+
// A modifier special is "pick any mix of this group's items totalling
|
|
640
|
+
// `quantity` units". That leaves exactly two shapes:
|
|
641
|
+
// - quantity 1 → a single pick, no units involved: the engine-native
|
|
642
|
+
// RADIO shape (same config half-half segments use) — ticking a row
|
|
643
|
+
// selects it, ticking another switches, and the required flag keeps
|
|
644
|
+
// the pick from being deselected.
|
|
645
|
+
// - quantity > 1 → ticks cannot express units nor repeats, so the group
|
|
646
|
+
// must render as stepper rows with the AGGREGATES pinning the exact
|
|
647
|
+
// total (min = max = quantity): under-selection errors, exceeding
|
|
648
|
+
// bounces, and each row can repeat the same item. `min_num_options`
|
|
649
|
+
// stays 1 (never null) so the group is declared REQUIRED for every
|
|
650
|
+
// consumer that reads it directly (`min_num_options ?? ... ?? 0`) —
|
|
651
|
+
// the AGGREGATES remain the enforcement, and `max_num_options` stays
|
|
652
|
+
// null so the radio switch (`max_num_options === 1`) never trips on a
|
|
653
|
+
// multi-unit group. The click quantity differs by necessity:
|
|
654
|
+
// · multi-item group → a click adds ONE unit (the cashier
|
|
655
|
+
// distributes the rest with the steppers),
|
|
656
|
+
// · single-item group → there is no choice to make, so a click
|
|
657
|
+
// selects the FULL quantity in one go, and the engine's
|
|
658
|
+
// lone-required-option auto-select seeds it with the same amount
|
|
659
|
+
// the moment the drawer opens — identical outcome to the modern
|
|
660
|
+
// flow's slot auto-fill.
|
|
661
|
+
const groupQuantity = Math.max(1, modifierSpecial.quantity || 1);
|
|
662
|
+
const isSingleOptionGroup = options.length === 1;
|
|
663
|
+
const selectionShape = groupQuantity === 1
|
|
664
|
+
? {
|
|
665
|
+
min_num_options: 1,
|
|
666
|
+
max_num_options: 1,
|
|
667
|
+
min_option_choice_quantity: null,
|
|
668
|
+
max_option_choice_quantity: null,
|
|
669
|
+
min_aggregate_options_quantity: null,
|
|
670
|
+
max_aggregate_options_quantity: null,
|
|
671
|
+
}
|
|
672
|
+
: {
|
|
673
|
+
min_num_options: 1,
|
|
674
|
+
max_num_options: null,
|
|
675
|
+
min_option_choice_quantity: isSingleOptionGroup ? groupQuantity : 1,
|
|
676
|
+
max_option_choice_quantity: groupQuantity,
|
|
677
|
+
min_aggregate_options_quantity: groupQuantity,
|
|
678
|
+
max_aggregate_options_quantity: groupQuantity,
|
|
679
|
+
};
|
|
680
|
+
modifiers.push({
|
|
681
|
+
// `_id` is the real modifier-special `_id` (like a catalog modifier id);
|
|
682
|
+
// `ref` points to the same source modifier-special.
|
|
683
|
+
_id: modifierSpecial._id,
|
|
684
|
+
ref: modifierSpecial._id,
|
|
685
|
+
name: modifierSpecial.name,
|
|
686
|
+
description: '',
|
|
687
|
+
active: true,
|
|
688
|
+
sold_out: [],
|
|
689
|
+
sort_id: modifierSpecial.sort_id,
|
|
690
|
+
...selectionShape,
|
|
691
|
+
num_free_options: modifierSpecial.num_free_items > 0 ? modifierSpecial.num_free_items : null,
|
|
692
|
+
options,
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
// ── Assemble the IItem ─────────────────────────────────────────
|
|
696
|
+
const item = {
|
|
697
|
+
_id: special._id,
|
|
698
|
+
brand_id: special.brand_id,
|
|
699
|
+
tenants: special.tenants,
|
|
700
|
+
category_id: special.category_id,
|
|
701
|
+
included_platforms: special.included_platforms,
|
|
702
|
+
name: special.name,
|
|
703
|
+
hide_name: false,
|
|
704
|
+
description: special.description,
|
|
705
|
+
active: special.active,
|
|
706
|
+
sold_out: special.sold_out,
|
|
707
|
+
sort_id: special.sort_id,
|
|
708
|
+
price,
|
|
709
|
+
discount_amount,
|
|
710
|
+
is_discount_percentage,
|
|
711
|
+
caveats: Array.from(new Set(allCaveats)),
|
|
712
|
+
dietary_preferences: Array.from(new Set(allDietaryPreferences)),
|
|
713
|
+
tax_rate: null,
|
|
714
|
+
keywords: Array.from(new Set(allKeywords)),
|
|
715
|
+
image_url: special.image_url,
|
|
716
|
+
ingredients: null,
|
|
717
|
+
item_special_hours: special.item_special_hours, // preserved for the availability layer
|
|
718
|
+
modifiers: modifiers.length > 0 ? modifiers : null,
|
|
719
|
+
is_featured: false,
|
|
720
|
+
featured_sort_id: 0,
|
|
721
|
+
display_price: special.display_price,
|
|
722
|
+
show_starting_from: special.show_starting_from,
|
|
723
|
+
createdAt: special.createdAt,
|
|
724
|
+
updatedAt: special.updatedAt,
|
|
725
|
+
};
|
|
726
|
+
return item;
|
|
727
|
+
}
|