The Purchasing & Procurement Module (/v1/purchase) manages vendor master data, supplier taxonomy, commercial affiliations, media gallery management, and enterprise integration with SAP Business One procurement documents. It serves as the authoritative source for goods and services vendors supplying inventory, materials, and services across all distribution centers.
Suppliers (App\Models\Purchase\Master\Supplier, table suppliers) represent goods and service vendors, manufacturers, wholesalers, and operational service providers. The architecture integrates local multi-tenant management with SAP Business One (OCRD CardCode) and downstream inventory cataloging.
company_id. All queries enforce company validation through the company-validator middleware. The standard testing company is Company 8.id vs uuid): All master endpoints accept either the integer primary key (id) or the RFC 4122 UUID v4 (uuid) transparently in URL paths.CastToBoolean): Procurement entities support fine-grained operational roles (is_goods_supplier, is_service_supplier, is_manufacturer, is_distributor, is_wholesaler, is_retailer, is_foreign_supplier, is_employee). These are stored as 'Y'/'N' in the database and serialized as native JSON booleans (true/false).deleted_at, deleted_by, restored_by). Dedicated routes allow viewing deleted records (/trasheds) and restoring them (/{id}/restore).GoalImageGallery): Supports primary logo storage (image_code) alongside multi-asset gallery codes (image_codes JSON array) for compliance documents, contracts, and facility photos.code) maps directly to the SAP Business One CardCode. The /documents endpoint queries SAP B1 purchase invoices (OPCH) live through the CompanyAction dual-adapter architecture./v1/purchase/master/suppliers
routes/v1/backend/purchase/purchase.php included in routes/v1/backend/backend.php.routes/v1/backend/purchase/master/master.php → routes/v1/backend/purchase/master/suppliers.php.App\Http\Controllers\V1\Backend\Purchase\Master\SupplierController](file:///khayyam/home/mgonzalo/apps/goal-backend/app/Http/Controllers/V1/Backend/Purchase/Master/SupplierController.php).Domain\Purchase\Master\Supplier\UpdateSupplierImageAction](file:///khayyam/home/mgonzalo/apps/goal-backend/domain/Purchase/Master/Supplier/UpdateSupplierImageAction.php): Multi-image gallery and logo synchronization.Domain\SB1\Purchases\ListSAPPurchaseInvoiceAction](file:///khayyam/home/mgonzalo/apps/goal-backend/domain/SB1/Purchases/ListSAPPurchaseInvoiceAction.php): Real-time SAP Business One purchase invoices retrieval.Every request must include standard security and stage headers:
Authorization: Bearer <access_token>
x-app-stage: development | staging | production
x-app-uid: <client_uuid_or_user_id>
Content-Type: application/json
Accept: application/json
| HTTP Method | Route Path | Action / Purpose | Key Query / Payload |
|---|---|---|---|
GET |
/v1/purchase/master/suppliers |
List paginated suppliers with filters | companyId, view, is_goods_supplier, is_service_supplier, search |
POST |
/v1/purchase/master/suppliers |
Create new supplier record | company_id, code, name, product_code_prefix, tax_id_type, tax_id_number, roles |
POST |
/v1/purchase/master/suppliers/bulk-import |
Excel mass upsert (runner / suppliers-mass); por fila: suppliers + business_partners rol proveedor en una transacción |
company_id, files[], template_has_comments |
GET |
/v1/purchase/master/suppliers/trasheds |
List soft-deleted suppliers | companyId, search, limit, skip, sort_field |
GET |
/v1/purchase/master/suppliers/{id} |
Inspect single supplier by ID or UUID | Path {id}, companyId, view |
PUT |
/v1/purchase/master/suppliers/{id} |
Update supplier attributes | Path {id}, updated fields |
DELETE |
/v1/purchase/master/suppliers/{id} |
Soft-delete supplier record | Path {id}, tracks deleted_by |
PUT |
/v1/purchase/master/suppliers/{id}/restore |
Restore soft-deleted supplier | Path {id}, tracks restored_by |
POST |
/v1/purchase/master/suppliers/{id}/upload-image |
Update supplier logo / gallery codes | image_codes array or image_code string |
GET |
/v1/purchase/master/suppliers/{id}/products |
List active products supplied | Path {id}, companyId |
GET |
/v1/purchase/master/suppliers/{id}/brands |
List distinct brands for supplier | Path {id}, companyId |
GET |
/v1/purchase/master/suppliers/{id}/categories |
List distinct categories for supplier | Path {id}, companyId |
GET |
/v1/purchase/master/suppliers/{id}/documents |
Live SAP B1 purchase invoices | Path {id}, companyId, limit |
GET /v1/purchase/master/suppliers)Retrieves a paginated list of suppliers scoped to the specified tenant company. Supports filtering by operational roles (is_goods_supplier, is_service_supplier), status view, full-text substring search, and field sorting.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
companyId |
integer |
Yes | - | Multi-tenant company identifier (e.g. 8). |
view |
string |
No | A |
View status filter: A (active), I (inactive), D (deleted), ALL (all including trashed). |
is_goods_supplier |
string |
No | - | Filter suppliers supplying merchandise (1 / Y / 0 / N). |
is_service_supplier |
string |
No | - | Filter suppliers providing operational services (1 / Y / 0 / N). |
search |
string |
No | - | Search term matched against id, code, and name. |
sort_field |
string |
No | id |
Sortable fields: id, code, name, created_at, deleted_at. |
sort_direction |
string |
No | asc |
Direction: asc or desc. |
limit |
integer |
No | 50 |
Maximum number of records to return. |
skip |
integer |
No | 0 |
Number of records to skip for pagination. |
GET /v1/purchase/master/suppliers?companyId=8&view=A&is_goods_supplier=1&search=BACKUS HTTP/1.1
Host: api.goal.com
Authorization: Bearer <token>
x-app-stage: development
x-app-uid: a1b2c3d4-e5f6-7a8b-9c0d-1e2f3a4b5c6d
200 OK){
"success": true,
"message": "Proceso realizado correctamente",
"data": [
{
"id": 2,
"company_id": 8,
"company": {
"id": 8,
"name": "DISTRIBUIDORA COMERCIAL S.A.",
"code": "DCOM"
},
"code": "P20100113610",
"name": "UNION DE CERVECERIAS PERUANAS BACKUS Y JOHNSTON S.A.A.",
"type": "JURIDICA",
"tax_id_type": "RUC",
"tax_id_number": "20100113610",
"valid_for": true,
"created_by": 1,
"updated_by": 14,
"updated_guard": "api",
"asset_owner": false,
"image_code": "media/suppliers/backus_logo.png",
"image_codes": [
"media/suppliers/backus_logo.png",
"media/suppliers/backus_plant.png"
],
"status": "A",
"is_goods_supplier": true,
"is_service_supplier": false,
"is_manufacturer": true,
"is_distributor": true,
"is_wholesaler": false,
"is_retailer": false,
"is_foreign_supplier": false,
"is_employee": false,
"created_at": "2024-01-15T08:30:00+00:00",
"updated_at": "2024-06-20T14:22:10+00:00",
"uuid": "4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d"
}
]
}
POST /v1/purchase/master/suppliers)Registers a new supplier in the system. Enforces compound uniqueness for (company_id, code) across both active and soft-deleted records.
{
"company_id": 8,
"code": "P20512345678",
"name": "DISTRIBUIDORA LOGISTICA DEL CENTRO S.A.C.",
"short_name": "LOGISTICA CENTRO",
"type": "JURIDICA",
"tax_id_type": "RUC",
"tax_id_number": "20512345678",
"valid_for": true,
"asset_owner": false,
"image_code": "media/suppliers/dist_centro.png",
"image_codes": [
"media/suppliers/dist_centro.png"
],
"status": "A",
"is_goods_supplier": true,
"is_service_supplier": true,
"is_manufacturer": false,
"is_distributor": true,
"is_wholesaler": true,
"is_retailer": false,
"is_foreign_supplier": false,
"is_employee": false
}
| Field | Type | Required | Description |
|---|---|---|---|
company_id |
integer |
Yes | Tenant company identifier. |
code |
string |
Yes | Unique supplier code / SAP CardCode (max: 20). |
name |
string |
Yes | Business trade name or legal entity name (max: 191). |
short_name |
string |
No | Display short name (max: 100). |
type |
string |
No | Entity categorization: JURIDICA or NATURAL. |
tax_id_type |
string |
No | Official document type (RUC, DNI, CE, PAS). |
tax_id_number |
string |
No | Identification number (e.g. 11 digits for RUC). |
valid_for |
boolean |
No | Commercial validity active flag. |
asset_owner |
boolean |
No | Indicates if supplier owns consigned field assets. |
image_code |
string |
No | Main logo storage key (max: 200). |
image_codes |
array |
No | Array of associated gallery media keys. |
status |
string |
No | Status code (A active, I inactive). |
is_* flags |
boolean |
No | Role classification flags (is_goods_supplier, etc.). |
200 OK){
"success": true,
"message": "Operación exitosa",
"data": {
"id": 105,
"company_id": 8,
"company": {
"id": 8,
"name": "DISTRIBUIDORA COMERCIAL S.A.",
"code": "DCOM"
},
"code": "P20512345678",
"name": "DISTRIBUIDORA LOGISTICA DEL CENTRO S.A.C.",
"type": "JURIDICA",
"tax_id_type": "RUC",
"tax_id_number": "20512345678",
"valid_for": true,
"created_by": 1,
"updated_by": null,
"updated_guard": null,
"asset_owner": false,
"image_code": "media/suppliers/dist_centro.png",
"image_codes": [
"media/suppliers/dist_centro.png"
],
"status": "A",
"is_goods_supplier": true,
"is_service_supplier": true,
"is_manufacturer": false,
"is_distributor": true,
"is_wholesaler": true,
"is_retailer": false,
"is_foreign_supplier": false,
"is_employee": false,
"created_at": "2026-10-16T16:30:00+00:00",
"updated_at": "2026-10-16T16:30:00+00:00",
"uuid": "e8c2f104-9a3b-4c5d-8e7f-1a2b3c4d5e6f"
}
}
GET /v1/purchase/master/suppliers/{id})Fetches a single supplier record. The {id} parameter supports either integer primary key or UUID string.
{id}: Integer ID (e.g. 2) or UUID (e.g. 4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d).companyId (query): Required tenant company identifier.view (query): Optional status filter (A, I, D, ALL).200 OK){
"success": true,
"message": "Operación exitosa",
"data": {
"id": 2,
"company_id": 8,
"code": "P20100113610",
"name": "UNION DE CERVECERIAS PERUANAS BACKUS Y JOHNSTON S.A.A.",
"type": "JURIDICA",
"tax_id_type": "RUC",
"tax_id_number": "20100113610",
"valid_for": true,
"image_code": "media/suppliers/backus_logo.png",
"image_codes": [
"media/suppliers/backus_logo.png",
"media/suppliers/backus_plant.png"
],
"status": "A",
"is_goods_supplier": true,
"is_service_supplier": false,
"is_manufacturer": true,
"is_distributor": true,
"is_wholesaler": false,
"is_retailer": false,
"is_foreign_supplier": false,
"is_employee": false,
"uuid": "4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d"
}
}
PUT /v1/purchase/master/suppliers/{id})Updates attributes for an existing supplier. Re-evaluates code uniqueness excluding the current record.
PUT /v1/purchase/master/suppliers/4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d HTTP/1.1
Host: api.goal.com
Authorization: Bearer <token>
Content-Type: application/json
{
"company_id": 8,
"name": "BACKUS Y JOHNSTON S.A.A. - MODERNO",
"is_goods_supplier": true,
"is_distributor": true,
"is_wholesaler": true
}
200 OK){
"success": true,
"message": "Registro se actualizó correctamente",
"data": {
"id": 2,
"company_id": 8,
"code": "P20100113610",
"name": "BACKUS Y JOHNSTON S.A.A. - MODERNO",
"is_goods_supplier": true,
"is_distributor": true,
"is_wholesaler": true,
"status": "A",
"uuid": "4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d"
}
}
DELETE / PUT restore)DELETE /v1/purchase/master/suppliers/{id})Marks the record as soft-deleted, sets deleted_by = auth()->user()->id, and nullifies restored_by.
{
"success": true,
"message": "Registro eliminado correctamente",
"data": null
}
PUT /v1/purchase/master/suppliers/{id}/restore)Restores a previously soft-deleted supplier, sets restored_by = auth()->user()->id, and nullifies deleted_by.
{
"success": true,
"message": "Registro restaurado correctamente",
"data": {
"id": 2,
"code": "P20100113610",
"status": "A",
"uuid": "4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d"
}
}
GET /v1/purchase/master/suppliers/trasheds)Lists all soft-deleted records for a company with sorting ordered by deleted_at desc.
GET /v1/purchase/master/suppliers/trasheds?companyId=8&limit=20 HTTP/1.1
POST /v1/purchase/master/suppliers/{id}/upload-image)Dispatched to [UpdateSupplierImageAction](file:///khayyam/home/mgonzalo/apps/goal-backend/domain/Purchase/Master/Supplier/UpdateSupplierImageAction.php). Accepts either an array of media codes or a single media code, updating image_codes and setting the primary image_code to the first entry.
{
"image_codes": [
"media/suppliers/backus_logo_2026.png",
"media/suppliers/backus_dist_cert.pdf",
"media/suppliers/backus_headquarters.jpg"
]
}
Note: Alternatively, sending {"image_code": "media/suppliers/single_logo.png"} is also supported.
200 OK){
"success": true,
"message": "Logo o imagen de proveedor actualizado correctamente",
"data": {
"id": 2,
"company_id": 8,
"image_code": "media/suppliers/backus_logo_2026.png",
"image_codes": [
"media/suppliers/backus_logo_2026.png",
"media/suppliers/backus_dist_cert.pdf",
"media/suppliers/backus_headquarters.jpg"
],
"uuid": "4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d"
}
}
GET /v1/purchase/master/suppliers/{id}/products)Retrieves the SKUs associated with the given supplier from the products table where supplier_id = ? and company_id = ?.
companyId: Tenant company ID.200 OK){
"success": true,
"message": "Proceso realizado correctamente",
"data": [
{
"id": 1001,
"code": "CERV001",
"name": "CERVEZA CRISTAL 650ML RETORNABLE",
"stock": 1420.0,
"status": "A"
},
{
"id": 1002,
"code": "CERV002",
"name": "CERVEZA PILSEN CALLAO 630ML RETORNABLE",
"stock": 980.0,
"status": "A"
},
{
"id": 1003,
"code": "CERV003",
"name": "CERVEZA CUSQUEÑA DORADA 330ML LATA",
"stock": 510.0,
"status": "A"
}
]
}
GET /v1/purchase/master/suppliers/{id}/brands)Queries all distinct commercial brands linked to the products of this supplier.
GET /v1/purchase/master/suppliers/2/brands?companyId=8 HTTP/1.1
200 OK){
"success": true,
"message": "Proceso realizado correctamente",
"data": [
{
"company_id": 8,
"id": 10,
"name": "CRISTAL",
"code": "CRIS"
},
{
"company_id": 8,
"id": 12,
"name": "CUSQUEÑA",
"code": "CUSQ"
},
{
"company_id": 8,
"id": 11,
"name": "PILSEN CALLAO",
"code": "PILS"
}
]
}
GET /v1/purchase/master/suppliers/{id}/categories)Queries all distinct taxonomy categories linked to the products of this supplier.
GET /v1/purchase/master/suppliers/2/categories?companyId=8 HTTP/1.1
200 OK){
"success": true,
"message": "Proceso realizado correctamente",
"data": [
{
"id": 1,
"name": "CERVEZAS NACIONALES",
"code": "CAT-CERV-NAC",
"status": "A"
},
{
"id": 4,
"name": "MALTAS Y BEBIDAS NUTRITIVAS",
"code": "CAT-MALT",
"status": "A"
}
]
}
GET /v1/purchase/master/suppliers/{id}/documents)Executes a live query against SAP Business One's purchase invoices table (OPCH / PCH1) via [ListSAPPurchaseInvoiceAction](file:///khayyam/home/mgonzalo/apps/goal-backend/domain/SB1/Purchases/ListSAPPurchaseInvoiceAction.php), matching the supplier's SAP CardCode.
companyId: Tenant company ID.limit: Number of documents to fetch (default 50).GET /v1/purchase/master/suppliers/2/documents?companyId=8&limit=10 HTTP/1.1
200 OK){
"success": true,
"message": "Operación exitosa",
"data": [
{
"doc_entry": 10452,
"doc_num": 8000452,
"card_code": "P20100113610",
"card_name": "UNION DE CERVECERIAS PERUANAS BACKUS Y JOHNSTON S.A.A.",
"p_invoice_num": "F001-0023451",
"doc_date": "2026-10-10",
"doc_due_date": "2026-11-09",
"tax_date": "2026-10-10",
"doc_cur": "PEN",
"doc_total": 45890.50,
"paid_to_date": 0.00,
"doc_status": "O",
"comments": "Compra mercadería lote octubre CD Huancayo",
"created_at": "2026-10-10T11:00:00+00:00"
}
]
}
Note: If the SAP Business One connection is unreachable or offline, the endpoint gracefully catches the exception and returns an empty list ("data": []) with a 200 HTTP code so as not to break the frontend detail view.
In the React frontend (goal-front), supplier management is accessible at /app/:companyId/purchases/suppliers.
GoalTab)When opening a supplier at /app/:companyId/purchases/suppliers/:id, the interface organizes data across 4 dedicated tabs:
is_goods_supplier, is_service_supplier, is_distributor, etc.).GMGridContainer using data from /products, /brands, and /categories with filtering by SKU, category, and stock balance./documents, including voucher series, issue date, due date, currency, and total amount.GoalImageGallery connected to /upload-image with immediate reactive thumbnail refresh.| Status Code | Description | Typical Cause |
|---|---|---|
200 OK |
Request succeeded | Record retrieved, updated, deleted, or listed successfully. |
400 Bad Request |
Constraint violation | Compound unique key (company_id, code) already exists. |
401 Unauthorized |
Missing / invalid token | Expired Bearer token or invalid stage header. |
403 Forbidden |
Access denied | User lacks permission to manage purchasing master data. |
404 Not Found |
Entity not found | Supplier ID/UUID does not exist in the given company. |
422 Unprocessable |
Validation error | Missing required fields (code, name, company_id). |
500 Server Error |
Backend internal error | Database or adapter exception. |
# 1. List active goods suppliers for Company 8
curl -X GET "http://127.0.0.1:8000/v1/purchase/master/suppliers?companyId=8&view=A&is_goods_supplier=1" \
-H "Authorization: Bearer <token>" \
-H "x-app-stage: development" \
-H "x-app-uid: 00000000-0000-0000-0000-000000000000" \
-H "Accept: application/json"
# 2. Inspect single supplier by UUID
curl -X GET "http://127.0.0.1:8000/v1/purchase/master/suppliers/4f9d2a1b-3c4e-5a6b-7c8d-9e0f1a2b3c4d?companyId=8" \
-H "Authorization: Bearer <token>" \
-H "x-app-stage: development" \
-H "x-app-uid: 00000000-0000-0000-0000-000000000000" \
-H "Accept: application/json"
# 3. Retrieve SAP purchase documents for supplier
curl -X GET "http://127.0.0.1:8000/v1/purchase/master/suppliers/2/documents?companyId=8&limit=10" \
-H "Authorization: Bearer <token>" \
-H "x-app-stage: development" \
-H "x-app-uid: 00000000-0000-0000-0000-000000000000" \
-H "Accept: application/json"