The Sales & Commercial Orders Module (/v1/sales) is the commercial engine of the GOAL platform. It orchestrates field presale capture, B2B digital orders, multi-step commercial state machines, discount authorizations, order-line dispatch and returns, invoicing synchronization with SAP Business One, territory planning, and prospect customer onboarding.
The module is registered in routes/v1/backend/backend.php via:
include 'sales/sales.php';
All endpoints inherit the base URL prefix /v1/sales and route through 5 core sub-route systems:
For exhaustive endpoint listings, schemas, and parameters of the sub-modules:
sales/master/master.php (Territories, Delivery Zones, Sales Teams, Portfolios, Sellers, Routes, Schedules, Catalog rules, and Channels)./v1/sales/draft/customers)./v1/sales/store/*)./v1/sales/invoices).All requests across the /v1/sales family require standard authentication and multi-tenant context:
Authorization: Bearer <access_token>
x-app-stage: <stage>
x-app-uid: <application_uuid>
Content-Type: application/json
Accept: application/json
All endpoints require companyId (as query parameter ?companyId={id} or request body property) to satisfy the company-validator and normalize-company-param middleware pipeline.
ActionResult)Every response conforms to App\Values\Core\ActionResult:
{
"success": true,
"message": "Operación exitosa.",
"data": { ... }
}
Standard HTTP status codes:
200 OK: Successful retrieval, update, or action execution.201 Created: Successful creation of order or line item.400 Bad Request: Domain action validation failure or invalid state transition.401 Unauthorized: Missing or invalid Bearer token / Keycloak session.403 Forbidden: Insufficient role or permission code (e.g. GOAL_V2_SALES_ORDER_INSERT).404 Not Found: Entity not found for specified ID or tenant company.422 Unprocessable Entity: Request body validation error.500 Internal Server Error: Unhandled backend exception./v1/sales/orders)App\Http\Controllers\V1\Backend\Sales\OrderControllerApp\Models\Orders\Orderroutes/v1/backend/sales/orders.php| Method | Endpoint | Description | Permission |
|---|---|---|---|
GET |
/v1/sales/orders |
Paginated listing of sales orders with extensive filters | Order:LIST |
POST |
/v1/sales/orders |
Create a new commercial order with optional line items | Order:INSERT |
GET |
/v1/sales/orders/{id} |
Retrieve order details and nested order lines | Order:LIST |
PUT |
/v1/sales/orders/{id} |
Update order headers and notes | Order:UPDATE |
DELETE |
/v1/sales/orders/{id} |
Soft delete order | Order:DELETE |
POST |
/v1/sales/orders/{id}/confirm |
Transition order from Draft to Confirmed | Order:CONFIRM |
POST |
/v1/sales/orders/{id}/approve |
Transition order to Approved for dispatch | Order:APPROVE |
POST |
/v1/sales/orders/{id}/cancel |
Cancel order and release stock/credit | Order:CANCEL |
POST |
/v1/sales/orders/{id}/request-discount |
Submit special discount authorization request | Order:REQUEST_DISCOUNT |
POST |
/v1/sales/orders/{id}/apply-discount |
Authorize requested discount (Supervisor) | Order:APPLY_DISCOUNT |
POST |
/v1/sales/orders/{id}/reject-discount |
Deny requested discount | Order:REJECT_DISCOUNT |
GET |
/v1/sales/orders/{id}/authorize-remote |
Authorize draft order via remote SAP DocEntry |
Authenticated |
GET |
/v1/sales/orders/{orderId}/lines |
List lines belonging to a specific order | Authenticated |
POST |
/v1/sales/orders/{orderId}/lines |
Add a line item to an order | Authenticated |
POST |
/v1/sales/orders/{orderId}/lines/bulk-update |
Mass update quantities/prices for order lines | Authenticated |
GET /v1/sales/orders?companyId=1&page=1&per_page=15&status=CONFIRMED&date_from=2026-10-01&date_to=2026-10-13
| Parameter | Type | Default | Description |
|---|---|---|---|
companyId |
integer |
Required | Operational company ID. |
page |
integer |
1 |
Page number. |
per_page |
integer |
15 |
Results per page. |
status |
string |
- | Order state (DRAFT, CONFIRMED, APPROVED, CANCELLED). |
order_type |
string |
- | Order category (PRESALE, STORE, WHOLESALE). |
order_source |
string |
- | Order origin channel (HANDHELD, B2B, PORTAL). |
customer_code |
string |
- | Customer CardCode filter. |
seller_code |
string |
- | Sales representative CardCode. |
date_from |
date |
- | Start date (YYYY-MM-DD). |
date_to |
date |
- | End date (YYYY-MM-DD). |
search |
string |
- | Search query over customer name, document, notes. |
remote_entry |
integer |
- | SAP Business One DocEntry reference. |
purchase_order |
string |
- | Customer purchase order reference (OC). |
200 OK{
"success": true,
"data": [
{
"id": 14205,
"company_id": 1,
"order_number": "ORD-2026-0014205",
"customer_code": "C20556677889",
"customer_name": "DISTRIBUIDORA COMERCIAL LIMA S.A.C.",
"customer_email": "ventas@discomlima.pe",
"customer_phone": "987654321",
"customer_document": "20556677889",
"order_type": "PRESALE",
"order_source": "HANDHELD",
"seller_code": "V012",
"seller_name": "CARLOS MENDOZA",
"warehouse_code": "01",
"branch_code": "CD-LIMA",
"delivery_date": "2026-10-14",
"status": "CONFIRMED",
"subtotal": 1250.00,
"tax_amount": 225.00,
"total_amount": 1475.00,
"discount_amount": 0.00,
"comments": "Entregar antes de las 11 AM",
"order_lines": [
{
"id": 48201,
"order_id": 14205,
"product_code": "CERV-CRIS-330",
"product_name": "CERVEZA CRISTAL 330ML RETORNABLE",
"quantity": 25,
"unit_price": 50.00,
"total_price": 1250.00,
"status": "PENDING"
}
]
}
],
"pagination": {
"current_page": 1,
"total_pages": 48,
"per_page": 15,
"total": 718,
"from": 1,
"to": 15
}
}
POST /v1/sales/orders
{
"companyId": 1,
"customer_code": "C20556677889",
"customer_name": "DISTRIBUIDORA COMERCIAL LIMA S.A.C.",
"customer_email": "ventas@discomlima.pe",
"customer_phone": "987654321",
"customer_document": "20556677889",
"order_type": "PRESALE",
"order_source": "HANDHELD",
"seller_code": "V012",
"seller_name": "CARLOS MENDOZA",
"warehouse_code": "01",
"branch_code": "CD-LIMA",
"delivery_date": "2026-10-14",
"comments": "Entregar en puerta trasera",
"lines": [
{
"product_code": "CERV-CRIS-330",
"product_name": "CERVEZA CRISTAL 330ML RETORNABLE",
"quantity": 20,
"unit_price": 50.00
},
{
"product_code": "CERV-PILS-330",
"product_name": "CERVEZA PILSEN 330ML RETORNABLE",
"quantity": 10,
"unit_price": 50.00
}
]
}
201 Created{
"success": true,
"message": "Order created successfully",
"data": {
"id": 14206,
"company_id": 1,
"order_number": "ORD-2026-0014206",
"status": "DRAFT",
"total_amount": 1500.00,
"created_at": "2026-10-13T16:25:00Z"
}
}
POST /v1/sales/orders/{id}/confirm — Verifies inventory availability and transitions order from DRAFT to CONFIRMED.POST /v1/sales/orders/{id}/approve — Validates customer credit line and marks order ready for dispatch queue (APPROVED).POST /v1/sales/orders/{id}/cancel — Releases reserved inventory and rolls back credit line holds (CANCELLED).When a sales representative requests a special price below authorized thresholds:
POST /v1/sales/orders/{id}/request-discount{
"companyId": 1,
"amount": 75.00,
"percent": 5.0,
"reason_code": "VOL_CAMPAIGN",
"reason_name": "Descuento por volumen de campaña de aniversario"
}
POST /v1/sales/orders/{id}/apply-discountPOST /v1/sales/orders/{id}/reject-discount/v1/sales/order-lines)App\Http\Controllers\V1\Backend\Sales\OrderLineControllerroutes/v1/backend/sales/orders.php| Method | Endpoint | Description |
|---|---|---|
GET |
/v1/sales/order-lines/{id} |
Retrieve order line item details |
PUT |
/v1/sales/order-lines/{id} |
Update quantity or pricing of line item |
DELETE |
/v1/sales/order-lines/{id} |
Delete line item from order |
POST |
/v1/sales/order-lines/{id}/deliver |
Mark line item as physically delivered |
POST |
/v1/sales/order-lines/{id}/cancel |
Cancel single line item |
POST |
/v1/sales/order-lines/{id}/return |
Record customer return for line item |
POST |
/v1/sales/order-lines/{id}/apply-promotion |
Attach promotional discount or bonus item to line |
PUT |
/v1/sales/order-lines/{id}/tracking |
Update fulfillment and logistics tracking data |
POST /v1/sales/orders/{orderId}/lines/bulk-update
{
"companyId": 1,
"lines": [
{
"id": 48201,
"quantity": 30,
"unit_price": 49.00
},
{
"id": 48202,
"quantity": 15,
"unit_price": 50.00
}
]
}