@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,2070 @@
|
|
|
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.getOrderItemComaparableData = void 0;
|
|
7
|
+
exports.getItemQuantityChangeResults = getItemQuantityChangeResults;
|
|
8
|
+
exports.getModifier = getModifier;
|
|
9
|
+
exports.syncOrderCoursesWithOrderItemsInCart = syncOrderCoursesWithOrderItemsInCart;
|
|
10
|
+
exports.calculateItemModifiersPrice = calculateItemModifiersPrice;
|
|
11
|
+
exports.getDiscountDetails = getDiscountDetails;
|
|
12
|
+
exports.calculateItemTotalWithTax = calculateItemTotalWithTax;
|
|
13
|
+
exports.getServiceFeeAmount = getServiceFeeAmount;
|
|
14
|
+
exports.getSurchargeAmount = getSurchargeAmount;
|
|
15
|
+
exports.calculateGstForItem = calculateGstForItem;
|
|
16
|
+
exports.calculateCartOrderInfoAndSyncData = calculateCartOrderInfoAndSyncData;
|
|
17
|
+
exports.getAddItemToCartData = getAddItemToCartData;
|
|
18
|
+
exports.getSplitCartItemToTwo = getSplitCartItemToTwo;
|
|
19
|
+
exports.getAddItemsToCartData = getAddItemsToCartData;
|
|
20
|
+
exports.getUpdateItemInCartData = getUpdateItemInCartData;
|
|
21
|
+
exports.getUpdateItemsInCartData = getUpdateItemsInCartData;
|
|
22
|
+
exports.getUpdateCartInfoData = getUpdateCartInfoData;
|
|
23
|
+
exports.getRemoveItemFromCartData = getRemoveItemFromCartData;
|
|
24
|
+
exports.getUpdatedCartInfoOnInit = getUpdatedCartInfoOnInit;
|
|
25
|
+
exports.getChangeCourseForItemData = getChangeCourseForItemData;
|
|
26
|
+
exports.getChangeCourseStatusData = getChangeCourseStatusData;
|
|
27
|
+
exports.getCartItemsObj = getCartItemsObj;
|
|
28
|
+
exports.getRemoveOfferFromCartData = getRemoveOfferFromCartData;
|
|
29
|
+
exports.getRemoveAllOffersFromCartData = getRemoveAllOffersFromCartData;
|
|
30
|
+
exports.calculateEligibleOfferDiscountDetails = calculateEligibleOfferDiscountDetails;
|
|
31
|
+
exports.getSyncOffersWithCartData = getSyncOffersWithCartData;
|
|
32
|
+
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
33
|
+
const lodash_1 = require("lodash");
|
|
34
|
+
const constants_1 = require("../../constants");
|
|
35
|
+
const utils_1 = require("../utils");
|
|
36
|
+
const platform_catalog_1 = require("../utils/platform-catalog");
|
|
37
|
+
function getItemQuantityChangeResults({ prevQuantity, newQuantity, prevItemDiscountDetails, }) {
|
|
38
|
+
let item_discount_details = prevItemDiscountDetails;
|
|
39
|
+
if (item_discount_details != null &&
|
|
40
|
+
item_discount_details.special_discount_id != null &&
|
|
41
|
+
item_discount_details.special_discount != null) {
|
|
42
|
+
let special_discount = item_discount_details.special_discount;
|
|
43
|
+
if (!item_discount_details.is_special_discount_percentage) {
|
|
44
|
+
const actualDiscount = item_discount_details.special_discount / prevQuantity;
|
|
45
|
+
special_discount = (0, utils_1.parseNum)(actualDiscount * newQuantity);
|
|
46
|
+
}
|
|
47
|
+
item_discount_details = {
|
|
48
|
+
...item_discount_details,
|
|
49
|
+
special_discount,
|
|
50
|
+
total_discount: 0,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return item_discount_details;
|
|
54
|
+
}
|
|
55
|
+
// ==========================================================><====================================================
|
|
56
|
+
function getModifier(_id, allModifiers) {
|
|
57
|
+
if (!allModifiers)
|
|
58
|
+
return null;
|
|
59
|
+
let foundModifier = null;
|
|
60
|
+
let found = false;
|
|
61
|
+
const recursive = (modifiers) => {
|
|
62
|
+
if (found)
|
|
63
|
+
return;
|
|
64
|
+
outer: for (let i = 0; i < modifiers.length; i++) {
|
|
65
|
+
if (found)
|
|
66
|
+
return;
|
|
67
|
+
const modifier = modifiers[i];
|
|
68
|
+
if (modifier._id === _id) {
|
|
69
|
+
foundModifier = modifier;
|
|
70
|
+
found = true;
|
|
71
|
+
break outer;
|
|
72
|
+
}
|
|
73
|
+
for (let j = 0; j < modifier.options.length; j++) {
|
|
74
|
+
const option = modifier.options[j];
|
|
75
|
+
if (option.modifiers != null && option.modifiers.length > 0) {
|
|
76
|
+
recursive(option.modifiers);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
recursive(allModifiers);
|
|
82
|
+
return foundModifier;
|
|
83
|
+
}
|
|
84
|
+
/* ======================><====================== */
|
|
85
|
+
function syncOrderCoursesWithOrderItemsInCart(order, courses) {
|
|
86
|
+
let dinein_details = order.dinein_details;
|
|
87
|
+
// we need to check if the order is dinein
|
|
88
|
+
if (constants_1.PLATFORMS_BY_ORDER_TYPE[constants_1.ORDER_TYPE_ENUM.DINE_IN].includes(order.platform)) {
|
|
89
|
+
// we need to check if the dineinCourses exist
|
|
90
|
+
if (dinein_details?.courses != null) {
|
|
91
|
+
// we get all the items ids from the order
|
|
92
|
+
const categories = order.categories ?? [];
|
|
93
|
+
const itemsIds = [];
|
|
94
|
+
for (let i = 0; i < categories.length; i++) {
|
|
95
|
+
const category = categories[i];
|
|
96
|
+
const items = category.items ?? [];
|
|
97
|
+
for (let j = 0; j < items.length; j++) {
|
|
98
|
+
itemsIds.push(items[j]._id);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// we delete the dineinCourses that are not in the itemsObj
|
|
102
|
+
let dineinCourses = [];
|
|
103
|
+
// we loop through the dineinCourses
|
|
104
|
+
for (let i = 0; i < dinein_details.courses.length; i++) {
|
|
105
|
+
// we get the course
|
|
106
|
+
const course = dinein_details.courses[i];
|
|
107
|
+
// we filter the items ids that are in the course
|
|
108
|
+
const courseItemIds = course.item_ids.filter((id) => itemsIds.includes(id));
|
|
109
|
+
if (courseItemIds.length === 0)
|
|
110
|
+
continue;
|
|
111
|
+
dineinCourses.push({
|
|
112
|
+
...course,
|
|
113
|
+
item_ids: Array.from(new Set(courseItemIds)),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
// if any of the items are not in the dineinCourses we need to assign them to the default
|
|
117
|
+
// this would ensure that all the items are in the dineinCourses
|
|
118
|
+
const itemsNotInCourses = itemsIds.filter((id) => !dineinCourses.some((course) => course.item_ids.includes(id)));
|
|
119
|
+
if (itemsNotInCourses.length > 0) {
|
|
120
|
+
// we check if there is a default course
|
|
121
|
+
const defaultCourse = courses.find((course) => course.default);
|
|
122
|
+
if (defaultCourse != null) {
|
|
123
|
+
// we check if the default course is already in the dineinCourses
|
|
124
|
+
const defaultCourseInDineinCourses = dineinCourses.find((course) => course.course_id === defaultCourse._id);
|
|
125
|
+
if (defaultCourseInDineinCourses) {
|
|
126
|
+
// we add the items to the default course
|
|
127
|
+
defaultCourseInDineinCourses.item_ids = Array.from(new Set(defaultCourseInDineinCourses.item_ids.concat(itemsNotInCourses)));
|
|
128
|
+
}
|
|
129
|
+
// if the default course is not in the dineinCourses we add it
|
|
130
|
+
else {
|
|
131
|
+
dineinCourses.push({
|
|
132
|
+
name: defaultCourse.name,
|
|
133
|
+
course_id: defaultCourse._id,
|
|
134
|
+
item_ids: Array.from(new Set(itemsNotInCourses)),
|
|
135
|
+
called: false,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// if there is no default course we add the items to the first course
|
|
141
|
+
const firstCourse = dineinCourses[0];
|
|
142
|
+
firstCourse.item_ids = Array.from(new Set(firstCourse.item_ids.concat(itemsNotInCourses)));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// we need to find totalCoursesAssigned, if totalCoursesAssigned is not equal to itemsIds.length
|
|
146
|
+
// This would mean there is an error in the algorithm
|
|
147
|
+
// So we would set the dineinCourses to null
|
|
148
|
+
const totalCoursesAssigned = dineinCourses.reduce((acc, course) => acc + course.item_ids.length, 0);
|
|
149
|
+
if (totalCoursesAssigned === 0 || totalCoursesAssigned !== itemsIds.length) {
|
|
150
|
+
dineinCourses = null;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// we need to sort the dineinCourses by the sort_id of the course mentioned in courses array
|
|
154
|
+
const sortIds = courses.reduce((acc, course) => {
|
|
155
|
+
acc[course._id] = course.sort_id;
|
|
156
|
+
return acc;
|
|
157
|
+
}, {});
|
|
158
|
+
dineinCourses.sort((a, b) => sortIds[a.course_id] - sortIds[b.course_id]);
|
|
159
|
+
}
|
|
160
|
+
dinein_details = {
|
|
161
|
+
...dinein_details,
|
|
162
|
+
courses: dineinCourses,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
dinein_details = null;
|
|
168
|
+
}
|
|
169
|
+
const newOrder = {
|
|
170
|
+
...order,
|
|
171
|
+
dinein_details,
|
|
172
|
+
};
|
|
173
|
+
return newOrder;
|
|
174
|
+
}
|
|
175
|
+
/* ======================><====================== */
|
|
176
|
+
function calculateItemModifiersPrice(item) {
|
|
177
|
+
let modifiersTotal = 0;
|
|
178
|
+
const calculations = (modifiers) => {
|
|
179
|
+
const modifiersLength = modifiers.length;
|
|
180
|
+
for (let i = 0; i < modifiersLength; i++) {
|
|
181
|
+
const ex = modifiers[i];
|
|
182
|
+
const options = ex.options;
|
|
183
|
+
const optionsLength = options.length;
|
|
184
|
+
for (let j = 0; j < optionsLength; j++) {
|
|
185
|
+
const op = options[j];
|
|
186
|
+
if (op.is_free)
|
|
187
|
+
continue;
|
|
188
|
+
modifiersTotal += op.price * op.quantity;
|
|
189
|
+
calculations(op.modifiers ?? []);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
calculations(item.modifiers ?? []);
|
|
194
|
+
return modifiersTotal;
|
|
195
|
+
}
|
|
196
|
+
/* ======================><====================== */
|
|
197
|
+
function getDiscountDetails(item_discount_details, itemTotalWithTaxAmount) {
|
|
198
|
+
if (!item_discount_details)
|
|
199
|
+
return null;
|
|
200
|
+
const { special_discount_id, special_discount, is_special_discount_percentage, loyalty_discount_id, loyalty_discount, is_loyalty_discount_percentage, voucher_discount_id, voucher_discount, is_voucher_discount_percentage, } = item_discount_details;
|
|
201
|
+
const discount_details = {
|
|
202
|
+
...item_discount_details,
|
|
203
|
+
total_discount: 0,
|
|
204
|
+
};
|
|
205
|
+
if (special_discount_id && special_discount) {
|
|
206
|
+
if (is_special_discount_percentage) {
|
|
207
|
+
discount_details.total_discount += (0, utils_1.getPercentageAmount)(itemTotalWithTaxAmount, special_discount);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
discount_details.total_discount += special_discount;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
delete discount_details.special_discount_reason;
|
|
215
|
+
}
|
|
216
|
+
if (loyalty_discount_id && loyalty_discount) {
|
|
217
|
+
if (is_loyalty_discount_percentage) {
|
|
218
|
+
discount_details.total_discount += (0, utils_1.getPercentageAmount)(itemTotalWithTaxAmount, loyalty_discount);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
discount_details.total_discount += loyalty_discount;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
delete discount_details.loyalty_discount_reason;
|
|
226
|
+
}
|
|
227
|
+
if (voucher_discount_id && voucher_discount) {
|
|
228
|
+
if (is_voucher_discount_percentage) {
|
|
229
|
+
discount_details.total_discount += (0, utils_1.getPercentageAmount)(itemTotalWithTaxAmount, voucher_discount);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
discount_details.total_discount += voucher_discount;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
delete discount_details.voucher_discount_reason;
|
|
237
|
+
}
|
|
238
|
+
discount_details.total_discount = (0, utils_1.parseNum)(discount_details.total_discount);
|
|
239
|
+
return discount_details;
|
|
240
|
+
}
|
|
241
|
+
/* ======================><====================== */
|
|
242
|
+
function calculateItemTotalWithTax(item) {
|
|
243
|
+
const modifiersTotal = calculateItemModifiersPrice(item);
|
|
244
|
+
// Item total without tax amount and without discount amount
|
|
245
|
+
// total is 20
|
|
246
|
+
const itemTotalWithoutTaxAndWithoutDiscount = (item.price + modifiersTotal) * item.quantity;
|
|
247
|
+
// Item discount details
|
|
248
|
+
// discount is 50%
|
|
249
|
+
// 50% of 20 is 10
|
|
250
|
+
const item_discount_details = getDiscountDetails(item.item_discount_details, itemTotalWithoutTaxAndWithoutDiscount);
|
|
251
|
+
// Item total without tax amount and with discount amount
|
|
252
|
+
// 20 - 10 = 10
|
|
253
|
+
// 10 is the item total without tax amount and with discount amount
|
|
254
|
+
const itemTotalWithoutTaxAndWithDiscount = itemTotalWithoutTaxAndWithoutDiscount - (item_discount_details?.total_discount ?? 0);
|
|
255
|
+
// Item tax amount with discount amount
|
|
256
|
+
// tax is 50%
|
|
257
|
+
// tax amount of 50% of 10 is 5
|
|
258
|
+
const itemTaxAmount = (0, utils_1.getPercentageAmount)(itemTotalWithoutTaxAndWithDiscount, item.tax_rate);
|
|
259
|
+
const itemSubtotal = (0, utils_1.parseNum)(itemTotalWithoutTaxAndWithDiscount + itemTaxAmount);
|
|
260
|
+
return { itemSubtotal, item_discount_details };
|
|
261
|
+
}
|
|
262
|
+
function getServiceFeeAmount(total, service_fee = 0, is_service_fee_percentage = false) {
|
|
263
|
+
// Add service fee to orderSubtotal
|
|
264
|
+
// Service fee is represented in percentage. We convert it to decimal
|
|
265
|
+
let serviceFeeAmt = service_fee ?? 0;
|
|
266
|
+
if (service_fee && service_fee > 0 && is_service_fee_percentage) {
|
|
267
|
+
serviceFeeAmt = (0, utils_1.getPercentageAmount)(total, service_fee);
|
|
268
|
+
}
|
|
269
|
+
// Add service fee as a fixed amount
|
|
270
|
+
return (0, utils_1.parseNum)(serviceFeeAmt);
|
|
271
|
+
}
|
|
272
|
+
function getSurchargeAmount(total, surcharge = 0, is_surcharge_percentage = false) {
|
|
273
|
+
// Add holiday surcharge to orderSubtotal
|
|
274
|
+
let surchargeAmt = surcharge ?? 0;
|
|
275
|
+
if (surcharge && surcharge > 0 && is_surcharge_percentage) {
|
|
276
|
+
// Add holiday surcharge to orderSubtotal
|
|
277
|
+
surchargeAmt = (0, utils_1.getPercentageAmount)(total, surchargeAmt);
|
|
278
|
+
}
|
|
279
|
+
return (0, utils_1.parseNum)(surchargeAmt);
|
|
280
|
+
}
|
|
281
|
+
function calculateGstForItem({ subtotal, totalOrderDiscount, applyGSTOnOriginalPrice, is_gst_inclusive, gst, totalItemsDiscount, grossAmount, netAmount, payablePrice, originalItemsPrice, surcharge, is_surcharge_taxable, is_surcharge_percentage, service_fee, is_service_fee_taxable, is_service_fee_percentage, apply_service_fee_on_original_price, }) {
|
|
282
|
+
let grand_total = subtotal;
|
|
283
|
+
// ===============================><===============================
|
|
284
|
+
if (is_surcharge_taxable) {
|
|
285
|
+
let surcharge_amount = 0;
|
|
286
|
+
if (is_surcharge_percentage) {
|
|
287
|
+
surcharge_amount = getSurchargeAmount(netAmount, surcharge, is_surcharge_percentage);
|
|
288
|
+
}
|
|
289
|
+
else if (surcharge) {
|
|
290
|
+
const proportion = netAmount / payablePrice;
|
|
291
|
+
surcharge_amount = proportion * surcharge;
|
|
292
|
+
}
|
|
293
|
+
grand_total += surcharge_amount;
|
|
294
|
+
}
|
|
295
|
+
if (is_service_fee_taxable) {
|
|
296
|
+
const p = apply_service_fee_on_original_price ? grossAmount : netAmount;
|
|
297
|
+
// Commented out because service fee does not apply on surcharge
|
|
298
|
+
// if (surcharge_amount) {
|
|
299
|
+
// p += surcharge_amount;
|
|
300
|
+
// }
|
|
301
|
+
let service_fee_amount = 0;
|
|
302
|
+
if (is_service_fee_percentage) {
|
|
303
|
+
service_fee_amount = getServiceFeeAmount(p, service_fee, is_service_fee_percentage);
|
|
304
|
+
}
|
|
305
|
+
else if (service_fee) {
|
|
306
|
+
const totalP = apply_service_fee_on_original_price ? originalItemsPrice : payablePrice;
|
|
307
|
+
const proportion = p / totalP;
|
|
308
|
+
service_fee_amount = proportion * service_fee;
|
|
309
|
+
}
|
|
310
|
+
grand_total += service_fee_amount;
|
|
311
|
+
}
|
|
312
|
+
// GST is represented in percentage. We convert it to decimal
|
|
313
|
+
if (applyGSTOnOriginalPrice) {
|
|
314
|
+
grand_total += totalItemsDiscount;
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
grand_total -= totalOrderDiscount;
|
|
318
|
+
}
|
|
319
|
+
let gst_amount = 0;
|
|
320
|
+
if (is_gst_inclusive) {
|
|
321
|
+
// If GST is inclusive, it means that the Tax is already included in the Sale Value
|
|
322
|
+
// However, we need to calculate the Sale Value without the Tax
|
|
323
|
+
// And then calculate the Tax amount from the Sale Value without Tax
|
|
324
|
+
gst_amount = (grand_total * gst) / (100 + gst);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
gst_amount = (0, utils_1.getPercentageAmount)(grand_total, gst);
|
|
328
|
+
// Add GST amount to orderSubtotal
|
|
329
|
+
grand_total += gst_amount;
|
|
330
|
+
}
|
|
331
|
+
return gst_amount;
|
|
332
|
+
}
|
|
333
|
+
function calculateCartOrderInfoAndSyncData(data, courses, listnerSettings, calculateItemMetadata) {
|
|
334
|
+
const isCompleted = data.order_status === constants_1.ORDER_STATUS_ENUM.COMPLETED;
|
|
335
|
+
/* ===============================><=============================== */
|
|
336
|
+
let subtotal = 0;
|
|
337
|
+
let totalItemsDiscount = 0;
|
|
338
|
+
const categories = [];
|
|
339
|
+
const length = data.categories?.length ?? 0;
|
|
340
|
+
for (let c = 0; c < length; c++) {
|
|
341
|
+
const category = data.categories[c];
|
|
342
|
+
const newItems = [];
|
|
343
|
+
const itemsLength = category.items.length;
|
|
344
|
+
for (let i = 0; i < itemsLength; i++) {
|
|
345
|
+
const item = category.items[i];
|
|
346
|
+
const { itemSubtotal, item_discount_details } = calculateItemTotalWithTax(item);
|
|
347
|
+
const newItem = {
|
|
348
|
+
...item,
|
|
349
|
+
is_ready: item.is_ready || isCompleted,
|
|
350
|
+
item_discount_details,
|
|
351
|
+
subtotal: itemSubtotal,
|
|
352
|
+
// These values will be auto calculated
|
|
353
|
+
_discount_amount: 0,
|
|
354
|
+
_gross_amount: 0,
|
|
355
|
+
_gst_amount: 0,
|
|
356
|
+
_net_amount: 0,
|
|
357
|
+
};
|
|
358
|
+
delete newItem.void_reason;
|
|
359
|
+
newItems.push(newItem);
|
|
360
|
+
if (item_discount_details != null && item_discount_details.total_discount > 0) {
|
|
361
|
+
totalItemsDiscount += item_discount_details.total_discount;
|
|
362
|
+
}
|
|
363
|
+
subtotal += itemSubtotal;
|
|
364
|
+
}
|
|
365
|
+
categories.push({
|
|
366
|
+
...category,
|
|
367
|
+
items: newItems,
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
const applyGSTOnOriginalPrice = data.exclude_discount_from_gst;
|
|
371
|
+
const order_discount_details = getDiscountDetails(data.order_discount_details, subtotal);
|
|
372
|
+
// This can be both negative or positive
|
|
373
|
+
const orderDiscount = order_discount_details?.total_discount ?? 0;
|
|
374
|
+
// However total order discount can never be negative
|
|
375
|
+
let totalOrderDiscount = orderDiscount;
|
|
376
|
+
if (totalOrderDiscount < 0) {
|
|
377
|
+
// if the total order discount is negative, then it is a surcharge
|
|
378
|
+
totalOrderDiscount = 0;
|
|
379
|
+
}
|
|
380
|
+
// Payable price is the price after applying order discount
|
|
381
|
+
// A discount in this case can be both negative or positive
|
|
382
|
+
// So in actual, payable price is the price of all items after applying all discounts and surcharges
|
|
383
|
+
const payablePrice = subtotal - orderDiscount;
|
|
384
|
+
// Original items price is the price of all items without any discount
|
|
385
|
+
// A discount in this case can only be positive
|
|
386
|
+
const originalItemsPrice = subtotal + totalItemsDiscount;
|
|
387
|
+
let grand_total = subtotal;
|
|
388
|
+
if (!applyGSTOnOriginalPrice) {
|
|
389
|
+
grand_total -= totalOrderDiscount;
|
|
390
|
+
}
|
|
391
|
+
// ===============================><===============================
|
|
392
|
+
let surcharge_amount = data.surcharge;
|
|
393
|
+
if (data.is_surcharge_taxable) {
|
|
394
|
+
surcharge_amount = getSurchargeAmount(payablePrice, data.surcharge, data.is_surcharge_percentage);
|
|
395
|
+
grand_total += surcharge_amount;
|
|
396
|
+
}
|
|
397
|
+
let service_fee_amount = data.service_fee;
|
|
398
|
+
if (data.is_service_fee_taxable) {
|
|
399
|
+
const p = data.apply_service_fee_on_original_price ? originalItemsPrice : payablePrice;
|
|
400
|
+
// Commented out because service fee does not apply on surcharge
|
|
401
|
+
// if (surcharge_amount) {
|
|
402
|
+
// p += surcharge_amount;
|
|
403
|
+
// }
|
|
404
|
+
service_fee_amount = getServiceFeeAmount(p, data.service_fee, data.is_service_fee_percentage);
|
|
405
|
+
grand_total += service_fee_amount;
|
|
406
|
+
}
|
|
407
|
+
// GST is represented in percentage. We convert it to decimal
|
|
408
|
+
let amount = grand_total;
|
|
409
|
+
if (applyGSTOnOriginalPrice) {
|
|
410
|
+
amount += totalItemsDiscount;
|
|
411
|
+
}
|
|
412
|
+
let gst_amount = 0;
|
|
413
|
+
const gst = data.gst ?? 0;
|
|
414
|
+
if (data.is_gst_inclusive) {
|
|
415
|
+
// If GST is inclusive, it means that the Tax is already included in the Sale Value
|
|
416
|
+
// However, we need to calculate the Sale Value without the Tax
|
|
417
|
+
// And then calculate the Tax amount from the Sale Value without Tax
|
|
418
|
+
gst_amount = (0, utils_1.parseFloatCeil)((amount * gst) / (100 + gst));
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
gst_amount = (0, utils_1.getPercentageAmount)(amount, gst);
|
|
422
|
+
// Add GST amount to orderSubtotal
|
|
423
|
+
grand_total += gst_amount;
|
|
424
|
+
}
|
|
425
|
+
if (applyGSTOnOriginalPrice) {
|
|
426
|
+
grand_total -= totalOrderDiscount;
|
|
427
|
+
}
|
|
428
|
+
// ===============================><===============================
|
|
429
|
+
if (!data.is_surcharge_taxable) {
|
|
430
|
+
surcharge_amount = getSurchargeAmount(payablePrice, data.surcharge, data.is_surcharge_percentage);
|
|
431
|
+
grand_total += surcharge_amount;
|
|
432
|
+
}
|
|
433
|
+
if (!data.is_service_fee_taxable) {
|
|
434
|
+
const p = data.apply_service_fee_on_original_price ? originalItemsPrice : payablePrice;
|
|
435
|
+
// Commented out because service fee does not apply on surcharge
|
|
436
|
+
// if (surcharge_amount) {
|
|
437
|
+
// p += surcharge_amount;
|
|
438
|
+
// }
|
|
439
|
+
service_fee_amount = getServiceFeeAmount(p, data.service_fee, data.is_service_fee_percentage);
|
|
440
|
+
grand_total += service_fee_amount;
|
|
441
|
+
}
|
|
442
|
+
// ===============================><===============================
|
|
443
|
+
// Add delivery fee to grand_total
|
|
444
|
+
let delivery_cost = 0;
|
|
445
|
+
if (listnerSettings != null) {
|
|
446
|
+
delivery_cost = (0, utils_1.getDeliveryAmt)({
|
|
447
|
+
platform: data.platform,
|
|
448
|
+
contemporary_delivery_cost: data.delivery_details?.delivery_cost ?? 0,
|
|
449
|
+
delivery_free_over: listnerSettings.delivery_free_over,
|
|
450
|
+
delivery_min_cost: listnerSettings.delivery_min_cost,
|
|
451
|
+
payable_price: payablePrice,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
else if (data.delivery_details != null) {
|
|
455
|
+
delivery_cost = data.delivery_details.delivery_cost;
|
|
456
|
+
}
|
|
457
|
+
grand_total += delivery_cost;
|
|
458
|
+
// TODO: We are not using tax_amount for now
|
|
459
|
+
const tax_amount = 0;
|
|
460
|
+
// Add tax amount to orderSubtotal
|
|
461
|
+
// grand_total += tax_amount;
|
|
462
|
+
// Add tip amount to grand_total
|
|
463
|
+
grand_total += data.tip_amount ?? 0;
|
|
464
|
+
// Add Card Charges to grand_total
|
|
465
|
+
const { cardCharges, amountCollected } = (0, utils_1.getCardChargesAndAmountCollected)(data.payments);
|
|
466
|
+
grand_total += cardCharges;
|
|
467
|
+
// ===============================><===============================
|
|
468
|
+
const delivery_details = data.delivery_details
|
|
469
|
+
? {
|
|
470
|
+
...data.delivery_details,
|
|
471
|
+
delivery_cost,
|
|
472
|
+
}
|
|
473
|
+
: null;
|
|
474
|
+
grand_total = (0, utils_1.parseNum)(grand_total);
|
|
475
|
+
// We will not add orderDiscount or itemDiscount if their value is negative
|
|
476
|
+
// because if they are negative, then they are surcharge
|
|
477
|
+
let total_discount_applied = 0;
|
|
478
|
+
total_discount_applied += totalOrderDiscount;
|
|
479
|
+
total_discount_applied += totalItemsDiscount;
|
|
480
|
+
let tax_invoice_provider_charges = 0;
|
|
481
|
+
if (gst > 0) {
|
|
482
|
+
tax_invoice_provider_charges = data.tax_invoice_provider_charges ?? 0;
|
|
483
|
+
if (listnerSettings != null && listnerSettings.tax_invoice_provider !== constants_1.TAX_INVOICE_PROVIDER_ENUM.NONE) {
|
|
484
|
+
const tax_invoice_charges = constants_1.TAX_INVOICE_PROVIDER_CHARGES_MAP.get(listnerSettings.tax_invoice_provider);
|
|
485
|
+
if (tax_invoice_charges != null) {
|
|
486
|
+
tax_invoice_provider_charges = tax_invoice_charges.fixed_charges;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
grand_total += tax_invoice_provider_charges;
|
|
491
|
+
const amount_collected = (0, utils_1.parseNum)(amountCollected);
|
|
492
|
+
const amount_earned = (0, utils_1.parseNum)(grand_total - cardCharges);
|
|
493
|
+
if (calculateItemMetadata) {
|
|
494
|
+
let leftGrossAmount = originalItemsPrice;
|
|
495
|
+
let leftNetAmount = payablePrice;
|
|
496
|
+
let leftDiscountAmount = total_discount_applied;
|
|
497
|
+
let leftGstAmount = gst_amount;
|
|
498
|
+
categories.forEach((category, categoryIndex) => {
|
|
499
|
+
const isLastCategory = categoryIndex === categories.length - 1;
|
|
500
|
+
category.items.forEach((item, itemIndex) => {
|
|
501
|
+
const isLastItem = isLastCategory && itemIndex === category.items.length - 1;
|
|
502
|
+
let itemDiscountAmount = item.item_discount_details?.total_discount ?? 0;
|
|
503
|
+
if (itemDiscountAmount < 0) {
|
|
504
|
+
itemDiscountAmount = 0;
|
|
505
|
+
}
|
|
506
|
+
let grossAmount = item.subtotal + itemDiscountAmount;
|
|
507
|
+
const orderDiscountAmount = (item.subtotal / (subtotal || 1)) * totalOrderDiscount;
|
|
508
|
+
let netAmount = item.subtotal - orderDiscountAmount;
|
|
509
|
+
let itemTotalDiscountAmount = itemDiscountAmount + orderDiscountAmount;
|
|
510
|
+
let itemGst = 0;
|
|
511
|
+
if (gst_amount > 0) {
|
|
512
|
+
itemGst += calculateGstForItem({
|
|
513
|
+
apply_service_fee_on_original_price: data.apply_service_fee_on_original_price,
|
|
514
|
+
applyGSTOnOriginalPrice,
|
|
515
|
+
gst,
|
|
516
|
+
is_gst_inclusive: data.is_gst_inclusive,
|
|
517
|
+
is_service_fee_percentage: data.is_service_fee_percentage,
|
|
518
|
+
is_service_fee_taxable: data.is_service_fee_taxable,
|
|
519
|
+
is_surcharge_percentage: data.is_surcharge_percentage,
|
|
520
|
+
is_surcharge_taxable: data.is_surcharge_taxable,
|
|
521
|
+
grossAmount,
|
|
522
|
+
netAmount,
|
|
523
|
+
originalItemsPrice,
|
|
524
|
+
payablePrice,
|
|
525
|
+
subtotal: item.subtotal,
|
|
526
|
+
service_fee: data.service_fee,
|
|
527
|
+
surcharge: data.surcharge,
|
|
528
|
+
totalItemsDiscount: itemDiscountAmount,
|
|
529
|
+
totalOrderDiscount: orderDiscountAmount,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
grossAmount = (0, utils_1.parseFloatCeil)(grossAmount);
|
|
533
|
+
netAmount = (0, utils_1.parseFloatCeil)(netAmount);
|
|
534
|
+
itemTotalDiscountAmount = (0, utils_1.parseFloatCeil)(itemTotalDiscountAmount);
|
|
535
|
+
itemGst = (0, utils_1.parseFloatCeil)(itemGst);
|
|
536
|
+
leftGrossAmount -= grossAmount;
|
|
537
|
+
leftNetAmount -= netAmount;
|
|
538
|
+
leftDiscountAmount -= itemTotalDiscountAmount;
|
|
539
|
+
leftGstAmount -= itemGst;
|
|
540
|
+
if (isLastItem) {
|
|
541
|
+
grossAmount += leftGrossAmount;
|
|
542
|
+
netAmount += leftNetAmount;
|
|
543
|
+
itemTotalDiscountAmount += leftDiscountAmount;
|
|
544
|
+
itemGst += leftGstAmount;
|
|
545
|
+
}
|
|
546
|
+
item._gross_amount = Math.max(grossAmount, 0);
|
|
547
|
+
item._net_amount = Math.max(netAmount, 0);
|
|
548
|
+
item._discount_amount = Math.max(itemTotalDiscountAmount, 0);
|
|
549
|
+
item._gst_amount = Math.max(itemGst, 0);
|
|
550
|
+
});
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
const cartData = {
|
|
554
|
+
...data,
|
|
555
|
+
categories,
|
|
556
|
+
order_discount_details,
|
|
557
|
+
total_discount_applied,
|
|
558
|
+
delivery_details,
|
|
559
|
+
tax_amount,
|
|
560
|
+
service_fee_amount,
|
|
561
|
+
surcharge_amount,
|
|
562
|
+
amount_collected,
|
|
563
|
+
amount_earned,
|
|
564
|
+
tax_invoice_provider_charges,
|
|
565
|
+
gst_amount,
|
|
566
|
+
price: (0, utils_1.parseNum)(originalItemsPrice),
|
|
567
|
+
grand_total,
|
|
568
|
+
};
|
|
569
|
+
// ===============================><===============================
|
|
570
|
+
let syncedData = cartData;
|
|
571
|
+
if (courses != null) {
|
|
572
|
+
syncedData = syncOrderCoursesWithOrderItemsInCart(cartData, courses);
|
|
573
|
+
}
|
|
574
|
+
return syncedData;
|
|
575
|
+
}
|
|
576
|
+
const getOrderItemComaparableData = (item) => ({
|
|
577
|
+
item_id: item.item_id,
|
|
578
|
+
menu_id: item.menu_id,
|
|
579
|
+
item_type: item.item_type,
|
|
580
|
+
name: item.name,
|
|
581
|
+
price: item.price,
|
|
582
|
+
item_discount_details: item.item_discount_details,
|
|
583
|
+
tax_rate: item.tax_rate,
|
|
584
|
+
special_instructions: item.special_instructions,
|
|
585
|
+
modifiers: item.modifiers,
|
|
586
|
+
_id: item._id,
|
|
587
|
+
quantity: item.quantity,
|
|
588
|
+
});
|
|
589
|
+
exports.getOrderItemComaparableData = getOrderItemComaparableData;
|
|
590
|
+
function getAddItemToCartData(data, payload, courses, listnerSettings) {
|
|
591
|
+
const getComparableItem = (item) => {
|
|
592
|
+
return {
|
|
593
|
+
item_id: item.item_id,
|
|
594
|
+
menu_id: item.menu_id,
|
|
595
|
+
item_type: item.item_type,
|
|
596
|
+
name: item.name,
|
|
597
|
+
price: item.price,
|
|
598
|
+
item_discount_details: getItemQuantityChangeResults({
|
|
599
|
+
prevQuantity: item.quantity,
|
|
600
|
+
newQuantity: 1,
|
|
601
|
+
prevItemDiscountDetails: item.item_discount_details,
|
|
602
|
+
}),
|
|
603
|
+
tax_rate: item.tax_rate,
|
|
604
|
+
special_instructions: item.special_instructions,
|
|
605
|
+
modifiers: item.modifiers,
|
|
606
|
+
};
|
|
607
|
+
};
|
|
608
|
+
const { category_id, name, item, chosen_course_id, replace_id } = payload;
|
|
609
|
+
const comparableItem = getComparableItem(item);
|
|
610
|
+
let mainItemId = item._id;
|
|
611
|
+
const orderData = { ...data };
|
|
612
|
+
// =====================><=====================
|
|
613
|
+
const categories = [...(orderData.categories ?? [])];
|
|
614
|
+
let didFindCategory = false;
|
|
615
|
+
const categoriesLength = categories.length;
|
|
616
|
+
for (let i = 0; i < categoriesLength; i++) {
|
|
617
|
+
const category = categories[i];
|
|
618
|
+
if (category.category_id !== category_id)
|
|
619
|
+
continue;
|
|
620
|
+
const allItems = [...category.items];
|
|
621
|
+
let didFindItem = false;
|
|
622
|
+
let itemExists = false;
|
|
623
|
+
const totalItems = allItems.length;
|
|
624
|
+
for (let j = 0; j < totalItems; j++) {
|
|
625
|
+
const itm = allItems[j];
|
|
626
|
+
if (itm._id === item._id) {
|
|
627
|
+
allItems[j] = item;
|
|
628
|
+
didFindItem = true;
|
|
629
|
+
break;
|
|
630
|
+
}
|
|
631
|
+
if (itm.item_id === item.item_id && !itm.is_split) {
|
|
632
|
+
itemExists = true;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (!didFindItem && itemExists) {
|
|
636
|
+
for (let j = 0; j < totalItems; j++) {
|
|
637
|
+
const itm = allItems[j];
|
|
638
|
+
if (itm.item_id === item.item_id &&
|
|
639
|
+
!itm.is_split &&
|
|
640
|
+
// We make sure that the item does not have loyalty_discount_id and voucher_discount_id
|
|
641
|
+
itm.item_discount_details?.loyalty_discount_id == null &&
|
|
642
|
+
itm.item_discount_details?.voucher_discount_id == null &&
|
|
643
|
+
(0, lodash_1.isEqual)(getComparableItem(itm), comparableItem)) {
|
|
644
|
+
mainItemId = replace_id ?? itm._id;
|
|
645
|
+
const newQuantity = item.quantity + itm.quantity;
|
|
646
|
+
allItems[j] = {
|
|
647
|
+
...item,
|
|
648
|
+
_id: mainItemId,
|
|
649
|
+
quantity: newQuantity,
|
|
650
|
+
item_discount_details: getItemQuantityChangeResults({
|
|
651
|
+
prevQuantity: item.quantity,
|
|
652
|
+
newQuantity,
|
|
653
|
+
prevItemDiscountDetails: item.item_discount_details,
|
|
654
|
+
}),
|
|
655
|
+
};
|
|
656
|
+
didFindItem = true;
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
if (!didFindItem) {
|
|
662
|
+
allItems.push(item);
|
|
663
|
+
}
|
|
664
|
+
categories[i] = {
|
|
665
|
+
...category,
|
|
666
|
+
items: allItems,
|
|
667
|
+
};
|
|
668
|
+
didFindCategory = true;
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
if (!didFindCategory) {
|
|
672
|
+
categories.push({
|
|
673
|
+
category_id,
|
|
674
|
+
name,
|
|
675
|
+
items: [item],
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
// =====================><=====================
|
|
679
|
+
if (chosen_course_id && orderData.dinein_details != null) {
|
|
680
|
+
const course = courses.find((c) => c._id === chosen_course_id);
|
|
681
|
+
if (course != null) {
|
|
682
|
+
const originalCourses = orderData.dinein_details.courses ?? [];
|
|
683
|
+
const originalCoursesLength = originalCourses.length;
|
|
684
|
+
const dineinCourses = [];
|
|
685
|
+
let isCourseFound = false;
|
|
686
|
+
for (let i = 0; i < originalCoursesLength; i++) {
|
|
687
|
+
const c = originalCourses[i];
|
|
688
|
+
const dineinCourseItemIds = c.item_ids.filter((id) => id !== mainItemId);
|
|
689
|
+
if (c.course_id === course._id) {
|
|
690
|
+
dineinCourses.push({
|
|
691
|
+
...c,
|
|
692
|
+
item_ids: dineinCourseItemIds.concat(mainItemId),
|
|
693
|
+
});
|
|
694
|
+
isCourseFound = true;
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
dineinCourses.push({
|
|
698
|
+
...c,
|
|
699
|
+
item_ids: dineinCourseItemIds,
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
if (!isCourseFound) {
|
|
704
|
+
dineinCourses.push({
|
|
705
|
+
course_id: course._id,
|
|
706
|
+
name: course.name,
|
|
707
|
+
item_ids: [mainItemId],
|
|
708
|
+
called: false,
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
const dinein_details = {
|
|
712
|
+
...orderData.dinein_details,
|
|
713
|
+
courses: dineinCourses,
|
|
714
|
+
};
|
|
715
|
+
// This is not a mutation. We are just updating the orderData
|
|
716
|
+
orderData.dinein_details = dinein_details;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const iterations = [];
|
|
720
|
+
if (orderData.iterations != null && orderData.iterations.length > 0) {
|
|
721
|
+
const orderItemIdsMap = {};
|
|
722
|
+
for (let i = 0; i < categories.length; i++) {
|
|
723
|
+
const category = categories[i];
|
|
724
|
+
const items = category.items;
|
|
725
|
+
for (let j = 0; j < items.length; j++) {
|
|
726
|
+
const item = items[j];
|
|
727
|
+
orderItemIdsMap[item._id] = item.quantity;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
const [firstIteration, ...restIterations] = orderData.iterations;
|
|
731
|
+
const firstIterationCategories = [];
|
|
732
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
733
|
+
const category = firstIteration.categories[i];
|
|
734
|
+
const allPrevItems = [];
|
|
735
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
736
|
+
const prevItem = category.items[j];
|
|
737
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
738
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
739
|
+
if (isRemovedItem) {
|
|
740
|
+
allPrevItems.push(prevItem);
|
|
741
|
+
}
|
|
742
|
+
else {
|
|
743
|
+
const updatedPrevItem = {
|
|
744
|
+
...prevItem,
|
|
745
|
+
};
|
|
746
|
+
delete updatedPrevItem.void_reason;
|
|
747
|
+
allPrevItems.push(updatedPrevItem);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
if (allPrevItems.length > 0) {
|
|
751
|
+
firstIterationCategories.push({
|
|
752
|
+
...category,
|
|
753
|
+
items: allPrevItems,
|
|
754
|
+
});
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
const firstIterationData = {
|
|
758
|
+
...firstIteration,
|
|
759
|
+
categories: firstIterationCategories,
|
|
760
|
+
};
|
|
761
|
+
iterations.push(firstIterationData);
|
|
762
|
+
iterations.push(...restIterations);
|
|
763
|
+
}
|
|
764
|
+
// =====================><=====================
|
|
765
|
+
const order = {
|
|
766
|
+
...orderData,
|
|
767
|
+
...(iterations.length > 0 && { iterations }),
|
|
768
|
+
categories,
|
|
769
|
+
};
|
|
770
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
771
|
+
return newData;
|
|
772
|
+
}
|
|
773
|
+
function getSplitCartItemToTwo({ data, orderItemId, courses, listnerSettings }) {
|
|
774
|
+
if (data.categories == null)
|
|
775
|
+
return data;
|
|
776
|
+
const newCategories = [];
|
|
777
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
778
|
+
const category = data.categories[i];
|
|
779
|
+
const newItems = [];
|
|
780
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
781
|
+
const item = {
|
|
782
|
+
...category.items[j],
|
|
783
|
+
};
|
|
784
|
+
if (item._id !== orderItemId) {
|
|
785
|
+
newItems.push(item);
|
|
786
|
+
continue;
|
|
787
|
+
}
|
|
788
|
+
if (item.quantity === 1) {
|
|
789
|
+
newItems.push(item);
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
const prevQuantity = item.quantity;
|
|
793
|
+
const newQuantity = item.quantity - 1;
|
|
794
|
+
const prevItemDiscountDetails = getItemQuantityChangeResults({
|
|
795
|
+
prevQuantity,
|
|
796
|
+
newQuantity,
|
|
797
|
+
prevItemDiscountDetails: item.item_discount_details,
|
|
798
|
+
});
|
|
799
|
+
const prevItem = {
|
|
800
|
+
...item,
|
|
801
|
+
quantity: newQuantity,
|
|
802
|
+
item_discount_details: prevItemDiscountDetails,
|
|
803
|
+
};
|
|
804
|
+
newItems.push(prevItem);
|
|
805
|
+
const _id = new bson_objectid_1.default(Math.floor(new bson_objectid_1.default(item._id).getTimestamp().getTime() / 1000) + 1).toHexString();
|
|
806
|
+
const newItemsDiscountDetails = getItemQuantityChangeResults({
|
|
807
|
+
prevQuantity,
|
|
808
|
+
newQuantity: 1,
|
|
809
|
+
prevItemDiscountDetails: item.item_discount_details,
|
|
810
|
+
});
|
|
811
|
+
newItems.push({
|
|
812
|
+
...item,
|
|
813
|
+
_id,
|
|
814
|
+
quantity: 1,
|
|
815
|
+
item_discount_details: newItemsDiscountDetails,
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
newCategories.push({
|
|
819
|
+
...category,
|
|
820
|
+
items: newItems,
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
const order = {
|
|
824
|
+
...data,
|
|
825
|
+
categories: newCategories,
|
|
826
|
+
};
|
|
827
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
828
|
+
return newData;
|
|
829
|
+
}
|
|
830
|
+
/* ======================><====================== */
|
|
831
|
+
function getAddItemsToCartData(data, payload, courses, listnerSettings) {
|
|
832
|
+
const newData = payload.reduce((acc, item) => getAddItemToCartData(acc, item, courses, listnerSettings), data);
|
|
833
|
+
return newData;
|
|
834
|
+
}
|
|
835
|
+
/* ======================><====================== */
|
|
836
|
+
function getUpdateItemInCartData(data, payload, courses, listnerSettings) {
|
|
837
|
+
const orderItemIdsMap = {};
|
|
838
|
+
let categories;
|
|
839
|
+
if (data.categories != null) {
|
|
840
|
+
categories = [];
|
|
841
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
842
|
+
const category = data.categories[i];
|
|
843
|
+
const items = [];
|
|
844
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
845
|
+
const item = category.items[j];
|
|
846
|
+
let newItem = item;
|
|
847
|
+
if (item._id === payload._id) {
|
|
848
|
+
newItem = {
|
|
849
|
+
...item,
|
|
850
|
+
...payload,
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
if (newItem.quantity > 0) {
|
|
854
|
+
items.push(newItem);
|
|
855
|
+
orderItemIdsMap[newItem._id] = newItem.quantity;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (items.length > 0) {
|
|
859
|
+
categories.push({
|
|
860
|
+
...category,
|
|
861
|
+
items,
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
const iterations = [];
|
|
867
|
+
if (payload.quantity != null && data.iterations != null && data.iterations.length > 0) {
|
|
868
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
869
|
+
const firstIterationCategories = [];
|
|
870
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
871
|
+
const category = firstIteration.categories[i];
|
|
872
|
+
const allPrevItems = [];
|
|
873
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
874
|
+
const prevItem = category.items[j];
|
|
875
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
876
|
+
const updatedPrevItem = {
|
|
877
|
+
...prevItem,
|
|
878
|
+
void_reason: payload.void_reason,
|
|
879
|
+
};
|
|
880
|
+
allPrevItems.push(updatedPrevItem);
|
|
881
|
+
}
|
|
882
|
+
else {
|
|
883
|
+
// A Removed Item is one that is not in the orderItemIdsMap
|
|
884
|
+
// Or it is in the orderItemIdsMap but its quantity is less than newItem.quantity
|
|
885
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
886
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
887
|
+
if (isRemovedItem) {
|
|
888
|
+
allPrevItems.push(prevItem);
|
|
889
|
+
}
|
|
890
|
+
else {
|
|
891
|
+
// If the item is not removed, then we make sure to remove the void_reason
|
|
892
|
+
const updatedPrevItem = {
|
|
893
|
+
...prevItem,
|
|
894
|
+
};
|
|
895
|
+
delete updatedPrevItem.void_reason;
|
|
896
|
+
allPrevItems.push(updatedPrevItem);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
if (allPrevItems.length > 0) {
|
|
901
|
+
firstIterationCategories.push({
|
|
902
|
+
...category,
|
|
903
|
+
items: allPrevItems,
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
const firstIterationData = {
|
|
908
|
+
...firstIteration,
|
|
909
|
+
categories: firstIterationCategories,
|
|
910
|
+
};
|
|
911
|
+
iterations.push(firstIterationData);
|
|
912
|
+
iterations.push(...restIterations);
|
|
913
|
+
}
|
|
914
|
+
const order = {
|
|
915
|
+
...data,
|
|
916
|
+
...(iterations.length > 0 && { iterations }),
|
|
917
|
+
categories,
|
|
918
|
+
};
|
|
919
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
920
|
+
return newData;
|
|
921
|
+
}
|
|
922
|
+
/* ======================><====================== */
|
|
923
|
+
function getUpdateItemsInCartData(data, payload, courses, listnerSettings) {
|
|
924
|
+
const newData = payload.reduce((acc, item) => getUpdateItemInCartData(acc, item, courses, listnerSettings), data);
|
|
925
|
+
return newData;
|
|
926
|
+
}
|
|
927
|
+
/* ======================><====================== */
|
|
928
|
+
function getUpdateCartInfoData(data, payload, courses, listnerSettings) {
|
|
929
|
+
const order = {
|
|
930
|
+
...data,
|
|
931
|
+
...payload,
|
|
932
|
+
};
|
|
933
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
934
|
+
return newData;
|
|
935
|
+
}
|
|
936
|
+
/* ======================><====================== */
|
|
937
|
+
function getRemoveItemFromCartData(data, payload, courses, listnerSettings) {
|
|
938
|
+
const orderItemIdsMap = {};
|
|
939
|
+
let categories;
|
|
940
|
+
if (data.categories != null) {
|
|
941
|
+
categories = [];
|
|
942
|
+
for (let i = 0; i < data.categories.length; i++) {
|
|
943
|
+
const category = data.categories[i];
|
|
944
|
+
const items = [];
|
|
945
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
946
|
+
const item = category.items[j];
|
|
947
|
+
if (item._id !== payload._id) {
|
|
948
|
+
items.push(item);
|
|
949
|
+
orderItemIdsMap[item._id] = item.quantity;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
if (items.length > 0) {
|
|
953
|
+
categories.push({
|
|
954
|
+
...category,
|
|
955
|
+
items,
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const iterations = [];
|
|
961
|
+
if (data.iterations != null && data.iterations.length > 0) {
|
|
962
|
+
const [firstIteration, ...restIterations] = data.iterations;
|
|
963
|
+
const firstIterationCategories = [];
|
|
964
|
+
for (let i = 0; i < firstIteration.categories.length; i++) {
|
|
965
|
+
const category = firstIteration.categories[i];
|
|
966
|
+
const allPrevItems = [];
|
|
967
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
968
|
+
const prevItem = category.items[j];
|
|
969
|
+
if (prevItem._id === payload._id && payload.void_reason != null) {
|
|
970
|
+
const newItem = {
|
|
971
|
+
...prevItem,
|
|
972
|
+
void_reason: payload.void_reason,
|
|
973
|
+
};
|
|
974
|
+
allPrevItems.push(newItem);
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
// A Removed Item is one that is not in the orderItemIdsMap
|
|
978
|
+
// Or it is in the orderItemIdsMap but its quantity is less than newItem.quantity
|
|
979
|
+
const currentItemQuantity = orderItemIdsMap[prevItem._id];
|
|
980
|
+
const isRemovedItem = !currentItemQuantity || currentItemQuantity < prevItem.quantity;
|
|
981
|
+
if (isRemovedItem) {
|
|
982
|
+
allPrevItems.push(prevItem);
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
// If the item is not removed, then we make sure to remove the void_reason
|
|
986
|
+
const updatedPrevItem = {
|
|
987
|
+
...prevItem,
|
|
988
|
+
};
|
|
989
|
+
delete updatedPrevItem.void_reason;
|
|
990
|
+
allPrevItems.push(updatedPrevItem);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
if (allPrevItems.length > 0) {
|
|
995
|
+
firstIterationCategories.push({
|
|
996
|
+
...category,
|
|
997
|
+
items: allPrevItems,
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
const firstIterationData = {
|
|
1002
|
+
...firstIteration,
|
|
1003
|
+
categories: firstIterationCategories,
|
|
1004
|
+
};
|
|
1005
|
+
iterations.push(firstIterationData);
|
|
1006
|
+
iterations.push(...restIterations);
|
|
1007
|
+
}
|
|
1008
|
+
const order = {
|
|
1009
|
+
...data,
|
|
1010
|
+
...(iterations.length > 0 && { iterations }),
|
|
1011
|
+
categories,
|
|
1012
|
+
};
|
|
1013
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
1014
|
+
return newData;
|
|
1015
|
+
}
|
|
1016
|
+
/* ======================>Order Object<====================== */
|
|
1017
|
+
function getUpdatedCartInfoOnInit(data, order, courses, platform, categories, mappedItems, tenantId, listnerSettings) {
|
|
1018
|
+
let payload = order;
|
|
1019
|
+
if (platform && data.platform !== order.platform && categories) {
|
|
1020
|
+
const newCategories = [];
|
|
1021
|
+
for (let i = 0; i < categories.length; i++) {
|
|
1022
|
+
const cat = categories[i];
|
|
1023
|
+
const newItems = [];
|
|
1024
|
+
for (let j = 0; j < cat.items.length; j++) {
|
|
1025
|
+
const item = cat.items[j];
|
|
1026
|
+
let catalogItem = mappedItems[item.item_id];
|
|
1027
|
+
if (catalogItem == null)
|
|
1028
|
+
continue;
|
|
1029
|
+
catalogItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenantId);
|
|
1030
|
+
if (catalogItem == null)
|
|
1031
|
+
continue;
|
|
1032
|
+
let newItem = item;
|
|
1033
|
+
// we get the price object from the catalogs
|
|
1034
|
+
const priceObj = catalogItem.price;
|
|
1035
|
+
const price = (0, utils_1.getPriceEnum)(priceObj, platform);
|
|
1036
|
+
// we get the discount object from the catalogs
|
|
1037
|
+
const discountObj = catalogItem.discount_amount;
|
|
1038
|
+
const discount_amount = (0, utils_1.getPriceEnum)(discountObj, platform);
|
|
1039
|
+
const is_discount_percentage = catalogItem.is_discount_percentage;
|
|
1040
|
+
// we get the tax object from the catalogs
|
|
1041
|
+
const taxObj = catalogItem.tax_rate;
|
|
1042
|
+
const tax_rate = (0, utils_1.getPriceEnum)(taxObj, platform);
|
|
1043
|
+
let modifiers = item.modifiers;
|
|
1044
|
+
if (item.modifiers != null && item.modifiers.length > 0) {
|
|
1045
|
+
const recursivelyUpdateModifiers = (modifiers) => {
|
|
1046
|
+
const newModifiers = [];
|
|
1047
|
+
for (let k = 0; k < modifiers.length; k++) {
|
|
1048
|
+
const orderItemModifier = modifiers[k];
|
|
1049
|
+
const catalogItemModifier = getModifier(orderItemModifier._id, catalogItem?.modifiers);
|
|
1050
|
+
if (catalogItemModifier != null) {
|
|
1051
|
+
const newOptions = [];
|
|
1052
|
+
for (let l = 0; l < orderItemModifier.options.length; l++) {
|
|
1053
|
+
const orderItemOption = orderItemModifier.options[l];
|
|
1054
|
+
let catalogModifierOption = catalogItemModifier.options.find((o) => o._id === orderItemOption._id);
|
|
1055
|
+
if (catalogModifierOption == null) {
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
catalogModifierOption = (0, platform_catalog_1.convertOptionToWorkableOption)(catalogModifierOption, platform);
|
|
1059
|
+
if (catalogModifierOption == null)
|
|
1060
|
+
continue;
|
|
1061
|
+
const optionPrice = (0, utils_1.getPriceEnum)(catalogModifierOption.price, platform);
|
|
1062
|
+
// =====================><=====================
|
|
1063
|
+
let optionModifiers = orderItemOption.modifiers;
|
|
1064
|
+
if (orderItemOption.modifiers != null && orderItemOption.modifiers.length > 0) {
|
|
1065
|
+
optionModifiers = recursivelyUpdateModifiers(orderItemOption.modifiers);
|
|
1066
|
+
}
|
|
1067
|
+
newOptions.push({
|
|
1068
|
+
...orderItemOption,
|
|
1069
|
+
price: optionPrice,
|
|
1070
|
+
modifiers: optionModifiers,
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
if (newOptions.length > 0) {
|
|
1074
|
+
const newModifier = {
|
|
1075
|
+
...orderItemModifier,
|
|
1076
|
+
options: newOptions,
|
|
1077
|
+
};
|
|
1078
|
+
newModifiers.push(newModifier);
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
return newModifiers;
|
|
1083
|
+
};
|
|
1084
|
+
modifiers = recursivelyUpdateModifiers(item.modifiers);
|
|
1085
|
+
}
|
|
1086
|
+
newItem = {
|
|
1087
|
+
...item,
|
|
1088
|
+
price,
|
|
1089
|
+
tax_rate,
|
|
1090
|
+
modifiers,
|
|
1091
|
+
item_discount_details: discountObj != null || item.item_discount_details != null
|
|
1092
|
+
? getItemQuantityChangeResults({
|
|
1093
|
+
prevQuantity: 1,
|
|
1094
|
+
newQuantity: item.quantity,
|
|
1095
|
+
prevItemDiscountDetails: {
|
|
1096
|
+
...item.item_discount_details,
|
|
1097
|
+
special_discount: discount_amount,
|
|
1098
|
+
is_special_discount_percentage: is_discount_percentage,
|
|
1099
|
+
total_discount: discount_amount,
|
|
1100
|
+
},
|
|
1101
|
+
})
|
|
1102
|
+
: null,
|
|
1103
|
+
};
|
|
1104
|
+
newItems.push(newItem);
|
|
1105
|
+
}
|
|
1106
|
+
if (newItems.length === 0)
|
|
1107
|
+
continue;
|
|
1108
|
+
newCategories.push({
|
|
1109
|
+
...cat,
|
|
1110
|
+
items: newItems,
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
payload = {
|
|
1114
|
+
...payload,
|
|
1115
|
+
categories: newCategories,
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
const orderData = getUpdateCartInfoData(data, payload, courses, listnerSettings);
|
|
1119
|
+
return orderData;
|
|
1120
|
+
}
|
|
1121
|
+
/* =================================><================================= */
|
|
1122
|
+
function getChangeCourseForItemData(data, itemId, new_course_id, courses, listnerSettings) {
|
|
1123
|
+
if (data.dinein_details == null)
|
|
1124
|
+
return data;
|
|
1125
|
+
// case 1: The course_id needs to be within courses
|
|
1126
|
+
const course = courses.find((c) => c._id === new_course_id);
|
|
1127
|
+
// if we can't find the course, then we return the data
|
|
1128
|
+
if (course == null)
|
|
1129
|
+
return data;
|
|
1130
|
+
// we make a shallow copy of the dinein_courses
|
|
1131
|
+
let dineinCourses = [...(data.dinein_details.courses ?? [])];
|
|
1132
|
+
// if the course is in the dineinCourses
|
|
1133
|
+
// we need to find the course that the item is in
|
|
1134
|
+
const foundCourse = dineinCourses.find((c) => c.item_ids.includes(itemId));
|
|
1135
|
+
// if the course is found and it has the same course_id as the new_course_id
|
|
1136
|
+
// then we don't need to do anything
|
|
1137
|
+
// so we return the data
|
|
1138
|
+
if (foundCourse?.course_id === new_course_id)
|
|
1139
|
+
return data;
|
|
1140
|
+
if (foundCourse != null) {
|
|
1141
|
+
// if the course is found then we remove the item from the course
|
|
1142
|
+
dineinCourses = dineinCourses.map((c) => c.course_id === foundCourse.course_id ? { ...c, item_ids: c.item_ids.filter((id) => id !== itemId) } : c);
|
|
1143
|
+
}
|
|
1144
|
+
// if the course is not in the dineinCourses, then we add it
|
|
1145
|
+
if (!dineinCourses.some((c) => c.course_id === course._id)) {
|
|
1146
|
+
dineinCourses.push({
|
|
1147
|
+
course_id: course._id,
|
|
1148
|
+
name: course.name,
|
|
1149
|
+
item_ids: [itemId],
|
|
1150
|
+
called: false,
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
// we add the item to the new course
|
|
1155
|
+
dineinCourses = dineinCourses.map((c) => c.course_id === new_course_id ? { ...c, item_ids: c.item_ids.concat(itemId) } : c);
|
|
1156
|
+
}
|
|
1157
|
+
const newOrderData = {
|
|
1158
|
+
...data,
|
|
1159
|
+
dinein_details: {
|
|
1160
|
+
...data.dinein_details,
|
|
1161
|
+
courses: dineinCourses,
|
|
1162
|
+
},
|
|
1163
|
+
};
|
|
1164
|
+
const syncedData = calculateCartOrderInfoAndSyncData(newOrderData, courses, listnerSettings);
|
|
1165
|
+
return syncedData;
|
|
1166
|
+
}
|
|
1167
|
+
/* ================================><================================= */
|
|
1168
|
+
function getChangeCourseStatusData(data, course_id, called, courses, listnerSettings) {
|
|
1169
|
+
const order = {
|
|
1170
|
+
...data,
|
|
1171
|
+
dinein_details: data.dinein_details
|
|
1172
|
+
? {
|
|
1173
|
+
...data.dinein_details,
|
|
1174
|
+
courses: data.dinein_details?.courses?.map((course) => course.course_id === course_id ? { ...course, called } : course) ?? null,
|
|
1175
|
+
}
|
|
1176
|
+
: null,
|
|
1177
|
+
};
|
|
1178
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
1179
|
+
return newData;
|
|
1180
|
+
}
|
|
1181
|
+
function getCartItemsObj({ currentIterationCategories, currentDineinCourses, previousIterationCategories, previousDineinCourses, mappedItems, shouldSortItemsViaId = true, platform, isAnEdit, sortType, }) {
|
|
1182
|
+
const isDineinOrder = constants_1.PLATFORMS_BY_ORDER_TYPE[constants_1.ORDER_TYPE_ENUM.DINE_IN].includes(platform);
|
|
1183
|
+
const newMappedItems = { ...mappedItems };
|
|
1184
|
+
if (Object.keys(newMappedItems).length === 0) {
|
|
1185
|
+
previousIterationCategories?.forEach((category) => {
|
|
1186
|
+
category.items.forEach((item) => {
|
|
1187
|
+
if (newMappedItems[item.item_id] == null) {
|
|
1188
|
+
newMappedItems[item.item_id] = {
|
|
1189
|
+
_id: item.item_id,
|
|
1190
|
+
type: item.item_type,
|
|
1191
|
+
name: item.name,
|
|
1192
|
+
category_id: category.category_id,
|
|
1193
|
+
category_name: category.name,
|
|
1194
|
+
tenants: [],
|
|
1195
|
+
category_image_url: '',
|
|
1196
|
+
image_url: '',
|
|
1197
|
+
description: '',
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
});
|
|
1202
|
+
currentIterationCategories?.forEach((category) => {
|
|
1203
|
+
category.items.forEach((item) => {
|
|
1204
|
+
if (newMappedItems[item.item_id] == null) {
|
|
1205
|
+
newMappedItems[item.item_id] = {
|
|
1206
|
+
_id: item.item_id,
|
|
1207
|
+
type: item.item_type,
|
|
1208
|
+
name: item.name,
|
|
1209
|
+
category_id: category.category_id,
|
|
1210
|
+
category_name: category.name,
|
|
1211
|
+
tenants: [],
|
|
1212
|
+
category_image_url: '',
|
|
1213
|
+
image_url: '',
|
|
1214
|
+
description: '',
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
// =====================><=====================
|
|
1221
|
+
const getCartItems = (items) => {
|
|
1222
|
+
const orderItems = items.map((item) => {
|
|
1223
|
+
const selectedItem = newMappedItems[item.item_id] ?? {};
|
|
1224
|
+
return {
|
|
1225
|
+
orderItem: item,
|
|
1226
|
+
image_url: selectedItem.image_url ?? '',
|
|
1227
|
+
description: selectedItem.description ?? '',
|
|
1228
|
+
category_name: selectedItem.category_name ?? '',
|
|
1229
|
+
category_id: selectedItem.category_id ?? '',
|
|
1230
|
+
};
|
|
1231
|
+
});
|
|
1232
|
+
if (shouldSortItemsViaId) {
|
|
1233
|
+
if (sortType === constants_1.SORT_TYPE_ENUM.DESC) {
|
|
1234
|
+
orderItems.sort((a, b) => (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime());
|
|
1235
|
+
}
|
|
1236
|
+
else {
|
|
1237
|
+
orderItems.sort((a, b) => (0, bson_objectid_1.default)(a.orderItem._id).getTimestamp().getTime() - (0, bson_objectid_1.default)(b.orderItem._id).getTimestamp().getTime());
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
return orderItems;
|
|
1241
|
+
};
|
|
1242
|
+
// =====================><=====================
|
|
1243
|
+
/*
|
|
1244
|
+
If the order has iterations in it, then we get the last iteration.
|
|
1245
|
+
We would compare the changes in the last iteration with the current iteration
|
|
1246
|
+
and show the changes in the cart.
|
|
1247
|
+
*/
|
|
1248
|
+
let totalItemsInCart = 0;
|
|
1249
|
+
const currentItems = [];
|
|
1250
|
+
if (currentIterationCategories != null) {
|
|
1251
|
+
for (let i = 0; i < currentIterationCategories.length; i++) {
|
|
1252
|
+
const category = currentIterationCategories[i];
|
|
1253
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
1254
|
+
const item = { ...category.items[j] };
|
|
1255
|
+
currentItems.push(item);
|
|
1256
|
+
totalItemsInCart += item.quantity;
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
let unChangedItems = currentItems;
|
|
1261
|
+
const editedItems = [];
|
|
1262
|
+
let removedItems = [];
|
|
1263
|
+
let newItems = [];
|
|
1264
|
+
let orderCourses = [];
|
|
1265
|
+
let disabledReason = '';
|
|
1266
|
+
// If previous iteration exists, then it's an update to the order.
|
|
1267
|
+
// In that case we would keep the previous iteration as it is and
|
|
1268
|
+
// compare the current iteration with the previous iteration.
|
|
1269
|
+
// If the current iteration is different from the previous iteration in any way
|
|
1270
|
+
// then we would update the current iteration with only those items that are different
|
|
1271
|
+
const isAnUpdate = isAnEdit ?? (previousIterationCategories != null && previousIterationCategories.length > 0);
|
|
1272
|
+
if (isAnUpdate) {
|
|
1273
|
+
// we need to compare the current iteration with the previous iteration
|
|
1274
|
+
const currentItemsMap = currentItems.reduce((acc, currentItem) => {
|
|
1275
|
+
acc[currentItem._id] = currentItem;
|
|
1276
|
+
return acc;
|
|
1277
|
+
}, {});
|
|
1278
|
+
const prevItems = [];
|
|
1279
|
+
const prevItemsMap = {};
|
|
1280
|
+
const prevCategories = previousIterationCategories ?? [];
|
|
1281
|
+
for (let i = 0; i < prevCategories.length; i++) {
|
|
1282
|
+
const category = prevCategories[i];
|
|
1283
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
1284
|
+
const prevItem = category.items[j];
|
|
1285
|
+
let item = prevItem;
|
|
1286
|
+
const currentItem = currentItemsMap[prevItem._id];
|
|
1287
|
+
if (currentItem != null && currentItem.is_ready != null) {
|
|
1288
|
+
item = {
|
|
1289
|
+
...item,
|
|
1290
|
+
is_ready: currentItem.is_ready,
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
prevItems.push(item);
|
|
1294
|
+
prevItemsMap[item._id] = item;
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
// NOTE: We will always set the items from currentItemsMap because we are dealing with current iteration
|
|
1298
|
+
unChangedItems = [];
|
|
1299
|
+
let totalTempRemovedItems = 0;
|
|
1300
|
+
for (let i = 0; i < prevItems.length; i++) {
|
|
1301
|
+
const prevItem = {
|
|
1302
|
+
...prevItems[i],
|
|
1303
|
+
};
|
|
1304
|
+
const currentItem = {
|
|
1305
|
+
...currentItemsMap[prevItem._id],
|
|
1306
|
+
};
|
|
1307
|
+
// Step 1: Get the items that are not present in the current iteration
|
|
1308
|
+
if (currentItemsMap[prevItem._id] == null) {
|
|
1309
|
+
removedItems.push(prevItem);
|
|
1310
|
+
}
|
|
1311
|
+
// Step 2: Get the items that are same in the current iteration
|
|
1312
|
+
else if ((0, lodash_1.isEqual)((0, exports.getOrderItemComaparableData)(currentItem), (0, exports.getOrderItemComaparableData)(prevItem))) {
|
|
1313
|
+
unChangedItems.push(prevItem);
|
|
1314
|
+
}
|
|
1315
|
+
// Step 3: Get the items that are present in the previous iteration but
|
|
1316
|
+
// This is turn for edit items
|
|
1317
|
+
// but we change logic for display purpose
|
|
1318
|
+
else {
|
|
1319
|
+
const currQty = currentItem.quantity;
|
|
1320
|
+
const prevQty = prevItem.quantity;
|
|
1321
|
+
if (currQty !== prevQty) {
|
|
1322
|
+
const subtotalForOne = currentItem.subtotal / currentItem.quantity;
|
|
1323
|
+
// currQty = 8
|
|
1324
|
+
// prevQty = 3
|
|
1325
|
+
// diff = 5
|
|
1326
|
+
const diff = currQty - prevQty;
|
|
1327
|
+
const changeQty = Math.abs(diff);
|
|
1328
|
+
const itm = {
|
|
1329
|
+
...currentItem,
|
|
1330
|
+
quantity: changeQty,
|
|
1331
|
+
subtotal: (0, utils_1.parseNum)(changeQty * subtotalForOne),
|
|
1332
|
+
};
|
|
1333
|
+
if (diff > 0) {
|
|
1334
|
+
// We need to show it as a new item
|
|
1335
|
+
newItems.push(itm);
|
|
1336
|
+
const unchangedQty = currQty - changeQty;
|
|
1337
|
+
const tempUnchangedItm = {
|
|
1338
|
+
...currentItem,
|
|
1339
|
+
quantity: unchangedQty,
|
|
1340
|
+
subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
|
|
1341
|
+
};
|
|
1342
|
+
unChangedItems.push(tempUnchangedItm);
|
|
1343
|
+
}
|
|
1344
|
+
else {
|
|
1345
|
+
itm.void_reason = prevItem.void_reason ?? currentItem.void_reason;
|
|
1346
|
+
// We need to show it as a removed item
|
|
1347
|
+
removedItems.push(itm);
|
|
1348
|
+
const unchangedQty = prevQty - changeQty;
|
|
1349
|
+
const tempUnchangedItm = {
|
|
1350
|
+
...currentItem,
|
|
1351
|
+
quantity: unchangedQty,
|
|
1352
|
+
subtotal: (0, utils_1.parseNum)(unchangedQty * subtotalForOne),
|
|
1353
|
+
};
|
|
1354
|
+
unChangedItems.push(tempUnchangedItm);
|
|
1355
|
+
totalTempRemovedItems++;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
else {
|
|
1359
|
+
const curr = {
|
|
1360
|
+
_id: currentItem._id,
|
|
1361
|
+
item_id: currentItem.item_id,
|
|
1362
|
+
menu_id: currentItem.menu_id,
|
|
1363
|
+
item_type: currentItem.item_type,
|
|
1364
|
+
name: currentItem.name,
|
|
1365
|
+
// price: number;
|
|
1366
|
+
// subtotal: number;
|
|
1367
|
+
// tax_rate: number;
|
|
1368
|
+
// quantity: number;
|
|
1369
|
+
special_instructions: currentItem.special_instructions,
|
|
1370
|
+
// item_discount_details: currentItem.item_discount_details,
|
|
1371
|
+
modifiers: currentItem.modifiers,
|
|
1372
|
+
};
|
|
1373
|
+
const prev = {
|
|
1374
|
+
_id: prevItem._id,
|
|
1375
|
+
item_id: prevItem.item_id,
|
|
1376
|
+
menu_id: prevItem.menu_id,
|
|
1377
|
+
item_type: prevItem.item_type,
|
|
1378
|
+
name: prevItem.name,
|
|
1379
|
+
// price: number;
|
|
1380
|
+
// subtotal: number;
|
|
1381
|
+
// tax_rate: number;
|
|
1382
|
+
// quantity: number;
|
|
1383
|
+
special_instructions: prevItem.special_instructions,
|
|
1384
|
+
// item_discount_details: prevItem.item_discount_details,
|
|
1385
|
+
modifiers: prevItem.modifiers,
|
|
1386
|
+
};
|
|
1387
|
+
const isBothEqual = (0, lodash_1.isEqual)(curr, prev);
|
|
1388
|
+
if (isBothEqual) {
|
|
1389
|
+
unChangedItems.push(currentItem);
|
|
1390
|
+
}
|
|
1391
|
+
else {
|
|
1392
|
+
// For edited item, we don't need to have tempUnchangedItemIds
|
|
1393
|
+
// because it's the turn for edited item
|
|
1394
|
+
editedItems.push(currentItem);
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
// Step 4: Get the items that are present in the current iteration
|
|
1400
|
+
// but not present in the previous iteration
|
|
1401
|
+
for (let i = 0; i < currentItems.length; i++) {
|
|
1402
|
+
const item = currentItems[i];
|
|
1403
|
+
if (prevItemsMap[item._id] == null) {
|
|
1404
|
+
newItems.push(item);
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
// Lastly, we need to check if any same item has been removed and added
|
|
1408
|
+
// If so, the we need to remove the item from removedItems and newItems, and add it to unChangedItems
|
|
1409
|
+
if (removedItems.length > 0 && newItems.length > 0) {
|
|
1410
|
+
const newItemsMap = newItems.reduce((acc, item) => {
|
|
1411
|
+
acc[item.item_id] = [...(acc[item.item_id] ?? []), item];
|
|
1412
|
+
return acc;
|
|
1413
|
+
}, {});
|
|
1414
|
+
const revertedRemovedItems = [];
|
|
1415
|
+
const revertedNewItems = [];
|
|
1416
|
+
const additionalNewItems = [];
|
|
1417
|
+
for (let i = 0; i < removedItems.length; i++) {
|
|
1418
|
+
const removedItem = removedItems[i];
|
|
1419
|
+
// Need to check if the removed item is present in the newItems
|
|
1420
|
+
const newItemsForItem = newItemsMap[removedItem.item_id];
|
|
1421
|
+
if (newItemsForItem == null)
|
|
1422
|
+
continue;
|
|
1423
|
+
if (newItemsForItem.length > 0) {
|
|
1424
|
+
const newItemsForItemLength = newItemsForItem.length;
|
|
1425
|
+
for (let j = 0; j < newItemsForItemLength; j++) {
|
|
1426
|
+
const newItem = newItemsForItem[j];
|
|
1427
|
+
const newI = {
|
|
1428
|
+
// _id: newItem._id,
|
|
1429
|
+
item_id: newItem.item_id,
|
|
1430
|
+
item_type: newItem.item_type,
|
|
1431
|
+
menu_id: newItem.menu_id,
|
|
1432
|
+
name: newItem.name,
|
|
1433
|
+
price: newItem.price,
|
|
1434
|
+
// subtotal: number;
|
|
1435
|
+
tax_rate: newItem.tax_rate,
|
|
1436
|
+
// quantity: newItem.quantity,
|
|
1437
|
+
special_instructions: newItem.special_instructions,
|
|
1438
|
+
// item_discount_details: newItem.item_discount_details,
|
|
1439
|
+
modifiers: newItem.modifiers,
|
|
1440
|
+
};
|
|
1441
|
+
const removedI = {
|
|
1442
|
+
// _id: removedItem._id,
|
|
1443
|
+
item_id: removedItem.item_id,
|
|
1444
|
+
item_type: removedItem.item_type,
|
|
1445
|
+
menu_id: removedItem.menu_id,
|
|
1446
|
+
name: removedItem.name,
|
|
1447
|
+
price: removedItem.price,
|
|
1448
|
+
// subtotal: number;
|
|
1449
|
+
tax_rate: removedItem.tax_rate,
|
|
1450
|
+
// quantity: removedItem.quantity,
|
|
1451
|
+
special_instructions: removedItem.special_instructions,
|
|
1452
|
+
// item_discount_details: removedItem.item_discount_details,
|
|
1453
|
+
modifiers: removedItem.modifiers,
|
|
1454
|
+
};
|
|
1455
|
+
if ((0, lodash_1.isEqual)(newI, removedI)) {
|
|
1456
|
+
if (newItem.quantity === removedItem.quantity) {
|
|
1457
|
+
newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
|
|
1458
|
+
if (newItemsMap[removedItem.item_id].length === 0) {
|
|
1459
|
+
delete newItemsMap[removedItem.item_id];
|
|
1460
|
+
}
|
|
1461
|
+
revertedNewItems.push(newItem);
|
|
1462
|
+
revertedRemovedItems.push(removedItem);
|
|
1463
|
+
// We will break the loop when ever we push to revertedRemovedItems
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
else {
|
|
1467
|
+
if (removedItem.quantity > newItem.quantity) {
|
|
1468
|
+
newItemsMap[removedItem.item_id] = newItemsForItem.filter((item) => item._id !== newItem._id);
|
|
1469
|
+
if (newItemsMap[removedItem.item_id].length === 0) {
|
|
1470
|
+
delete newItemsMap[removedItem.item_id];
|
|
1471
|
+
}
|
|
1472
|
+
revertedNewItems.push(newItem);
|
|
1473
|
+
const subtotalForSingle = removedItem.subtotal / removedItem.quantity;
|
|
1474
|
+
// We will only minus the quantity from removedItem
|
|
1475
|
+
const newQuantity = removedItem.quantity - newItem.quantity;
|
|
1476
|
+
const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
|
|
1477
|
+
removedItem.quantity = newQuantity;
|
|
1478
|
+
removedItem.subtotal = newSubtotal;
|
|
1479
|
+
}
|
|
1480
|
+
else {
|
|
1481
|
+
revertedRemovedItems.push(removedItem);
|
|
1482
|
+
const nQuantity = newItem.quantity;
|
|
1483
|
+
const subtotalForSingle = newItem.subtotal / nQuantity;
|
|
1484
|
+
const newQuantity = nQuantity - removedItem.quantity;
|
|
1485
|
+
const newSubtotal = (0, utils_1.parseNum)(newQuantity * subtotalForSingle);
|
|
1486
|
+
newItem.quantity = newQuantity;
|
|
1487
|
+
newItem.subtotal = newSubtotal;
|
|
1488
|
+
// =====================><=====================
|
|
1489
|
+
const remainingQuantity = nQuantity - newQuantity;
|
|
1490
|
+
const adItem = {
|
|
1491
|
+
...newItem,
|
|
1492
|
+
quantity: remainingQuantity,
|
|
1493
|
+
subtotal: (0, utils_1.parseNum)(remainingQuantity * subtotalForSingle),
|
|
1494
|
+
};
|
|
1495
|
+
additionalNewItems.push(adItem);
|
|
1496
|
+
// We will break the loop when ever we push to revertedRemovedItems
|
|
1497
|
+
break;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
else {
|
|
1504
|
+
delete newItemsMap[removedItem.item_id];
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
for (let i = 0; i < revertedRemovedItems.length; i++) {
|
|
1508
|
+
const rItem = revertedRemovedItems[i];
|
|
1509
|
+
removedItems = removedItems.filter((item) => item._id !== rItem._id);
|
|
1510
|
+
}
|
|
1511
|
+
for (let i = 0; i < revertedNewItems.length; i++) {
|
|
1512
|
+
const nItem = revertedNewItems[i];
|
|
1513
|
+
newItems = newItems.filter((item) => item._id !== nItem._id);
|
|
1514
|
+
unChangedItems.push(nItem);
|
|
1515
|
+
}
|
|
1516
|
+
for (let i = 0; i < additionalNewItems.length; i++) {
|
|
1517
|
+
const aItem = additionalNewItems[i];
|
|
1518
|
+
unChangedItems.push(aItem);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
// =====================><=====================
|
|
1522
|
+
// we need to check if courses have been removed in current iteration
|
|
1523
|
+
let coursesChanged = false;
|
|
1524
|
+
const previousCourses = previousDineinCourses ?? [];
|
|
1525
|
+
const currentCourses = currentDineinCourses ?? [];
|
|
1526
|
+
if (isDineinOrder) {
|
|
1527
|
+
if (previousCourses.length > 0 && currentCourses.length === 0) {
|
|
1528
|
+
orderCourses = previousCourses.map((course) => ({
|
|
1529
|
+
cartItemsObj: {
|
|
1530
|
+
unChangedItems: [],
|
|
1531
|
+
editedItems: [],
|
|
1532
|
+
removedItems: getCartItems(course.item_ids.map((itemId) => prevItemsMap[itemId])),
|
|
1533
|
+
newItems: [],
|
|
1534
|
+
},
|
|
1535
|
+
course_id: course.course_id,
|
|
1536
|
+
name: course.name,
|
|
1537
|
+
called: course.called,
|
|
1538
|
+
has_already_been_called: false,
|
|
1539
|
+
is_removed: true,
|
|
1540
|
+
total_amount: 0,
|
|
1541
|
+
totalSelectedItems: 0,
|
|
1542
|
+
}));
|
|
1543
|
+
}
|
|
1544
|
+
else if (previousCourses.length > 0 || currentCourses.length > 0) {
|
|
1545
|
+
const prevCoursesMap = {};
|
|
1546
|
+
const currentCoursesMap = {};
|
|
1547
|
+
let allCourseIds = new Set();
|
|
1548
|
+
for (let i = 0; i < previousCourses.length; i++) {
|
|
1549
|
+
const course = previousCourses[i];
|
|
1550
|
+
prevCoursesMap[course.course_id] = course;
|
|
1551
|
+
allCourseIds.add(course.course_id);
|
|
1552
|
+
}
|
|
1553
|
+
for (let i = 0; i < currentCourses.length; i++) {
|
|
1554
|
+
const course = currentCourses[i];
|
|
1555
|
+
currentCoursesMap[course.course_id] = course;
|
|
1556
|
+
allCourseIds.add(course.course_id);
|
|
1557
|
+
}
|
|
1558
|
+
allCourseIds = Array.from(allCourseIds);
|
|
1559
|
+
orderCourses = allCourseIds.map((courseId) => {
|
|
1560
|
+
const prevCourse = prevCoursesMap[courseId];
|
|
1561
|
+
const currentCourse = currentCoursesMap[courseId];
|
|
1562
|
+
let called;
|
|
1563
|
+
let has_already_been_called;
|
|
1564
|
+
let total_amount;
|
|
1565
|
+
let totalCourseItems;
|
|
1566
|
+
let name;
|
|
1567
|
+
let unChangedCourseItems = [];
|
|
1568
|
+
let editedCourseItems = [];
|
|
1569
|
+
let removedCourseItems = [];
|
|
1570
|
+
let newCourseItems = [];
|
|
1571
|
+
if (!prevCourse && currentCourse) {
|
|
1572
|
+
called = currentCourse.called;
|
|
1573
|
+
has_already_been_called = false;
|
|
1574
|
+
name = currentCourse.name;
|
|
1575
|
+
newCourseItems = [];
|
|
1576
|
+
total_amount = 0;
|
|
1577
|
+
totalCourseItems = 0;
|
|
1578
|
+
for (let i = 0; i < currentCourse.item_ids.length; i++) {
|
|
1579
|
+
const itemId = currentCourse.item_ids[i];
|
|
1580
|
+
const item = currentItemsMap[itemId];
|
|
1581
|
+
if (item == null)
|
|
1582
|
+
continue;
|
|
1583
|
+
newCourseItems.push(item);
|
|
1584
|
+
total_amount += item.subtotal;
|
|
1585
|
+
totalCourseItems += item.quantity;
|
|
1586
|
+
}
|
|
1587
|
+
}
|
|
1588
|
+
else {
|
|
1589
|
+
const prevCourseItemIds = new Set(prevCourse?.item_ids ?? []);
|
|
1590
|
+
const currentCourseItemIds = new Set(currentCourse?.item_ids ?? []);
|
|
1591
|
+
const course = currentCourse ?? prevCourse;
|
|
1592
|
+
name = course.name;
|
|
1593
|
+
called = course.called;
|
|
1594
|
+
has_already_been_called = prevCourse?.called ?? false;
|
|
1595
|
+
total_amount = 0;
|
|
1596
|
+
totalCourseItems = 0;
|
|
1597
|
+
unChangedCourseItems = [];
|
|
1598
|
+
editedCourseItems = [];
|
|
1599
|
+
removedCourseItems = [];
|
|
1600
|
+
newCourseItems = [];
|
|
1601
|
+
for (let i = 0; i < unChangedItems.length; i++) {
|
|
1602
|
+
const item = unChangedItems[i];
|
|
1603
|
+
const existsInCurrent = currentCourseItemIds.has(item._id);
|
|
1604
|
+
if (!existsInCurrent)
|
|
1605
|
+
continue;
|
|
1606
|
+
const existsInPrev = prevCourseItemIds.has(item._id);
|
|
1607
|
+
if (existsInPrev) {
|
|
1608
|
+
unChangedCourseItems.push(item);
|
|
1609
|
+
}
|
|
1610
|
+
else {
|
|
1611
|
+
item.special_instructions = `[Course changed]\n${item.special_instructions}`.trim();
|
|
1612
|
+
editedCourseItems.push(item);
|
|
1613
|
+
}
|
|
1614
|
+
total_amount += item.subtotal;
|
|
1615
|
+
totalCourseItems += item.quantity;
|
|
1616
|
+
}
|
|
1617
|
+
for (let i = 0; i < editedItems.length; i++) {
|
|
1618
|
+
const item = editedItems[i];
|
|
1619
|
+
const existsInCurrent = currentCourseItemIds.has(item._id);
|
|
1620
|
+
if (!existsInCurrent)
|
|
1621
|
+
continue;
|
|
1622
|
+
const existsInPrev = prevCourseItemIds.has(item._id);
|
|
1623
|
+
if (!existsInPrev) {
|
|
1624
|
+
item.special_instructions = `[Course changed]\n${item.special_instructions}`.trim();
|
|
1625
|
+
}
|
|
1626
|
+
editedCourseItems.push(item);
|
|
1627
|
+
total_amount += item.subtotal;
|
|
1628
|
+
totalCourseItems += item.quantity;
|
|
1629
|
+
}
|
|
1630
|
+
for (let i = 0; i < removedItems.length; i++) {
|
|
1631
|
+
const item = removedItems[i];
|
|
1632
|
+
// A removed item can only be in the prevCourseItemIds
|
|
1633
|
+
if (prevCourseItemIds.has(item._id)) {
|
|
1634
|
+
removedCourseItems.push(item);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
for (let i = 0; i < newItems.length; i++) {
|
|
1638
|
+
const item = newItems[i];
|
|
1639
|
+
if (currentCourseItemIds.has(item._id)) {
|
|
1640
|
+
newCourseItems.push(item);
|
|
1641
|
+
total_amount += item.subtotal;
|
|
1642
|
+
totalCourseItems += item.quantity;
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
if (!coursesChanged) {
|
|
1647
|
+
coursesChanged = unChangedCourseItems.length !== prevCourse?.item_ids.length;
|
|
1648
|
+
}
|
|
1649
|
+
const courseItem = {
|
|
1650
|
+
cartItemsObj: {
|
|
1651
|
+
unChangedItems: getCartItems(unChangedCourseItems),
|
|
1652
|
+
editedItems: getCartItems(editedCourseItems),
|
|
1653
|
+
removedItems: getCartItems(removedCourseItems),
|
|
1654
|
+
newItems: getCartItems(newCourseItems),
|
|
1655
|
+
},
|
|
1656
|
+
course_id: courseId,
|
|
1657
|
+
is_removed: false,
|
|
1658
|
+
called,
|
|
1659
|
+
has_already_been_called,
|
|
1660
|
+
total_amount,
|
|
1661
|
+
totalSelectedItems: (0, utils_1.parseNum)(totalCourseItems, true),
|
|
1662
|
+
name,
|
|
1663
|
+
};
|
|
1664
|
+
return courseItem;
|
|
1665
|
+
});
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
// =====================><=====================
|
|
1669
|
+
disabledReason =
|
|
1670
|
+
!coursesChanged &&
|
|
1671
|
+
unChangedItems.length === prevItems.length &&
|
|
1672
|
+
newItems.length === 0 &&
|
|
1673
|
+
removedItems.length === 0 &&
|
|
1674
|
+
editedItems.length === 0 &&
|
|
1675
|
+
previousCourses.length === currentCourses.length
|
|
1676
|
+
? 'No changes in the order'
|
|
1677
|
+
: prevItems.length === removedItems.length - totalTempRemovedItems &&
|
|
1678
|
+
editedItems.length === 0 &&
|
|
1679
|
+
newItems.length === 0
|
|
1680
|
+
? 'At least one item is required'
|
|
1681
|
+
: '';
|
|
1682
|
+
}
|
|
1683
|
+
else if (isDineinOrder && currentDineinCourses != null && currentDineinCourses.length > 0) {
|
|
1684
|
+
orderCourses = currentDineinCourses.map((course) => {
|
|
1685
|
+
const unChangedCourseItems = [];
|
|
1686
|
+
let total_amount = 0;
|
|
1687
|
+
let totalCourseItems = 0;
|
|
1688
|
+
for (let i = 0; i < unChangedItems.length; i++) {
|
|
1689
|
+
const item = unChangedItems[i];
|
|
1690
|
+
if (course.item_ids.includes(item._id)) {
|
|
1691
|
+
unChangedCourseItems.push(item);
|
|
1692
|
+
total_amount += item.subtotal;
|
|
1693
|
+
totalCourseItems += item.quantity;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
return {
|
|
1697
|
+
cartItemsObj: {
|
|
1698
|
+
unChangedItems: getCartItems(unChangedCourseItems),
|
|
1699
|
+
editedItems: [],
|
|
1700
|
+
removedItems: [],
|
|
1701
|
+
newItems: [],
|
|
1702
|
+
},
|
|
1703
|
+
course_id: course.course_id,
|
|
1704
|
+
name: course.name,
|
|
1705
|
+
called: course.called,
|
|
1706
|
+
has_already_been_called: false,
|
|
1707
|
+
is_removed: false,
|
|
1708
|
+
total_amount,
|
|
1709
|
+
totalSelectedItems: (0, utils_1.parseNum)(totalCourseItems, true),
|
|
1710
|
+
};
|
|
1711
|
+
});
|
|
1712
|
+
}
|
|
1713
|
+
if (sortType === constants_1.SORT_TYPE_ENUM.DESC) {
|
|
1714
|
+
orderCourses.reverse();
|
|
1715
|
+
}
|
|
1716
|
+
const cartItemsObj = {
|
|
1717
|
+
unChangedItems: getCartItems(unChangedItems),
|
|
1718
|
+
editedItems: getCartItems(editedItems),
|
|
1719
|
+
removedItems: getCartItems(removedItems),
|
|
1720
|
+
newItems: getCartItems(newItems),
|
|
1721
|
+
totalSelectedItems: (0, utils_1.parseNum)(totalItemsInCart, true),
|
|
1722
|
+
disabledReason,
|
|
1723
|
+
orderCourses,
|
|
1724
|
+
isAnUpdate,
|
|
1725
|
+
};
|
|
1726
|
+
return cartItemsObj;
|
|
1727
|
+
}
|
|
1728
|
+
// ================================><================================= //
|
|
1729
|
+
function getRemoveOfferFromCartData(data, offer_id, courses, listnerSettings) {
|
|
1730
|
+
const categories = data.categories ?? [];
|
|
1731
|
+
let order_discount_details = data.order_discount_details;
|
|
1732
|
+
if (order_discount_details != null) {
|
|
1733
|
+
// we check if either the loyalty_discount_id or voucher_discount_id
|
|
1734
|
+
if (order_discount_details.loyalty_discount_id === offer_id) {
|
|
1735
|
+
order_discount_details = {
|
|
1736
|
+
...order_discount_details,
|
|
1737
|
+
loyalty_discount_id: undefined,
|
|
1738
|
+
loyalty_discount_name: undefined,
|
|
1739
|
+
loyalty_discount: undefined,
|
|
1740
|
+
is_loyalty_discount_percentage: false,
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
else if (order_discount_details.voucher_discount_id === offer_id) {
|
|
1744
|
+
order_discount_details = {
|
|
1745
|
+
...order_discount_details,
|
|
1746
|
+
voucher_discount_id: undefined,
|
|
1747
|
+
voucher_discount_name: undefined,
|
|
1748
|
+
voucher_discount: undefined,
|
|
1749
|
+
is_voucher_discount_percentage: false,
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
const newCategories = [];
|
|
1754
|
+
for (let i = 0; i < categories.length; i++) {
|
|
1755
|
+
const category = categories[i];
|
|
1756
|
+
const newItems = [];
|
|
1757
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
1758
|
+
const item = category.items[j];
|
|
1759
|
+
// we check if either the loyalty_discount_id or voucher_discount_id
|
|
1760
|
+
// is present in the item_discount_details
|
|
1761
|
+
// if it is then we remove the items from cart
|
|
1762
|
+
if (item.item_discount_details != null) {
|
|
1763
|
+
if (item.item_discount_details.loyalty_discount_id === offer_id) {
|
|
1764
|
+
continue;
|
|
1765
|
+
}
|
|
1766
|
+
else if (item.item_discount_details.voucher_discount_id === offer_id) {
|
|
1767
|
+
continue;
|
|
1768
|
+
}
|
|
1769
|
+
else {
|
|
1770
|
+
newItems.push(item);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
else {
|
|
1774
|
+
newItems.push(item);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
newCategories.push({
|
|
1778
|
+
...category,
|
|
1779
|
+
items: newItems,
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
const order = {
|
|
1783
|
+
...data,
|
|
1784
|
+
categories: newCategories,
|
|
1785
|
+
order_discount_details,
|
|
1786
|
+
};
|
|
1787
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
1788
|
+
return newData;
|
|
1789
|
+
}
|
|
1790
|
+
// ================================><================================= //
|
|
1791
|
+
function getRemoveAllOffersFromCartData(data, courses, listnerSettings, offerIds) {
|
|
1792
|
+
const categories = data.categories ?? [];
|
|
1793
|
+
let order_discount_details = data.order_discount_details;
|
|
1794
|
+
if (order_discount_details != null) {
|
|
1795
|
+
// we check if either the loyalty_discount_id or voucher_discount_id
|
|
1796
|
+
if (order_discount_details.loyalty_discount_id != null &&
|
|
1797
|
+
(offerIds == null || offerIds.includes(order_discount_details.loyalty_discount_id))) {
|
|
1798
|
+
order_discount_details = {
|
|
1799
|
+
...order_discount_details,
|
|
1800
|
+
loyalty_discount_id: undefined,
|
|
1801
|
+
loyalty_discount_name: undefined,
|
|
1802
|
+
loyalty_discount: undefined,
|
|
1803
|
+
is_loyalty_discount_percentage: false,
|
|
1804
|
+
};
|
|
1805
|
+
}
|
|
1806
|
+
if (order_discount_details.voucher_discount_id != null &&
|
|
1807
|
+
(offerIds == null || offerIds.includes(order_discount_details.voucher_discount_id))) {
|
|
1808
|
+
order_discount_details = {
|
|
1809
|
+
...order_discount_details,
|
|
1810
|
+
voucher_discount_id: undefined,
|
|
1811
|
+
voucher_discount_name: undefined,
|
|
1812
|
+
voucher_discount: undefined,
|
|
1813
|
+
is_voucher_discount_percentage: false,
|
|
1814
|
+
};
|
|
1815
|
+
}
|
|
1816
|
+
}
|
|
1817
|
+
const newCategories = [];
|
|
1818
|
+
for (let i = 0; i < categories.length; i++) {
|
|
1819
|
+
const category = categories[i];
|
|
1820
|
+
const newItems = [];
|
|
1821
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
1822
|
+
const item = category.items[j];
|
|
1823
|
+
// we check if either the loyalty_discount_id or voucher_discount_id
|
|
1824
|
+
// is present in the item_discount_details
|
|
1825
|
+
// if it is then we remove the items from cart
|
|
1826
|
+
if (item.item_discount_details != null) {
|
|
1827
|
+
if (item.item_discount_details.loyalty_discount_id != null &&
|
|
1828
|
+
(offerIds == null || offerIds.includes(item.item_discount_details.loyalty_discount_id))) {
|
|
1829
|
+
continue;
|
|
1830
|
+
}
|
|
1831
|
+
else if (item.item_discount_details.voucher_discount_id != null &&
|
|
1832
|
+
(offerIds == null || offerIds.includes(item.item_discount_details.voucher_discount_id))) {
|
|
1833
|
+
continue;
|
|
1834
|
+
}
|
|
1835
|
+
else {
|
|
1836
|
+
newItems.push(item);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
else {
|
|
1840
|
+
newItems.push(item);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
newCategories.push({
|
|
1844
|
+
...category,
|
|
1845
|
+
items: newItems,
|
|
1846
|
+
});
|
|
1847
|
+
}
|
|
1848
|
+
const order = {
|
|
1849
|
+
...data,
|
|
1850
|
+
categories: newCategories,
|
|
1851
|
+
order_discount_details,
|
|
1852
|
+
};
|
|
1853
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
1854
|
+
return newData;
|
|
1855
|
+
}
|
|
1856
|
+
// ================================><================================= //
|
|
1857
|
+
/**
|
|
1858
|
+
* Calculate the eligible subtotal by excluding items/categories in excluded_refs
|
|
1859
|
+
*/
|
|
1860
|
+
function calculateEligibleOfferDiscountDetails(categories, excluded_refs) {
|
|
1861
|
+
if (!categories?.length)
|
|
1862
|
+
return { subtotal: 0, hasExcludedRefs: false };
|
|
1863
|
+
let eligibleSubtotal = 0;
|
|
1864
|
+
let hasExcludedRefs = false;
|
|
1865
|
+
for (const category of categories) {
|
|
1866
|
+
// Skip entire category if it's in excluded_refs
|
|
1867
|
+
if (excluded_refs.includes(category.category_id)) {
|
|
1868
|
+
hasExcludedRefs = true;
|
|
1869
|
+
continue;
|
|
1870
|
+
}
|
|
1871
|
+
// Otherwise, check each item
|
|
1872
|
+
for (const item of category.items ?? []) {
|
|
1873
|
+
if (excluded_refs.includes(item.item_id)) {
|
|
1874
|
+
hasExcludedRefs = true;
|
|
1875
|
+
}
|
|
1876
|
+
else {
|
|
1877
|
+
eligibleSubtotal += item.subtotal ?? 0;
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
}
|
|
1881
|
+
return { subtotal: eligibleSubtotal, hasExcludedRefs };
|
|
1882
|
+
}
|
|
1883
|
+
// ================================><================================= //
|
|
1884
|
+
function getSyncOffersWithCartData(data, courses, listnerSettings, unlockedOffersApplicableTimes, // Record<offer_id, times can be applied>
|
|
1885
|
+
offers) {
|
|
1886
|
+
const unlockedOffersMap = {
|
|
1887
|
+
...unlockedOffersApplicableTimes,
|
|
1888
|
+
};
|
|
1889
|
+
let hasChanges = false;
|
|
1890
|
+
const categories = data.categories ?? [];
|
|
1891
|
+
let order_discount_details = data.order_discount_details;
|
|
1892
|
+
if (order_discount_details != null) {
|
|
1893
|
+
// we check if either the loyalty_discount_id or voucher_discount_id
|
|
1894
|
+
const loyaltyDiscountId = order_discount_details.loyalty_discount_id;
|
|
1895
|
+
if (loyaltyDiscountId != null) {
|
|
1896
|
+
if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
|
|
1897
|
+
order_discount_details = {
|
|
1898
|
+
...order_discount_details,
|
|
1899
|
+
loyalty_discount_id: undefined,
|
|
1900
|
+
loyalty_discount_name: undefined,
|
|
1901
|
+
loyalty_discount: undefined,
|
|
1902
|
+
is_loyalty_discount_percentage: false,
|
|
1903
|
+
};
|
|
1904
|
+
hasChanges = true;
|
|
1905
|
+
}
|
|
1906
|
+
else {
|
|
1907
|
+
// Find the offer to check for excluded_refs
|
|
1908
|
+
const loyaltyOffer = offers.find((o) => o._id === loyaltyDiscountId);
|
|
1909
|
+
if (loyaltyOffer?.reward_discount != null) {
|
|
1910
|
+
let discount_value = loyaltyOffer.reward_discount.discount_value;
|
|
1911
|
+
const { excluded_refs, is_discount_percentage } = loyaltyOffer.reward_discount;
|
|
1912
|
+
// Handle excluded_refs - items/categories that should not receive discount
|
|
1913
|
+
if (excluded_refs != null && excluded_refs.length > 0) {
|
|
1914
|
+
const { subtotal: eligibleSubtotal, hasExcludedRefs } = calculateEligibleOfferDiscountDetails(categories, excluded_refs);
|
|
1915
|
+
if (hasExcludedRefs) {
|
|
1916
|
+
// Static discounts with exclusions are not supported - silently skip
|
|
1917
|
+
if (!is_discount_percentage) {
|
|
1918
|
+
order_discount_details = {
|
|
1919
|
+
...order_discount_details,
|
|
1920
|
+
loyalty_discount_id: undefined,
|
|
1921
|
+
loyalty_discount_name: undefined,
|
|
1922
|
+
loyalty_discount: undefined,
|
|
1923
|
+
is_loyalty_discount_percentage: false,
|
|
1924
|
+
};
|
|
1925
|
+
hasChanges = true;
|
|
1926
|
+
}
|
|
1927
|
+
else if (eligibleSubtotal <= 0) {
|
|
1928
|
+
// If no eligible items, silently skip
|
|
1929
|
+
order_discount_details = {
|
|
1930
|
+
...order_discount_details,
|
|
1931
|
+
loyalty_discount_id: undefined,
|
|
1932
|
+
loyalty_discount_name: undefined,
|
|
1933
|
+
loyalty_discount: undefined,
|
|
1934
|
+
is_loyalty_discount_percentage: false,
|
|
1935
|
+
};
|
|
1936
|
+
hasChanges = true;
|
|
1937
|
+
}
|
|
1938
|
+
else {
|
|
1939
|
+
// Convert percentage to static value based on eligible subtotal
|
|
1940
|
+
discount_value = (eligibleSubtotal * discount_value) / 100;
|
|
1941
|
+
discount_value = Math.min(discount_value, eligibleSubtotal);
|
|
1942
|
+
order_discount_details = {
|
|
1943
|
+
...order_discount_details,
|
|
1944
|
+
loyalty_discount: (0, utils_1.parseNum)(discount_value),
|
|
1945
|
+
is_loyalty_discount_percentage: false,
|
|
1946
|
+
};
|
|
1947
|
+
hasChanges = true;
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
unlockedOffersMap[loyaltyDiscountId] -= 1;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
const voucherDiscountId = order_discount_details.voucher_discount_id;
|
|
1956
|
+
if (voucherDiscountId != null) {
|
|
1957
|
+
if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
|
|
1958
|
+
order_discount_details = {
|
|
1959
|
+
...order_discount_details,
|
|
1960
|
+
voucher_discount_id: undefined,
|
|
1961
|
+
voucher_discount_name: undefined,
|
|
1962
|
+
voucher_discount: undefined,
|
|
1963
|
+
is_voucher_discount_percentage: false,
|
|
1964
|
+
};
|
|
1965
|
+
hasChanges = true;
|
|
1966
|
+
}
|
|
1967
|
+
else {
|
|
1968
|
+
// Find the offer to check for excluded_refs
|
|
1969
|
+
const voucherOffer = offers.find((o) => o._id === voucherDiscountId);
|
|
1970
|
+
if (voucherOffer?.reward_discount != null) {
|
|
1971
|
+
let discount_value = voucherOffer.reward_discount.discount_value;
|
|
1972
|
+
const { excluded_refs, is_discount_percentage } = voucherOffer.reward_discount;
|
|
1973
|
+
// Handle excluded_refs - items/categories that should not receive discount
|
|
1974
|
+
if (excluded_refs != null && excluded_refs.length > 0) {
|
|
1975
|
+
const { subtotal: eligibleSubtotal, hasExcludedRefs } = calculateEligibleOfferDiscountDetails(categories, excluded_refs);
|
|
1976
|
+
if (hasExcludedRefs) {
|
|
1977
|
+
// Static discounts with exclusions are not supported - silently skip
|
|
1978
|
+
if (!is_discount_percentage) {
|
|
1979
|
+
order_discount_details = {
|
|
1980
|
+
...order_discount_details,
|
|
1981
|
+
voucher_discount_id: undefined,
|
|
1982
|
+
voucher_discount_name: undefined,
|
|
1983
|
+
voucher_discount: undefined,
|
|
1984
|
+
is_voucher_discount_percentage: false,
|
|
1985
|
+
};
|
|
1986
|
+
hasChanges = true;
|
|
1987
|
+
}
|
|
1988
|
+
else if (eligibleSubtotal <= 0) {
|
|
1989
|
+
// If no eligible items, silently skip
|
|
1990
|
+
order_discount_details = {
|
|
1991
|
+
...order_discount_details,
|
|
1992
|
+
voucher_discount_id: undefined,
|
|
1993
|
+
voucher_discount_name: undefined,
|
|
1994
|
+
voucher_discount: undefined,
|
|
1995
|
+
is_voucher_discount_percentage: false,
|
|
1996
|
+
};
|
|
1997
|
+
hasChanges = true;
|
|
1998
|
+
}
|
|
1999
|
+
else {
|
|
2000
|
+
// Convert percentage to static value based on eligible subtotal
|
|
2001
|
+
discount_value = (eligibleSubtotal * discount_value) / 100;
|
|
2002
|
+
discount_value = Math.min(discount_value, eligibleSubtotal);
|
|
2003
|
+
order_discount_details = {
|
|
2004
|
+
...order_discount_details,
|
|
2005
|
+
voucher_discount: (0, utils_1.parseNum)(discount_value),
|
|
2006
|
+
is_voucher_discount_percentage: false,
|
|
2007
|
+
};
|
|
2008
|
+
hasChanges = true;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
unlockedOffersMap[voucherDiscountId] -= 1;
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
const newCategories = [];
|
|
2018
|
+
for (let i = 0; i < categories.length; i++) {
|
|
2019
|
+
const category = categories[i];
|
|
2020
|
+
const newItems = [];
|
|
2021
|
+
for (let j = 0; j < category.items.length; j++) {
|
|
2022
|
+
const item = category.items[j];
|
|
2023
|
+
// we check if either the loyalty_discount_id or voucher_discount_id
|
|
2024
|
+
// is present in the item_discount_details
|
|
2025
|
+
// if it is then we remove the items from cart
|
|
2026
|
+
if (item.item_discount_details != null) {
|
|
2027
|
+
const loyaltyDiscountId = item.item_discount_details.loyalty_discount_id;
|
|
2028
|
+
if (loyaltyDiscountId != null) {
|
|
2029
|
+
if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
|
|
2030
|
+
hasChanges = true;
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
else {
|
|
2034
|
+
unlockedOffersMap[loyaltyDiscountId] -= 1;
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
const voucherDiscountId = item.item_discount_details.voucher_discount_id;
|
|
2038
|
+
if (voucherDiscountId != null) {
|
|
2039
|
+
if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
|
|
2040
|
+
hasChanges = true;
|
|
2041
|
+
continue;
|
|
2042
|
+
}
|
|
2043
|
+
else {
|
|
2044
|
+
unlockedOffersMap[voucherDiscountId] -= 1;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
newItems.push(item);
|
|
2048
|
+
}
|
|
2049
|
+
else {
|
|
2050
|
+
newItems.push(item);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
newCategories.push({
|
|
2054
|
+
...category,
|
|
2055
|
+
items: newItems,
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
if (hasChanges) {
|
|
2059
|
+
const order = {
|
|
2060
|
+
...data,
|
|
2061
|
+
categories: newCategories,
|
|
2062
|
+
order_discount_details,
|
|
2063
|
+
};
|
|
2064
|
+
const newData = calculateCartOrderInfoAndSyncData(order, courses, listnerSettings);
|
|
2065
|
+
return newData;
|
|
2066
|
+
}
|
|
2067
|
+
else {
|
|
2068
|
+
return data;
|
|
2069
|
+
}
|
|
2070
|
+
}
|