@managesome/eposmatic-toolkit 0.3.7 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/constants/ANALYTICS.js +146 -0
- package/esm/constants/API_ERRORS.js +6 -0
- package/esm/constants/COMMON.js +369 -0
- package/esm/constants/DELIVERY.js +45 -0
- package/esm/constants/DIALER_ENUMS.js +11 -0
- package/esm/constants/ENUMS.js +1988 -0
- package/esm/constants/FBR_ENUMS.js +18 -0
- package/esm/constants/HUBRISE_ENUMS.js +179 -0
- package/esm/constants/INTERNAL_ENUMS.js +49 -0
- package/esm/constants/NOTIFICATIONS.js +6 -0
- package/esm/constants/ORDER.js +251 -0
- package/esm/constants/PRA_ENUMS.js +18 -0
- package/esm/constants/REPORT_WEBVIEW.js +28 -0
- package/esm/constants/RFQ_GO.js +83 -0
- package/esm/constants/SMARTPAY_ENUMS.js +55 -0
- package/esm/constants/SOCKET.js +149 -0
- package/esm/constants/SRB_ENUMS.js +13 -0
- package/esm/constants/SWITCHPAY.js +28 -0
- package/esm/constants/TENANT_ENUMS.js +90 -0
- package/esm/constants/TENANT_PURCHASE_ORDER.js +91 -0
- package/esm/constants/WALLET.js +51 -0
- package/esm/constants/WAREHOUSE_ANALYTICS.js +28 -0
- package/esm/constants/WAREHOUSE_ENUMS.js +420 -0
- package/esm/constants/WAREHOUSE_PURCHASE_ORDER.js +97 -0
- package/esm/constants/WEBVIEW.js +43 -0
- package/esm/constants/WORKER_ENDPOINTS.js +79 -0
- package/esm/constants/index.js +27 -0
- package/esm/constants/types.js +2 -0
- package/esm/helpers/fbr/generate-invoice.js +94 -0
- package/esm/helpers/fbr/index.js +1 -0
- package/esm/helpers/hubrise/hubrise-catalog.js +304 -0
- package/esm/helpers/hubrise/index.js +1 -0
- package/esm/helpers/index.js +9 -0
- package/esm/helpers/kpra/generate-invoice.js +26 -0
- package/esm/helpers/kpra/index.js +1 -0
- package/esm/helpers/order/generate-order.js +508 -0
- package/esm/helpers/order/generate-warehouse-internal-movement.js +71 -0
- package/esm/helpers/order/generate-warehouse-purchase-order-rfq.js +176 -0
- package/esm/helpers/order/generate-warehouse-purchase-order.js +187 -0
- package/esm/helpers/order/generate-warehouse-sale-order-rfq.js +176 -0
- package/esm/helpers/order/generate-warehouse-sale-order.js +149 -0
- package/esm/helpers/order/index.js +6 -0
- package/esm/helpers/pra/generate-invoice.js +94 -0
- package/esm/helpers/pra/index.js +1 -0
- package/esm/helpers/srb/generate-invoice.js +68 -0
- package/esm/helpers/srb/index.js +1 -0
- package/esm/helpers/store/all-orders-actions.js +17 -0
- package/esm/helpers/store/all-tenant-purchase-orders-actions.js +45 -0
- package/esm/helpers/store/all-warehouse-purchase-order-rfqs-actions.js +66 -0
- package/esm/helpers/store/all-warehouse-purchase-order-vendor-return-actions.js +50 -0
- package/esm/helpers/store/all-warehouse-purchase-orders-actions.js +49 -0
- package/esm/helpers/store/all-warehouse-sale-order-invoices-actions.js +132 -0
- package/esm/helpers/store/all-warehouse-sale-order-rfqs-actions.js +66 -0
- package/esm/helpers/store/all-warehouse-sale-orders-actions.js +72 -0
- package/esm/helpers/store/cart-actions.js +3563 -0
- package/esm/helpers/store/catalog-actions.js +379 -0
- package/esm/helpers/store/common-order-actions.js +937 -0
- package/esm/helpers/store/common-tenant-purchase-order-actions.js +440 -0
- package/esm/helpers/store/common-warehouse-internal-movement-actions.js +95 -0
- package/esm/helpers/store/common-warehouse-purchase-order-actions.js +530 -0
- package/esm/helpers/store/common-warehouse-purchase-order-receipt-actions.js +33 -0
- package/esm/helpers/store/common-warehouse-purchase-order-rfq-actions.js +523 -0
- package/esm/helpers/store/common-warehouse-purchase-order-vendor-return-actions.js +25 -0
- package/esm/helpers/store/common-warehouse-sale-order-actions.js +483 -0
- package/esm/helpers/store/common-warehouse-sale-order-invoice-actions.js +54 -0
- package/esm/helpers/store/common-warehouse-sale-order-rfq-actions.js +523 -0
- package/esm/helpers/store/index.js +26 -0
- package/esm/helpers/store/offline-ordering.js +251 -0
- package/esm/helpers/store/tenant-purchase-orders-cart-actions.js +379 -0
- package/esm/helpers/store/warehouse-purchase-order-rfq-cart-actions.js +360 -0
- package/esm/helpers/store/warehouse-purchase-orders-cart-actions.js +470 -0
- package/esm/helpers/store/warehouse-sale-order-rfq-cart-actions.js +359 -0
- package/esm/helpers/store/warehouse-sale-orders-cart-actions.js +456 -0
- package/esm/helpers/types/api-types.js +1 -0
- package/esm/helpers/types/cart-actions.js +1 -0
- package/esm/helpers/types/cart-helpers.js +1 -0
- package/esm/helpers/types/catalog.js +1 -0
- package/esm/helpers/types/common.js +1 -0
- package/esm/helpers/types/deliverect_menu.js +1 -0
- package/esm/helpers/types/email-templates.js +1 -0
- package/esm/helpers/types/fbr-generate-invoice.js +1 -0
- package/esm/helpers/types/halfhalf.js +1 -0
- package/esm/helpers/types/hubrise_catalog.js +1 -0
- package/esm/helpers/types/hubrise_customers.js +1 -0
- package/esm/helpers/types/hubrise_deliveries.js +1 -0
- package/esm/helpers/types/hubrise_location.js +1 -0
- package/esm/helpers/types/hubrise_orders.js +1 -0
- package/esm/helpers/types/index.js +33 -0
- package/esm/helpers/types/internal-leads.js +1 -0
- package/esm/helpers/types/inventory-catalog.js +1 -0
- package/esm/helpers/types/kpra-generate-invoice.js +1 -0
- package/esm/helpers/types/marketing.js +1 -0
- package/esm/helpers/types/order-engine.js +1 -0
- package/esm/helpers/types/pra-generate-invoice.js +1 -0
- package/esm/helpers/types/report-webview.js +1 -0
- package/esm/helpers/types/reports.js +1 -0
- package/esm/helpers/types/smartpay-apis.js +2 -0
- package/esm/helpers/types/specials.js +1 -0
- package/esm/helpers/types/split_bill.js +1 -0
- package/esm/helpers/types/srb-generate-invoice.js +1 -0
- package/esm/helpers/types/switchpay.js +1 -0
- package/esm/helpers/types/tenant-purchase-order-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-catalog.js +1 -0
- package/esm/helpers/types/warehouse-purchase-order-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-purchase-order-rfq-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-sale-order-cart-actions.js +1 -0
- package/esm/helpers/types/warehouse-sale-order-rfq-cart-actions.js +1 -0
- package/esm/helpers/types/workers.js +1 -0
- package/esm/helpers/utils/asaanbill-identifier-helpers.js +31 -0
- package/esm/helpers/utils/business-day-helpers.js +201 -0
- package/esm/helpers/utils/cart-helpers.js +156 -0
- package/esm/helpers/utils/catalog-conversion.js +129 -0
- package/esm/helpers/utils/code-redemption-helpers.js +452 -0
- package/esm/helpers/utils/color-helpers.js +31 -0
- package/esm/helpers/utils/common.js +368 -0
- package/esm/helpers/utils/crypt.js +40 -0
- package/esm/helpers/utils/customers-helpers.js +15 -0
- package/esm/helpers/utils/delivery-area-helpers.js +42 -0
- package/esm/helpers/utils/delivery-helpers.js +87 -0
- package/esm/helpers/utils/denominations-helpers.js +53 -0
- package/esm/helpers/utils/dinein.js +39 -0
- package/esm/helpers/utils/discount-helpers.js +55 -0
- package/esm/helpers/utils/email-helpers.js +111 -0
- package/esm/helpers/utils/error-helpers.js +14 -0
- package/esm/helpers/utils/expense.js +26 -0
- package/esm/helpers/utils/getFormFieldsDiff.js +15 -0
- package/esm/helpers/utils/gift-card-helpers.js +258 -0
- package/esm/helpers/utils/halfhalf-setup-helpers.js +779 -0
- package/esm/helpers/utils/hourly-comparison-report-helpers.js +851 -0
- package/esm/helpers/utils/hr-helpers.js +62 -0
- package/esm/helpers/utils/hubrise-utils.js +32 -0
- package/esm/helpers/utils/image-helpers.js +95 -0
- package/esm/helpers/utils/image-url-helpers.js +96 -0
- package/esm/helpers/utils/index.js +96 -0
- package/esm/helpers/utils/ingredients.js +26 -0
- package/esm/helpers/utils/internal-amount-helpers.js +49 -0
- package/esm/helpers/utils/inventory.js +123 -0
- package/esm/helpers/utils/inventory_entries.js +91 -0
- package/esm/helpers/utils/inventory_transactions.js +91 -0
- package/esm/helpers/utils/item-report-helpers.js +2603 -0
- package/esm/helpers/utils/items-comparison-report-helpers.js +1057 -0
- package/esm/helpers/utils/kds-helpers.js +43 -0
- package/esm/helpers/utils/location-helpers.js +13 -0
- package/esm/helpers/utils/menu-helpers.js +44 -0
- package/esm/helpers/utils/minified-catalog.js +428 -0
- package/esm/helpers/utils/offer-apply-helpers.js +613 -0
- package/esm/helpers/utils/offers-helpers.js +3351 -0
- package/esm/helpers/utils/operational-roles-helpers.js +33 -0
- package/esm/helpers/utils/order-engine.js +1409 -0
- package/esm/helpers/utils/order-history.js +208 -0
- package/esm/helpers/utils/payment-comparison-report-helpers.js +873 -0
- package/esm/helpers/utils/payment-helpers.js +302 -0
- package/esm/helpers/utils/pdf-generator.js +110 -0
- package/esm/helpers/utils/platform-catalog.js +306 -0
- package/esm/helpers/utils/platform-num.js +188 -0
- package/esm/helpers/utils/platform-specific-tenant-shifts.js +19 -0
- package/esm/helpers/utils/price-conversion.js +24 -0
- package/esm/helpers/utils/printer-helpers.js +319 -0
- package/esm/helpers/utils/public-holidays-helpers.js +8 -0
- package/esm/helpers/utils/ratings-comparison-report-helpers.js +1187 -0
- package/esm/helpers/utils/receipt-engine.js +1050 -0
- package/esm/helpers/utils/review-helpers.js +391 -0
- package/esm/helpers/utils/rider-tracking.js +12 -0
- package/esm/helpers/utils/riders-report-helpers.js +1590 -0
- package/esm/helpers/utils/sales-comparison-report-helpers.js +1259 -0
- package/esm/helpers/utils/sales-comparitive-report-helpers.js +939 -0
- package/esm/helpers/utils/sales-overview-report-helpers.js +1046 -0
- package/esm/helpers/utils/sales-summary-report-helpers.js +877 -0
- package/esm/helpers/utils/scan-code-helpers.js +31 -0
- package/esm/helpers/utils/selection-model.js +68 -0
- package/esm/helpers/utils/shift-window-helpers.js +148 -0
- package/esm/helpers/utils/simplified-catalog.js +107 -0
- package/esm/helpers/utils/simplified-halfhalf.js +101 -0
- package/esm/helpers/utils/simplified-specials.js +107 -0
- package/esm/helpers/utils/simplified-tenant.js +411 -0
- package/esm/helpers/utils/specials-helpers.js +727 -0
- package/esm/helpers/utils/tenant-calendar-helpers.js +67 -0
- package/esm/helpers/utils/tenant-cash-drawer-sessions-helpers.js +248 -0
- package/esm/helpers/utils/tenant-cash-drawers-helpers.js +31 -0
- package/esm/helpers/utils/tenant-cash-in-out-helpers.js +47 -0
- package/esm/helpers/utils/tenant-day-sessions-helpers.js +167 -0
- package/esm/helpers/utils/tenant-instore-shift-sessions-helpers.js +227 -0
- package/esm/helpers/utils/tenant-staff-helpers.js +19 -0
- package/esm/helpers/utils/tenant_cash_in_hand_transactions.js +31 -0
- package/esm/helpers/utils/time-helpers.js +142 -0
- package/esm/helpers/utils/void-items-report-helpers.js +529 -0
- package/esm/helpers/utils/void-order-items-helpers.js +32 -0
- package/esm/helpers/utils/voidations-summary-report-helpers.js +800 -0
- package/esm/helpers/utils/wallet-helpers.js +22 -0
- package/esm/helpers/utils/wallet-redemption-helpers.js +46 -0
- package/esm/helpers/utils/warehouse-catalog-conversion.js +117 -0
- package/esm/helpers/utils/warehouse-inventory.js +59 -0
- package/esm/helpers/utils/warehouse-purchase-order-engine.js +27 -0
- package/esm/helpers/utils/warehouse-purchase-order-receipt-engine.js +205 -0
- package/esm/helpers/utils/warehouse-purchase-order-x-report-helpers.js +1432 -0
- package/esm/helpers/utils/warehouse-sale-order-engine.js +27 -0
- package/esm/helpers/utils/warehouse-sale-order-receipt-engine.js +207 -0
- package/esm/helpers/utils/warehouse-sale-order-x-report-helpers.js +1 -0
- package/esm/helpers/utils/warehouse-sale-x-report-helpers.js +1434 -0
- package/esm/helpers/utils/warehouse-settings-helpers.js +37 -0
- package/esm/helpers/utils/warehouse-void-purchase-order-items-helpers.js +34 -0
- package/esm/helpers/utils/warehouse-void-purchase-order-items-report-helpers.js +18 -0
- package/esm/helpers/utils/warehouse-void-sale-order-items-helpers.js +34 -0
- package/esm/helpers/utils/warehouse-void-sale-order-items-report-helpers.js +18 -0
- package/esm/helpers/utils/warehouse_inventory_transactions.js +91 -0
- package/esm/helpers/utils/x-report-helpers.js +1850 -0
- package/esm/index.js +3 -0
- package/esm/schemas/index.js +2 -0
- package/esm/schemas/models/app_configs.js +36 -0
- package/esm/schemas/models/applied_order_discounts.js +103 -0
- package/esm/schemas/models/brands.js +56 -0
- package/esm/schemas/models/categories.js +74 -0
- package/esm/schemas/models/close_dates.js +63 -0
- package/esm/schemas/models/common-models.js +449 -0
- package/esm/schemas/models/courses.js +62 -0
- package/esm/schemas/models/customer_redemptions.js +82 -0
- package/esm/schemas/models/customers.js +269 -0
- package/esm/schemas/models/deliveries.js +137 -0
- package/esm/schemas/models/delivery_areas.js +97 -0
- package/esm/schemas/models/dinein_floors.js +55 -0
- package/esm/schemas/models/dinein_tables.js +97 -0
- package/esm/schemas/models/dinein_tables_fingerprints.js +96 -0
- package/esm/schemas/models/discounts.js +87 -0
- package/esm/schemas/models/expense_categories.js +61 -0
- package/esm/schemas/models/expense_details.js +130 -0
- package/esm/schemas/models/gift_cards.js +342 -0
- package/esm/schemas/models/halfhalf_setup.js +142 -0
- package/esm/schemas/models/index.js +111 -0
- package/esm/schemas/models/internal_customers.js +139 -0
- package/esm/schemas/models/internal_invoices.js +119 -0
- package/esm/schemas/models/internal_leads.js +78 -0
- package/esm/schemas/models/internal_operational_roles.js +85 -0
- package/esm/schemas/models/internal_staffs.js +65 -0
- package/esm/schemas/models/inventories.js +103 -0
- package/esm/schemas/models/inventory_categories.js +52 -0
- package/esm/schemas/models/inventory_transactions.js +143 -0
- package/esm/schemas/models/item_transactions.js +117 -0
- package/esm/schemas/models/items.js +341 -0
- package/esm/schemas/models/marketing_fingerprints.js +92 -0
- package/esm/schemas/models/menus.js +66 -0
- package/esm/schemas/models/messaging_devices.js +99 -0
- package/esm/schemas/models/modifier_extras.js +120 -0
- package/esm/schemas/models/offers.js +470 -0
- package/esm/schemas/models/offers_fingerprints.js +61 -0
- package/esm/schemas/models/operational_roles.js +155 -0
- package/esm/schemas/models/orders.js +1051 -0
- package/esm/schemas/models/printer_settings.js +245 -0
- package/esm/schemas/models/public_holidays.js +58 -0
- package/esm/schemas/models/reservations.js +127 -0
- package/esm/schemas/models/reviews.js +145 -0
- package/esm/schemas/models/rewards_usage.js +61 -0
- package/esm/schemas/models/riders.js +75 -0
- package/esm/schemas/models/specials.js +169 -0
- package/esm/schemas/models/staff_shifts.js +66 -0
- package/esm/schemas/models/tenant-activity-logs.js +126 -0
- package/esm/schemas/models/tenant_active_jobs.js +77 -0
- package/esm/schemas/models/tenant_calendar.js +89 -0
- package/esm/schemas/models/tenant_cash_drawer_sessions.js +208 -0
- package/esm/schemas/models/tenant_cash_drawers.js +60 -0
- package/esm/schemas/models/tenant_cash_in_hand_transactions.js +69 -0
- package/esm/schemas/models/tenant_cash_in_out.js +104 -0
- package/esm/schemas/models/tenant_clients.js +66 -0
- package/esm/schemas/models/tenant_day_sessions.js +166 -0
- package/esm/schemas/models/tenant_hr_attendance_records.js +87 -0
- package/esm/schemas/models/tenant_hr_biometric_enrollments.js +69 -0
- package/esm/schemas/models/tenant_hr_departments.js +42 -0
- package/esm/schemas/models/tenant_hr_documents.js +71 -0
- package/esm/schemas/models/tenant_hr_employees.js +172 -0
- package/esm/schemas/models/tenant_hr_leave_requests.js +80 -0
- package/esm/schemas/models/tenant_hr_payrolls.js +131 -0
- package/esm/schemas/models/tenant_hr_performance_reviews.js +58 -0
- package/esm/schemas/models/tenant_hr_policies.js +57 -0
- package/esm/schemas/models/tenant_hr_positions.js +48 -0
- package/esm/schemas/models/tenant_hr_shift_schedules.js +84 -0
- package/esm/schemas/models/tenant_hr_shifts.js +64 -0
- package/esm/schemas/models/tenant_instore_shift_sessions.js +204 -0
- package/esm/schemas/models/tenant_instore_shifts.js +63 -0
- package/esm/schemas/models/tenant_inventory_department_transactions.js +116 -0
- package/esm/schemas/models/tenant_inventory_department_utilities.js +85 -0
- package/esm/schemas/models/tenant_inventory_departments.js +55 -0
- package/esm/schemas/models/tenant_inventory_entries.js +131 -0
- package/esm/schemas/models/tenant_metadata.js +88 -0
- package/esm/schemas/models/tenant_order_item_instructions.js +66 -0
- package/esm/schemas/models/tenant_purchase_order_vendor_returns.js +80 -0
- package/esm/schemas/models/tenant_purchase_orders.js +158 -0
- package/esm/schemas/models/tenant_shifts.js +57 -0
- package/esm/schemas/models/tenant_staffs.js +129 -0
- package/esm/schemas/models/tenant_vendors.js +99 -0
- package/esm/schemas/models/tenants.js +811 -0
- package/esm/schemas/models/terminal_devices.js +63 -0
- package/esm/schemas/models/tokens.js +73 -0
- package/esm/schemas/models/track_order_numbers.js +42 -0
- package/esm/schemas/models/void_order_items.js +210 -0
- package/esm/schemas/models/vouchers.js +101 -0
- package/esm/schemas/models/wallet_transactions.js +128 -0
- package/esm/schemas/models/wallets.js +44 -0
- package/esm/schemas/models/warehouse-activity-logs.js +144 -0
- package/esm/schemas/models/warehouse_categories.js +83 -0
- package/esm/schemas/models/warehouse_clients.js +81 -0
- package/esm/schemas/models/warehouse_communications.js +226 -0
- package/esm/schemas/models/warehouse_internal_movements.js +463 -0
- package/esm/schemas/models/warehouse_inventory_entries.js +125 -0
- package/esm/schemas/models/warehouse_inventory_lot_serial_numbers.js +188 -0
- package/esm/schemas/models/warehouse_inventory_transactions.js +133 -0
- package/esm/schemas/models/warehouse_item_transactions.js +97 -0
- package/esm/schemas/models/warehouse_items.js +173 -0
- package/esm/schemas/models/warehouse_operational_roles.js +87 -0
- package/esm/schemas/models/warehouse_purchase_order_receipts.js +163 -0
- package/esm/schemas/models/warehouse_purchase_order_rfqs.js +339 -0
- package/esm/schemas/models/warehouse_purchase_order_vendor_returns.js +199 -0
- package/esm/schemas/models/warehouse_purchase_orders.js +334 -0
- package/esm/schemas/models/warehouse_sale_deliveries.js +155 -0
- package/esm/schemas/models/warehouse_sale_invoices.js +229 -0
- package/esm/schemas/models/warehouse_sale_order_rfqs.js +340 -0
- package/esm/schemas/models/warehouse_sale_orders.js +322 -0
- package/esm/schemas/models/warehouse_staffs.js +104 -0
- package/esm/schemas/models/warehouse_track_order_numbers.js +73 -0
- package/esm/schemas/models/warehouse_vendors.js +99 -0
- package/esm/schemas/models/warehouse_void_purchase_order_items.js +174 -0
- package/esm/schemas/models/warehouse_void_sale_order_items.js +174 -0
- package/esm/schemas/models/warehouses.js +253 -0
- package/esm/schemas/types/app_configs.js +1 -0
- package/esm/schemas/types/applied_order_discounts.js +1 -0
- package/esm/schemas/types/brands.js +1 -0
- package/esm/schemas/types/categories.js +1 -0
- package/esm/schemas/types/close_dates.js +1 -0
- package/esm/schemas/types/common.js +1 -0
- package/esm/schemas/types/courses.js +1 -0
- package/esm/schemas/types/customer_redemptions.js +1 -0
- package/esm/schemas/types/customers.js +1 -0
- package/esm/schemas/types/deliveries.js +1 -0
- package/esm/schemas/types/delivery_areas.js +1 -0
- package/esm/schemas/types/dinein_floors.js +1 -0
- package/esm/schemas/types/dinein_tables.js +1 -0
- package/esm/schemas/types/dinein_tables_fingerprints.js +1 -0
- package/esm/schemas/types/discounts.js +1 -0
- package/esm/schemas/types/expense_categories.js +1 -0
- package/esm/schemas/types/expense_details.js +1 -0
- package/esm/schemas/types/gift_cards.js +1 -0
- package/esm/schemas/types/halfhalf_setup.js +1 -0
- package/esm/schemas/types/index.js +113 -0
- package/esm/schemas/types/internal_customers.js +1 -0
- package/esm/schemas/types/internal_invoices.js +1 -0
- package/esm/schemas/types/internal_leads.js +1 -0
- package/esm/schemas/types/internal_operational_roles.js +16 -0
- package/esm/schemas/types/internal_staffs.js +1 -0
- package/esm/schemas/types/inventories.js +1 -0
- package/esm/schemas/types/inventory_categories.js +1 -0
- package/esm/schemas/types/inventory_department_transactions.js +1 -0
- package/esm/schemas/types/inventory_department_utilities.js +1 -0
- package/esm/schemas/types/inventory_departments.js +1 -0
- package/esm/schemas/types/inventory_transactions.js +1 -0
- package/esm/schemas/types/item_transactions.js +1 -0
- package/esm/schemas/types/items.js +1 -0
- package/esm/schemas/types/marketing_fingerprints.js +1 -0
- package/esm/schemas/types/menus.js +1 -0
- package/esm/schemas/types/messaging_devices.js +1 -0
- package/esm/schemas/types/modifier_extras.js +1 -0
- package/esm/schemas/types/multi_tenants.js +1 -0
- package/esm/schemas/types/offers.js +1 -0
- package/esm/schemas/types/offers_fingerprints.js +1 -0
- package/esm/schemas/types/operational_roles.js +15 -0
- package/esm/schemas/types/orders.js +1 -0
- package/esm/schemas/types/printer_settings.js +1 -0
- package/esm/schemas/types/public_holidays.js +1 -0
- package/esm/schemas/types/reservations.js +1 -0
- package/esm/schemas/types/reviews.js +1 -0
- package/esm/schemas/types/rewards_usage.js +1 -0
- package/esm/schemas/types/riders.js +1 -0
- package/esm/schemas/types/specials.js +1 -0
- package/esm/schemas/types/staff_shifts.js +1 -0
- package/esm/schemas/types/tenant-activity-logs.js +1 -0
- package/esm/schemas/types/tenant_active_jobs.js +1 -0
- package/esm/schemas/types/tenant_calendar.js +1 -0
- package/esm/schemas/types/tenant_cash_drawer_sessions.js +1 -0
- package/esm/schemas/types/tenant_cash_drawers.js +1 -0
- package/esm/schemas/types/tenant_cash_in_hand_transactions.js +1 -0
- package/esm/schemas/types/tenant_cash_in_out.js +1 -0
- package/esm/schemas/types/tenant_clients.js +1 -0
- package/esm/schemas/types/tenant_day_sessions.js +1 -0
- package/esm/schemas/types/tenant_hr_attendance_records.js +1 -0
- package/esm/schemas/types/tenant_hr_biometric_enrollments.js +1 -0
- package/esm/schemas/types/tenant_hr_departments.js +1 -0
- package/esm/schemas/types/tenant_hr_documents.js +1 -0
- package/esm/schemas/types/tenant_hr_employees.js +1 -0
- package/esm/schemas/types/tenant_hr_leave_requests.js +1 -0
- package/esm/schemas/types/tenant_hr_payrolls.js +1 -0
- package/esm/schemas/types/tenant_hr_performance_reviews.js +1 -0
- package/esm/schemas/types/tenant_hr_policies.js +1 -0
- package/esm/schemas/types/tenant_hr_positions.js +1 -0
- package/esm/schemas/types/tenant_hr_shift_schedules.js +1 -0
- package/esm/schemas/types/tenant_hr_shifts.js +1 -0
- package/esm/schemas/types/tenant_instore_shift_sessions.js +1 -0
- package/esm/schemas/types/tenant_instore_shifts.js +1 -0
- package/esm/schemas/types/tenant_inventory_entries.js +1 -0
- package/esm/schemas/types/tenant_metadata.js +1 -0
- package/esm/schemas/types/tenant_order_item_instructions.js +1 -0
- package/esm/schemas/types/tenant_purchase_order_vendor_returns.js +1 -0
- package/esm/schemas/types/tenant_purchase_orders.js +1 -0
- package/esm/schemas/types/tenant_shifts.js +1 -0
- package/esm/schemas/types/tenant_staffs.js +1 -0
- package/esm/schemas/types/tenant_vendors.js +1 -0
- package/esm/schemas/types/tenants.js +1 -0
- package/esm/schemas/types/terminal_devices.js +1 -0
- package/esm/schemas/types/tokens.js +1 -0
- package/esm/schemas/types/track_order_numbers.js +1 -0
- package/esm/schemas/types/void_order_items.js +1 -0
- package/esm/schemas/types/vouchers.js +1 -0
- package/esm/schemas/types/wallet_transactions.js +1 -0
- package/esm/schemas/types/wallets.js +1 -0
- package/esm/schemas/types/warehouse-activity-logs.js +1 -0
- package/esm/schemas/types/warehouse_categories.js +1 -0
- package/esm/schemas/types/warehouse_clients.js +1 -0
- package/esm/schemas/types/warehouse_communications.js +1 -0
- package/esm/schemas/types/warehouse_internal_movements.js +1 -0
- package/esm/schemas/types/warehouse_inventory_entries.js +1 -0
- package/esm/schemas/types/warehouse_inventory_lot_serial_numbers.js +1 -0
- package/esm/schemas/types/warehouse_inventory_transactions.js +1 -0
- package/esm/schemas/types/warehouse_item_transactions.js +1 -0
- package/esm/schemas/types/warehouse_items.js +1 -0
- package/esm/schemas/types/warehouse_operational_roles.js +15 -0
- package/esm/schemas/types/warehouse_purchase_order_receipts.js +18 -0
- package/esm/schemas/types/warehouse_purchase_order_rfqs.js +1 -0
- package/esm/schemas/types/warehouse_purchase_order_vendor_returns.js +1 -0
- package/esm/schemas/types/warehouse_purchase_orders.js +1 -0
- package/esm/schemas/types/warehouse_sale_deliveries.js +1 -0
- package/esm/schemas/types/warehouse_sale_invoices.js +1 -0
- package/esm/schemas/types/warehouse_sale_order_rfqs.js +1 -0
- package/esm/schemas/types/warehouse_sale_orders.js +1 -0
- package/esm/schemas/types/warehouse_staffs.js +1 -0
- package/esm/schemas/types/warehouse_track_order_numbers.js +1 -0
- package/esm/schemas/types/warehouse_vendors.js +1 -0
- package/esm/schemas/types/warehouse_void_purchase_order_items.js +1 -0
- package/esm/schemas/types/warehouse_void_sale_order_items.js +1 -0
- package/esm/schemas/types/warehouses.js +1 -0
- package/lib/helpers/utils/order-engine.js +6 -1
- package/lib/tests/soldout-option-default-guard.test.d.ts +1 -0
- package/lib/tests/soldout-option-default-guard.test.js +126 -0
- package/package.json +6 -3
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { CUSTOMER_REDEMPTION_TYPE_ENUM, GIFT_CARD_REWARD_TYPE_ENUM, MYSTERY_GIFT_TYPE_ENUM, PATHWAY_TO_UNLOCK_TYPE_ENUM, WALLET_CASHBACK_LOYALTY_DISCOUNT_ID, } from '../../constants';
|
|
2
|
+
import { buildWalletGiftCardRedemptionClaimPatch, calculateCustomerSpendableGiftCardCodes } from './offers-helpers';
|
|
3
|
+
import { getWalletGiftCardRedemptionClaims } from './wallet-redemption-helpers';
|
|
4
|
+
function normalizeCode(code) {
|
|
5
|
+
if (code == null) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const normalizedCode = code.trim().toUpperCase();
|
|
9
|
+
return normalizedCode.length > 0 ? normalizedCode : null;
|
|
10
|
+
}
|
|
11
|
+
function toPositiveInteger(value, fallback = 0) {
|
|
12
|
+
const parsedValue = Number(value);
|
|
13
|
+
if (!Number.isFinite(parsedValue) || parsedValue <= 0) {
|
|
14
|
+
return fallback;
|
|
15
|
+
}
|
|
16
|
+
return Math.floor(parsedValue);
|
|
17
|
+
}
|
|
18
|
+
function getCustomerRedemptionCount(customerOfferRedemptionCounts, type, id) {
|
|
19
|
+
const normalizedId = id?.trim();
|
|
20
|
+
if (normalizedId == null || normalizedId.length === 0 || customerOfferRedemptionCounts == null) {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
const typedCount = customerOfferRedemptionCounts[type]?.[normalizedId];
|
|
24
|
+
if (typedCount != null) {
|
|
25
|
+
return toPositiveInteger(typedCount, 0);
|
|
26
|
+
}
|
|
27
|
+
const legacyFlatCounts = customerOfferRedemptionCounts;
|
|
28
|
+
return toPositiveInteger(legacyFlatCounts[normalizedId], 0);
|
|
29
|
+
}
|
|
30
|
+
function getCustomerUsedCount(customerOfferRedemptionCounts, id) {
|
|
31
|
+
return getCustomerRedemptionCount(customerOfferRedemptionCounts, CUSTOMER_REDEMPTION_TYPE_ENUM.USED, id);
|
|
32
|
+
}
|
|
33
|
+
function getCustomerAssignedCount(customerOfferRedemptionCounts, id) {
|
|
34
|
+
return getCustomerRedemptionCount(customerOfferRedemptionCounts, CUSTOMER_REDEMPTION_TYPE_ENUM.ASSIGNED, id);
|
|
35
|
+
}
|
|
36
|
+
function getRewardMaxAssignmentsPerCustomer(rewardResource) {
|
|
37
|
+
return rewardResource.max_assignments_per_customer ?? rewardResource.max_uses_per_customer ?? null;
|
|
38
|
+
}
|
|
39
|
+
function isResourceExpired(expireAt) {
|
|
40
|
+
if (expireAt == null) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const expiryTime = new Date(expireAt).getTime();
|
|
44
|
+
return Number.isFinite(expiryTime) && expiryTime <= Date.now();
|
|
45
|
+
}
|
|
46
|
+
export function getDirectWalletGiftCardUsageGate({ giftCard, customerOfferRedemptionCounts, }) {
|
|
47
|
+
if (!giftCard.active || isResourceExpired(giftCard.expire_at)) {
|
|
48
|
+
return {
|
|
49
|
+
blocked: true,
|
|
50
|
+
usedCount: 0,
|
|
51
|
+
maxUsesPerCustomer: giftCard.max_uses_per_customer ?? null,
|
|
52
|
+
message: 'This gift card reward is not available right now.',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (giftCard.max_uses != null && giftCard.used_count >= giftCard.max_uses) {
|
|
56
|
+
return {
|
|
57
|
+
blocked: true,
|
|
58
|
+
usedCount: 0,
|
|
59
|
+
maxUsesPerCustomer: giftCard.max_uses_per_customer ?? null,
|
|
60
|
+
message: 'This gift card has been fully used.',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const maxUsesPerCustomer = giftCard.max_uses_per_customer ?? null;
|
|
64
|
+
if (maxUsesPerCustomer == null) {
|
|
65
|
+
return {
|
|
66
|
+
blocked: false,
|
|
67
|
+
usedCount: getCustomerUsedCount(customerOfferRedemptionCounts, giftCard._id),
|
|
68
|
+
maxUsesPerCustomer: null,
|
|
69
|
+
message: null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
if (customerOfferRedemptionCounts == null) {
|
|
73
|
+
return {
|
|
74
|
+
blocked: true,
|
|
75
|
+
usedCount: 0,
|
|
76
|
+
maxUsesPerCustomer,
|
|
77
|
+
message: 'Unable to verify your gift card usage limit right now.',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const usedCount = getCustomerUsedCount(customerOfferRedemptionCounts, giftCard._id);
|
|
81
|
+
if (usedCount >= maxUsesPerCustomer) {
|
|
82
|
+
return {
|
|
83
|
+
blocked: true,
|
|
84
|
+
usedCount,
|
|
85
|
+
maxUsesPerCustomer,
|
|
86
|
+
message: 'You have reached your personal limit for this gift card.',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
blocked: false,
|
|
91
|
+
usedCount,
|
|
92
|
+
maxUsesPerCustomer,
|
|
93
|
+
message: null,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function getVoucherRewardIdsFromGiftCard(giftCard, mysteryGiftType) {
|
|
97
|
+
if (giftCard.reward_type === GIFT_CARD_REWARD_TYPE_ENUM.VOUCHER) {
|
|
98
|
+
return Object.keys(giftCard.reward_voucher?.voucher_ids ?? {});
|
|
99
|
+
}
|
|
100
|
+
if (giftCard.reward_type === GIFT_CARD_REWARD_TYPE_ENUM.MYSTERY_GIFT && giftCard.reward_mystery_gift != null) {
|
|
101
|
+
const normalizedMysteryGiftType = mysteryGiftType?.toString() ?? null;
|
|
102
|
+
const shouldUseVoucherReward = normalizedMysteryGiftType === MYSTERY_GIFT_TYPE_ENUM.VOUCHER ||
|
|
103
|
+
giftCard.reward_mystery_gift.choice_of_rewards.includes(MYSTERY_GIFT_TYPE_ENUM.VOUCHER);
|
|
104
|
+
if (!shouldUseVoucherReward) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
return Object.keys(giftCard.reward_mystery_gift.reward_voucher?.voucher_ids ?? {});
|
|
108
|
+
}
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
export function getGiftCardRewardVoucherAssignmentGate({ giftCard, vouchers, customerOfferRedemptionCounts, mysteryGiftType, currentCartAssignmentCount = 0, claimsIncrement = 0, }) {
|
|
112
|
+
const voucherIds = getVoucherRewardIdsFromGiftCard(giftCard, mysteryGiftType);
|
|
113
|
+
if (voucherIds.length === 0) {
|
|
114
|
+
return {
|
|
115
|
+
blocked: false,
|
|
116
|
+
message: null,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
for (let i = 0; i < voucherIds.length; i++) {
|
|
120
|
+
const voucherId = voucherIds[i];
|
|
121
|
+
const voucher = vouchers.find((voucherItem) => voucherItem._id === voucherId);
|
|
122
|
+
if (voucher == null || !voucher.active || isResourceExpired(voucher.expire_at)) {
|
|
123
|
+
return {
|
|
124
|
+
blocked: true,
|
|
125
|
+
message: 'This voucher reward is not available right now.',
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
if (voucher.max_assignments != null &&
|
|
129
|
+
voucher.assigned_count +
|
|
130
|
+
toPositiveInteger(currentCartAssignmentCount, 0) +
|
|
131
|
+
toPositiveInteger(claimsIncrement, 0) >
|
|
132
|
+
voucher.max_assignments) {
|
|
133
|
+
return {
|
|
134
|
+
blocked: true,
|
|
135
|
+
message: 'This voucher reward is no longer available.',
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const maxAssignmentsPerCustomer = getRewardMaxAssignmentsPerCustomer(voucher);
|
|
139
|
+
if (maxAssignmentsPerCustomer == null) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (customerOfferRedemptionCounts == null) {
|
|
143
|
+
return {
|
|
144
|
+
blocked: true,
|
|
145
|
+
message: 'Unable to verify your personal limit for this reward right now.',
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
if (getCustomerAssignedCount(customerOfferRedemptionCounts, voucher._id) +
|
|
149
|
+
toPositiveInteger(currentCartAssignmentCount, 0) +
|
|
150
|
+
toPositiveInteger(claimsIncrement, 0) >
|
|
151
|
+
maxAssignmentsPerCustomer) {
|
|
152
|
+
return {
|
|
153
|
+
blocked: true,
|
|
154
|
+
message: 'You have reached your personal limit for this reward.',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
blocked: false,
|
|
160
|
+
message: null,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function getWalletGiftCardClaimGate({ currentWalletRedemptions, giftCard, vouchers, customerOfferRedemptionCounts, claimsIncrement = 1, mysteryGiftType, }) {
|
|
164
|
+
const safeClaimsIncrement = toPositiveInteger(claimsIncrement, 1);
|
|
165
|
+
const currentGiftCardClaimCount = getWalletGiftCardRedemptionClaims(currentWalletRedemptions?.gift_cards)
|
|
166
|
+
.filter((claim) => claim.gift_card_id === giftCard._id)
|
|
167
|
+
.reduce((total, claim) => total + claim.redeemed_times, 0);
|
|
168
|
+
const directUsageGate = getDirectWalletGiftCardUsageGate({
|
|
169
|
+
giftCard,
|
|
170
|
+
customerOfferRedemptionCounts,
|
|
171
|
+
});
|
|
172
|
+
if (directUsageGate.blocked) {
|
|
173
|
+
return {
|
|
174
|
+
blocked: true,
|
|
175
|
+
message: directUsageGate.message,
|
|
176
|
+
usedCount: directUsageGate.usedCount,
|
|
177
|
+
maxUsesPerCustomer: directUsageGate.maxUsesPerCustomer,
|
|
178
|
+
currentCartClaimCount: currentGiftCardClaimCount,
|
|
179
|
+
claimsIncrement: safeClaimsIncrement,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (directUsageGate.maxUsesPerCustomer != null &&
|
|
183
|
+
directUsageGate.usedCount + currentGiftCardClaimCount + safeClaimsIncrement > directUsageGate.maxUsesPerCustomer) {
|
|
184
|
+
return {
|
|
185
|
+
blocked: true,
|
|
186
|
+
message: 'You have reached your personal limit for this gift card.',
|
|
187
|
+
usedCount: directUsageGate.usedCount,
|
|
188
|
+
maxUsesPerCustomer: directUsageGate.maxUsesPerCustomer,
|
|
189
|
+
currentCartClaimCount: currentGiftCardClaimCount,
|
|
190
|
+
claimsIncrement: safeClaimsIncrement,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
const voucherRewardAssignmentGate = getGiftCardRewardVoucherAssignmentGate({
|
|
194
|
+
giftCard,
|
|
195
|
+
vouchers,
|
|
196
|
+
customerOfferRedemptionCounts,
|
|
197
|
+
mysteryGiftType,
|
|
198
|
+
currentCartAssignmentCount: currentGiftCardClaimCount,
|
|
199
|
+
claimsIncrement: safeClaimsIncrement,
|
|
200
|
+
});
|
|
201
|
+
if (voucherRewardAssignmentGate.blocked) {
|
|
202
|
+
return {
|
|
203
|
+
blocked: true,
|
|
204
|
+
message: voucherRewardAssignmentGate.message,
|
|
205
|
+
usedCount: directUsageGate.usedCount,
|
|
206
|
+
maxUsesPerCustomer: directUsageGate.maxUsesPerCustomer,
|
|
207
|
+
currentCartClaimCount: currentGiftCardClaimCount,
|
|
208
|
+
claimsIncrement: safeClaimsIncrement,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
blocked: false,
|
|
213
|
+
message: null,
|
|
214
|
+
usedCount: directUsageGate.usedCount,
|
|
215
|
+
maxUsesPerCustomer: directUsageGate.maxUsesPerCustomer,
|
|
216
|
+
currentCartClaimCount: currentGiftCardClaimCount,
|
|
217
|
+
claimsIncrement: safeClaimsIncrement,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
export function buildValidatedWalletGiftCardRedemptionClaimPatch({ currentWalletRedemptions, giftCard, vouchers, customerOfferRedemptionCounts, claimsIncrement = 1, mysteryGiftType, }) {
|
|
221
|
+
const safeClaimsIncrement = toPositiveInteger(claimsIncrement, 1);
|
|
222
|
+
const sourceOfTruth = getWalletRedemptionsSourceOfTruth({
|
|
223
|
+
offers: [],
|
|
224
|
+
vouchers,
|
|
225
|
+
giftCards: [giftCard],
|
|
226
|
+
redeemedOffers: null,
|
|
227
|
+
walletRedemptions: currentWalletRedemptions,
|
|
228
|
+
orderDiscountDetails: null,
|
|
229
|
+
customerGiftCardCodes: null,
|
|
230
|
+
customerOfferRedemptionCounts,
|
|
231
|
+
pendingGiftCardClaim: {
|
|
232
|
+
giftCardId: giftCard._id,
|
|
233
|
+
claimsIncrement: safeClaimsIncrement,
|
|
234
|
+
mysteryGiftType,
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
const giftCardStats = sourceOfTruth.giftCardStatsById[giftCard._id];
|
|
238
|
+
if (giftCardStats == null || !giftCardStats.claimable) {
|
|
239
|
+
return {
|
|
240
|
+
success: false,
|
|
241
|
+
walletPatch: {},
|
|
242
|
+
errorMessage: giftCardStats?.claim_block_message ?? 'You cannot apply this gift card right now.',
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
success: true,
|
|
247
|
+
walletPatch: buildWalletGiftCardRedemptionClaimPatch({
|
|
248
|
+
currentWalletRedemptions,
|
|
249
|
+
giftCardId: giftCard._id,
|
|
250
|
+
claimsIncrement: safeClaimsIncrement,
|
|
251
|
+
mysteryGiftType,
|
|
252
|
+
}),
|
|
253
|
+
errorMessage: null,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function getRedeemedVoucherPathwayOfferIdsInternal({ offers, redeemedOffers, }) {
|
|
257
|
+
if (redeemedOffers == null) {
|
|
258
|
+
return [];
|
|
259
|
+
}
|
|
260
|
+
const offerById = new Map();
|
|
261
|
+
for (let i = 0; i < offers.length; i++) {
|
|
262
|
+
offerById.set(offers[i]._id, offers[i]);
|
|
263
|
+
}
|
|
264
|
+
const offerIds = Object.keys(redeemedOffers);
|
|
265
|
+
const voucherPathwayOfferIds = [];
|
|
266
|
+
for (let i = 0; i < offerIds.length; i++) {
|
|
267
|
+
const offerId = offerIds[i];
|
|
268
|
+
const redeemedTimes = toPositiveInteger(redeemedOffers[offerId], 0);
|
|
269
|
+
if (redeemedTimes <= 0) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const offer = offerById.get(offerId);
|
|
273
|
+
if (offer == null || offer.pathway_to_unlock_type !== PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER) {
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (offer.pathway_to_unlock_type_vouchers == null) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
voucherPathwayOfferIds.push(offerId);
|
|
280
|
+
}
|
|
281
|
+
return voucherPathwayOfferIds;
|
|
282
|
+
}
|
|
283
|
+
export function getRedeemedVoucherPathwayOfferIds(args) {
|
|
284
|
+
return getRedeemedVoucherPathwayOfferIdsInternal(args);
|
|
285
|
+
}
|
|
286
|
+
function getVoucherCodesForOffer(offer, vouchersById) {
|
|
287
|
+
if (offer.pathway_to_unlock_type !== PATHWAY_TO_UNLOCK_TYPE_ENUM.VOUCHER ||
|
|
288
|
+
offer.pathway_to_unlock_type_vouchers == null) {
|
|
289
|
+
return [];
|
|
290
|
+
}
|
|
291
|
+
const voucherCodes = [];
|
|
292
|
+
const voucherIds = offer.pathway_to_unlock_type_vouchers.voucher_ids;
|
|
293
|
+
for (let i = 0; i < voucherIds.length; i++) {
|
|
294
|
+
const voucher = vouchersById.get(voucherIds[i]);
|
|
295
|
+
if (voucher == null) {
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
const normalizedCode = normalizeCode(voucher.code);
|
|
299
|
+
if (normalizedCode == null) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
voucherCodes.push(normalizedCode);
|
|
303
|
+
}
|
|
304
|
+
return voucherCodes;
|
|
305
|
+
}
|
|
306
|
+
export function getWalletRedemptionsSourceOfTruth({ offers, vouchers, giftCards, redeemedOffers, walletRedemptions, orderDiscountDetails, customerGiftCardCodes, customerOfferRedemptionCounts, pendingGiftCardClaim, }) {
|
|
307
|
+
const activeVoucherOfferIds = getRedeemedVoucherPathwayOfferIdsInternal({
|
|
308
|
+
offers,
|
|
309
|
+
redeemedOffers,
|
|
310
|
+
});
|
|
311
|
+
const offerById = new Map();
|
|
312
|
+
const vouchersById = new Map();
|
|
313
|
+
const giftCardsById = new Map();
|
|
314
|
+
for (let i = 0; i < offers.length; i++) {
|
|
315
|
+
offerById.set(offers[i]._id, offers[i]);
|
|
316
|
+
}
|
|
317
|
+
for (let i = 0; i < vouchers.length; i++) {
|
|
318
|
+
vouchersById.set(vouchers[i]._id, vouchers[i]);
|
|
319
|
+
}
|
|
320
|
+
for (let i = 0; i < giftCards.length; i++) {
|
|
321
|
+
giftCardsById.set(giftCards[i]._id, giftCards[i]);
|
|
322
|
+
}
|
|
323
|
+
const voucherCodesInUse = new Set();
|
|
324
|
+
for (let i = 0; i < activeVoucherOfferIds.length; i++) {
|
|
325
|
+
const offer = offerById.get(activeVoucherOfferIds[i]);
|
|
326
|
+
if (offer == null) {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
const voucherCodes = getVoucherCodesForOffer(offer, vouchersById);
|
|
330
|
+
for (let j = 0; j < voucherCodes.length; j++) {
|
|
331
|
+
voucherCodesInUse.add(voucherCodes[j]);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const normalizedVoucherReferenceCode = normalizeCode(orderDiscountDetails?.voucher_reference_number);
|
|
335
|
+
const activeVoucherCode = voucherCodesInUse.size === 0
|
|
336
|
+
? null
|
|
337
|
+
: normalizedVoucherReferenceCode != null && voucherCodesInUse.has(normalizedVoucherReferenceCode)
|
|
338
|
+
? normalizedVoucherReferenceCode
|
|
339
|
+
: (Array.from(voucherCodesInUse.values()).sort((a, b) => a.localeCompare(b))[0] ?? null);
|
|
340
|
+
const normalizedWalletGiftCardClaims = getWalletGiftCardRedemptionClaims(walletRedemptions?.gift_cards);
|
|
341
|
+
const appliedGiftCardIds = normalizedWalletGiftCardClaims.map((walletGiftCardClaim) => walletGiftCardClaim.gift_card_id);
|
|
342
|
+
const normalizedLoyaltyDiscountId = orderDiscountDetails?.loyalty_discount_id?.trim() ?? null;
|
|
343
|
+
const isWalletCashbackLoyaltyDiscount = normalizedLoyaltyDiscountId === WALLET_CASHBACK_LOYALTY_DISCOUNT_ID;
|
|
344
|
+
let activeGiftCardId = null;
|
|
345
|
+
if (appliedGiftCardIds.length === 1) {
|
|
346
|
+
activeGiftCardId = appliedGiftCardIds[0];
|
|
347
|
+
}
|
|
348
|
+
else if (normalizedLoyaltyDiscountId != null &&
|
|
349
|
+
!isWalletCashbackLoyaltyDiscount &&
|
|
350
|
+
appliedGiftCardIds.includes(normalizedLoyaltyDiscountId)) {
|
|
351
|
+
activeGiftCardId = normalizedLoyaltyDiscountId;
|
|
352
|
+
}
|
|
353
|
+
else if (appliedGiftCardIds.length > 0) {
|
|
354
|
+
activeGiftCardId = appliedGiftCardIds[0];
|
|
355
|
+
}
|
|
356
|
+
else if (normalizedLoyaltyDiscountId != null &&
|
|
357
|
+
!isWalletCashbackLoyaltyDiscount &&
|
|
358
|
+
giftCardsById.has(normalizedLoyaltyDiscountId)) {
|
|
359
|
+
activeGiftCardId = normalizedLoyaltyDiscountId;
|
|
360
|
+
}
|
|
361
|
+
const activeGiftCardCode = activeGiftCardId == null ? null : normalizeCode(giftCardsById.get(activeGiftCardId)?.code);
|
|
362
|
+
const spendableGiftCardCodes = calculateCustomerSpendableGiftCardCodes({
|
|
363
|
+
customerGiftCardCodes,
|
|
364
|
+
loyaltyReferenceNumber: orderDiscountDetails?.loyalty_reference_number,
|
|
365
|
+
loyaltyDiscountId: orderDiscountDetails?.loyalty_discount_id,
|
|
366
|
+
walletGiftCardRedemptions: walletRedemptions?.gift_cards,
|
|
367
|
+
giftCards,
|
|
368
|
+
}).giftCardCodes;
|
|
369
|
+
const normalizedCustomerGiftCardCodes = {};
|
|
370
|
+
if (customerGiftCardCodes != null) {
|
|
371
|
+
const entries = Object.entries(customerGiftCardCodes);
|
|
372
|
+
for (let i = 0; i < entries.length; i++) {
|
|
373
|
+
const [code, count] = entries[i];
|
|
374
|
+
const normalizedCode = normalizeCode(code);
|
|
375
|
+
if (normalizedCode == null) {
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
const parsedCount = toPositiveInteger(count, 0);
|
|
379
|
+
if (parsedCount <= 0) {
|
|
380
|
+
continue;
|
|
381
|
+
}
|
|
382
|
+
normalizedCustomerGiftCardCodes[normalizedCode] = parsedCount;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const appliedGiftCardIdSet = new Set(appliedGiftCardIds);
|
|
386
|
+
const giftCardStatsById = {};
|
|
387
|
+
const pendingGiftCardClaimId = pendingGiftCardClaim?.giftCardId?.toString().trim();
|
|
388
|
+
for (let i = 0; i < giftCards.length; i++) {
|
|
389
|
+
const giftCard = giftCards[i];
|
|
390
|
+
const normalizedGiftCardCode = normalizeCode(giftCard.code);
|
|
391
|
+
if (normalizedGiftCardCode == null) {
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
394
|
+
const isPendingGiftCardClaim = pendingGiftCardClaimId === giftCard._id;
|
|
395
|
+
const claimGate = getWalletGiftCardClaimGate({
|
|
396
|
+
currentWalletRedemptions: walletRedemptions,
|
|
397
|
+
giftCard,
|
|
398
|
+
vouchers,
|
|
399
|
+
customerOfferRedemptionCounts,
|
|
400
|
+
claimsIncrement: isPendingGiftCardClaim ? pendingGiftCardClaim?.claimsIncrement : 1,
|
|
401
|
+
mysteryGiftType: isPendingGiftCardClaim ? pendingGiftCardClaim?.mysteryGiftType : giftCard.reward_type,
|
|
402
|
+
});
|
|
403
|
+
giftCardStatsById[giftCard._id] = {
|
|
404
|
+
gift_card_id: giftCard._id,
|
|
405
|
+
code: normalizedGiftCardCode,
|
|
406
|
+
owned_count: normalizedCustomerGiftCardCodes[normalizedGiftCardCode] ?? 0,
|
|
407
|
+
spendable_count: spendableGiftCardCodes[normalizedGiftCardCode] ?? 0,
|
|
408
|
+
used_count: claimGate.usedCount,
|
|
409
|
+
max_uses_per_customer: claimGate.maxUsesPerCustomer,
|
|
410
|
+
current_cart_claim_count: claimGate.currentCartClaimCount,
|
|
411
|
+
next_claim_increment: claimGate.claimsIncrement,
|
|
412
|
+
is_usage_exhausted: claimGate.blocked,
|
|
413
|
+
claimable: !claimGate.blocked,
|
|
414
|
+
claim_block_message: claimGate.message,
|
|
415
|
+
is_applied: appliedGiftCardIdSet.has(giftCard._id) ||
|
|
416
|
+
(!isWalletCashbackLoyaltyDiscount && normalizedLoyaltyDiscountId === giftCard._id),
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
let activeCodeType = null;
|
|
420
|
+
if (activeVoucherCode != null && activeGiftCardCode != null) {
|
|
421
|
+
if (normalizedVoucherReferenceCode === activeVoucherCode) {
|
|
422
|
+
activeCodeType = 'voucher';
|
|
423
|
+
}
|
|
424
|
+
else if (!isWalletCashbackLoyaltyDiscount &&
|
|
425
|
+
normalizeCode(orderDiscountDetails?.loyalty_reference_number) === activeGiftCardCode) {
|
|
426
|
+
activeCodeType = 'gift-card';
|
|
427
|
+
}
|
|
428
|
+
else if (activeVoucherOfferIds.length > 0) {
|
|
429
|
+
activeCodeType = 'voucher';
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
activeCodeType = 'gift-card';
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
else if (activeVoucherCode != null) {
|
|
436
|
+
activeCodeType = 'voucher';
|
|
437
|
+
}
|
|
438
|
+
else if (activeGiftCardCode != null) {
|
|
439
|
+
activeCodeType = 'gift-card';
|
|
440
|
+
}
|
|
441
|
+
const activeCode = activeCodeType === 'voucher' ? activeVoucherCode : activeCodeType === 'gift-card' ? activeGiftCardCode : null;
|
|
442
|
+
return {
|
|
443
|
+
activeCode,
|
|
444
|
+
activeCodeType,
|
|
445
|
+
activeVoucherCode,
|
|
446
|
+
activeGiftCardCode,
|
|
447
|
+
activeGiftCardId,
|
|
448
|
+
activeVoucherOfferIds,
|
|
449
|
+
appliedGiftCardIds,
|
|
450
|
+
giftCardStatsById,
|
|
451
|
+
};
|
|
452
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Function to generate a lighter shade of a color
|
|
2
|
+
export function getLightColorShade(color, percent) {
|
|
3
|
+
const factor = 1 + percent / 100;
|
|
4
|
+
const r = Math.min(255, Math.round(parseInt(color.substring(1, 3), 16) * factor));
|
|
5
|
+
const g = Math.min(255, Math.round(parseInt(color.substring(3, 5), 16) * factor));
|
|
6
|
+
const b = Math.min(255, Math.round(parseInt(color.substring(5, 7), 16) * factor));
|
|
7
|
+
// check if color has opacity
|
|
8
|
+
const opacity = color.length > 7 ? color.substring(7, 9) : '';
|
|
9
|
+
return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')}${opacity}`;
|
|
10
|
+
}
|
|
11
|
+
// ====================>>><<<====================
|
|
12
|
+
// Function to generate a darker shade of a color
|
|
13
|
+
export function getDarkColorShade(color, percent) {
|
|
14
|
+
const factor = 1 - percent / 100;
|
|
15
|
+
const r = Math.max(0, Math.round(parseInt(color.substring(1, 3), 16) * factor));
|
|
16
|
+
const g = Math.max(0, Math.round(parseInt(color.substring(3, 5), 16) * factor));
|
|
17
|
+
const b = Math.max(0, Math.round(parseInt(color.substring(5, 7), 16) * factor));
|
|
18
|
+
// check if color has opacity
|
|
19
|
+
const opacity = color.length > 7 ? color.substring(7, 9) : '';
|
|
20
|
+
return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')}${opacity}`;
|
|
21
|
+
}
|
|
22
|
+
// ====================>>><<<====================
|
|
23
|
+
export function getContrastColor(hexColor) {
|
|
24
|
+
const r = parseInt(hexColor.substring(1, 3), 16);
|
|
25
|
+
const g = parseInt(hexColor.substring(3, 5), 16);
|
|
26
|
+
const b = parseInt(hexColor.substring(5, 7), 16);
|
|
27
|
+
// Calculate relative luminance using the formula for sRGB color space
|
|
28
|
+
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
29
|
+
// Determine whether to use white or black as contrast color
|
|
30
|
+
return luminance > 0.5 ? '#000000' : '#ffffff';
|
|
31
|
+
}
|