Each delivery in SansiStore passes through a strictly enforced sequence of statuses. The allowed transitions are defined inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ProcesosAgilesUMSS/sansistore/llms.txt
Use this file to discover all available pages before exploring further.
deliveryStatusFlow.ts and validated both client-side and server-side before any Firestore write. The full detail view for an individual delivery lives at /delivery/order/[orderId], rendered by the DeliveryOrderDetailPage component with a RouteGuard that restricts access to the mensajero role.
Status flow diagram
The primary happy-path route is:Status reference
assigned — order waiting for acceptance
assigned — order waiting for acceptance
The delivery document exists and
courierId is set, but the courier has not yet confirmed they will take it. The order appears in the Pedidos asignados section of the MessengerDashboard.Triggered by: Admin assigning an order to a courier in the admin panel.Allowed next statuses: accepted, pending_reassignment.Important: assigned status does not block the courier from accepting other orders — only accepted and in_transit count as active deliveries. A courier can have multiple assigned deliveries visible at the same time.accepted — courier has taken the order
accepted — courier has taken the order
The courier confirmed they will deliver this order. From this point the courier is considered busy and cannot accept another delivery until this one is resolved.Triggered by:
acceptMessengerOrder — requires the server-side eligibility check to pass first. Records updatedAt on the delivery document.Allowed next statuses: in_transit, not_delivered.UI action: Tapping Aceptar pedido on an assigned order card and confirming the ConfirmAssignedOrderActionModal dialog.in_transit — courier is on the way
in_transit — courier is on the way
The courier has picked up the package and is en route to the customer. The delivery detail page (
/delivery/order/{orderId}) is the primary workspace from this point.Triggered by: setMessengerOrderStatus(order, 'in_transit') — also writes inTransitAt to the delivery document.Allowed next statuses: delivered, not_delivered, cancelled.UI action: Tapping Iniciar entrega on the delivery detail page.delivered — order successfully handed over
delivered — order successfully handed over
The customer received the package and payment was collected. This is a terminal status — no further transitions are possible.Triggered by:
registerMessengerCashPayment — atomically writes to orders, deliveries, and payments in a single batch. Sets customerConfirmed: true and customerConfirmedAt on the delivery.Key fields written:deliveries/{id}.amountCollected— cash collected from the customerdeliveries/{id}.customerConfirmed: trueorders/{id}.paymentStatus: 'COBRADO'payments/{paymentId}.collectedAt
not_delivered — delivery attempt failed
not_delivered — delivery attempt failed
The courier attempted the delivery but could not complete it — customer not home, address not found, or similar. This is a terminal status unless reprogramming is requested.Triggered by:
markMessengerOrderAsNotDelivered. Writes incidentType: 'delivery_problem', incidentReason, incidentNotes, reportedAt, and reportedBy to the delivery document. Also creates a document in the undelivered_orders collection for inventory operator review.UI action: Tapping No entregado on the delivery detail page and filling in the UndeliveredModal with a reason and notes.cancelled — order cancelled for non-payment
cancelled — order cancelled for non-payment
The customer refused to pay or was unable to pay. The order is cancelled and no cash was collected.Triggered by:
markMessengerOrderAsCancelledByNoPayment. Writes cancellationReason: 'Falta de pago del cliente', cancellationNotes, cancelledAt, cancelledBy, and amountCollected: 0 to the delivery. Also creates a document in cancelled_orders and updates the linked payment document.UI action: Tapping Cancelar por falta de pago and confirming the CancelNoPaymentModal.pending_reassignment — courier rejected the order
pending_reassignment — courier rejected the order
The courier actively declined to take an assigned order. The admin can reassign it to a different courier.Triggered by:
setMessengerOrderStatus(order, 'pending_reassignment', rejectionReason). Writes rejectionReason and rejectedAt to both the delivery and order documents.Allowed next statuses: None — the courier’s relationship with this order ends here. Admin reassigns from the admin panel.reprogrammed — delivery rescheduled
reprogrammed — delivery rescheduled
A failed delivery that was rescheduled for a new date. After reprogramming, the status returns to
assigned so the courier (or a different courier) can accept it again with attemptNumber incremented.Key fields written:reprogramReason— reason for reschedulingnewDeliveryAt— new scheduled delivery datereprogrammedAt— timestamp of the rescheduling actionattemptNumber— incremented on each reprogramming cycle
assigned (resets the flow for another attempt).Delivery detail page fields
The/delivery/order/[orderId] page displays the following key fields from the MessengerOrder type:
| Field | Type | Description |
|---|---|---|
cashToCollect | number | Amount in Bolivianos the courier must collect |
customerConfirmed | boolean | Set to true when the courier registers the final payment |
secret | string | Unique delivery code used to confirm receipt with the customer |
deliveryLat / deliveryLng | number | Customer coordinates loaded from the locations collection |
reprogramReason | string | null | Reason entered when rescheduling a failed delivery |
newDeliveryAt | Date | null | Rescheduled delivery date |
reprogrammedAt | Date | null | Timestamp when the reprogramming was recorded |
Transition validation
All status transitions are validated byassertCanTransitionDeliveryStatus before any Firestore write. The allowed transitions table is defined as:
setMessengerOrderStatus with an invalid transition throws:
Delivery acceptance eligibility
Before a courier can move an order fromassigned to accepted, the assertCanAcceptMessengerOrder function queries Firestore to check for existing active deliveries:
accepted or in_transit. Statuses like assigned, delivered, not_delivered, cancelled, pending_reassignment, and reprogrammed do not block acceptance.