The Jobs module is the operational heart of B2B Import ERP. Every billable or warranty-covered service engagement lives here as a work order — a structured record that captures planning dates, the assigned technician, activities performed in the field, materials consumed, and the digital sign-off documents required for closure. Jobs are always traceable to the requirement that originated them and, optionally, to the approved quote that priced the work.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ency07/B2B-import/llms.txt
Use this file to discover all available pages before exploring further.
Job Lifecycle
A job follows a strict, audit-enforced state machine. No status can be changed directly in the database — all transitions must pass through domain services that validate permissions, write to the audit log, and fire business events.| Status | Meaning |
|---|---|
PENDIENTE | Job created, awaiting scheduling |
PROGRAMADO | Technician and date assigned; assigned_user_id and planned_start_date are required |
EN_EJECUCION | Work has started; actual_start_date is required to enter this state |
SUSPENDIDO | Temporarily paused; can resume to EN_EJECUCION |
FINALIZADO | All non-cancelled activities are COMPLETADA; system sets actual_end_date automatically |
ENTREGADO | A DELIVERY_NOTE document in PUBLICADO status must be attached before this transition |
CERRADO | Final state — fully immutable; triggers automatic warranty generation |
CANCELADO | Reachable from PENDIENTE or PROGRAMADO; requires cancel_reason ≥ 10 characters |
When a job reaches
CERRADO, a 12-month warranty record is automatically created via the generate_warranty_on_job_close database trigger. See the Warranties module for details.Job Creation Flow
Jobs are never created manually in isolation — they are generated automatically by a database trigger (trg_create_job_on_ot) when a requirement transitions to the OT_GENERADA status. The trigger:
- Looks up the approved quote linked to the requirement.
- Resolves the
site_idandarea_idfrom the assigned engineering user. - Inserts a new
jobsrow inPENDIENTEstatus, copyingclient_id,title,description,priority, andassigned_user_idfrom the requirement. - Writes a
JOB_CREATEDbusiness event for downstream notifications.
requirement_id foreign key on every job provides a permanent back-link to the originating requirement, and quote_id links to the approved commercial proposal.
Key Fields
Thejobs table (migration 20260617000006_jobs_core.sql) defines the following primary fields:
| Field | Type | Description |
|---|---|---|
job_code | varchar(50) | Auto-generated code in format JOB-000001; unique per tenant |
tenant_id | uuid | Multi-tenant isolation key; enforced by RLS |
client_id | uuid | FK → clients; the customer receiving the service |
requirement_id | uuid | FK → requirements; the originating request |
quote_id | uuid | FK → quotes; nullable, set when an approved quote exists |
assigned_user_id | uuid | FK → users; the lead technician |
site_id / area_id | uuid | Physical location of the work |
planned_start_date | timestamp | Scheduled start; required for PROGRAMADO |
planned_end_date | timestamp | Scheduled end |
actual_start_date | timestamp | Set when entering EN_EJECUCION |
actual_end_date | timestamp | Set automatically when all activities complete |
estimated_hours | numeric(10,2) | Planned effort |
actual_hours | numeric(10,2) | Actual recorded effort |
priority | enum | LOW, MEDIUM, HIGH, or CRITICAL |
status | varchar(50) | Current lifecycle state (see above) |
cancel_reason | text | Mandatory when cancelling; minimum 10 characters |
Activities
Each job contains one or more child activity records in thejob_activities table. Activities follow their own parallel state machine (PENDIENTE → PROGRAMADA → EN_EJECUCION → COMPLETADA, with SUSPENDIDA and CANCELADA as side-states) and drive the parent job’s state through automatic propagation triggers:
- When any activity moves to
EN_EJECUCION, the parent job automatically advances fromPENDIENTEorPROGRAMADOtoEN_EJECUCION. - When all non-cancelled activities reach
COMPLETADA, the parent job automatically advances toFINALIZADOandactual_end_dateis stamped. - When a job is
CANCELADO, all open activities are automatically set toCANCELADA.
{job_code}-01, {job_code}-02, etc. Key activity fields:
| Field | Description |
|---|---|
activity_code | Auto-generated from parent job code + sequence suffix |
title | Short description of the task |
assigned_user_id | Technician responsible for this activity |
planned_start_date / planned_end_date | Must fall within the parent job’s planned date range |
actual_start_date / actual_end_date | Stamped during execution |
estimated_hours / actual_hours | Time tracking fields |
status | Current activity state |
Planned dates for activities are validated by the
validate_activity_dates trigger — an activity cannot be scheduled outside its parent job’s date range. Changing the job’s planned dates also validates that no existing activities would fall outside the new range.Materials Consumed
When technicians use parts or equipment on site, those are recorded asinventory_movements with movement_type = 'Salida'. Every outbound movement requires a job_id (enforced at the database level by chk_movement_job_required). When the movement is applied, the system automatically:
- Deducts stock from the relevant warehouse.
- Stamps the average cost to the movement.
- Fires a
JOB_MATERIAL_CONSUMEDbusiness event with quantity and cost details.
Attached Documents
Jobs support structured document attachments through the Documents module. Thedocuments table links to a job via entity_type = 'JOB' and entity_id = <job_id>. Supported document types include:
Orden de Trabajo
The formal work order issued at the start of the job.
Plano / Memoria Técnica
Engineering drawings and technical specifications.
Fotografías
Photo evidence captured during field execution.
Acta de Entrega
Client sign-off document required before transitioning to
ENTREGADO. Must be in PUBLICADO status.RBAC Permissions
| Permission | Roles |
|---|---|
jobs.create (manual) | ADMIN_EMPRESA, GERENTE_GENERAL, DIR_OPERACIONES |
jobs.manage (edit, reschedule) | ADMIN_EMPRESA, GERENTE_GENERAL, DIR_OPERACIONES, TECNICO_CAMPO |
jobs.view | All internal roles; AUDITOR can view soft-deleted records |
jobs.close | GERENTE_GENERAL, DIR_OPERACIONES |
jobs and job_activities ensures all reads and writes are scoped to the authenticated user’s tenant_id.
Dashboard URL
Access the jobs board at:<code> with your tenant’s URL code (e.g., apex or demo).