@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,302 @@
|
|
|
1
|
+
import ObjectID from 'bson-objectid';
|
|
2
|
+
import { PAYMENT_EXTENSION_ENUM, PAYMENT_STATUS_ENUM, PAYMENT_TYPE_ENUM } from '../../constants';
|
|
3
|
+
import { parseNum } from './common';
|
|
4
|
+
export function getPaymentAmountPayed(payment, allowCreditPayments) {
|
|
5
|
+
if (payment.payment_type !== PAYMENT_TYPE_ENUM.UNPAID &&
|
|
6
|
+
(payment.payment_id !== null || allowCreditPayments) &&
|
|
7
|
+
(payment.payment_status === PAYMENT_STATUS_ENUM.SETTLED ||
|
|
8
|
+
payment.payment_status === PAYMENT_STATUS_ENUM.REFUNDED ||
|
|
9
|
+
(allowCreditPayments &&
|
|
10
|
+
payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER &&
|
|
11
|
+
payment.payment_status === PAYMENT_STATUS_ENUM.PENDING))) {
|
|
12
|
+
const cardFee = payment.card_details?.card_charges ?? 0;
|
|
13
|
+
// Amount Paid Can be more than amount due in case of cash payment
|
|
14
|
+
let changeAmount = 0;
|
|
15
|
+
let amountPaid = 0;
|
|
16
|
+
let amountRefunded = 0;
|
|
17
|
+
let totalAmountPaid = 0;
|
|
18
|
+
if (payment.amount_paid > 0) {
|
|
19
|
+
if (payment.amount_paid > payment.amount_due) {
|
|
20
|
+
amountPaid += payment.amount_due;
|
|
21
|
+
changeAmount += payment.amount_paid - payment.amount_due;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
amountPaid += payment.amount_paid;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (payment.amount_refunded > 0) {
|
|
28
|
+
amountRefunded += payment.amount_refunded > payment.amount_due ? payment.amount_due : payment.amount_refunded;
|
|
29
|
+
}
|
|
30
|
+
amountPaid += cardFee;
|
|
31
|
+
totalAmountPaid += amountPaid;
|
|
32
|
+
totalAmountPaid -= amountRefunded;
|
|
33
|
+
return {
|
|
34
|
+
amountPaid,
|
|
35
|
+
changeAmount,
|
|
36
|
+
amountRefunded,
|
|
37
|
+
totalAmountPaid,
|
|
38
|
+
cardFee,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
amountPaid: 0,
|
|
43
|
+
changeAmount: 0,
|
|
44
|
+
amountRefunded: 0,
|
|
45
|
+
totalAmountPaid: 0,
|
|
46
|
+
cardFee: 0,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function getOrderPaymentsDetails(grand_total, payments) {
|
|
50
|
+
let payed = 0;
|
|
51
|
+
let amountLeft = parseNum(grand_total ?? 0);
|
|
52
|
+
let cardCharges = 0;
|
|
53
|
+
let change = 0;
|
|
54
|
+
let creditAmount = 0;
|
|
55
|
+
payments?.forEach((payment) => {
|
|
56
|
+
const { totalAmountPaid, changeAmount, cardFee } = getPaymentAmountPayed(payment);
|
|
57
|
+
payed += totalAmountPaid;
|
|
58
|
+
amountLeft -= totalAmountPaid;
|
|
59
|
+
change += changeAmount;
|
|
60
|
+
cardCharges += cardFee;
|
|
61
|
+
if (payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER &&
|
|
62
|
+
payment.payment_status === PAYMENT_STATUS_ENUM.PENDING) {
|
|
63
|
+
creditAmount += payment.amount_due;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
amountPayedSoFar: payed,
|
|
68
|
+
amountLeftToPay: amountLeft,
|
|
69
|
+
cardCharges,
|
|
70
|
+
change,
|
|
71
|
+
creditAmount,
|
|
72
|
+
existingPayments: (payments ?? []).filter((payment) => payment.payment_type !== PAYMENT_TYPE_ENUM.UNPAID && payment.amount_due > 0),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function getTotalCardCharges(payments) {
|
|
76
|
+
return (payments?.reduce((acc, payment) => {
|
|
77
|
+
if (payment.card_details == null || payment.payment_id == null)
|
|
78
|
+
return acc;
|
|
79
|
+
return acc + payment.card_details.card_charges;
|
|
80
|
+
}, 0) ?? 0);
|
|
81
|
+
}
|
|
82
|
+
export function getPaymentTypeTotalAmount(payments, paymentType, allowCreditPayments) {
|
|
83
|
+
return (payments?.reduce((acc, payment) => {
|
|
84
|
+
if (payment.payment_type !== paymentType)
|
|
85
|
+
return acc;
|
|
86
|
+
return acc + getPaymentAmountPayed(payment, allowCreditPayments).totalAmountPaid;
|
|
87
|
+
}, 0) ?? 0);
|
|
88
|
+
}
|
|
89
|
+
export function getCardChargesAndAmountCollected(payments) {
|
|
90
|
+
let cardCharges = 0;
|
|
91
|
+
let amountCollected = 0;
|
|
92
|
+
let amountPaid = 0;
|
|
93
|
+
let totalComplemetaryAmount = 0;
|
|
94
|
+
let totalRefundedAmount = 0;
|
|
95
|
+
const paymentsArray = payments ?? [];
|
|
96
|
+
for (let i = 0; i < paymentsArray.length; i++) {
|
|
97
|
+
const payment = paymentsArray[i];
|
|
98
|
+
const { totalAmountPaid, cardFee } = getPaymentAmountPayed(payment);
|
|
99
|
+
amountPaid += totalAmountPaid;
|
|
100
|
+
cardCharges += cardFee;
|
|
101
|
+
const collected = totalAmountPaid - cardFee;
|
|
102
|
+
amountCollected += collected;
|
|
103
|
+
if (payment.payment_type === PAYMENT_TYPE_ENUM.COMPLIMENTARY &&
|
|
104
|
+
payment.payment_status === PAYMENT_STATUS_ENUM.SETTLED) {
|
|
105
|
+
totalComplemetaryAmount += collected;
|
|
106
|
+
}
|
|
107
|
+
else if (payment.payment_status === PAYMENT_STATUS_ENUM.REFUNDED) {
|
|
108
|
+
totalRefundedAmount += Math.abs(collected);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
totalComplemetaryAmount -= totalRefundedAmount;
|
|
112
|
+
if (totalComplemetaryAmount > 0) {
|
|
113
|
+
amountCollected -= totalComplemetaryAmount;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
cardCharges,
|
|
117
|
+
amountCollected,
|
|
118
|
+
amountPaid,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export function isOrderFullyPaid(grandTotal, payments, allowCreditPayments) {
|
|
122
|
+
const amountPaidSoFar = payments?.reduce((acc, payment) => {
|
|
123
|
+
const totalAmountPaid = getPaymentAmountPayed(payment, allowCreditPayments).totalAmountPaid;
|
|
124
|
+
return acc + totalAmountPaid;
|
|
125
|
+
}, 0) ?? 0;
|
|
126
|
+
return Number(amountPaidSoFar.toFixed(2)) >= parseNum(grandTotal);
|
|
127
|
+
}
|
|
128
|
+
export function syncPayments(payments) {
|
|
129
|
+
const newPayments = [];
|
|
130
|
+
const complimentaryPayments = [];
|
|
131
|
+
const refundedPayments = [];
|
|
132
|
+
const payLaterPayments = [];
|
|
133
|
+
for (let i = 0; i < payments.length; i++) {
|
|
134
|
+
const payment = payments[i];
|
|
135
|
+
if (payment.payment_type === PAYMENT_TYPE_ENUM.COMPLIMENTARY &&
|
|
136
|
+
payment.payment_status === PAYMENT_STATUS_ENUM.SETTLED) {
|
|
137
|
+
complimentaryPayments.push(payment);
|
|
138
|
+
}
|
|
139
|
+
else if (payment.payment_status === PAYMENT_STATUS_ENUM.REFUNDED) {
|
|
140
|
+
refundedPayments.push(payment);
|
|
141
|
+
}
|
|
142
|
+
else if (payment.payment_type === PAYMENT_TYPE_ENUM.PAY_LATER) {
|
|
143
|
+
payLaterPayments.push(payment);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
newPayments.push(payment);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
// Combine PAY_LATER payments
|
|
150
|
+
if (payLaterPayments.length > 1) {
|
|
151
|
+
const totalPayLaterAmount = payLaterPayments.reduce((acc, payment) => acc + payment.amount_due, 0);
|
|
152
|
+
const firstPayLater = payLaterPayments[0];
|
|
153
|
+
const combinedPayLater = {
|
|
154
|
+
...firstPayLater,
|
|
155
|
+
amount_due: totalPayLaterAmount,
|
|
156
|
+
amount_paid: totalPayLaterAmount,
|
|
157
|
+
};
|
|
158
|
+
newPayments.push(combinedPayLater);
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
newPayments.push(...payLaterPayments);
|
|
162
|
+
}
|
|
163
|
+
if (complimentaryPayments.length > 0 && refundedPayments.length > 0) {
|
|
164
|
+
const totalComplemetaryAmount = complimentaryPayments.reduce((acc, payment) => acc + getPaymentAmountPayed(payment).totalAmountPaid, 0);
|
|
165
|
+
const totalRefundedAmount = refundedPayments.reduce((acc, payment) => acc + getPaymentAmountPayed(payment).totalAmountPaid, 0);
|
|
166
|
+
const diff = Math.abs(totalComplemetaryAmount) - Math.abs(totalRefundedAmount);
|
|
167
|
+
if (diff > 0) {
|
|
168
|
+
// This means that there is some amount that is complimentary and not refunded
|
|
169
|
+
// So we need to create a new payment for the remaining amount
|
|
170
|
+
const comp = complimentaryPayments[0];
|
|
171
|
+
const newPayment = {
|
|
172
|
+
...comp,
|
|
173
|
+
amount_due: diff,
|
|
174
|
+
amount_paid: diff,
|
|
175
|
+
};
|
|
176
|
+
newPayments.push(newPayment);
|
|
177
|
+
}
|
|
178
|
+
else if (diff < 0) {
|
|
179
|
+
// This means that there is some amount that is refunded and not complimentary
|
|
180
|
+
// So we need to create a new payment for the remaining amount
|
|
181
|
+
const refund = refundedPayments[0];
|
|
182
|
+
const newPayment = {
|
|
183
|
+
...refund,
|
|
184
|
+
amount_due: Math.abs(diff),
|
|
185
|
+
amount_paid: Math.abs(diff),
|
|
186
|
+
};
|
|
187
|
+
newPayments.push(newPayment);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
newPayments.push(...complimentaryPayments);
|
|
192
|
+
newPayments.push(...refundedPayments);
|
|
193
|
+
}
|
|
194
|
+
return newPayments;
|
|
195
|
+
}
|
|
196
|
+
// ============================>>><<<==============================
|
|
197
|
+
export function getSortedPayments(payments) {
|
|
198
|
+
return [...payments].sort((a, b) => ObjectID(a._id)
|
|
199
|
+
.getTimestamp()
|
|
200
|
+
.getTime() -
|
|
201
|
+
ObjectID(b._id)
|
|
202
|
+
.getTimestamp()
|
|
203
|
+
.getTime());
|
|
204
|
+
}
|
|
205
|
+
// ============================>>><<<==============================
|
|
206
|
+
// Regular expression to match the pattern `D${Number}` followed by a percentage or empty string
|
|
207
|
+
const discountPattern = /^D(\d+(\.\d+)?)(%)?$/;
|
|
208
|
+
// Regular expression to match the pattern `SC${Number}` followed by a percentage or empty string
|
|
209
|
+
const serviceChargesPattern = /^SC(\d+(\.\d+)?)(%)?$/;
|
|
210
|
+
export function checkIfPaymentIsSpecialType(paymentType) {
|
|
211
|
+
const paymentTypeUpper = paymentType.toUpperCase().split('_');
|
|
212
|
+
return paymentTypeUpper.some((word) => discountPattern.test(word) || serviceChargesPattern.test(word));
|
|
213
|
+
}
|
|
214
|
+
export function parsePaymentDiscount(paymentType) {
|
|
215
|
+
// Test if the paymentType matches the pattern
|
|
216
|
+
const match = paymentType.match(discountPattern);
|
|
217
|
+
if (match) {
|
|
218
|
+
const amount = parseNum(parseFloat(match[1]), true);
|
|
219
|
+
const isPercentage = !!match[3]; // true if % is present
|
|
220
|
+
// Check if the percentage discount is valid
|
|
221
|
+
if (isPercentage && amount > 100) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
amount,
|
|
226
|
+
isPercentage,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
export function parsePaymentServiceCharge(paymentType) {
|
|
232
|
+
// Test if the paymentType matches the pattern
|
|
233
|
+
const match = paymentType.match(serviceChargesPattern);
|
|
234
|
+
if (match) {
|
|
235
|
+
const amount = parseNum(parseFloat(match[1]), true);
|
|
236
|
+
const isPercentage = !!match[3]; // true if % is present
|
|
237
|
+
// Check if the percentage discount is valid
|
|
238
|
+
if (isPercentage && amount > 100) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
amount,
|
|
243
|
+
isPercentage,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
export function getPaymentSmartTitle(paymentType) {
|
|
249
|
+
const splitted = paymentType.toUpperCase().split('_');
|
|
250
|
+
let details = null;
|
|
251
|
+
let extensionType = PAYMENT_EXTENSION_ENUM.NONE;
|
|
252
|
+
for (let i = 0; i < splitted.length; i++) {
|
|
253
|
+
const word = splitted[i];
|
|
254
|
+
details = parsePaymentDiscount(word);
|
|
255
|
+
if (details != null) {
|
|
256
|
+
// Remove the discount part from the splitted array
|
|
257
|
+
splitted.splice(i, 1);
|
|
258
|
+
extensionType = PAYMENT_EXTENSION_ENUM.DISCOUNT;
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
details = parsePaymentServiceCharge(word);
|
|
263
|
+
if (details != null) {
|
|
264
|
+
// Remove the discount part from the splitted array
|
|
265
|
+
splitted.splice(i, 1);
|
|
266
|
+
extensionType = PAYMENT_EXTENSION_ENUM.SERVICE_CHARGE;
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
title: splitted.join(' '),
|
|
273
|
+
details,
|
|
274
|
+
extensionType,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
export const getQRCodePaymentLink = (grandTotal, payments) => {
|
|
278
|
+
if (!grandTotal || !payments)
|
|
279
|
+
return null;
|
|
280
|
+
const isFullyPaid = isOrderFullyPaid(grandTotal, payments, true);
|
|
281
|
+
if (isFullyPaid)
|
|
282
|
+
return null;
|
|
283
|
+
let qrLink = undefined;
|
|
284
|
+
let amount = undefined;
|
|
285
|
+
let scanMessage = 'Scan To Pay';
|
|
286
|
+
const raastPayment = payments.find((p) => p.payment_status === PAYMENT_STATUS_ENUM.PENDING && p?.payment_type === PAYMENT_TYPE_ENUM.RAAST_PAY);
|
|
287
|
+
if (raastPayment) {
|
|
288
|
+
const raw = raastPayment?.card_details?.card_number;
|
|
289
|
+
// Only accept a real QR payload (not the initial placeholder)
|
|
290
|
+
qrLink = raw != null && raw !== '**** **** **** ****' ? raw : undefined;
|
|
291
|
+
amount = raastPayment?.amount_due;
|
|
292
|
+
scanMessage = 'Scan & Pay via EasyPaisa, JazzCash or Bank App';
|
|
293
|
+
}
|
|
294
|
+
if (!qrLink || !amount) {
|
|
295
|
+
return null;
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
qrLink,
|
|
299
|
+
amount: parseNum(amount),
|
|
300
|
+
scanMessage,
|
|
301
|
+
};
|
|
302
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom PDF generator that creates a PDF from a JPEG base64 image.
|
|
3
|
+
* This is a lightweight solution that doesn't require any external PDF libraries.
|
|
4
|
+
*/
|
|
5
|
+
export function createPdfFromJpegBase64(jpegBase64, widthPx, heightPx, options = {}) {
|
|
6
|
+
const { padding = 20, backgroundColor = '#ffffff' } = options;
|
|
7
|
+
// Remove data URL prefix if present
|
|
8
|
+
const base64Data = jpegBase64.replace(/^data:image\/jpeg;base64,/, '');
|
|
9
|
+
const binaryData = atob(base64Data);
|
|
10
|
+
const imageBytes = new Uint8Array(binaryData.length);
|
|
11
|
+
for (let i = 0; i < binaryData.length; i++) {
|
|
12
|
+
imageBytes[i] = binaryData.charCodeAt(i);
|
|
13
|
+
}
|
|
14
|
+
// Convert pixels to PDF points (72 DPI)
|
|
15
|
+
const pxToPt = 72 / 96;
|
|
16
|
+
const imgWidthPt = widthPx * pxToPt;
|
|
17
|
+
const imgHeightPt = heightPx * pxToPt;
|
|
18
|
+
const paddingPt = padding * pxToPt;
|
|
19
|
+
// Page dimensions with padding
|
|
20
|
+
const pageWidthPt = imgWidthPt + paddingPt * 2;
|
|
21
|
+
const pageHeightPt = imgHeightPt + paddingPt * 2;
|
|
22
|
+
// Parse background color
|
|
23
|
+
const bgHex = backgroundColor.replace('#', '');
|
|
24
|
+
const bgR = parseInt(bgHex.substring(0, 2), 16) / 255;
|
|
25
|
+
const bgG = parseInt(bgHex.substring(2, 4), 16) / 255;
|
|
26
|
+
const bgB = parseInt(bgHex.substring(4, 6), 16) / 255;
|
|
27
|
+
// Build PDF manually
|
|
28
|
+
const objects = [];
|
|
29
|
+
const offsets = [];
|
|
30
|
+
// Object 1: Catalog
|
|
31
|
+
objects.push('1 0 obj\n<< /Type /Catalog /Pages 2 0 R >>\nendobj\n');
|
|
32
|
+
// Object 2: Pages
|
|
33
|
+
objects.push('2 0 obj\n<< /Type /Pages /Kids [3 0 R] /Count 1 >>\nendobj\n');
|
|
34
|
+
// Object 3: Page
|
|
35
|
+
objects.push(`3 0 obj\n<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${pageWidthPt.toFixed(2)} ${pageHeightPt.toFixed(2)}] /Contents 4 0 R /Resources << /XObject << /Im0 5 0 R >> >> >>\nendobj\n`);
|
|
36
|
+
// Object 4: Content stream (draw background rectangle and image)
|
|
37
|
+
// PDF coordinate system has origin at bottom-left, so we need to position image at (padding, padding) from bottom-left
|
|
38
|
+
const contentStream = [
|
|
39
|
+
'q', // Save graphics state
|
|
40
|
+
`${bgR.toFixed(3)} ${bgG.toFixed(3)} ${bgB.toFixed(3)} rg`, // Set fill color (RGB)
|
|
41
|
+
`0 0 ${pageWidthPt.toFixed(2)} ${pageHeightPt.toFixed(2)} re`, // Rectangle covering full page
|
|
42
|
+
'f', // Fill
|
|
43
|
+
'Q', // Restore graphics state
|
|
44
|
+
'q', // Save graphics state for image
|
|
45
|
+
`${imgWidthPt.toFixed(2)} 0 0 ${imgHeightPt.toFixed(2)} ${paddingPt.toFixed(2)} ${paddingPt.toFixed(2)} cm`, // Transform matrix: scale and translate
|
|
46
|
+
'/Im0 Do', // Draw image
|
|
47
|
+
'Q', // Restore graphics state
|
|
48
|
+
].join('\n');
|
|
49
|
+
objects.push(`4 0 obj\n<< /Length ${contentStream.length} >>\nstream\n${contentStream}\nendstream\nendobj\n`);
|
|
50
|
+
// Object 5: Image XObject
|
|
51
|
+
objects.push(`5 0 obj\n<< /Type /XObject /Subtype /Image /Width ${widthPx} /Height ${heightPx} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${imageBytes.length} >>\nstream\n`);
|
|
52
|
+
// Build the PDF
|
|
53
|
+
const header = '%PDF-1.4\n%\xFF\xFF\xFF\xFF\n';
|
|
54
|
+
const headerBytes = new TextEncoder().encode(header);
|
|
55
|
+
// Calculate offsets
|
|
56
|
+
let currentOffset = headerBytes.length;
|
|
57
|
+
for (let i = 0; i < objects.length; i++) {
|
|
58
|
+
offsets.push(currentOffset);
|
|
59
|
+
if (i === 4) {
|
|
60
|
+
// Image object - add stream length
|
|
61
|
+
currentOffset += new TextEncoder().encode(objects[i]).length + imageBytes.length;
|
|
62
|
+
currentOffset += new TextEncoder().encode('\nendstream\nendobj\n').length;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
currentOffset += new TextEncoder().encode(objects[i]).length;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Build xref table
|
|
69
|
+
const xrefOffset = currentOffset;
|
|
70
|
+
let xref = `xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`;
|
|
71
|
+
for (const offset of offsets) {
|
|
72
|
+
xref += `${offset.toString().padStart(10, '0')} 00000 n \n`;
|
|
73
|
+
}
|
|
74
|
+
// Trailer
|
|
75
|
+
const trailer = `trailer\n<< /Size ${objects.length + 1} /Root 1 0 R >>\nstartxref\n${xrefOffset}\n%%EOF`;
|
|
76
|
+
// Combine all parts
|
|
77
|
+
const obj1to4 = objects.slice(0, 4).join('');
|
|
78
|
+
const obj5Header = objects[4];
|
|
79
|
+
const obj5Footer = '\nendstream\nendobj\n';
|
|
80
|
+
const part1 = new TextEncoder().encode(header + obj1to4 + obj5Header);
|
|
81
|
+
const part2 = new TextEncoder().encode(obj5Footer + xref + trailer);
|
|
82
|
+
const pdfBytes = new Uint8Array(part1.length + imageBytes.length + part2.length);
|
|
83
|
+
pdfBytes.set(part1, 0);
|
|
84
|
+
pdfBytes.set(imageBytes, part1.length);
|
|
85
|
+
pdfBytes.set(part2, part1.length + imageBytes.length);
|
|
86
|
+
return pdfBytes;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Converts PDF bytes to a base64 string
|
|
90
|
+
*/
|
|
91
|
+
export function pdfBytesToBase64(pdfBytes) {
|
|
92
|
+
let binary = '';
|
|
93
|
+
for (let i = 0; i < pdfBytes.length; i++) {
|
|
94
|
+
binary += String.fromCharCode(pdfBytes[i]);
|
|
95
|
+
}
|
|
96
|
+
return btoa(binary);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Downloads a PDF from bytes
|
|
100
|
+
*/
|
|
101
|
+
export function downloadPdfBlob(pdfBytes, filename) {
|
|
102
|
+
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
|
|
103
|
+
const url = URL.createObjectURL(blob);
|
|
104
|
+
const link = document.createElement('a');
|
|
105
|
+
link.href = url;
|
|
106
|
+
link.download = filename;
|
|
107
|
+
link.click();
|
|
108
|
+
URL.revokeObjectURL(url);
|
|
109
|
+
link.remove();
|
|
110
|
+
}
|