@managesome/eposmatic-toolkit 0.2.212
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/LICENSE +13 -0
- package/lib/constants/ANALYTICS.d.ts +477 -0
- package/lib/constants/ANALYTICS.js +148 -0
- package/lib/constants/COMMON.d.ts +72 -0
- package/lib/constants/COMMON.js +334 -0
- package/lib/constants/DELIVERY.d.ts +14 -0
- package/lib/constants/DELIVERY.js +48 -0
- package/lib/constants/ENUMS.d.ts +1008 -0
- package/lib/constants/ENUMS.js +1693 -0
- package/lib/constants/FBR_ENUMS.d.ts +15 -0
- package/lib/constants/FBR_ENUMS.js +21 -0
- package/lib/constants/HUBRISE_ENUMS.d.ts +74 -0
- package/lib/constants/HUBRISE_ENUMS.js +182 -0
- package/lib/constants/NOTIFICATIONS.d.ts +5 -0
- package/lib/constants/NOTIFICATIONS.js +9 -0
- package/lib/constants/ORDER.d.ts +15 -0
- package/lib/constants/ORDER.js +242 -0
- package/lib/constants/PRA_ENUMS.d.ts +15 -0
- package/lib/constants/PRA_ENUMS.js +21 -0
- package/lib/constants/PURCHASE_ORDER.d.ts +14 -0
- package/lib/constants/PURCHASE_ORDER.js +53 -0
- package/lib/constants/SMARTPAY_ENUMS.d.ts +42 -0
- package/lib/constants/SMARTPAY_ENUMS.js +58 -0
- package/lib/constants/SOCKET.d.ts +95 -0
- package/lib/constants/SOCKET.js +135 -0
- package/lib/constants/SRB_ENUMS.d.ts +10 -0
- package/lib/constants/SRB_ENUMS.js +16 -0
- package/lib/constants/SWITCHPAY.d.ts +4 -0
- package/lib/constants/SWITCHPAY.js +8 -0
- package/lib/constants/WALLET.d.ts +13 -0
- package/lib/constants/WALLET.js +54 -0
- package/lib/constants/WAREHOUSE_ANALYTICS.d.ts +239 -0
- package/lib/constants/WAREHOUSE_ANALYTICS.js +31 -0
- package/lib/constants/WAREHOUSE_INVOICE.d.ts +14 -0
- package/lib/constants/WAREHOUSE_INVOICE.js +35 -0
- package/lib/constants/WEBVIEW.d.ts +44 -0
- package/lib/constants/WEBVIEW.js +50 -0
- package/lib/constants/index.d.ts +19 -0
- package/lib/constants/index.js +35 -0
- package/lib/constants/types.d.ts +408 -0
- package/lib/constants/types.js +3 -0
- package/lib/helpers/fbr/generate-invoice.d.ts +10 -0
- package/lib/helpers/fbr/generate-invoice.js +97 -0
- package/lib/helpers/fbr/index.d.ts +1 -0
- package/lib/helpers/fbr/index.js +17 -0
- package/lib/helpers/hubrise/hubrise-catalog.d.ts +43 -0
- package/lib/helpers/hubrise/hubrise-catalog.js +314 -0
- package/lib/helpers/hubrise/index.d.ts +1 -0
- package/lib/helpers/hubrise/index.js +17 -0
- package/lib/helpers/index.d.ts +9 -0
- package/lib/helpers/index.js +25 -0
- package/lib/helpers/kpra/generate-invoice.d.ts +8 -0
- package/lib/helpers/kpra/generate-invoice.js +29 -0
- package/lib/helpers/kpra/index.d.ts +1 -0
- package/lib/helpers/kpra/index.js +17 -0
- package/lib/helpers/order/generate-order.d.ts +12 -0
- package/lib/helpers/order/generate-order.js +409 -0
- package/lib/helpers/order/generate-purchase-order.d.ts +11 -0
- package/lib/helpers/order/generate-purchase-order.js +196 -0
- package/lib/helpers/order/generate-warehouse-invoice.d.ts +11 -0
- package/lib/helpers/order/generate-warehouse-invoice.js +196 -0
- package/lib/helpers/order/index.d.ts +3 -0
- package/lib/helpers/order/index.js +19 -0
- package/lib/helpers/pra/generate-invoice.d.ts +10 -0
- package/lib/helpers/pra/generate-invoice.js +97 -0
- package/lib/helpers/pra/index.d.ts +1 -0
- package/lib/helpers/pra/index.js +17 -0
- package/lib/helpers/srb/generate-invoice.d.ts +13 -0
- package/lib/helpers/srb/generate-invoice.js +48 -0
- package/lib/helpers/srb/index.d.ts +1 -0
- package/lib/helpers/srb/index.js +17 -0
- package/lib/helpers/store/all-orders-actions.d.ts +5 -0
- package/lib/helpers/store/all-orders-actions.js +23 -0
- package/lib/helpers/store/all-purchase-orders-actions.d.ts +13 -0
- package/lib/helpers/store/all-purchase-orders-actions.js +56 -0
- package/lib/helpers/store/all-warehouse-invoice-actions.d.ts +13 -0
- package/lib/helpers/store/all-warehouse-invoice-actions.js +58 -0
- package/lib/helpers/store/cart-actions.d.ts +159 -0
- package/lib/helpers/store/cart-actions.js +2070 -0
- package/lib/helpers/store/catalog-actions.d.ts +23 -0
- package/lib/helpers/store/catalog-actions.js +216 -0
- package/lib/helpers/store/common-order-actions.d.ts +36 -0
- package/lib/helpers/store/common-order-actions.js +878 -0
- package/lib/helpers/store/common-purchase-order-actions.d.ts +31 -0
- package/lib/helpers/store/common-purchase-order-actions.js +543 -0
- package/lib/helpers/store/common-warehouse-invoice-actions.d.ts +31 -0
- package/lib/helpers/store/common-warehouse-invoice-actions.js +545 -0
- package/lib/helpers/store/index.d.ts +11 -0
- package/lib/helpers/store/index.js +27 -0
- package/lib/helpers/store/offline-ordering.d.ts +15 -0
- package/lib/helpers/store/offline-ordering.js +258 -0
- package/lib/helpers/store/purchase-orders-cart-actions.d.ts +56 -0
- package/lib/helpers/store/purchase-orders-cart-actions.js +486 -0
- package/lib/helpers/store/warehouse-cart-actions.d.ts +54 -0
- package/lib/helpers/store/warehouse-cart-actions.js +486 -0
- package/lib/helpers/store/warehouse-catalog-actions.d.ts +4 -0
- package/lib/helpers/store/warehouse-catalog-actions.js +46 -0
- package/lib/helpers/store/warehouse-invoice-cart-actions.d.ts +56 -0
- package/lib/helpers/store/warehouse-invoice-cart-actions.js +486 -0
- package/lib/helpers/types/cart-actions.d.ts +33 -0
- package/lib/helpers/types/cart-actions.js +2 -0
- package/lib/helpers/types/cart-helpers.d.ts +7 -0
- package/lib/helpers/types/cart-helpers.js +2 -0
- package/lib/helpers/types/catalog.d.ts +149 -0
- package/lib/helpers/types/catalog.js +2 -0
- package/lib/helpers/types/common.d.ts +69 -0
- package/lib/helpers/types/common.js +2 -0
- package/lib/helpers/types/deliverect_menu.d.ts +51 -0
- package/lib/helpers/types/deliverect_menu.js +2 -0
- package/lib/helpers/types/email-templates.d.ts +173 -0
- package/lib/helpers/types/email-templates.js +2 -0
- package/lib/helpers/types/fbr-generate-invoice.d.ts +40 -0
- package/lib/helpers/types/fbr-generate-invoice.js +2 -0
- package/lib/helpers/types/hubrise_catalog.d.ts +123 -0
- package/lib/helpers/types/hubrise_catalog.js +2 -0
- package/lib/helpers/types/hubrise_customers.d.ts +36 -0
- package/lib/helpers/types/hubrise_customers.js +2 -0
- package/lib/helpers/types/hubrise_deliveries.d.ts +19 -0
- package/lib/helpers/types/hubrise_deliveries.js +2 -0
- package/lib/helpers/types/hubrise_location.d.ts +31 -0
- package/lib/helpers/types/hubrise_location.js +2 -0
- package/lib/helpers/types/hubrise_orders.d.ts +86 -0
- package/lib/helpers/types/hubrise_orders.js +2 -0
- package/lib/helpers/types/index.d.ts +25 -0
- package/lib/helpers/types/index.js +41 -0
- package/lib/helpers/types/internal-leads.d.ts +11 -0
- package/lib/helpers/types/internal-leads.js +2 -0
- package/lib/helpers/types/kpra-generate-invoice.d.ts +6 -0
- package/lib/helpers/types/kpra-generate-invoice.js +2 -0
- package/lib/helpers/types/marketing.d.ts +12 -0
- package/lib/helpers/types/marketing.js +2 -0
- package/lib/helpers/types/order-engine.d.ts +39 -0
- package/lib/helpers/types/order-engine.js +2 -0
- package/lib/helpers/types/pra-generate-invoice.d.ts +40 -0
- package/lib/helpers/types/pra-generate-invoice.js +2 -0
- package/lib/helpers/types/printer-settings.d.ts +11 -0
- package/lib/helpers/types/printer-settings.js +3 -0
- package/lib/helpers/types/purchase-order-cart-actions.d.ts +26 -0
- package/lib/helpers/types/purchase-order-cart-actions.js +2 -0
- package/lib/helpers/types/reports.d.ts +150 -0
- package/lib/helpers/types/reports.js +2 -0
- package/lib/helpers/types/smartpay-apis.d.ts +170 -0
- package/lib/helpers/types/smartpay-apis.js +3 -0
- package/lib/helpers/types/split_bill.d.ts +20 -0
- package/lib/helpers/types/split_bill.js +2 -0
- package/lib/helpers/types/srb-generate-invoice.d.ts +27 -0
- package/lib/helpers/types/srb-generate-invoice.js +2 -0
- package/lib/helpers/types/switchpay.d.ts +10 -0
- package/lib/helpers/types/switchpay.js +2 -0
- package/lib/helpers/types/usable-offers.d.ts +27 -0
- package/lib/helpers/types/usable-offers.js +2 -0
- package/lib/helpers/types/warehouse-cart-actions.d.ts +51 -0
- package/lib/helpers/types/warehouse-cart-actions.js +2 -0
- package/lib/helpers/types/warehouse-catalog.d.ts +4 -0
- package/lib/helpers/types/warehouse-catalog.js +2 -0
- package/lib/helpers/types/warehouse-invoice-cart-actions.d.ts +26 -0
- package/lib/helpers/types/warehouse-invoice-cart-actions.js +2 -0
- package/lib/helpers/types/workers.d.ts +256 -0
- package/lib/helpers/types/workers.js +2 -0
- package/lib/helpers/utils/cart-helpers.d.ts +48 -0
- package/lib/helpers/utils/cart-helpers.js +151 -0
- package/lib/helpers/utils/catalog-conversion.d.ts +9 -0
- package/lib/helpers/utils/catalog-conversion.js +123 -0
- package/lib/helpers/utils/color-helpers.d.ts +3 -0
- package/lib/helpers/utils/color-helpers.js +36 -0
- package/lib/helpers/utils/common.d.ts +36 -0
- package/lib/helpers/utils/common.js +332 -0
- package/lib/helpers/utils/comparison-report-helpers.d.ts +27 -0
- package/lib/helpers/utils/comparison-report-helpers.js +802 -0
- package/lib/helpers/utils/comparitive-report-helpers.d.ts +7 -0
- package/lib/helpers/utils/comparitive-report-helpers.js +826 -0
- package/lib/helpers/utils/crypt.d.ts +4 -0
- package/lib/helpers/utils/crypt.js +49 -0
- package/lib/helpers/utils/customers-helpers.d.ts +2 -0
- package/lib/helpers/utils/customers-helpers.js +17 -0
- package/lib/helpers/utils/delivery-area-helpers.d.ts +4 -0
- package/lib/helpers/utils/delivery-area-helpers.js +47 -0
- package/lib/helpers/utils/delivery-helpers.d.ts +2 -0
- package/lib/helpers/utils/delivery-helpers.js +15 -0
- package/lib/helpers/utils/dinein.d.ts +10 -0
- package/lib/helpers/utils/dinein.js +47 -0
- package/lib/helpers/utils/discount-helpers.d.ts +8 -0
- package/lib/helpers/utils/discount-helpers.js +59 -0
- package/lib/helpers/utils/email-helpers.d.ts +17 -0
- package/lib/helpers/utils/email-helpers.js +99 -0
- package/lib/helpers/utils/error-helpers.d.ts +9 -0
- package/lib/helpers/utils/error-helpers.js +18 -0
- package/lib/helpers/utils/expense.d.ts +4 -0
- package/lib/helpers/utils/expense.js +42 -0
- package/lib/helpers/utils/getFormFieldsDiff.d.ts +3 -0
- package/lib/helpers/utils/getFormFieldsDiff.js +18 -0
- package/lib/helpers/utils/halfhalf-setup-helpers.d.ts +22 -0
- package/lib/helpers/utils/halfhalf-setup-helpers.js +133 -0
- package/lib/helpers/utils/hourly-comparison-report-helpers.d.ts +50 -0
- package/lib/helpers/utils/hourly-comparison-report-helpers.js +861 -0
- package/lib/helpers/utils/hubrise-utils.d.ts +11 -0
- package/lib/helpers/utils/hubrise-utils.js +38 -0
- package/lib/helpers/utils/image-helpers.d.ts +3 -0
- package/lib/helpers/utils/image-helpers.js +100 -0
- package/lib/helpers/utils/index.d.ts +68 -0
- package/lib/helpers/utils/index.js +84 -0
- package/lib/helpers/utils/ingredients.d.ts +3 -0
- package/lib/helpers/utils/ingredients.js +30 -0
- package/lib/helpers/utils/inventory.d.ts +4 -0
- package/lib/helpers/utils/inventory.js +122 -0
- package/lib/helpers/utils/inventory_transactions.d.ts +3 -0
- package/lib/helpers/utils/inventory_transactions.js +95 -0
- package/lib/helpers/utils/invoice-x-report-helpers.d.ts +58 -0
- package/lib/helpers/utils/invoice-x-report-helpers.js +1432 -0
- package/lib/helpers/utils/item-report-helpers.d.ts +28 -0
- package/lib/helpers/utils/item-report-helpers.js +2494 -0
- package/lib/helpers/utils/items-comparison-report-helpers.d.ts +30 -0
- package/lib/helpers/utils/items-comparison-report-helpers.js +1066 -0
- package/lib/helpers/utils/kds-helpers.d.ts +8 -0
- package/lib/helpers/utils/kds-helpers.js +46 -0
- package/lib/helpers/utils/location-helpers.d.ts +1 -0
- package/lib/helpers/utils/location-helpers.js +16 -0
- package/lib/helpers/utils/menu-helpers.d.ts +8 -0
- package/lib/helpers/utils/menu-helpers.js +48 -0
- package/lib/helpers/utils/minified-catalog.d.ts +17 -0
- package/lib/helpers/utils/minified-catalog.js +440 -0
- package/lib/helpers/utils/offers-helpers.d.ts +47 -0
- package/lib/helpers/utils/offers-helpers.js +899 -0
- package/lib/helpers/utils/operational-roles-helpers.d.ts +2 -0
- package/lib/helpers/utils/operational-roles-helpers.js +36 -0
- package/lib/helpers/utils/order-engine.d.ts +48 -0
- package/lib/helpers/utils/order-engine.js +754 -0
- package/lib/helpers/utils/order-history.d.ts +15 -0
- package/lib/helpers/utils/order-history.js +211 -0
- package/lib/helpers/utils/payment-comparison-report-helpers.d.ts +16 -0
- package/lib/helpers/utils/payment-comparison-report-helpers.js +882 -0
- package/lib/helpers/utils/payment-helpers.d.ts +38 -0
- package/lib/helpers/utils/payment-helpers.js +285 -0
- package/lib/helpers/utils/pdf-generator.d.ts +19 -0
- package/lib/helpers/utils/pdf-generator.js +115 -0
- package/lib/helpers/utils/platform-catalog.d.ts +11 -0
- package/lib/helpers/utils/platform-catalog.js +234 -0
- package/lib/helpers/utils/platform-num.d.ts +9 -0
- package/lib/helpers/utils/platform-num.js +128 -0
- package/lib/helpers/utils/platform-specific-tenant-shifts.d.ts +8 -0
- package/lib/helpers/utils/platform-specific-tenant-shifts.js +22 -0
- package/lib/helpers/utils/price-conversion.d.ts +6 -0
- package/lib/helpers/utils/price-conversion.js +32 -0
- package/lib/helpers/utils/printer-helpers.d.ts +3 -0
- package/lib/helpers/utils/printer-helpers.js +74 -0
- package/lib/helpers/utils/public-holidays-helpers.d.ts +2 -0
- package/lib/helpers/utils/public-holidays-helpers.js +11 -0
- package/lib/helpers/utils/purchase-order-engine.d.ts +9 -0
- package/lib/helpers/utils/purchase-order-engine.js +34 -0
- package/lib/helpers/utils/purchase-order-receipt-engine.d.ts +149 -0
- package/lib/helpers/utils/purchase-order-receipt-engine.js +214 -0
- package/lib/helpers/utils/purchase-order-x-report-helpers.d.ts +58 -0
- package/lib/helpers/utils/purchase-order-x-report-helpers.js +1440 -0
- package/lib/helpers/utils/ratings-comparison-report-helpers.d.ts +37 -0
- package/lib/helpers/utils/ratings-comparison-report-helpers.js +1194 -0
- package/lib/helpers/utils/receipt-engine.d.ts +165 -0
- package/lib/helpers/utils/receipt-engine.js +856 -0
- package/lib/helpers/utils/review-helpers.d.ts +9 -0
- package/lib/helpers/utils/review-helpers.js +398 -0
- package/lib/helpers/utils/rider-tracking.d.ts +1 -0
- package/lib/helpers/utils/rider-tracking.js +16 -0
- package/lib/helpers/utils/riders-report-helpers.d.ts +62 -0
- package/lib/helpers/utils/riders-report-helpers.js +1598 -0
- package/lib/helpers/utils/sales-comparison-report-helpers.d.ts +31 -0
- package/lib/helpers/utils/sales-comparison-report-helpers.js +1266 -0
- package/lib/helpers/utils/sales-comparitive-report-helpers.d.ts +7 -0
- package/lib/helpers/utils/sales-comparitive-report-helpers.js +945 -0
- package/lib/helpers/utils/sales-overview-report-helpers.d.ts +30 -0
- package/lib/helpers/utils/sales-overview-report-helpers.js +1052 -0
- package/lib/helpers/utils/sales-summary-report-helpers.d.ts +30 -0
- package/lib/helpers/utils/sales-summary-report-helpers.js +883 -0
- package/lib/helpers/utils/short-inventory.d.ts +3 -0
- package/lib/helpers/utils/short-inventory.js +26 -0
- package/lib/helpers/utils/simplified-catalog.d.ts +8 -0
- package/lib/helpers/utils/simplified-catalog.js +115 -0
- package/lib/helpers/utils/simplified-tenant.d.ts +255 -0
- package/lib/helpers/utils/simplified-tenant.js +337 -0
- package/lib/helpers/utils/simplified-warehouse-catalog.d.ts +10 -0
- package/lib/helpers/utils/simplified-warehouse-catalog.js +108 -0
- package/lib/helpers/utils/specials-helpers.d.ts +42 -0
- package/lib/helpers/utils/specials-helpers.js +216 -0
- package/lib/helpers/utils/stock-details.d.ts +3 -0
- package/lib/helpers/utils/stock-details.js +26 -0
- package/lib/helpers/utils/stock-wastage.d.ts +3 -0
- package/lib/helpers/utils/stock-wastage.js +26 -0
- package/lib/helpers/utils/tenant-staff-helpers.d.ts +2 -0
- package/lib/helpers/utils/tenant-staff-helpers.js +22 -0
- package/lib/helpers/utils/terminal-devices-helpers.d.ts +2 -0
- package/lib/helpers/utils/terminal-devices-helpers.js +13 -0
- package/lib/helpers/utils/time-helpers.d.ts +16 -0
- package/lib/helpers/utils/time-helpers.js +57 -0
- package/lib/helpers/utils/void-items-report-helpers.d.ts +13 -0
- package/lib/helpers/utils/void-items-report-helpers.js +526 -0
- package/lib/helpers/utils/void-order-items-helpers.d.ts +3 -0
- package/lib/helpers/utils/void-order-items-helpers.js +36 -0
- package/lib/helpers/utils/voidations-summary-report-helpers.d.ts +24 -0
- package/lib/helpers/utils/voidations-summary-report-helpers.js +807 -0
- package/lib/helpers/utils/wallet-helpers.d.ts +2 -0
- package/lib/helpers/utils/wallet-helpers.js +25 -0
- package/lib/helpers/utils/warehouse-catalog-conversion.d.ts +7 -0
- package/lib/helpers/utils/warehouse-catalog-conversion.js +89 -0
- package/lib/helpers/utils/warehouse-inventory.d.ts +2 -0
- package/lib/helpers/utils/warehouse-inventory.js +53 -0
- package/lib/helpers/utils/warehouse-invoice-order-engine.d.ts +11 -0
- package/lib/helpers/utils/warehouse-invoice-order-engine.js +39 -0
- package/lib/helpers/utils/warehouse-order-engine.d.ts +9 -0
- package/lib/helpers/utils/warehouse-order-engine.js +34 -0
- package/lib/helpers/utils/warehouse-settings-helpers.d.ts +2 -0
- package/lib/helpers/utils/warehouse-settings-helpers.js +30 -0
- package/lib/helpers/utils/warehouse_inventory_transactions.d.ts +3 -0
- package/lib/helpers/utils/warehouse_inventory_transactions.js +95 -0
- package/lib/helpers/utils/x-report-helpers.d.ts +65 -0
- package/lib/helpers/utils/x-report-helpers.js +1858 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +19 -0
- package/lib/schemas/index.d.ts +2 -0
- package/lib/schemas/index.js +18 -0
- package/lib/schemas/models/app_configs.d.ts +34 -0
- package/lib/schemas/models/app_configs.js +39 -0
- package/lib/schemas/models/applied-order-discounts.d.ts +80 -0
- package/lib/schemas/models/applied-order-discounts.js +106 -0
- package/lib/schemas/models/brand.d.ts +45 -0
- package/lib/schemas/models/brand.js +45 -0
- package/lib/schemas/models/cash_drawer_sessions.d.ts +107 -0
- package/lib/schemas/models/cash_drawer_sessions.js +78 -0
- package/lib/schemas/models/cash_drawers.d.ts +44 -0
- package/lib/schemas/models/cash_drawers.js +46 -0
- package/lib/schemas/models/cash_in_out.d.ts +110 -0
- package/lib/schemas/models/cash_in_out.js +81 -0
- package/lib/schemas/models/category.d.ts +60 -0
- package/lib/schemas/models/category.js +67 -0
- package/lib/schemas/models/close_dates.d.ts +50 -0
- package/lib/schemas/models/close_dates.js +56 -0
- package/lib/schemas/models/common-models.d.ts +493 -0
- package/lib/schemas/models/common-models.js +444 -0
- package/lib/schemas/models/courses.d.ts +77 -0
- package/lib/schemas/models/courses.js +55 -0
- package/lib/schemas/models/customers.d.ts +443 -0
- package/lib/schemas/models/customers.js +197 -0
- package/lib/schemas/models/deliveries.d.ts +123 -0
- package/lib/schemas/models/deliveries.js +112 -0
- package/lib/schemas/models/delivery_areas.d.ts +263 -0
- package/lib/schemas/models/delivery_areas.js +100 -0
- package/lib/schemas/models/dinein_floors.d.ts +44 -0
- package/lib/schemas/models/dinein_floors.js +45 -0
- package/lib/schemas/models/dinein_table_fingerprints.d.ts +65 -0
- package/lib/schemas/models/dinein_table_fingerprints.js +85 -0
- package/lib/schemas/models/dinein_tables.d.ts +68 -0
- package/lib/schemas/models/dinein_tables.js +82 -0
- package/lib/schemas/models/discounts.d.ts +1254 -0
- package/lib/schemas/models/discounts.js +90 -0
- package/lib/schemas/models/drivers.d.ts +55 -0
- package/lib/schemas/models/drivers.js +60 -0
- package/lib/schemas/models/expense_category.d.ts +83 -0
- package/lib/schemas/models/expense_category.js +64 -0
- package/lib/schemas/models/expense_details.d.ts +266 -0
- package/lib/schemas/models/expense_details.js +113 -0
- package/lib/schemas/models/halfhalf_setup.d.ts +1541 -0
- package/lib/schemas/models/halfhalf_setup.js +109 -0
- package/lib/schemas/models/index.d.ts +65 -0
- package/lib/schemas/models/index.js +81 -0
- package/lib/schemas/models/instore_shift_sessions.d.ts +146 -0
- package/lib/schemas/models/instore_shift_sessions.js +125 -0
- package/lib/schemas/models/instore_shifts.d.ts +50 -0
- package/lib/schemas/models/instore_shifts.js +55 -0
- package/lib/schemas/models/internal_expense_details.d.ts +55 -0
- package/lib/schemas/models/internal_expense_details.js +63 -0
- package/lib/schemas/models/internal_leads.d.ts +69 -0
- package/lib/schemas/models/internal_leads.js +81 -0
- package/lib/schemas/models/internal_restaurant_details.d.ts +64 -0
- package/lib/schemas/models/internal_restaurant_details.js +77 -0
- package/lib/schemas/models/inventory.d.ts +99 -0
- package/lib/schemas/models/inventory.js +87 -0
- package/lib/schemas/models/inventory_categories.d.ts +50 -0
- package/lib/schemas/models/inventory_categories.js +55 -0
- package/lib/schemas/models/inventory_transactions.d.ts +83 -0
- package/lib/schemas/models/inventory_transactions.js +110 -0
- package/lib/schemas/models/item.d.ts +10822 -0
- package/lib/schemas/models/item.js +329 -0
- package/lib/schemas/models/item_transactions.d.ts +71 -0
- package/lib/schemas/models/item_transactions.js +95 -0
- package/lib/schemas/models/marketing_fingerprints.d.ts +62 -0
- package/lib/schemas/models/marketing_fingerprints.js +81 -0
- package/lib/schemas/models/menu.d.ts +905 -0
- package/lib/schemas/models/menu.js +69 -0
- package/lib/schemas/models/messaging_devices.d.ts +63 -0
- package/lib/schemas/models/messaging_devices.js +74 -0
- package/lib/schemas/models/modifier_extras.d.ts +516 -0
- package/lib/schemas/models/modifier_extras.js +123 -0
- package/lib/schemas/models/offers.d.ts +1067 -0
- package/lib/schemas/models/offers.js +286 -0
- package/lib/schemas/models/offers_fingerprints.d.ts +50 -0
- package/lib/schemas/models/offers_fingerprints.js +63 -0
- package/lib/schemas/models/operational_roles.d.ts +263 -0
- package/lib/schemas/models/operational_roles.js +158 -0
- package/lib/schemas/models/order.d.ts +15284 -0
- package/lib/schemas/models/order.js +819 -0
- package/lib/schemas/models/platform.d.ts +34 -0
- package/lib/schemas/models/platform.js +30 -0
- package/lib/schemas/models/printer_settings.d.ts +217 -0
- package/lib/schemas/models/printer_settings.js +234 -0
- package/lib/schemas/models/public_holidays.d.ts +173 -0
- package/lib/schemas/models/public_holidays.js +61 -0
- package/lib/schemas/models/purchase_orders.d.ts +2675 -0
- package/lib/schemas/models/purchase_orders.js +327 -0
- package/lib/schemas/models/reservations.d.ts +66 -0
- package/lib/schemas/models/reservations.js +88 -0
- package/lib/schemas/models/reviews.d.ts +98 -0
- package/lib/schemas/models/reviews.js +148 -0
- package/lib/schemas/models/rider.d.ts +65 -0
- package/lib/schemas/models/rider.js +74 -0
- package/lib/schemas/models/short_inventory.d.ts +65 -0
- package/lib/schemas/models/short_inventory.js +46 -0
- package/lib/schemas/models/specials.d.ts +2551 -0
- package/lib/schemas/models/specials.js +145 -0
- package/lib/schemas/models/staff_shifts.d.ts +77 -0
- package/lib/schemas/models/staff_shifts.js +69 -0
- package/lib/schemas/models/stock_consumption.d.ts +77 -0
- package/lib/schemas/models/stock_consumption.js +64 -0
- package/lib/schemas/models/stock_entry.d.ts +65 -0
- package/lib/schemas/models/stock_entry.js +46 -0
- package/lib/schemas/models/stock_wastage.d.ts +71 -0
- package/lib/schemas/models/stock_wastage.js +54 -0
- package/lib/schemas/models/tenant.d.ts +468 -0
- package/lib/schemas/models/tenant.js +673 -0
- package/lib/schemas/models/tenant_days.d.ts +134 -0
- package/lib/schemas/models/tenant_days.js +110 -0
- package/lib/schemas/models/tenant_metadata.d.ts +77 -0
- package/lib/schemas/models/tenant_metadata.js +91 -0
- package/lib/schemas/models/tenant_shift_sessions.d.ts +146 -0
- package/lib/schemas/models/tenant_shift_sessions.js +125 -0
- package/lib/schemas/models/tenant_shifts.d.ts +53 -0
- package/lib/schemas/models/tenant_shifts.js +60 -0
- package/lib/schemas/models/tenant_staff.d.ts +896 -0
- package/lib/schemas/models/tenant_staff.js +96 -0
- package/lib/schemas/models/terminal_devices.d.ts +62 -0
- package/lib/schemas/models/terminal_devices.js +74 -0
- package/lib/schemas/models/tokens.d.ts +59 -0
- package/lib/schemas/models/tokens.js +109 -0
- package/lib/schemas/models/track_order_number.d.ts +395 -0
- package/lib/schemas/models/track_order_number.js +45 -0
- package/lib/schemas/models/void_order_items.d.ts +173 -0
- package/lib/schemas/models/void_order_items.js +169 -0
- package/lib/schemas/models/wallet.d.ts +38 -0
- package/lib/schemas/models/wallet.js +37 -0
- package/lib/schemas/models/wallet_transactions.d.ts +74 -0
- package/lib/schemas/models/wallet_transactions.js +96 -0
- package/lib/schemas/models/warehouse.d.ts +156 -0
- package/lib/schemas/models/warehouse.js +213 -0
- package/lib/schemas/models/warehouse_categories.d.ts +56 -0
- package/lib/schemas/models/warehouse_categories.js +65 -0
- package/lib/schemas/models/warehouse_clients.d.ts +53 -0
- package/lib/schemas/models/warehouse_clients.js +61 -0
- package/lib/schemas/models/warehouse_inventory_transactions.d.ts +83 -0
- package/lib/schemas/models/warehouse_inventory_transactions.js +110 -0
- package/lib/schemas/models/warehouse_invoices.d.ts +2675 -0
- package/lib/schemas/models/warehouse_invoices.js +327 -0
- package/lib/schemas/models/warehouse_item_transactions.d.ts +74 -0
- package/lib/schemas/models/warehouse_item_transactions.js +100 -0
- package/lib/schemas/models/warehouse_items.d.ts +131 -0
- package/lib/schemas/models/warehouse_items.js +127 -0
- package/lib/schemas/models/warehouse_operational_roles.d.ts +77 -0
- package/lib/schemas/models/warehouse_operational_roles.js +90 -0
- package/lib/schemas/models/warehouse_settings.d.ts +40 -0
- package/lib/schemas/models/warehouse_settings.js +40 -0
- package/lib/schemas/models/warehouse_staff.d.ts +65 -0
- package/lib/schemas/models/warehouse_staff.js +78 -0
- package/lib/schemas/models/warehouse_track_order_number.d.ts +50 -0
- package/lib/schemas/models/warehouse_track_order_number.js +52 -0
- package/lib/schemas/models/warehouse_vendors.d.ts +89 -0
- package/lib/schemas/models/warehouse_vendors.js +73 -0
- package/lib/schemas/types/app_configs.d.ts +9 -0
- package/lib/schemas/types/app_configs.js +2 -0
- package/lib/schemas/types/applied-order-discounts.d.ts +22 -0
- package/lib/schemas/types/applied-order-discounts.js +2 -0
- package/lib/schemas/types/brand.d.ts +32 -0
- package/lib/schemas/types/brand.js +2 -0
- package/lib/schemas/types/cash_drawer_sessions.d.ts +18 -0
- package/lib/schemas/types/cash_drawer_sessions.js +2 -0
- package/lib/schemas/types/cash_drawers.d.ts +9 -0
- package/lib/schemas/types/cash_drawers.js +2 -0
- package/lib/schemas/types/cash_in_out.d.ts +19 -0
- package/lib/schemas/types/cash_in_out.js +2 -0
- package/lib/schemas/types/category.d.ts +15 -0
- package/lib/schemas/types/category.js +2 -0
- package/lib/schemas/types/close_dates.d.ts +12 -0
- package/lib/schemas/types/close_dates.js +2 -0
- package/lib/schemas/types/common.d.ts +34 -0
- package/lib/schemas/types/common.js +2 -0
- package/lib/schemas/types/courses.d.ts +15 -0
- package/lib/schemas/types/courses.js +2 -0
- package/lib/schemas/types/customers.d.ts +51 -0
- package/lib/schemas/types/customers.js +2 -0
- package/lib/schemas/types/deliveries.d.ts +28 -0
- package/lib/schemas/types/deliveries.js +2 -0
- package/lib/schemas/types/delivery_areas.d.ts +23 -0
- package/lib/schemas/types/delivery_areas.js +2 -0
- package/lib/schemas/types/dinein_floors.d.ts +23 -0
- package/lib/schemas/types/dinein_floors.js +2 -0
- package/lib/schemas/types/dinein_tables.d.ts +19 -0
- package/lib/schemas/types/dinein_tables.js +2 -0
- package/lib/schemas/types/dinein_tables_fingerprints.d.ts +17 -0
- package/lib/schemas/types/dinein_tables_fingerprints.js +2 -0
- package/lib/schemas/types/discounts.d.ts +21 -0
- package/lib/schemas/types/discounts.js +2 -0
- package/lib/schemas/types/drivers.d.ts +13 -0
- package/lib/schemas/types/drivers.js +2 -0
- package/lib/schemas/types/expense_category.d.ts +20 -0
- package/lib/schemas/types/expense_category.js +2 -0
- package/lib/schemas/types/expense_details.d.ts +26 -0
- package/lib/schemas/types/expense_details.js +2 -0
- package/lib/schemas/types/halfhalf_setup.d.ts +26 -0
- package/lib/schemas/types/halfhalf_setup.js +2 -0
- package/lib/schemas/types/index.d.ts +67 -0
- package/lib/schemas/types/index.js +83 -0
- package/lib/schemas/types/instore_shift_sessions.d.ts +33 -0
- package/lib/schemas/types/instore_shift_sessions.js +2 -0
- package/lib/schemas/types/instore_shifts.d.ts +11 -0
- package/lib/schemas/types/instore_shifts.js +2 -0
- package/lib/schemas/types/internal_expense_details.d.ts +14 -0
- package/lib/schemas/types/internal_expense_details.js +2 -0
- package/lib/schemas/types/internal_leads.d.ts +18 -0
- package/lib/schemas/types/internal_leads.js +2 -0
- package/lib/schemas/types/internal_restaurant_details.d.ts +17 -0
- package/lib/schemas/types/internal_restaurant_details.js +2 -0
- package/lib/schemas/types/inventory.d.ts +48 -0
- package/lib/schemas/types/inventory.js +2 -0
- package/lib/schemas/types/inventory_categories.d.ts +11 -0
- package/lib/schemas/types/inventory_categories.js +2 -0
- package/lib/schemas/types/inventory_transactions.d.ts +23 -0
- package/lib/schemas/types/inventory_transactions.js +2 -0
- package/lib/schemas/types/item.d.ts +88 -0
- package/lib/schemas/types/item.js +2 -0
- package/lib/schemas/types/item_transactions.d.ts +19 -0
- package/lib/schemas/types/item_transactions.js +2 -0
- package/lib/schemas/types/marketing.d.ts +10 -0
- package/lib/schemas/types/marketing.js +2 -0
- package/lib/schemas/types/marketing_fingerprints.d.ts +16 -0
- package/lib/schemas/types/marketing_fingerprints.js +2 -0
- package/lib/schemas/types/menu.d.ts +17 -0
- package/lib/schemas/types/menu.js +2 -0
- package/lib/schemas/types/messaging_devices.d.ts +16 -0
- package/lib/schemas/types/messaging_devices.js +2 -0
- package/lib/schemas/types/modifier_extras.d.ts +31 -0
- package/lib/schemas/types/modifier_extras.js +2 -0
- package/lib/schemas/types/multi_tenants.d.ts +24 -0
- package/lib/schemas/types/multi_tenants.js +2 -0
- package/lib/schemas/types/offers.d.ts +82 -0
- package/lib/schemas/types/offers.js +2 -0
- package/lib/schemas/types/offers_fingerprints.d.ts +11 -0
- package/lib/schemas/types/offers_fingerprints.js +2 -0
- package/lib/schemas/types/operational_roles.d.ts +41 -0
- package/lib/schemas/types/operational_roles.js +18 -0
- package/lib/schemas/types/order.d.ts +225 -0
- package/lib/schemas/types/order.js +2 -0
- package/lib/schemas/types/platform.d.ts +6 -0
- package/lib/schemas/types/platform.js +2 -0
- package/lib/schemas/types/pos_days.d.ts +29 -0
- package/lib/schemas/types/pos_days.js +2 -0
- package/lib/schemas/types/pos_shifts.d.ts +33 -0
- package/lib/schemas/types/pos_shifts.js +2 -0
- package/lib/schemas/types/printer_settings.d.ts +83 -0
- package/lib/schemas/types/printer_settings.js +3 -0
- package/lib/schemas/types/public_holidays.d.ts +14 -0
- package/lib/schemas/types/public_holidays.js +2 -0
- package/lib/schemas/types/purchase_orders.d.ts +69 -0
- package/lib/schemas/types/purchase_orders.js +2 -0
- package/lib/schemas/types/reservations.d.ts +17 -0
- package/lib/schemas/types/reservations.js +2 -0
- package/lib/schemas/types/reviews.d.ts +28 -0
- package/lib/schemas/types/reviews.js +2 -0
- package/lib/schemas/types/rider.d.ts +16 -0
- package/lib/schemas/types/rider.js +2 -0
- package/lib/schemas/types/short_inventory.d.ts +9 -0
- package/lib/schemas/types/short_inventory.js +2 -0
- package/lib/schemas/types/specials.d.ts +42 -0
- package/lib/schemas/types/specials.js +2 -0
- package/lib/schemas/types/split_bill.d.ts +18 -0
- package/lib/schemas/types/split_bill.js +2 -0
- package/lib/schemas/types/staff_shifts.d.ts +15 -0
- package/lib/schemas/types/staff_shifts.js +2 -0
- package/lib/schemas/types/stock_consumption.d.ts +13 -0
- package/lib/schemas/types/stock_consumption.js +2 -0
- package/lib/schemas/types/stock_entry.d.ts +9 -0
- package/lib/schemas/types/stock_entry.js +2 -0
- package/lib/schemas/types/stock_wastage.d.ts +11 -0
- package/lib/schemas/types/stock_wastage.js +2 -0
- package/lib/schemas/types/tenant.d.ts +175 -0
- package/lib/schemas/types/tenant.js +2 -0
- package/lib/schemas/types/tenant_days.d.ts +29 -0
- package/lib/schemas/types/tenant_days.js +2 -0
- package/lib/schemas/types/tenant_metadata.d.ts +13 -0
- package/lib/schemas/types/tenant_metadata.js +2 -0
- package/lib/schemas/types/tenant_shift_sessions.d.ts +33 -0
- package/lib/schemas/types/tenant_shift_sessions.js +2 -0
- package/lib/schemas/types/tenant_shifts.d.ts +13 -0
- package/lib/schemas/types/tenant_shifts.js +2 -0
- package/lib/schemas/types/tenant_staff.d.ts +22 -0
- package/lib/schemas/types/tenant_staff.js +2 -0
- package/lib/schemas/types/terminal_devices.d.ts +16 -0
- package/lib/schemas/types/terminal_devices.js +2 -0
- package/lib/schemas/types/third_party_payments.d.ts +41 -0
- package/lib/schemas/types/third_party_payments.js +2 -0
- package/lib/schemas/types/tokens.d.ts +15 -0
- package/lib/schemas/types/tokens.js +2 -0
- package/lib/schemas/types/track_order_number.d.ts +10 -0
- package/lib/schemas/types/track_order_number.js +2 -0
- package/lib/schemas/types/used_ingredients.d.ts +8 -0
- package/lib/schemas/types/used_ingredients.js +2 -0
- package/lib/schemas/types/void_order_items.d.ts +36 -0
- package/lib/schemas/types/void_order_items.js +2 -0
- package/lib/schemas/types/wallet.d.ts +7 -0
- package/lib/schemas/types/wallet.js +2 -0
- package/lib/schemas/types/wallet_transactions.d.ts +20 -0
- package/lib/schemas/types/wallet_transactions.js +2 -0
- package/lib/schemas/types/warehouse.d.ts +47 -0
- package/lib/schemas/types/warehouse.js +2 -0
- package/lib/schemas/types/warehouse_categories.d.ts +13 -0
- package/lib/schemas/types/warehouse_categories.js +2 -0
- package/lib/schemas/types/warehouse_clients.d.ts +13 -0
- package/lib/schemas/types/warehouse_clients.js +2 -0
- package/lib/schemas/types/warehouse_inventory_transactions.d.ts +23 -0
- package/lib/schemas/types/warehouse_inventory_transactions.js +2 -0
- package/lib/schemas/types/warehouse_invoices.d.ts +69 -0
- package/lib/schemas/types/warehouse_invoices.js +2 -0
- package/lib/schemas/types/warehouse_item_transactions.d.ts +20 -0
- package/lib/schemas/types/warehouse_item_transactions.js +2 -0
- package/lib/schemas/types/warehouse_items.d.ts +65 -0
- package/lib/schemas/types/warehouse_items.js +2 -0
- package/lib/schemas/types/warehouse_operational_roles.d.ts +22 -0
- package/lib/schemas/types/warehouse_operational_roles.js +18 -0
- package/lib/schemas/types/warehouse_settings.d.ts +8 -0
- package/lib/schemas/types/warehouse_settings.js +2 -0
- package/lib/schemas/types/warehouse_staff.d.ts +17 -0
- package/lib/schemas/types/warehouse_staff.js +2 -0
- package/lib/schemas/types/warehouse_track_order_number.d.ts +11 -0
- package/lib/schemas/types/warehouse_track_order_number.js +2 -0
- package/lib/schemas/types/warehouse_vendors.d.ts +16 -0
- package/lib/schemas/types/warehouse_vendors.js +2 -0
- package/package.json +59 -0
|
@@ -0,0 +1,754 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.hasMissedRequiredItemModifier = hasMissedRequiredItemModifier;
|
|
7
|
+
exports.syncOrderEngineItem = syncOrderEngineItem;
|
|
8
|
+
exports.checkIfModifiersExist = checkIfModifiersExist;
|
|
9
|
+
exports.makeSpaceForFreeOptions = makeSpaceForFreeOptions;
|
|
10
|
+
exports.convertOrderEngineItemToOrderItem = convertOrderEngineItemToOrderItem;
|
|
11
|
+
exports.convertItemDiscountToOrderItemDiscount = convertItemDiscountToOrderItemDiscount;
|
|
12
|
+
exports.convertCatalogItemToOrderEngineItem = convertCatalogItemToOrderEngineItem;
|
|
13
|
+
exports.hasRequiredModifier = hasRequiredModifier;
|
|
14
|
+
exports.convertItemToOrderItem = convertItemToOrderItem;
|
|
15
|
+
exports.setCheckFieldInOrderEngineItem = setCheckFieldInOrderEngineItem;
|
|
16
|
+
exports.setIncrementOrderEngineItemQuantity = setIncrementOrderEngineItemQuantity;
|
|
17
|
+
exports.setUpdateSelectedOrderEngineOptionQuantity = setUpdateSelectedOrderEngineOptionQuantity;
|
|
18
|
+
exports.getFlattenedOrderEngineItemModifiers = getFlattenedOrderEngineItemModifiers;
|
|
19
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
20
|
+
const constants_1 = require("../../constants");
|
|
21
|
+
const store_1 = require("../store");
|
|
22
|
+
const common_1 = require("./common");
|
|
23
|
+
const platform_catalog_1 = require("./platform-catalog");
|
|
24
|
+
/* ==========================================================><==================================================== */
|
|
25
|
+
function hasMissedRequiredItemModifier(currentModifiers, platform) {
|
|
26
|
+
let missedModifier = null;
|
|
27
|
+
if (!currentModifiers)
|
|
28
|
+
return false;
|
|
29
|
+
const findMissedRequiredModifiers = (modifiers) => {
|
|
30
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
31
|
+
if (missedModifier)
|
|
32
|
+
break;
|
|
33
|
+
const modifier = modifiers[i];
|
|
34
|
+
let totalDefaultOptions = 0;
|
|
35
|
+
const options = modifier.options.filter((option) => option.active && !option.excluded_platforms.includes(platform));
|
|
36
|
+
if (options.length === 0) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const defaultOptionsWithModifiers = [];
|
|
40
|
+
for (let j = 0; j < options.length; j++) {
|
|
41
|
+
const option = options[j];
|
|
42
|
+
if (!option.default)
|
|
43
|
+
continue;
|
|
44
|
+
totalDefaultOptions += modifier.min_option_choice_quantity || 1;
|
|
45
|
+
if (option.modifiers != null && option.modifiers.length > 0) {
|
|
46
|
+
defaultOptionsWithModifiers.push(option);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const totalRequiredOptions = modifier.min_aggregate_options_quantity ?? modifier.min_num_options ?? 0;
|
|
50
|
+
if (!missedModifier && totalRequiredOptions && totalRequiredOptions > totalDefaultOptions) {
|
|
51
|
+
missedModifier = modifier;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
for (let j = 0; j < defaultOptionsWithModifiers.length; j++) {
|
|
55
|
+
const option = defaultOptionsWithModifiers[j];
|
|
56
|
+
const optionModifiers = option.modifiers;
|
|
57
|
+
findMissedRequiredModifiers(optionModifiers ?? []);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
findMissedRequiredModifiers(currentModifiers);
|
|
62
|
+
return missedModifier !== null;
|
|
63
|
+
}
|
|
64
|
+
function syncOrderEngineItem(orderEngineItem) {
|
|
65
|
+
// Calculate modifiers total and find errors
|
|
66
|
+
let error = null;
|
|
67
|
+
function calcModifiersTotal(modifiers) {
|
|
68
|
+
let total = 0;
|
|
69
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
70
|
+
const modifier = modifiers[i];
|
|
71
|
+
if (modifier.default) {
|
|
72
|
+
for (let j = 0; j < modifier.options.length; j++) {
|
|
73
|
+
const option = modifier.options[j];
|
|
74
|
+
if (!option.default)
|
|
75
|
+
continue;
|
|
76
|
+
const quantity = option.quantity || 1;
|
|
77
|
+
// Add option price to total
|
|
78
|
+
total += (option.price || 0) * quantity;
|
|
79
|
+
// Recursively process nested modifiers
|
|
80
|
+
if (option.modifiers?.length > 0) {
|
|
81
|
+
total += calcModifiersTotal(option.modifiers);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return total;
|
|
87
|
+
}
|
|
88
|
+
function findFirstError(modifiers, parentPath = '', parentOptionName = '') {
|
|
89
|
+
if (error)
|
|
90
|
+
return; // Early exit if error already found
|
|
91
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
92
|
+
const modifier = modifiers[i];
|
|
93
|
+
const currentPath = parentPath ? `${parentPath}_${modifier._id}` : modifier._id;
|
|
94
|
+
let totalDefaults = 0;
|
|
95
|
+
if (modifier.default) {
|
|
96
|
+
for (let j = 0; j < modifier.options.length; j++) {
|
|
97
|
+
const option = modifier.options[j];
|
|
98
|
+
if (!option.default)
|
|
99
|
+
continue;
|
|
100
|
+
const quantity = option.quantity || 1;
|
|
101
|
+
totalDefaults += quantity;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Check if current modifier meets minimum/maximum requirements
|
|
105
|
+
const minRequired = modifier.min_aggregate_options_quantity ?? modifier.min_num_options ?? 0;
|
|
106
|
+
const maxRequired = modifier.max_aggregate_options_quantity ?? modifier.max_num_options ?? Infinity;
|
|
107
|
+
if (minRequired > 0 && totalDefaults < minRequired) {
|
|
108
|
+
const modifierName = parentOptionName ? `${parentOptionName} > ${modifier.name}` : modifier.name;
|
|
109
|
+
error = {
|
|
110
|
+
error_id: currentPath,
|
|
111
|
+
error_message: `Select ${minRequired > 1 ? `${minRequired} options` : 'an option'} for ${modifierName}`,
|
|
112
|
+
};
|
|
113
|
+
return; // Stop immediately when error found
|
|
114
|
+
}
|
|
115
|
+
else if (totalDefaults > maxRequired) {
|
|
116
|
+
const modifierName = parentOptionName ? `${parentOptionName} › ${modifier.name}` : modifier.name;
|
|
117
|
+
error = {
|
|
118
|
+
error_id: currentPath,
|
|
119
|
+
error_message: `Max ${maxRequired > 1 ? `${maxRequired} options` : 'option'} Selectable for ${modifierName}`,
|
|
120
|
+
};
|
|
121
|
+
return; // Stop immediately when error found
|
|
122
|
+
}
|
|
123
|
+
// Process nested modifiers depth-first
|
|
124
|
+
if (modifier.default) {
|
|
125
|
+
for (let j = 0; j < modifier.options.length; j++) {
|
|
126
|
+
const option = modifier.options[j];
|
|
127
|
+
if (!option.default)
|
|
128
|
+
continue;
|
|
129
|
+
// Recursively check nested modifiers
|
|
130
|
+
if (option.modifiers?.length > 0) {
|
|
131
|
+
const optionPath = `${currentPath}_${option._id}`;
|
|
132
|
+
findFirstError(option.modifiers, optionPath, option.name);
|
|
133
|
+
if (error)
|
|
134
|
+
return; // Stop if error found in nested modifiers
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const modifiersTotal = calcModifiersTotal(orderEngineItem.modifiers);
|
|
141
|
+
findFirstError(orderEngineItem.modifiers);
|
|
142
|
+
// Item total without tax amount and without discount amount
|
|
143
|
+
// total is 20
|
|
144
|
+
const itemTotalWithoutTaxAndWithoutDiscount = (orderEngineItem.price + modifiersTotal) * orderEngineItem.quantity;
|
|
145
|
+
// Item discount details
|
|
146
|
+
// discount is 50%
|
|
147
|
+
// 50% of 20 is 10
|
|
148
|
+
const item_discount_details = (0, store_1.getDiscountDetails)(orderEngineItem.item_discount_details, itemTotalWithoutTaxAndWithoutDiscount);
|
|
149
|
+
// Item total without tax amount and with discount amount
|
|
150
|
+
// 20 - 10 = 10
|
|
151
|
+
// 10 is the item total without tax amount and with discount amount
|
|
152
|
+
const itemTotalWithoutTaxAndWithDiscount = itemTotalWithoutTaxAndWithoutDiscount - (item_discount_details?.total_discount ?? 0);
|
|
153
|
+
// Item tax amount with discount amount
|
|
154
|
+
// tax is 50%
|
|
155
|
+
// tax amount of 50% of 10 is 5
|
|
156
|
+
const itemTaxAmount = (0, common_1.getPercentageAmount)(itemTotalWithoutTaxAndWithDiscount, orderEngineItem.tax_rate);
|
|
157
|
+
const itemTotal = (0, common_1.parseNum)(itemTotalWithoutTaxAndWithoutDiscount + itemTaxAmount);
|
|
158
|
+
const itemSubtotal = (0, common_1.parseNum)(itemTotalWithoutTaxAndWithDiscount + itemTaxAmount);
|
|
159
|
+
const updatedOrderEngineItem = {
|
|
160
|
+
...orderEngineItem,
|
|
161
|
+
gross_total: itemTotal,
|
|
162
|
+
subtotal: itemSubtotal,
|
|
163
|
+
item_discount_details,
|
|
164
|
+
error_id: error?.error_id,
|
|
165
|
+
error_message: error?.error_message,
|
|
166
|
+
};
|
|
167
|
+
return updatedOrderEngineItem;
|
|
168
|
+
}
|
|
169
|
+
// ==========================================================><====================================================
|
|
170
|
+
function checkIfModifiersExist(modifiers, platform) {
|
|
171
|
+
if (!modifiers || !platform)
|
|
172
|
+
return false;
|
|
173
|
+
return modifiers.some((modifier) => modifier.active &&
|
|
174
|
+
modifier.options.some((option) => option.active &&
|
|
175
|
+
!option.excluded_platforms.includes(platform) &&
|
|
176
|
+
(0, platform_catalog_1.findApplicableSchedule)(option.item_modifier_option_special_hours, platform) !== false));
|
|
177
|
+
}
|
|
178
|
+
/* =========================>POS Actions<============================ */
|
|
179
|
+
function makeSpaceForFreeOptions(options, num_free_options) {
|
|
180
|
+
// Login for implementing free items
|
|
181
|
+
if (!num_free_options)
|
|
182
|
+
return options;
|
|
183
|
+
const defaultPriceOptions = options
|
|
184
|
+
.filter((option) => option.default)
|
|
185
|
+
.sort((a, b) => a.price * a.quantity - b.price * b.quantity)
|
|
186
|
+
.map((option, index) => index + 1 > num_free_options ? { ...option, is_free: false } : { ...option, is_free: true });
|
|
187
|
+
const nonDefaultOptions = [];
|
|
188
|
+
for (let i = 0; i < options.length; i++) {
|
|
189
|
+
const option = options[i];
|
|
190
|
+
if (!option.default) {
|
|
191
|
+
nonDefaultOptions.push({ ...option, is_free: false });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return [...defaultPriceOptions, ...nonDefaultOptions].sort((a, b) => a.sort_id - b.sort_id);
|
|
195
|
+
}
|
|
196
|
+
function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderItemModifiers, platform, tenantId, excludeRefs, zeroPriceRefs, loyaltyRefs, voucherRefs, keepOptionalModifiersAtBottom, soldoutModifiers, depth = 0, }) {
|
|
197
|
+
function getSortedModifiers(modifiers = []) {
|
|
198
|
+
const sortedModifiers = modifiers.sort((a, b) => a.sort_id - b.sort_id);
|
|
199
|
+
return sortedModifiers;
|
|
200
|
+
}
|
|
201
|
+
function getSortedOptions(options = []) {
|
|
202
|
+
return options.sort((a, b) => a.sort_id - b.sort_id);
|
|
203
|
+
}
|
|
204
|
+
const filteredModifiers = (0, platform_catalog_1.getPlatformModifiers)(modifiers, platform);
|
|
205
|
+
const orderEngineModifiers = [];
|
|
206
|
+
if (!platform || !filteredModifiers || filteredModifiers.length === 0)
|
|
207
|
+
return [];
|
|
208
|
+
let sortedModifiers = getSortedModifiers(filteredModifiers);
|
|
209
|
+
if (keepOptionalModifiersAtBottom) {
|
|
210
|
+
const requiredModifiers = [];
|
|
211
|
+
const optionalModifiers = [];
|
|
212
|
+
sortedModifiers.forEach((modifier) => {
|
|
213
|
+
const isRequired = (modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
214
|
+
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0);
|
|
215
|
+
if (isRequired) {
|
|
216
|
+
requiredModifiers.push(modifier);
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
optionalModifiers.push(modifier);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
sortedModifiers = [...requiredModifiers, ...optionalModifiers];
|
|
223
|
+
}
|
|
224
|
+
const sortedModifiersLength = sortedModifiers.length;
|
|
225
|
+
for (let i = 0; i < sortedModifiersLength; i++) {
|
|
226
|
+
const modifier = sortedModifiers[i];
|
|
227
|
+
if (modifier.options.length === 0)
|
|
228
|
+
continue;
|
|
229
|
+
// If excludeRefs is present then we exclude those modifiers
|
|
230
|
+
if (excludeRefs != null && excludeRefs.includes(modifier.ref))
|
|
231
|
+
continue;
|
|
232
|
+
const orderItemModifier = orderItemModifiers?.find((orderModifier) => orderModifier._id === modifier._id);
|
|
233
|
+
const orderEngineSingleModifier = {
|
|
234
|
+
...modifier,
|
|
235
|
+
depth,
|
|
236
|
+
default: false,
|
|
237
|
+
options: [],
|
|
238
|
+
};
|
|
239
|
+
const sortedOptions = getSortedOptions(modifier.options);
|
|
240
|
+
const sortedOptionsLength = sortedOptions.length;
|
|
241
|
+
let totalDefaultOptions = 0;
|
|
242
|
+
for (let j = 0; j < sortedOptionsLength; j++) {
|
|
243
|
+
const option = sortedOptions[j];
|
|
244
|
+
if (excludeRefs != null && excludeRefs.includes(option.ref))
|
|
245
|
+
continue;
|
|
246
|
+
// Default values would be used in case of new order
|
|
247
|
+
const { modifiers: orderItemOptionModifiers, is_free = false, price = (0, platform_catalog_1.getPriceEnum)(option.price, platform), quantity = modifier.min_option_choice_quantity || 1, _id, } = orderItemModifier?.options.find((orderOption) => orderOption._id === option._id) ?? {};
|
|
248
|
+
let qty = quantity;
|
|
249
|
+
const isSoldout = option.sold_out.includes(tenantId) || soldoutModifiers?.includes(option.ref);
|
|
250
|
+
let isDefaultOption = false;
|
|
251
|
+
if (!isSoldout && option.active) {
|
|
252
|
+
if (_id != null) {
|
|
253
|
+
isDefaultOption = true;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
isDefaultOption = Boolean(option.default) && totalDefaultOptions < (modifier.max_num_options ?? 0);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (isDefaultOption) {
|
|
260
|
+
totalDefaultOptions++;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
qty = 1;
|
|
264
|
+
}
|
|
265
|
+
const newModifiers = convertCatalogItemModifierToOrderEngineItemModifier({
|
|
266
|
+
modifiers: option.modifiers,
|
|
267
|
+
orderItemModifiers: orderItemOptionModifiers,
|
|
268
|
+
platform,
|
|
269
|
+
tenantId,
|
|
270
|
+
excludeRefs,
|
|
271
|
+
zeroPriceRefs,
|
|
272
|
+
loyaltyRefs,
|
|
273
|
+
voucherRefs,
|
|
274
|
+
keepOptionalModifiersAtBottom,
|
|
275
|
+
soldoutModifiers,
|
|
276
|
+
depth: depth + 1,
|
|
277
|
+
});
|
|
278
|
+
// If zeroPriceRefs is present then we set the price to 0
|
|
279
|
+
const optionPrice = zeroPriceRefs != null && (zeroPriceRefs.includes(option.ref) || zeroPriceRefs.includes(modifier.ref))
|
|
280
|
+
? 0
|
|
281
|
+
: price;
|
|
282
|
+
const orderEngineSingleOption = {
|
|
283
|
+
...option,
|
|
284
|
+
default: isDefaultOption,
|
|
285
|
+
price: optionPrice,
|
|
286
|
+
quantity: qty,
|
|
287
|
+
modifiers: newModifiers,
|
|
288
|
+
is_free,
|
|
289
|
+
loyalty_applied: false,
|
|
290
|
+
voucher_applied: false,
|
|
291
|
+
};
|
|
292
|
+
if (loyaltyRefs != null &&
|
|
293
|
+
(loyaltyRefs.includes(orderEngineSingleOption.ref) || loyaltyRefs.includes(modifier.ref))) {
|
|
294
|
+
orderEngineSingleOption.loyalty_applied = true;
|
|
295
|
+
}
|
|
296
|
+
if (voucherRefs != null &&
|
|
297
|
+
(voucherRefs.includes(orderEngineSingleOption.ref) || voucherRefs.includes(modifier.ref))) {
|
|
298
|
+
orderEngineSingleOption.voucher_applied = true;
|
|
299
|
+
}
|
|
300
|
+
orderEngineSingleModifier.options.push(orderEngineSingleOption);
|
|
301
|
+
}
|
|
302
|
+
if (!orderItemModifier) {
|
|
303
|
+
const options = makeSpaceForFreeOptions(orderEngineSingleModifier.options, modifier.num_free_options);
|
|
304
|
+
orderEngineSingleModifier.options = options;
|
|
305
|
+
}
|
|
306
|
+
orderEngineSingleModifier.default = totalDefaultOptions > 0;
|
|
307
|
+
orderEngineModifiers.push(orderEngineSingleModifier);
|
|
308
|
+
}
|
|
309
|
+
return orderEngineModifiers;
|
|
310
|
+
}
|
|
311
|
+
/* ==========================================================><==================================================== */
|
|
312
|
+
function convertOrderEngineOptionsToOrderItemOptions(options, tenantId) {
|
|
313
|
+
const newOptions = [];
|
|
314
|
+
for (let i = 0; i < options.length; i++) {
|
|
315
|
+
const option = options[i];
|
|
316
|
+
if (!option.default || !option.active)
|
|
317
|
+
continue;
|
|
318
|
+
newOptions.push({
|
|
319
|
+
_id: option._id,
|
|
320
|
+
ref: option.ref,
|
|
321
|
+
name: option.name,
|
|
322
|
+
price: option.price,
|
|
323
|
+
quantity: option.quantity,
|
|
324
|
+
is_free: option.is_free,
|
|
325
|
+
modifiers: convertOrderEngineModifiersToOrderItemModifiers(option.modifiers, tenantId),
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
return newOptions;
|
|
329
|
+
}
|
|
330
|
+
function convertOrderEngineModifiersToOrderItemModifiers(modifiers, tenantId) {
|
|
331
|
+
const newModifiers = [];
|
|
332
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
333
|
+
const modifier = modifiers[i];
|
|
334
|
+
if (!modifier.default || !modifier.active)
|
|
335
|
+
continue;
|
|
336
|
+
const options = convertOrderEngineOptionsToOrderItemOptions(modifier.options, tenantId);
|
|
337
|
+
if (options.length === 0)
|
|
338
|
+
continue;
|
|
339
|
+
newModifiers.push({
|
|
340
|
+
_id: modifier._id,
|
|
341
|
+
ref: modifier.ref,
|
|
342
|
+
name: modifier.name,
|
|
343
|
+
options,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
return newModifiers;
|
|
347
|
+
}
|
|
348
|
+
function convertOrderEngineItemToOrderItem(orderItem, tenantId) {
|
|
349
|
+
return {
|
|
350
|
+
_id: orderItem._id,
|
|
351
|
+
item_id: orderItem.item_id,
|
|
352
|
+
menu_id: orderItem.menu_id,
|
|
353
|
+
item_type: orderItem.item_type,
|
|
354
|
+
is_ready: orderItem.is_ready,
|
|
355
|
+
is_split: orderItem.is_split,
|
|
356
|
+
name: orderItem.name,
|
|
357
|
+
price: orderItem.price,
|
|
358
|
+
subtotal: orderItem.price,
|
|
359
|
+
item_discount_details: orderItem.item_discount_details,
|
|
360
|
+
quantity: orderItem.quantity,
|
|
361
|
+
tax_rate: orderItem.tax_rate,
|
|
362
|
+
special_instructions: orderItem.special_instructions,
|
|
363
|
+
modifiers: convertOrderEngineModifiersToOrderItemModifiers(orderItem.modifiers, tenantId),
|
|
364
|
+
// These values will be auto calculated
|
|
365
|
+
_discount_amount: 0,
|
|
366
|
+
_gross_amount: 0,
|
|
367
|
+
_gst_amount: 0,
|
|
368
|
+
_net_amount: 0,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
// ==========================================================><====================================================
|
|
372
|
+
function convertItemDiscountToOrderItemDiscount(discount_amount, is_special_discount_percentage, platform, discountId) {
|
|
373
|
+
// apply discount to item if its present
|
|
374
|
+
let defaultItemDiscountDetails = null;
|
|
375
|
+
// If it's a new item and there is a discount on the item
|
|
376
|
+
if (discount_amount) {
|
|
377
|
+
const discountAmount = (0, platform_catalog_1.getPriceEnum)(discount_amount, platform);
|
|
378
|
+
const discountName = 'Special Discount';
|
|
379
|
+
// apply discount to item
|
|
380
|
+
defaultItemDiscountDetails = {
|
|
381
|
+
...(defaultItemDiscountDetails ?? {}),
|
|
382
|
+
special_discount: discountAmount,
|
|
383
|
+
special_discount_id: discountId,
|
|
384
|
+
special_discount_name: discountName,
|
|
385
|
+
is_special_discount_percentage,
|
|
386
|
+
// This will be auto calculated
|
|
387
|
+
total_discount: 0,
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
return defaultItemDiscountDetails;
|
|
391
|
+
}
|
|
392
|
+
function convertCatalogItemToOrderEngineItem({ item, orderItem, platform, tenantId, excludeRefs, zeroPriceRefs, orderItemType, applyLoyalty, applyVoucher, keepOptionalModifiersAtBottom, defaultMenuId, soldoutModifiers, }) {
|
|
393
|
+
// Default values will be used in case of new order
|
|
394
|
+
// we need to find the applicable schedule for the item
|
|
395
|
+
const applicableSchedule = (0, platform_catalog_1.findApplicableSchedule)(item.item_special_hours, platform);
|
|
396
|
+
const orderEngineModifiers = convertCatalogItemModifierToOrderEngineItemModifier({
|
|
397
|
+
modifiers: item.modifiers,
|
|
398
|
+
orderItemModifiers: orderItem?.modifiers,
|
|
399
|
+
platform,
|
|
400
|
+
tenantId,
|
|
401
|
+
excludeRefs,
|
|
402
|
+
zeroPriceRefs,
|
|
403
|
+
loyaltyRefs: applyLoyalty?.refs,
|
|
404
|
+
voucherRefs: applyVoucher?.refs,
|
|
405
|
+
keepOptionalModifiersAtBottom,
|
|
406
|
+
soldoutModifiers,
|
|
407
|
+
});
|
|
408
|
+
let itemPrice = item.price;
|
|
409
|
+
let discount_amount = item.discount_amount;
|
|
410
|
+
let is_special_discount_percentage = item.is_discount_percentage;
|
|
411
|
+
const defaultItemPrice = zeroPriceRefs != null && zeroPriceRefs.includes(item._id) ? 0 : (0, platform_catalog_1.getPriceEnum)(itemPrice, platform);
|
|
412
|
+
// if applicable schedule is an object then we need to check its price and discount
|
|
413
|
+
if (typeof applicableSchedule !== 'boolean') {
|
|
414
|
+
// apply price to item if its present
|
|
415
|
+
if (applicableSchedule.price != null) {
|
|
416
|
+
itemPrice = applicableSchedule.price;
|
|
417
|
+
}
|
|
418
|
+
// apply discount to item if its present
|
|
419
|
+
if (applicableSchedule.discount_amount != null) {
|
|
420
|
+
discount_amount = applicableSchedule.discount_amount;
|
|
421
|
+
is_special_discount_percentage = applicableSchedule.is_discount_percentage;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const { _id = (0, bson_objectid_1.default)().toHexString(), menu_id = defaultMenuId,
|
|
425
|
+
// For New Item, If zeroPriceRefs is present then we set the price to 0
|
|
426
|
+
price = defaultItemPrice, tax_rate = (0, platform_catalog_1.getPriceEnum)(item.tax_rate, platform), quantity = 1, subtotal = 0, special_instructions = '', item_discount_details = convertItemDiscountToOrderItemDiscount(discount_amount, is_special_discount_percentage, platform, item._id), item_type = orderItemType, is_ready, is_split, } = orderItem ?? {};
|
|
427
|
+
const orderEngineItem = syncOrderEngineItem({
|
|
428
|
+
_id,
|
|
429
|
+
category_id: item.category_id,
|
|
430
|
+
item_id: item._id,
|
|
431
|
+
name: item.name,
|
|
432
|
+
description: item.description,
|
|
433
|
+
image_url: item.image_url,
|
|
434
|
+
// For Edit Case
|
|
435
|
+
menu_id,
|
|
436
|
+
item_type,
|
|
437
|
+
is_ready,
|
|
438
|
+
is_split,
|
|
439
|
+
price,
|
|
440
|
+
tax_rate,
|
|
441
|
+
quantity,
|
|
442
|
+
subtotal,
|
|
443
|
+
gross_total: 0,
|
|
444
|
+
loyalty_applied: applyLoyalty != null && applyLoyalty.refs.includes(item._id),
|
|
445
|
+
voucher_applied: applyVoucher != null && applyVoucher.refs.includes(item._id),
|
|
446
|
+
special_instructions,
|
|
447
|
+
item_discount_details,
|
|
448
|
+
modifiers: orderEngineModifiers,
|
|
449
|
+
});
|
|
450
|
+
return orderEngineItem;
|
|
451
|
+
}
|
|
452
|
+
function hasRequiredModifier(currentModifiers) {
|
|
453
|
+
if (!currentModifiers)
|
|
454
|
+
return false;
|
|
455
|
+
return currentModifiers.some((modifier) => modifier.active && Boolean(modifier.min_num_options || modifier.min_aggregate_options_quantity));
|
|
456
|
+
}
|
|
457
|
+
/* ==========================================================><==================================================== */
|
|
458
|
+
function convertOptionsToOrderItemOptions(options, min_option_choice_quantity, platform, is_free = false, tenantId) {
|
|
459
|
+
if (!platform)
|
|
460
|
+
return [];
|
|
461
|
+
const newOptions = [];
|
|
462
|
+
for (let i = 0; i < options.length; i++) {
|
|
463
|
+
const option = options[i];
|
|
464
|
+
if (!option.default || !option.active || option.excluded_platforms.includes(platform))
|
|
465
|
+
continue;
|
|
466
|
+
const price = (0, platform_catalog_1.getPriceEnum)(option.price, platform);
|
|
467
|
+
newOptions.push({
|
|
468
|
+
_id: option._id,
|
|
469
|
+
ref: option.ref,
|
|
470
|
+
name: option.name,
|
|
471
|
+
price,
|
|
472
|
+
quantity: min_option_choice_quantity || 1,
|
|
473
|
+
is_free,
|
|
474
|
+
modifiers: convertItemModifiersToOrderItemModifiers(option.modifiers, platform, tenantId),
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return newOptions;
|
|
478
|
+
}
|
|
479
|
+
function convertItemModifiersToOrderItemModifiers(modifiers, platform, tenantId) {
|
|
480
|
+
if (!modifiers || !platform)
|
|
481
|
+
return [];
|
|
482
|
+
const newModifiers = [];
|
|
483
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
484
|
+
const modifier = modifiers[i];
|
|
485
|
+
if (!modifier.active)
|
|
486
|
+
continue;
|
|
487
|
+
const options = convertOptionsToOrderItemOptions(modifier.options, modifier.min_option_choice_quantity, platform, false, tenantId);
|
|
488
|
+
if (options.length === 0)
|
|
489
|
+
continue;
|
|
490
|
+
newModifiers.push({
|
|
491
|
+
_id: modifier._id,
|
|
492
|
+
ref: modifier.ref,
|
|
493
|
+
name: modifier.name,
|
|
494
|
+
options,
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return newModifiers;
|
|
498
|
+
}
|
|
499
|
+
function convertItemToOrderItem(item, menu_id, platform, tenantId, orderItemType = constants_1.ORDER_ITEM_TYPE_ENUM.ITEM) {
|
|
500
|
+
const _id = (0, bson_objectid_1.default)().toHexString();
|
|
501
|
+
const price = (0, platform_catalog_1.getPriceEnum)(item.price, platform);
|
|
502
|
+
const tax_rate = (0, platform_catalog_1.getPriceEnum)(item.tax_rate, platform);
|
|
503
|
+
// apply discount to item if its present
|
|
504
|
+
let defaultItemDiscountDetails = null;
|
|
505
|
+
// If it's a new item and there is a discount on the item
|
|
506
|
+
if (item.discount_amount != null) {
|
|
507
|
+
const discountAmount = (0, platform_catalog_1.getPriceEnum)(item.discount_amount, platform);
|
|
508
|
+
const discountId = item._id;
|
|
509
|
+
const discountName = 'Special Discount';
|
|
510
|
+
// apply discount to item
|
|
511
|
+
defaultItemDiscountDetails = {
|
|
512
|
+
...(defaultItemDiscountDetails ?? {}),
|
|
513
|
+
special_discount: discountAmount,
|
|
514
|
+
special_discount_id: discountId,
|
|
515
|
+
special_discount_name: discountName,
|
|
516
|
+
is_special_discount_percentage: item.is_discount_percentage,
|
|
517
|
+
// This will be auto calculated
|
|
518
|
+
total_discount: 0,
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
return {
|
|
522
|
+
_id,
|
|
523
|
+
item_id: item._id,
|
|
524
|
+
menu_id,
|
|
525
|
+
item_type: orderItemType,
|
|
526
|
+
name: item.name,
|
|
527
|
+
price,
|
|
528
|
+
subtotal: price,
|
|
529
|
+
quantity: 1,
|
|
530
|
+
special_instructions: '',
|
|
531
|
+
item_discount_details: defaultItemDiscountDetails,
|
|
532
|
+
tax_rate,
|
|
533
|
+
modifiers: convertItemModifiersToOrderItemModifiers(item.modifiers, platform, tenantId),
|
|
534
|
+
// These values will be auto calculated
|
|
535
|
+
_discount_amount: 0,
|
|
536
|
+
_gross_amount: 0,
|
|
537
|
+
_gst_amount: 0,
|
|
538
|
+
_net_amount: 0,
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
/*
|
|
542
|
+
|
|
543
|
+
*/
|
|
544
|
+
function setCheckFieldInOrderEngineItem(orderEngineItem, identifier, shouldCheck) {
|
|
545
|
+
const setUpdateOptions = (modifier, ids, level) => {
|
|
546
|
+
const optionId = ids[level];
|
|
547
|
+
if (!optionId)
|
|
548
|
+
return modifier.options;
|
|
549
|
+
const isLastLevel = level === ids.length - 1 || level === ids.length - 2;
|
|
550
|
+
const isRadioType = modifier.max_num_options === 1;
|
|
551
|
+
const isChoiceType = modifier.min_option_choice_quantity != null || modifier.max_option_choice_quantity != null;
|
|
552
|
+
const maxNumOptions = modifier.max_num_options ?? 0;
|
|
553
|
+
const maxAggregate = (modifier.max_aggregate_options_quantity != null && modifier.max_aggregate_options_quantity > maxNumOptions
|
|
554
|
+
? modifier.max_aggregate_options_quantity
|
|
555
|
+
: maxNumOptions) || modifier.options.length;
|
|
556
|
+
let newOptions = [];
|
|
557
|
+
let totalDefaults = 0;
|
|
558
|
+
for (let i = 0; i < modifier.options.length; i++) {
|
|
559
|
+
let option = modifier.options[i];
|
|
560
|
+
let isDefault = option.default;
|
|
561
|
+
let modifiers = option.modifiers;
|
|
562
|
+
let quantity = option.quantity || 1;
|
|
563
|
+
if (option._id === optionId) {
|
|
564
|
+
if (isLastLevel) {
|
|
565
|
+
isDefault = shouldCheck;
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
isDefault = true;
|
|
569
|
+
modifiers = setUpdateModifiers(option.modifiers, ids, level + 1);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (isChoiceType) {
|
|
573
|
+
if (isDefault) {
|
|
574
|
+
if (isLastLevel && option._id === optionId) {
|
|
575
|
+
quantity = modifier.min_option_choice_quantity || 1;
|
|
576
|
+
}
|
|
577
|
+
totalDefaults += quantity;
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
quantity = 1;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
else if (isRadioType) {
|
|
584
|
+
if (option._id !== optionId && shouldCheck) {
|
|
585
|
+
isDefault = false;
|
|
586
|
+
}
|
|
587
|
+
quantity = 1;
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
quantity = 1;
|
|
591
|
+
if (isDefault) {
|
|
592
|
+
totalDefaults += quantity;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
option = { ...option, default: isDefault, modifiers, quantity };
|
|
596
|
+
newOptions.push(option);
|
|
597
|
+
}
|
|
598
|
+
if (isLastLevel) {
|
|
599
|
+
if (totalDefaults > maxAggregate) {
|
|
600
|
+
newOptions = newOptions.map((option) => (option._id === optionId ? { ...option, default: false } : option));
|
|
601
|
+
}
|
|
602
|
+
newOptions = makeSpaceForFreeOptions(newOptions, modifier.num_free_options);
|
|
603
|
+
}
|
|
604
|
+
return newOptions;
|
|
605
|
+
};
|
|
606
|
+
const setUpdateModifiers = (currentModifiers, ids, level) => {
|
|
607
|
+
const modifierId = ids[level];
|
|
608
|
+
if (!modifierId)
|
|
609
|
+
return currentModifiers;
|
|
610
|
+
const newModifiers = [];
|
|
611
|
+
for (let i = 0; i < currentModifiers.length; i++) {
|
|
612
|
+
let modifier = currentModifiers[i];
|
|
613
|
+
if (modifier._id === modifierId) {
|
|
614
|
+
const options = setUpdateOptions(modifier, ids, level + 1);
|
|
615
|
+
modifier = { ...modifier, default: true, options };
|
|
616
|
+
}
|
|
617
|
+
newModifiers.push(modifier);
|
|
618
|
+
}
|
|
619
|
+
return newModifiers;
|
|
620
|
+
};
|
|
621
|
+
const allIds = identifier.split('_').filter((id) => id.trim() !== '');
|
|
622
|
+
const modifiers = setUpdateModifiers(orderEngineItem.modifiers, allIds, 0);
|
|
623
|
+
const updatedOrderEngineItem = syncOrderEngineItem({ ...orderEngineItem, modifiers });
|
|
624
|
+
return updatedOrderEngineItem;
|
|
625
|
+
}
|
|
626
|
+
function setIncrementOrderEngineItemQuantity(orderEngineItem, increment) {
|
|
627
|
+
const newQuantity = increment + orderEngineItem.quantity;
|
|
628
|
+
const item_discount_details = (0, store_1.getItemQuantityChangeResults)({
|
|
629
|
+
newQuantity,
|
|
630
|
+
prevQuantity: orderEngineItem.quantity,
|
|
631
|
+
prevItemDiscountDetails: orderEngineItem.item_discount_details,
|
|
632
|
+
});
|
|
633
|
+
const updatedOrderEngineItem = syncOrderEngineItem({
|
|
634
|
+
...orderEngineItem,
|
|
635
|
+
quantity: newQuantity,
|
|
636
|
+
item_discount_details,
|
|
637
|
+
});
|
|
638
|
+
return updatedOrderEngineItem;
|
|
639
|
+
}
|
|
640
|
+
function setUpdateSelectedOrderEngineOptionQuantity(orderEngineItem, identifier, newQuantity, isIncrement) {
|
|
641
|
+
const setUpdateOptions = (modifier, ids, level) => {
|
|
642
|
+
const optionId = ids[level];
|
|
643
|
+
if (!optionId)
|
|
644
|
+
return modifier.options;
|
|
645
|
+
const isLastLevel = level === ids.length - 1 || level === ids.length - 2;
|
|
646
|
+
const minChoiceQty = modifier.min_option_choice_quantity || 1;
|
|
647
|
+
const maxNumOptions = modifier.max_num_options ?? 0;
|
|
648
|
+
const maxAggregate = (modifier.max_aggregate_options_quantity != null && modifier.max_aggregate_options_quantity > maxNumOptions
|
|
649
|
+
? modifier.max_aggregate_options_quantity
|
|
650
|
+
: maxNumOptions) || modifier.options.length;
|
|
651
|
+
let newOptions = [];
|
|
652
|
+
let totalDefaults = 0;
|
|
653
|
+
let prevOptionQuantity = 1;
|
|
654
|
+
for (let i = 0; i < modifier.options.length; i++) {
|
|
655
|
+
let option = modifier.options[i];
|
|
656
|
+
let quantity = option.quantity || 1;
|
|
657
|
+
let modifiers = option.modifiers;
|
|
658
|
+
let isDefault = option.default;
|
|
659
|
+
if (option._id === optionId) {
|
|
660
|
+
if (isLastLevel) {
|
|
661
|
+
prevOptionQuantity = quantity;
|
|
662
|
+
quantity = isIncrement ? quantity + newQuantity : newQuantity;
|
|
663
|
+
// If quantity is less than the threshold, unselect the option and set quantity to 1
|
|
664
|
+
if (quantity < minChoiceQty) {
|
|
665
|
+
isDefault = false;
|
|
666
|
+
quantity = 1;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
modifiers = setUpdateModifiers(option.modifiers, ids, level + 1);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
if (isDefault) {
|
|
674
|
+
totalDefaults += quantity;
|
|
675
|
+
}
|
|
676
|
+
option = { ...option, default: isDefault, quantity, modifiers };
|
|
677
|
+
newOptions.push(option);
|
|
678
|
+
}
|
|
679
|
+
if (isLastLevel) {
|
|
680
|
+
if (totalDefaults > maxAggregate) {
|
|
681
|
+
newOptions = newOptions.map((option) => option._id === optionId ? { ...option, quantity: prevOptionQuantity || 1 } : option);
|
|
682
|
+
}
|
|
683
|
+
newOptions = makeSpaceForFreeOptions(newOptions, modifier.num_free_options);
|
|
684
|
+
}
|
|
685
|
+
return newOptions;
|
|
686
|
+
};
|
|
687
|
+
const setUpdateModifiers = (currentModifiers, ids, level) => {
|
|
688
|
+
const modifierId = ids[level];
|
|
689
|
+
if (!modifierId)
|
|
690
|
+
return currentModifiers;
|
|
691
|
+
const newModifiers = [];
|
|
692
|
+
for (let i = 0; i < currentModifiers.length; i++) {
|
|
693
|
+
let modifier = currentModifiers[i];
|
|
694
|
+
if (modifier._id === modifierId) {
|
|
695
|
+
const options = setUpdateOptions(modifier, ids, level + 1);
|
|
696
|
+
modifier = { ...modifier, options };
|
|
697
|
+
}
|
|
698
|
+
newModifiers.push(modifier);
|
|
699
|
+
}
|
|
700
|
+
return newModifiers;
|
|
701
|
+
};
|
|
702
|
+
const allIds = identifier.split('_').filter((id) => id.trim() !== '');
|
|
703
|
+
const modifiers = setUpdateModifiers(orderEngineItem.modifiers, allIds, 0);
|
|
704
|
+
const updatedOrderEngineItem = syncOrderEngineItem({ ...orderEngineItem, modifiers });
|
|
705
|
+
return updatedOrderEngineItem;
|
|
706
|
+
}
|
|
707
|
+
function getFlattenedOrderEngineItemModifiers(modifiers, keepOptionalModifiersAtBottom) {
|
|
708
|
+
let result = [];
|
|
709
|
+
const flatten = (modifiers, parentId = '') => {
|
|
710
|
+
modifiers.forEach((modifier) => {
|
|
711
|
+
let newParentId = `${parentId}_${modifier._id}`;
|
|
712
|
+
if (parentId.length === 0) {
|
|
713
|
+
newParentId = modifier._id;
|
|
714
|
+
}
|
|
715
|
+
const updatedOptions = [...modifier.options];
|
|
716
|
+
const subModifiers = [];
|
|
717
|
+
modifier.options?.forEach((option, index) => {
|
|
718
|
+
if (option.default && option.modifiers.length > 0) {
|
|
719
|
+
updatedOptions[index] = {
|
|
720
|
+
...option,
|
|
721
|
+
modifiers: [],
|
|
722
|
+
};
|
|
723
|
+
option.modifiers.forEach((subModifier) => {
|
|
724
|
+
const updatedSubModifier = {
|
|
725
|
+
...subModifier,
|
|
726
|
+
_id: `${option._id}_${subModifier._id}`,
|
|
727
|
+
name: `${option.name} › ${subModifier.name}`,
|
|
728
|
+
};
|
|
729
|
+
subModifiers.push(updatedSubModifier);
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
result.push({ ...modifier, _id: newParentId, options: updatedOptions });
|
|
734
|
+
flatten(subModifiers, newParentId);
|
|
735
|
+
});
|
|
736
|
+
};
|
|
737
|
+
flatten(modifiers);
|
|
738
|
+
if (keepOptionalModifiersAtBottom) {
|
|
739
|
+
const required = [];
|
|
740
|
+
const optional = [];
|
|
741
|
+
result.forEach((modifier) => {
|
|
742
|
+
const isRequired = (modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
743
|
+
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0);
|
|
744
|
+
if (isRequired) {
|
|
745
|
+
required.push(modifier);
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
optional.push(modifier);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
result = [...required, ...optional];
|
|
752
|
+
}
|
|
753
|
+
return result;
|
|
754
|
+
}
|