Order Processing Flow
Relevant source files
The following files were used as context for generating this wiki page:
- packages/common/src/entities/Order.ts
- packages/core/src/graphql/orders/orders.types.graphql
- packages/merchant-tablet-ionic/src/pages/+warehouse/warehouse.ts
- packages/shop-mobile-ionic/src/app/pages/+products/+order/order.page.ts
- packages/shop-mobile-ionic/src/app/pages/+products/+order/+order-info/order-info.page.ts
- packages/admin-web-angular/src/app/pages/+warehouses/+warehouse/+warehouse-order/warehouse-order.component.ts
- packages/admin-web-angular/src/assets/i18n/en.json
The Order Processing Flow is a core feature of the Ever Demand platform, managing the entire lifecycle of an order from its creation to final delivery. This system is designed to be real-time and reactive, providing consistent state management across multiple applications, including the customer-facing mobile app, the merchant tablet app for warehouses, and the admin web interface.
The flow is driven by a series of status updates that track an order's progress through two main phases: warehouse processing and carrier delivery. Each phase has its own set of detailed statuses, allowing for granular tracking and management. This ensures that all stakeholders (customers, merchants, and carriers) have an up-to-date view of the order's current state.
Order Data Model
The Order entity is the central data structure in the processing flow. It links together the customer, warehouse, carrier, and the products being purchased.
Sources: packages/common/src/entities/Order.ts, packages/core/src/graphql/orders/orders.types.graphql
Entity Relationship Diagram
This diagram illustrates the relationships between the Order entity and other key entities in the system.
Key Order Fields
The following table describes the most important fields in the Order entity.
| Field | Type | Description |
|---|---|---|
id | String | Unique identifier for the order. |
userId | String | The ID of the user who placed the order. |
warehouseId | String | The ID of the warehouse/store fulfilling the order. |
carrierId | String | The ID of the carrier assigned to deliver the order. Can be null. |
products | [OrderProduct] | An array of products included in the order. |
isCompleted | Boolean | Flag indicating if the order has been successfully completed. |
isCancelled | Boolean | Flag indicating if the order has been cancelled. |
isPaid | Boolean | Flag indicating if the payment has been processed. |
totalPrice | Float | The total cost of the order. |
warehouseStatus | Int | A numeric code representing the order's status within the warehouse. See Order Warehouse Statuses. |
carrierStatus | Int | A numeric code representing the order's delivery status. See Order Carrier Statuses. |
orderNumber | Int | A sequential number for orders within the same day for a warehouse, used for quick identification. |
Sources: packages/common/src/entities/Order.ts:18-87, packages/core/src/graphql/orders/orders.types.graphql:1-29
Order Lifecycle and Statuses
The order lifecycle is managed through two distinct but related status enumerations: OrderWarehouseStatus and OrderCarrierStatus. These statuses are updated via GraphQL mutations and drive the real-time updates across all client applications.
Order State Machine
The following diagram shows the typical progression of an order through the various warehouse and carrier statuses.
Order Warehouse Statuses
These statuses track the order's progress within the merchant's warehouse, from confirmation to handover to a carrier.
| Enum Value | Status Text | Description |
|---|---|---|
0 | Created | The initial status when an order is first created. |
1 | Confirmed | The warehouse has confirmed receipt of the order. |
2 | Processing | The warehouse has started preparing the order. |
3 | Allocation Started | The process of allocating items from inventory has begun. |
4 | Allocation Finished | All items for the order have been successfully allocated. |
5 | Packaging Started | The order is being packaged for delivery. |
6 | Packaged | The order is fully packaged and ready for pickup. |
7 | Given to Carrier | The order has been handed over to the delivery carrier. |
200 | Allocation Failed | There was a problem allocating items for the order (e.g., out of stock). |
201 | Packaging Failed | There was a problem during the packaging process. |
Sources: packages/core/src/graphql/orders/orders.types.graphql:102-113, packages/admin-web-angular/src/assets/i18n/en.json:620-630
Order Carrier Statuses
These statuses track the order's journey from the moment a carrier accepts the delivery until it reaches the customer.
| Enum Value | Status Text | Description |
|---|---|---|
0 | No Carrier | No carrier has been assigned or has accepted the order yet. |
1 | Order Selected For Delivery | A carrier has accepted the delivery job. |
2 | Order Picked Up | The carrier has picked up the packaged order from the warehouse. |
3 | Order In Delivery | The carrier is on the way to the customer's location. |
4 | Arrived To Client | The carrier has arrived at the delivery destination. |
5 | Delivered | The order has been successfully delivered to the customer. |
204 | Delivery Issues | The carrier encountered an issue during delivery. |
205 | Client Refuse to Take Order | The customer refused to accept the delivery. |
Sources: packages/core/src/graphql/orders/orders.types.graphql:115-124, packages/admin-web-angular/src/assets/i18n/en.json:631-639
Core Operations
Order Creation
Orders can be created from various client applications. The admin web application, for example, provides a wizard-based interface for merchants to create orders on behalf of customers.
The creation process involves:
- Selecting an existing customer or creating a new one.
- Adding products to the order.
- Submitting the order details to the backend.
The WarehouseOrdersService handles the createOrder mutation, which requires a userId, warehouseId, and a list of products.
Status Updates
The order flow is advanced by updating the warehouseStatus and carrierStatus fields. This is done through dedicated GraphQL mutations.
Status Update Sequence Diagram
This diagram shows the flow of a status update from a client application.
GraphQL Mutations
| Mutation | Parameters | Description |
|---|---|---|
updateOrderWarehouseStatus | orderId: String!, status: OrderWarehouseStatus! | Updates the warehouse processing status of an order. Used by the merchant/warehouse application. |
updateOrderCarrierStatus | orderId: String!, status: OrderCarrierStatus! | Updates the delivery status of an order. Used by the carrier application. |
Sources: packages/core/src/graphql/orders/orders.types.graphql:133-141
Client-Side Order Tracking
Client applications subscribe to order updates to provide a real-time view of the order's progress.
Customer Mobile App
The customer's mobile app simplifies the detailed warehouseStatus and carrierStatus into a high-level, easy-to-understand delivery status.
The currentStatus logic in the mobile app determines which stage to display on the progress bar:
- Warehouse: If the order has not yet been picked up by a carrier (
carrierStatus < CarrierPickedUpOrder). - Carrier: If the order has been picked up but not yet arrived (
carrierStatus >= CarrierPickedUpOrderandcarrierStatus < CarrierArrivedToCustomer). - Customer: If the carrier has arrived at the customer's location (
carrierStatus >= CarrierArrivedToCustomer). - Completed: If the order's
isCompletedflag is true.
The app also checks for issue statuses (>= 200) to display error messages to the customer.
Sources: packages/shop-mobile-ionic/src/app/pages/+products/+order/order.page.ts:121-137, packages/shop-mobile-ionic/src/app/pages/+products/+order/+order-info/order-info.page.ts:145-161
Merchant Tablet App
The merchant tablet app allows warehouse staff to manage incoming orders. It provides buttons to advance the order through the warehouse processing stages, such as "Start Processing", "Packaged", and "Given to Carrier". Each action triggers the updateOrderWarehouseStatus mutation. The app also allows scanning a barcode to quickly find and update an order.
Sources: packages/merchant-tablet-ionic/src/pages/+warehouse/warehouse.ts:100-117, 173-180
Summary
The Order Processing Flow in Ever Demand is a robust, state-driven system that coordinates actions and information across customers, warehouses, and carriers. By leveraging a detailed Order model and distinct status enums for warehouse and carrier operations, the platform provides granular, real-time tracking. GraphQL mutations serve as the primary mechanism for state transitions, while client applications intelligently interpret these states to provide a user-friendly experience tailored to each user's role.