# DOC. SERVICIOS APP - SHALOM CONTROL

# Embarques

# Control/carguero/listar - (1,2) [indexCooler]

## 🧾 **Descripción**

*Este servicio valida un **código de cooler (BINS, COOLER o PALLET)** y retorna la **lista de guías (OSE)** que tienen paquetes dentro del cooler y aún no están embarcadas.*

*Realiza consultas combinadas en **CentOS** y **Empresarial**, arma las guías agrupando cantidades y devuelve un resumen estructurado.*

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Findex-cooler"><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /index-cooler`**</span></div></div>---

## 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cooler%22%3A-%22string%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cooler"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1108" data-start="764"><thead data-end="808" data-start="764"><tr data-end="808" data-start="764"><th data-col-size="sm" data-end="772" data-start="764">Campo</th><th data-col-size="sm" data-end="779" data-start="772">Tipo</th><th data-col-size="sm" data-end="793" data-start="779">Obligatorio</th><th data-col-size="md" data-end="808" data-start="793">Descripción</th></tr></thead><tbody data-end="1108" data-start="854"><tr data-end="947" data-start="854"><td data-col-size="sm" data-end="863" data-start="854">cooler</td><td data-col-size="sm" data-end="872" data-start="863">string</td><td data-col-size="sm" data-end="877" data-start="872">Sí</td><td data-col-size="md" data-end="947" data-start="877">Código escaneado del cooler (debe contener BINS, COOLER o PALLET).</td></tr><tr data-end="1007" data-start="948"><td data-col-size="sm" data-end="958" data-start="948">usuario</td><td data-col-size="sm" data-end="967" data-start="958">string</td><td data-col-size="sm" data-end="972" data-start="967">Sí</td><td data-col-size="md" data-end="1007" data-start="972">Usuario que ejecuta el proceso.</td></tr><tr data-end="1064" data-start="1008"><td data-col-size="sm" data-end="1019" data-start="1008">terminal</td><td data-col-size="sm" data-end="1028" data-start="1019">string</td><td data-col-size="sm" data-end="1033" data-start="1028">No</td><td data-col-size="md" data-end="1064" data-start="1033">Terminal desde donde opera.</td></tr><tr data-end="1108" data-start="1065"><td data-col-size="sm" data-end="1074" data-start="1065">cap\_id</td><td data-col-size="sm" data-end="1083" data-start="1074">string</td><td data-col-size="sm" data-end="1088" data-start="1083">No</td><td data-col-size="md" data-end="1108" data-start="1088">ID de capacidad.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Generalmente protegido por token o cabecera de sesión (dependiendo del middleware definido). No se valida en la función directamente.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Validaciones iniciales**
    
    
    - Verifica que `cooler` y `usuario` existan.
    - Valida que `cooler` contenga: `BINS` o `COOLER` o `PALLET`.
2. **Verifica existencia del cooler**  
    Busca en `emp_cooler`:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> id, codigo_barra, cap_id<span class="hljs-keyword">FROM</span> emp_cooler<span class="hljs-keyword">WHERE</span> codigo_barra = <cooler>  <span class="hljs-keyword">AND</span> estado = <span class="hljs-number">1</span><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> id <span class="hljs-keyword">DESC</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>Si no existe → *“Aún no hay paquetes en el cooler”*
3. **Obtiene paquetes del cooler aún no embarcados**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> ose_id, codigo_barra <span class="hljs-keyword">AS</span> cooler, numero, usuario, fecha<span class="hljs-keyword">FROM</span> emp_cooler_guias<span class="hljs-keyword">WHERE</span> codigo_barra = <cooler>  <span class="hljs-keyword">AND</span> estado_embarque = <span class="hljs-number">0</span>  <span class="hljs-keyword">AND</span> estado = <span class="hljs-number">1</span><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> fecha <span class="hljs-keyword">DESC</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
4. **Agrupa paquetes por OSE**
    
    
    - Extrae los primeros dígitos del campo `numero`.
    - Agrupa cantidades por OSE.
5. **Obtiene datos adicionales de la OSE**  
    Consulta empresarial:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> osd.osd_osid <span class="hljs-keyword">AS</span> ose_id,       os.ose_nroguiacliente <span class="hljs-keyword">AS</span> guia,       SUM(osd.osd_unidad) <span class="hljs-keyword">AS</span> cantidad<span class="hljs-keyword">FROM</span> emp_os_detalle osd<span class="hljs-keyword">LEFT JOIN</span> emp_ordenservicio os <span class="hljs-keyword">ON</span> os.ose_id = osd.osd_osid<span class="hljs-keyword">WHERE</span> osd.osd_eliminado = <span class="hljs-number">0</span>  <span class="hljs-keyword">AND</span> osd.osd_osid <span class="hljs-keyword">IN</span> <ose_ids><span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span> osd.osd_osid`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
    </div></div>
6. **Construye respuesta final**  
    Por cada OSE:
    
    
    - código del cooler
    - usuario y fecha del último registro
    - cantidades únicas encontradas
    - cantidad total desde la OS
    - número de guía del cliente

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"lista guias embarcadas."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">12345</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cooler"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"COOLER-001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"jlopez"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-20 10:15:00"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cantidades"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"10,12"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">22</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"GUIA-998877"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ **Posibles Errores**

### 1. Cooler no enviado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el cooler vuelva a intentarlo"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Usuario no enviado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el usuario vuelva a intentarlo"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. Código de cooler inválido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Cooler inválido. Debe contener la palabra BINS o COOLER"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>*(Tu código acepta PALLET también, pero el mensaje no lo menciona.)*

### 4. Cooler no tiene registros activos

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Aun no hay paquetes en el cooler"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 5. No hay paquetes no embarcados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Aun no hay paquetes en el cooler"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_cooler**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-%22number%22%2C-%22c"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"codigo_barra"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_cooler\_guias**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cooler"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"numero"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_os\_detalle + emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21cooler--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !cooler -> errorif !usuario -> errorif cooler not contains ["BINS", "COOLER", "PALLET"] -> errorcoolerData = SELECT from emp_cooler where codigo=cooler and estado=1if empty -> errorpaquetes = SELECT from emp_cooler_guias where cooler=cooler and estado_embarque=0if empty -> erroragrupar paquetes por ose_id:    extract cantidades from numerodetalles = SELECT cantidades y guía por cada ose_idcombinar datos:    return lista por cada ose_id con cantidades únicas + total OS`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# control/carguero/obtener - [show]

**PATH:** /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/CargueroController.php

## 🧾 **Descripción**

Obtiene la **información detallada de un carguero programado** (`cap_id`) incluyendo:

- Datos del carguero (fecha, placas, choferes, ruta)
- Listado de terminales (para reemplazar IDs por nombres)
- Orígenes, destinos y escalas (transformados a formato legible)
- Cantidad de guías embarcadas asociadas al carguero
- Suma total del monto final de dichas guías

Este servicio consolida datos provenientes de varias tablas del sistema Empresarial.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fcarguero%2Fshow"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">**<span style="color: rgb(224, 62, 45);">`POST /carguero/show`</span>**</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1138" data-start="816"><thead data-end="866" data-start="816"><tr data-end="866" data-start="816"><th data-col-size="sm" data-end="828" data-start="816">Campo</th><th data-col-size="sm" data-end="837" data-start="828">Tipo</th><th data-col-size="sm" data-end="851" data-start="837">Obligatorio</th><th data-col-size="md" data-end="866" data-start="851">Descripción</th></tr></thead><tbody data-end="1138" data-start="918"><tr data-end="975" data-start="918"><td data-col-size="sm" data-end="930" data-start="918">cap\_id</td><td data-col-size="sm" data-end="939" data-start="930">number</td><td data-col-size="sm" data-end="944" data-start="939">Sí</td><td data-col-size="md" data-end="975" data-start="944">ID del carguero programado.</td></tr><tr data-end="1054" data-start="976"><td data-col-size="sm" data-end="988" data-start="976">terminal</td><td data-col-size="sm" data-end="997" data-start="988">string</td><td data-col-size="sm" data-end="1002" data-start="997">No</td><td data-col-size="md" data-end="1054" data-start="1002">Terminal origen (no se usa en la lógica actual).</td></tr><tr data-end="1138" data-start="1055"><td data-col-size="sm" data-end="1067" data-start="1055">usuario</td><td data-col-size="sm" data-end="1076" data-start="1067">string</td><td data-col-size="sm" data-end="1081" data-start="1076">No</td><td data-col-size="md" data-end="1138" data-start="1081">Usuario que consulta (no se usa en la lógica actual).</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

El servicio depende del middleware configurado (token, sesión, etc).  
No valida autenticación dentro del método.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Validación inicial**
    
    
    - Si no se envía `cap_id` → retorna error.
2. **Obtiene datos del carguero**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> fecha, choferes, ruta, placas, origen, destino, cerrado<span class="hljs-keyword">FROM</span> emp_cargprogramado<span class="hljs-keyword">WHERE</span> cap_id <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>cap_id<span class="hljs-operator">></span>`</div></div>
3. **Obtiene lista de terminales**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> ter_id, ter_nombre<span class="hljs-keyword">FROM</span> emp_terminal`</div></div>
    - Se genera un mapa `ter_id → nombre`.
4. **Convierte origen/destino (JSON) a texto descriptivo**
    
    
    - Decodifica arrays JSON.
    - Reemplaza cada ID por: `ID + nombre_terminal`
    - Calcula campos:
        
        
        - `origenes`
        - `destinos`
        - `escalas` (unión única de ambos)
5. **Obtiene guías relacionadas al carguero**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> ose_montofinal, ose_id<span class="hljs-keyword">FROM</span> emp_ordenservicio<span class="hljs-keyword">WHERE</span> ose_ultimo_carprog_embarque = <cap_id><span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> ose_ultima_fecha_embarque <span class="hljs-keyword">DESC</span>`</div></div>
6. Calcula:
    
    
    - `cantidad`: número de guías
    - `suma`: suma total de `ose_montofinal`
7. Elimina campos originales `origen` y `destino` del objeto final.
8. **Retorna JSON con todos los datos del carguero.**

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de cargueros"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-15 10:00:00"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1287</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"chofer1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHO123"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"chofer2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CHO456"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"ruta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"RUTA-09"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"placa1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ABC-123"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"placa2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"DEF-456"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cerrado"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"origenes"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"1 Terminal Lima"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"3 Terminal Arequipa"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"destinos"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"5 Terminal Piura"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"escalas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"1 Terminal Lima"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"3 Terminal Arequipa"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"5 Terminal Piura"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">42</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"suma"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">15789.50</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. Falta `cap_id`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar un id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. `cap_id` no existe en la BD

*(La función no valida explícitamente este caso, pero retornará `data = null`)*

Ejemplo de respuesta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de cargueros"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*(Opcionalmente podrías corregir esto en backend.)*

---

# 📚 **Schemas (estructuras usadas)**

### **emp\_cargprogramado**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"chofer1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"chofer2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ruta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"placa1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"placa2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cerrado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json[]"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json[]"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_terminal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ter_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_montofinal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"float"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_ultimo_carprog_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21cap_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !cap_id -> errorcarguero = SELECT * FROM emp_cargprogramado WHERE cap_id = cap_idterminales = SELECT ter_id, ter_nombre FROM emp_terminalmapaTerminal = {ter_id: nombre}carguero.origenes = parseJSON(carguero.origen)carguero.destinos = parseJSON(carguero.destino)escalas = union(origenes, destinos)reemplazar cada ID por "ID + nombre_terminal"guias = SELECT ose_id, ose_montofinal FROM emp_ordenservicio        WHERE ose_ultimo_carprog_embarque = cap_idcarguero.cantidad = count(guias)carguero.suma = sum(ose_montofinal)return carguero`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/embarque/listar - [index]

## 🧾 **Descripción**

Este servicio retorna la **lista de órdenes de servicio embarcadas** asociadas a un **cargoprogramación (cap\_id)**.  
Además, incluye:

- Datos de origen/destino
- Estado de embarque
- Contenido detallado de las unidades (KG, sobres, bultos, etc.)
- Cantidades totales
- Nombre del remitente
- Guía de cliente
- Ruta generada (origen - destino)

Adicionalmente, permite filtrar por número de guía del cliente.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fordenes-embarq"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /ordenes-embarque`**</span></div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pagina"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1066" data-start="809"><thead data-end="853" data-start="809"><tr data-end="853" data-start="809"><th data-col-size="sm" data-end="817" data-start="809">Campo</th><th data-col-size="sm" data-end="824" data-start="817">Tipo</th><th data-col-size="sm" data-end="838" data-start="824">Obligatorio</th><th data-col-size="sm" data-end="853" data-start="838">Descripción</th></tr></thead><tbody data-end="1066" data-start="899"><tr data-end="962" data-start="899"><td data-col-size="sm" data-end="908" data-start="899">cap\_id</td><td data-col-size="sm" data-end="917" data-start="908">number</td><td data-col-size="sm" data-end="922" data-start="917">Sí</td><td data-col-size="sm" data-end="962" data-start="922">ID de carga programación (embarque).</td></tr><tr data-end="1013" data-start="963"><td data-col-size="sm" data-end="972" data-start="963">pagina</td><td data-col-size="sm" data-end="981" data-start="972">number</td><td data-col-size="sm" data-end="986" data-start="981">Sí</td><td data-col-size="sm" data-end="1013" data-start="986">Página para paginación.</td></tr><tr data-end="1066" data-start="1014"><td data-col-size="sm" data-end="1021" data-start="1014">guia</td><td data-col-size="sm" data-end="1030" data-start="1021">string</td><td data-col-size="sm" data-end="1035" data-start="1030">No</td><td data-col-size="sm" data-end="1066" data-start="1035">Número de guía del cliente.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Autenticación estándar del sistema (token/cabecera middleware). No validado directamente en la función.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Valida que `cap_id` exista**.  
    Si no → *“Es obligatorio enviar un id”*
2. **Construye filtros**
    
    
    - Siempre por: `ose_ultimo_carprog_embarque = cap_id`
    - Opcional: `ose_nroguiacliente = guia`
3. **Obtiene las órdenes de servicio** (`emp_ordenservicio`), paginadas (15 registros por página).  
    Incluye campos como:
    
    
    - fecha de preferencia de partida
    - monto final
    - remitente/destinatario
    - tipo de pago
    - origen / destino
    - usuario creador
    - estado de pago
    - etc.
4. **Carga los terminales** (`emp_terminal`) para convertir IDs → nombres y alias.
5. **Si no existen órdenes**  
    → *“No ha embarcado nada aun”*
6. **Obtiene detalles de contenido** (`emp_os_detalle`) por OSE:
    
    
    - Agrupa por tipo de precio
    - Suma cantidades
    - Genera estructura como: `"5 KG, 2 SB"`
7. **Obtiene historial de embarque** (`emp_embarque_historial`)
    
    
    - Determina si la guía está embarcada o no
    - Paquetes embarcados
    - Total de paquetes
8. **Obtiene abreviaturas de tipos de pago** (`emp_atributos`)
    
    
    - Convierte código → abreviatura
9. **Integra la información para cada OSE**
    
    
    - contenido
    - cantidad total
    - estado de guía (“GUIA EMBARCADA” / “SIN GUIA”)
    - paquetes embarcados
    - origen y destino por nombre
    - ruta generada (alias-origen → alias-destino)
10. **Obtiene nombres de remitentes** (`emp_persona`)  
    Convierte DNI → nombre completo.
11. **Reemplaza remitente DNI → nombre**.
12. **Retorna lista final** con toda la información enriquecida.

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de ordenes"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-24 08:15:00"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">150.50</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"GC-2300122"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"remitente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"JUAN PÉREZ GARCÍA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"destinatario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMPRESA XYZ"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"tipo_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CR"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIMA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AREQUIPA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"amendoza"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">554433</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"estado_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"PAGADO"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"tipo_entrega"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"DELIVERY"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"contenido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"3 KG, 2 SB"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ruta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIM - AQP"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"embarque_guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"GUIA EMBARCADA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cant_paq"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">5</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cant_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">5</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"embarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-string">"PKG001"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"PKG002"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"PKG003"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"PKG004"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"PKG005"</span><span class="hljs-punctuation">]</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. Falta `cap_id`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar un id"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. No hay órdenes embarcadas aún

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No ha embarcado nada aun"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. No hay órdenes coincidentes con la guía filtrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No ha embarcado nada aun"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_nroguiacliente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_remiteempresa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (DNI)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_destinaempresa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_servpagotipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termorigenatencion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termdestinoentrega"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_montofinal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_os\_detalle**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_embarque\_historial**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22emb_ose_id%22%3A-%22num"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"emb_ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_estado_guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cant_paquetes_embarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (coma separada)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cant_paquetes_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_terminal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ter_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"alias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_persona**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22documento%22%3A-%22stri"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"documento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21cap_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !cap_id -> errorwhere = { ose_ultimo_carprog_embarque = cap_id }if guia -> add filter guiaordenes = get OS with paginationif empty -> errorose_ids = extract idsdetalles = query emp_os_detalle grouped by tipo and ose_idarmar contenido y cantidad totalembarques = query emp_embarque_historial for cap_idarmar estado de guía y paquetes embarcadosatributos = abreviaturas de tipo de pagoterminales = mapear origen/destinofor each orden:    combinar detalles + embarques + terminales + atributos    construir ruta    guardar remitente DNIpersonas = query emp_persona for remitentesreemplazar DNI → nombrereturn lista enriquecida`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/carguero/qr - [generateQrMassive]

**PATH:** /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/CargueroController.php

## 🧾 **Descripción**

Genera un registro QR asociado a un **carguero programado (cap\_id)**.  
Obtiene automáticamente la **placa** del vehículo asignado y registra:

- cap\_id
- placa
- usuario
- terminal
- fecha de creación

El registro se almacena en la tabla `emp_cargprogramado_qr` en la base de datos **CentOS**.

*Nota:* El código contiene una validación de contraseña deshabilitada (comentada).

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fgenerate-qr-ma"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /generate-qr-massive`**</span></div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22password%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"password"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"placa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (ignorado, se reemplaza con la placa obtenida)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Reglas

- `password`: opcional actualmente (validación comentada).
- `usuario`: requerido.
- `cap_id`: requerido.
- `terminal`: requerido.
- `placa`: ignorado, se obtiene desde la BD.

---

# 🔐 **Seguridad**

La función no fuerza autenticación ni validación de contraseña porque está comentada, pero originalmente pretendía validar:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-hash%3A%3Acheck%28strtoupp"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`Hash::<span class="hljs-built_in">check</span>(<span class="hljs-built_in">strtoupper</span>(password), usr_clave)`</div></div>La seguridad dependerá del middleware externo del proyecto.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Recibe parámetros del request:**  
    `password`, `usuario`, `cap_id`, `terminal`, `placa` (pero placa será ignorada).
2. **Obtiene la placa real del carguero** desde Empresarial:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> cap_cargueroid <span class="hljs-keyword">AS</span> placa<span class="hljs-keyword">FROM</span> emp_cargprogramado<span class="hljs-keyword">WHERE</span> cap_id = <cap_id>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
3. **Preparar datos para el QR:**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`{  cap_id,  car_placa (placa obtenida),  user (usuario),  ter_id (terminal),  fecha_crea (timestamp actual)}`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
4. **Inserta registro en CentOS:**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> emp_cargprogramado_qr<span class="hljs-keyword">RETURNING</span> id`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
5. **Si la inserción falla → error**  
    **Si inserta correctamente → éxito**

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Qr Generado con éxito"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. Error al insertar el registro

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error en el servicio vuelva a intentar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. cap\_id no encontrado (si la consulta no retorna placa)

*(El código no valida este error explícitamente, pero sería un caso real posible)*

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró carguero asociado al cap_id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Error inesperado (excepción del servidor)

*(No manejado explícitamente, pero debe considerarse)*

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error interno del servidor"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_cargprogramado**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_cargueroid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (placa)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_cargprogramado\_qr**

Campos insertados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"car_placa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"user"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_crea"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-receive-password%2C-us"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`receive password, usuario, cap_id, terminal, placa// Validar contraseña (actualmente deshabilitado)placaReal = SELECT placa FROM emp_cargprogramado WHERE cap_id = cap_iddata = {    cap_id: cap_id,    car_placa: placaReal,    user: usuario,    ter_id: terminal,    fecha_crea: now()}id = INSERT INTO emp_cargprogramado_qr(data)if !id:    return errorreturn éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/embarque/cerrar - [cerrar]

PATH: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/EmbarqueController.php

## 🧾 **Descripción**

Este servicio realiza el **cierre de embarque** para un carguero (cap\_id).  
Procesa todas las **órdenes de servicio asociadas al carguero**, registra el embarque individual de cada una, actualiza sus estados y marca el carguero como embarcado.

Además:

- Actualiza el historial de embarque.
- Procesa posibles transbordos.
- Actualiza el detalle del carguero.
- Registra un reporte de embarque.
- Retorna confirmación del cierre.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fcerrar"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /cerrar`**</span></div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1172" data-start="893"><thead data-end="937" data-start="893"><tr data-end="937" data-start="893"><th data-col-size="sm" data-end="901" data-start="893">Campo</th><th data-col-size="sm" data-end="908" data-start="901">Tipo</th><th data-col-size="sm" data-end="922" data-start="908">Obligatorio</th><th data-col-size="sm" data-end="937" data-start="922">Descripción</th></tr></thead><tbody data-end="1172" data-start="983"><tr data-end="1046" data-start="983"><td data-col-size="sm" data-end="992" data-start="983">cap\_id</td><td data-col-size="sm" data-end="1001" data-start="992">number</td><td data-col-size="sm" data-end="1006" data-start="1001">Sí</td><td data-col-size="sm" data-end="1046" data-start="1006">ID del carguero programado a cerrar.</td></tr><tr data-end="1112" data-start="1047"><td data-col-size="sm" data-end="1058" data-start="1047">terminal</td><td data-col-size="sm" data-end="1067" data-start="1058">string</td><td data-col-size="sm" data-end="1072" data-start="1067">Sí</td><td data-col-size="sm" data-end="1112" data-start="1072">Terminal donde se realiza el cierre.</td></tr><tr data-end="1172" data-start="1113"><td data-col-size="sm" data-end="1123" data-start="1113">usuario</td><td data-col-size="sm" data-end="1132" data-start="1123">string</td><td data-col-size="sm" data-end="1137" data-start="1132">Sí</td><td data-col-size="sm" data-end="1172" data-start="1137">Usuario que ejecuta el proceso.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Controlada por autenticación global (middleware).  
El servicio no valida tokens directamente.

---

# 🧠 **Flujo del Servicio (resumen real)**

### 1. **Obtiene órdenes asociadas al cap\_id**

Consulta `emp_ordenservicio`:

- No eliminadas
- Asignadas al carguero (`ose_ultimo_carprog_embarque = cap_id`)

Si:

- No hay órdenes, o
- Todas ya están cerradas (`ose_estadoembarque = '1'`)  
    → Retorna “Carguero cerrado”.

---

### 2. **Marca historial de embarque como cerrado**

Actualiza `emp_embarque_historial`:

- Donde status = 1
- Y emb\_estado\_cierre = 0  
    → Lo cambia a 1.

---

### 3. **Iteración por cada orden**

Para cada orden:

#### a) Obtiene placa del carguero

Desde `emp_cargprogramado`.

#### b) Si la orden está en estado de reparto `T`, registra transbordo

Actualiza `emp_transbordo`:

- tra\_estado = "SI"
- registra usuario, fecha y placa del carguero

#### c) Registra el embarque en `emp_embarque`

Guarda:

- ose\_id
- cap\_id
- terminal
- fecha de embarque
- usuario creador
- observaciones temporales almacenadas en la orden

#### d) Actualiza estado de la orden en `emp_ordenservicio`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-ose_estadoembarque-%3D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-attr">ose_estadoembarque</span> = <span class="hljs-number">1</span><span class="hljs-attr">ose_terminalactual</span> = terminal<span class="hljs-attr">ose_estadodesembarque</span> = <span class="hljs-number">0</span><span class="hljs-attr">ose_reparto_estado</span> = <span class="hljs-number">0</span><span class="hljs-attr">ose_movilidad_reparto</span> = null<span class="hljs-attr">ose_estado_paquete_embarque</span> = <span class="hljs-number">0</span><span class="hljs-attr">ose_estado_guia_embarque</span> = <span class="hljs-number">0</span><span class="hljs-attr">estado_os</span> = <span class="hljs-string">"Embarque"</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 4. **Actualiza detalle del carguero (emp\_cargprogramado\_detalle)**

Si existe registro:

- Agrega el terminal a la lista `id_terminal`
- Cambia `cap_estado_embarque` a 1

Si no existe:

- Inserta nuevo registro con ese terminal y estado de embarque = 1.

---

### 5. **Calcula monto total embarcado**

Suma `ose_montofinal` de todas las OS:

- No eliminadas
- De ese terminal
- Con estado embarque E o 1
- Y asignadas al carguero

---

### 6. **Registra un reporte de embarque**

Inserta en `emp_cargprogramado_reporte`:

- cap\_id
- terminal
- usuario
- fecha
- tipo\_estado = “Embarque”
- flete = monto total

---

### 7. **Retorna respuesta**

Devuelve:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se grabó el Embarque correctamente."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Se grabó el Embarque correctamente."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. No hay órdenes para embarcar o ya están cerradas

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Carguero cerrado."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*Es el único error explícito que retorna el servicio.*

---

# 📚 **Schemas (estructuras usadas)**

*(Basado exclusivamente en los campos usados en el código)*

### **emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_ultima_fecha_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_reparto_estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_emb_obs_tipo_temp"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_emb_obs_mensaje_temp"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_emb_obs_usuario_temp"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_emb_obs_fecha_temp"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_emb_obs_urlimg_temp"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estadoembarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_embarque\_historial**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22emb_carg_id%22%3A-%22nu"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"emb_carg_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_estado_cierre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_transbordo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22tra_osid%22%3A-%22numbe"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"tra_osid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tra_estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tra_salidaid2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tra_user2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tra_fecha2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tra_carguero2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_embarque**

Campos insertados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22emb_ordenservicio"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"emb_ordenservicioid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cargprograid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_horaembarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_terminalembarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"eliminado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fhcrea"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usercreaid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_obs_tipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_obs_mensaje"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_obs_usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_obs_fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_obs_urlimg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_cargprogramado\_detalle**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"id_terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_estado_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_cargprogramado\_reporte**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"id_terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario_reg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fechareg"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"flete"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-ordenes-%3D-select-os-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`ordenes = SELECT OS where cap_idsi ordenes vacío o todas cerradas:    return "Carguero cerrado"actualizar emp_embarque_historial: emb_estado_cierre = 1para cada orden:    cargar placa del carguero    si reparto_estado == T:        actualizar transbordo    insertar en emp_embarque (datos de la OS)    actualizar emp_ordenservicio:        estadoembarque = 1        terminalactual = terminal        otros estados...actualizar o insertar emp_cargprogramado_detallemonto = suma montofinal de ordenes embarcadas del terminal y cap_idinsertar reporte en emp_cargprogramado_reportereturn success`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/embarque/validar - [validar]

PATH: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/EmbarqueController.php

## 🧾 **Descripción**

Este servicio valida si una **Orden de Servicio (OSE)** puede ser procesada para embarque, verificando:

- Que la guía exista y no esté anulada.
- Que corresponda al terminal.
- Que cuente con código QR o clave según el tipo de cliente.
- Que cumpla validaciones adicionales mediante `validar_grt()`.

El servicio evita el embarque de guías que estén incompletas, anuladas o sin documentación obligatoria.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fvalidar-guia"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">**`POST /validar-guia`**</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"numero"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_cierre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"APP | PDA"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1411" data-start="884"><thead data-end="928" data-start="884"><tr data-end="928" data-start="884"><th data-col-size="sm" data-end="892" data-start="884">Campo</th><th data-col-size="sm" data-end="899" data-start="892">Tipo</th><th data-col-size="sm" data-end="913" data-start="899">Obligatorio</th><th data-col-size="md" data-end="928" data-start="913">Descripción</th></tr></thead><tbody data-end="1411" data-start="974"><tr data-end="1028" data-start="974"><td data-col-size="sm" data-end="983" data-start="974">ose\_id</td><td data-col-size="sm" data-end="992" data-start="983">number</td><td data-col-size="sm" data-end="997" data-start="992">Sí</td><td data-col-size="md" data-end="1028" data-start="997">ID de la Orden de Servicio.</td></tr><tr data-end="1077" data-start="1029"><td data-col-size="sm" data-end="1040" data-start="1029">cantidad</td><td data-col-size="sm" data-end="1049" data-start="1040">number</td><td data-col-size="sm" data-end="1054" data-start="1049">Sí</td><td data-col-size="md" data-end="1077" data-start="1054">Cantidad escaneada.</td></tr><tr data-end="1175" data-start="1078"><td data-col-size="sm" data-end="1087" data-start="1078">numero</td><td data-col-size="sm" data-end="1096" data-start="1087">string</td><td data-col-size="sm" data-end="1102" data-start="1096">No\*</td><td data-col-size="md" data-end="1175" data-start="1102">Número del paquete escaneado. *(Si no existe, no se valida embarque)*</td></tr><tr data-end="1238" data-start="1176"><td data-col-size="sm" data-end="1186" data-start="1176">usuario</td><td data-col-size="sm" data-end="1195" data-start="1186">string</td><td data-col-size="sm" data-end="1200" data-start="1195">Sí</td><td data-col-size="md" data-end="1238" data-start="1200">Usuario que realiza la validación.</td></tr><tr data-end="1305" data-start="1239"><td data-col-size="sm" data-end="1250" data-start="1239">terminal</td><td data-col-size="sm" data-end="1259" data-start="1250">string</td><td data-col-size="sm" data-end="1264" data-start="1259">Sí</td><td data-col-size="md" data-end="1305" data-start="1264">Terminal donde se realiza el proceso.</td></tr><tr data-end="1364" data-start="1306"><td data-col-size="sm" data-end="1320" data-start="1306">tipo\_cierre</td><td data-col-size="sm" data-end="1329" data-start="1320">string</td><td data-col-size="sm" data-end="1334" data-start="1329">Sí</td><td data-col-size="md" data-end="1364" data-start="1334">Tipo de cierre: APP o PDA.</td></tr><tr data-end="1411" data-start="1365"><td data-col-size="sm" data-end="1374" data-start="1365">cap\_id</td><td data-col-size="sm" data-end="1383" data-start="1374">string</td><td data-col-size="sm" data-end="1388" data-start="1383">Sí</td><td data-col-size="md" data-end="1411" data-start="1388">Capacidad asociada.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Depende del middleware del proyecto.  
La función **no valida seguridad interna**, se asume que ya llega un request autenticado.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Validaciones básicas del Request**
    
    
    - Verifica existencia de:
        
        
        - `ose_id`
        - `cantidad`
        - `usuario`
        - `terminal`
        - `cap_id`
        - `tipo_cierre` ∈ {APP, PDA}
    - Si **no existe `numero`**, retorna:
        
        > "Embarque de guías no se valida."
2. **Consulta Orden de Servicio**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> ose_id, ose_estadoPago, ose_nroguiacliente, ose_code_qr,       ose_termdestinoentrega, ose_remiteempresa, ose_destinaempresa,       ose_termorigenatencion, ose_fhpreferenciapartida,       ose_remitecontactomail, ose_remitecontactofono<span class="hljs-keyword">FROM</span> emp_ordenservicio<span class="hljs-keyword">WHERE</span> ose_id <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>ose_id<span class="hljs-operator">></span>`</div></div>Validaciones:
    
    
    - Si no existe: ❌ "Guía no encontrada."
    - Si está anulada (`ose_estadoPago = 'AN'`): ❌ "La guía se encuentra anulada."
    - Si no corresponde al terminal destino: ❌ "La Orden de Servicio ya se encuentra en su destino."
3. **Validaciones por tipo de cliente**
    
    
    - Si tiene información de remitente con reglas especiales:
        
        
        - Si `remitecontactomail == '0'` → ❌ “Primero debe confirmar la guía en empresarial.”
    - Si cliente es tipo `"CLIENTES"`:
        
        
        - Busca clave en `emp_code_send`
        - Busca adicionales en `emp_adicionales`
        - Si no tiene clave ni adicionales → ❌ “La Orden de Servicio no tiene clave Creada.”
    - Si **no es cliente tipo especial**, verifica QR:
        
        
        - Si no tiene QR → ❌ “La Orden de Servicio no tiene código QR.”
4. **Validación adicional mediante `validar_grt()`**  
    Llama:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-built_in">validar_grt</span>(ose_id, cap_id, remiteempresa, destinaempresa)`</div></div>
    - Si falla, retorna error directo.
5. **Si todo es correcto**  
    Retorna:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Orden de servicio validada."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Orden de servicio validada."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. Falta ose\_id

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta ose_id."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. No se valida porque no se envió número

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Embarque de guias no se valida."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Falta algún parámetro obligatorio

Ejemplo — falta terminal:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta terminal."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. Guía no encontrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Guia no encontrada."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 5. Guía anulada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La guía se encuentra anulada."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 6. Terminal incorrecto

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La Orden de Servicio ya se encuentra en su destino."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 7. Guía sin confirmación

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Primero debe confirmar la guía en empresarial."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 8. No tiene clave creada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La Orden de Servicio no tiene clave Creada."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 9. No tiene QR

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La Orden de Servicio no tiene código QR."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"error"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 10. Error por validar GRT

Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Error en validación GRT."</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"password"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_ordenservicio**

Campos utilizados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estadoPago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_nroguiacliente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_code_qr"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termdestinoentrega"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_remiteempresa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_destinaempresa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termorigenatencion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_fhpreferenciapartida"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_remitecontactomail"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_remitecontactofono"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_code\_send**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22idose%22%3A-%22number%22%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"idose"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"password"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_adicionales**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22adc_ordenservicio"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"adc_ordenservicioid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"adc_tipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21ose_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !ose_id -> errorif !numero -> return "Embarque de guías no se valida."if !cantidad or !usuario or !terminal or !cap_id -> errorif tipo_cierre not in ["APP", "PDA"] -> errororden = SELECT FROM emp_ordenservicio WHERE ose_idif !orden -> errorif estadoPago == 'AN' -> errorif orden.destino != terminal -> errorvalidaciones cliente:    if remitenteMail == '0' -> error    if CLIENTES and no clave y no adicional -> error    else if no QR -> errorvalida_grt = validar_grt(...)if !success -> return valida_grtreturn success`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/embarque/paquete -[storeQuantities]

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/EmbarqueController.php

## 🧾 **Descripción**

Este servicio registra el **embarque de paquetes** para una Orden de Servicio (OS).  
Valida toda la información crítica del embarque, verifica restricciones de rutas, valida si la OS está apta para embarque (QR / clave / no anulada), confirma cantidades, registra procesos históricos, actualiza estados de embarque y permite manejar escenarios:

- Embarque normal
- Embarque masivo
- Embarque aéreo
- Embarque desde cooler

Es uno de los servicios centrales del módulo logístico.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fstore-quantiti"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /store-quantities`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-12345%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">12345</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">12</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cantidades"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"1,2,3,4"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"jlopez"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">7</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_cierre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"APP"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">881</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cierre_aereo"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cooler"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"placa"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"traspaso"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Campos requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1647" data-start="1084"><thead data-end="1128" data-start="1084"><tr data-end="1128" data-start="1084"><th data-col-size="sm" data-end="1092" data-start="1084">Campo</th><th data-col-size="sm" data-end="1099" data-start="1092">Tipo</th><th data-col-size="sm" data-end="1113" data-start="1099">Obligatorio</th><th data-col-size="sm" data-end="1128" data-start="1113">Descripción</th></tr></thead><tbody data-end="1647" data-start="1174"><tr data-end="1239" data-start="1174"><td data-col-size="sm" data-end="1183" data-start="1174">ose\_id</td><td data-col-size="sm" data-end="1192" data-start="1183">number</td><td data-col-size="sm" data-end="1197" data-start="1192">Sí</td><td data-col-size="sm" data-end="1239" data-start="1197">ID de la Orden de Servicio a embarcar.</td></tr><tr data-end="1305" data-start="1240"><td data-col-size="sm" data-end="1251" data-start="1240">cantidad</td><td data-col-size="sm" data-end="1260" data-start="1251">number</td><td data-col-size="sm" data-end="1265" data-start="1260">Sí</td><td data-col-size="sm" data-end="1305" data-start="1265">Cantidad total declarada a embarcar.</td></tr><tr data-end="1382" data-start="1306"><td data-col-size="sm" data-end="1319" data-start="1306">cantidades</td><td data-col-size="sm" data-end="1334" data-start="1319">string (CSV)</td><td data-col-size="sm" data-end="1339" data-start="1334">Sí</td><td data-col-size="sm" data-end="1382" data-start="1339">Paquetes escaneados para este embarque.</td></tr><tr data-end="1450" data-start="1383"><td data-col-size="sm" data-end="1393" data-start="1383">usuario</td><td data-col-size="sm" data-end="1402" data-start="1393">string</td><td data-col-size="sm" data-end="1407" data-start="1402">Sí</td><td data-col-size="sm" data-end="1450" data-start="1407">Usuario que está realizando el proceso.</td></tr><tr data-end="1512" data-start="1451"><td data-col-size="sm" data-end="1462" data-start="1451">terminal</td><td data-col-size="sm" data-end="1471" data-start="1462">number</td><td data-col-size="sm" data-end="1476" data-start="1471">Sí</td><td data-col-size="sm" data-end="1512" data-start="1476">Terminal desde donde se embarca.</td></tr><tr data-end="1583" data-start="1513"><td data-col-size="sm" data-end="1527" data-start="1513">tipo\_cierre</td><td data-col-size="sm" data-end="1544" data-start="1527">"APP" | "PDA"</td><td data-col-size="sm" data-end="1549" data-start="1544">Sí</td><td data-col-size="sm" data-end="1583" data-start="1549">Tipo de registro del embarque.</td></tr><tr data-end="1647" data-start="1584"><td data-col-size="sm" data-end="1593" data-start="1584">cap\_id</td><td data-col-size="sm" data-end="1602" data-start="1593">number</td><td data-col-size="sm" data-end="1607" data-start="1602">Sí</td><td data-col-size="sm" data-end="1647" data-start="1607">Carguero (ruta programada) asignado.</td></tr></tbody></table>

</div></div>### Campos opcionales

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-descripci"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="2003" data-start="1671"><thead data-end="1701" data-start="1671"><tr data-end="1701" data-start="1671"><th data-col-size="sm" data-end="1679" data-start="1671">Campo</th><th data-col-size="sm" data-end="1686" data-start="1679">Tipo</th><th data-col-size="md" data-end="1701" data-start="1686">Descripción</th></tr></thead><tbody data-end="2003" data-start="1734"><tr data-end="1809" data-start="1734"><td data-col-size="sm" data-end="1749" data-start="1734">cierre\_aereo</td><td data-col-size="sm" data-end="1758" data-start="1749">number</td><td data-col-size="md" data-end="1809" data-start="1758">ID del cierre a registrar si es embarque aéreo.</td></tr><tr data-end="1874" data-start="1810"><td data-col-size="sm" data-end="1819" data-start="1810">cooler</td><td data-col-size="sm" data-end="1828" data-start="1819">string</td><td data-col-size="md" data-end="1874" data-start="1828">Código del cooler si se embarca desde uno.</td></tr><tr data-end="1928" data-start="1875"><td data-col-size="sm" data-end="1883" data-start="1875">placa</td><td data-col-size="sm" data-end="1892" data-start="1883">string</td><td data-col-size="md" data-end="1928" data-start="1892">Para embarque masivo (opcional).</td></tr><tr data-end="2003" data-start="1929"><td data-col-size="sm" data-end="1940" data-start="1929">traspaso</td><td data-col-size="sm" data-end="1955" data-start="1940">number (0/1)</td><td data-col-size="md" data-end="2003" data-start="1955">Indica si permite traspaso entre terminales.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Servicio protegido mediante autenticación de API interna del sistema.  
Requiere usuario autenticado y terminal válida.

---

# 🧠 **Flujo del Servicio (resumen real)**

A continuación, el flujo real y completo basado en tu código:

---

### 🔹 **1. Validación de parámetros obligatorios**

- ose\_id
- cantidades
- cantidad
- usuario
- terminal
- cap\_id
- tipo\_cierre (solo APP o PDA)

---

### 🔹 **2. Obtiene la Orden de Servicio**

Consulta: `emp_ordenservicio`  
Valida:

- Existe la OS
- No está anulada
- Tiene QR o clave (según reglas del contacto)
- Terminal de destino coincide para permitir embarque

---

### 🔹 **3. Valida retención de embarque aéreo**

Consulta: `emp_retencion_embarque_aereo`  
Si existe → no permite embarque.

---

### 🔹 **4. Valida terminales, rutas y restricciones del carguero**

Consulta: `emp_cargprogramado`

Verifica:

- Que el origen del carguero incluya la terminal actual (a menos que sea traspaso).
- Restricciones de destino.
- Que si es destino aéreo, la ruta sea aérea.

Si alguna restricción aplica → error.

---

### 🔹 **5. Obtiene cantidades totales de la OS**

Consulta: `emp_os_detalle`  
Calcula unidades totales.

---

### 🔹 **6. Verifica paquetes previamente desembarcados**

Consulta: `emp_procesos_historial_app`  
Si encuentra que todos los paquetes ya están en destino → bloquea embarque.

---

### 🔹 **7. Verifica embarques previos**

Consulta: `emp_embarque_historial`  
Evalúa:

- embarque actual
- cantidades ya registradas
- estado de guía
- si ya está 100% embarcada

Si ya embarcó todos los paquetes → error.

---

### 🔹 **8. Registra o actualiza el embarque**

Dos escenarios:

#### a) **Primer registro**

Inserta en:  
`emp_embarque_historial`

#### b) **Actualización**

Actualiza registro existente.

---

### 🔹 **9. Actualiza el estado de la Orden de Servicio**

Actualiza en `emp_ordenservicio`:

- estado de paquete
- último carguero
- estado de embarque general
- fecha de embarque
- marcas de validación

---

### 🔹 **10. Registra proceso histórico**

En:  
`emp_procesos_historial_app`

- Si no existe → inserta
- Si existe → actualiza cantidades

---

### 🔹 **11. Procesos adicionales**

- Si es embarque aéreo → actualiza `emp_embarque_aereo`
- Si embarca desde cooler → marca estado del registro en `emp_cooler_guias`

---

### 🔹 **12. Respuesta final**

Devuelve éxito y número de guía.

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Paquetes de la OS: 458822 embarcados con éxito."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ **Posibles Errores**

### 1. Campos faltantes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta cantidad."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. OS no encontrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Guia no encontrada."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. OS anulada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La guía se encuentra anulada."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. OS sin QR o clave válida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La Orden de Servicio no tiene código QR."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 5. Terminal no permitida

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La Orden de Servicio ya se encuentra en su destino."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 6. Restricción de embarque aéreo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--5"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La guia tiene una retención de embarque aereo, no se puede embarcar"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 7. Restricción de ruta

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--6"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"En la ruta X no puede embarcar para el destino Y."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 8. Paquetes ya embarcados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--7"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ya fueron embarcados todos los paquetes de la guia."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 9. Error al actualizar embarque aéreo o cooler

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--8"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Ocurrió un error al embarcar la OS: XXXX"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_nroguiacliente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estadoPago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_code_qr"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termorigenatencion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termdestinoentrega"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_fhpreferenciapartida"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_embarque\_historial**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22emb_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"emb_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cant_paquetes_embarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cant_paquetes_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_carg_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_procesos\_historial\_app**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-%22number%22%2C-%22i"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"idose"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"idcarguero"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_metodo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cant_paquetes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_cooler\_guias**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22codigo_barra%22%3A-%22s"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"codigo_barra"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"0|1"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_embarque\_aereo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cierre_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number|null"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-validar-par%C3%A1metros-r"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`validar parámetros requeridosorden = obtener OSsi no existe o está anulada -> errorvalidar QR o clavevalidar terminal de destinovalidar retenciones aéreasvalidar rutas, orígenes, restriccionesdetalle = obtener total de paquetes de OSprocesos_previos = obtener historialsi todos los paquetes ya están en destino -> errorembarques_previos = obtener embarquessi ya embarcados todos -> errorsi no existe embarque actual:    insertar registro de embarquesino:    actualizar registro existenteactualizar estado de OSregistrar proceso históricosi cierre_aereo -> actualizar emp_embarque_aereosi cooler -> actualizar emp_cooler_guiasreturn éxito`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# control/embarque/obtener - [show]

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/EmbarqueController.php

## 🧾 **Descripción**

Obtiene la información completa de una **Orden de Servicio (OSE)**, incluyendo:

- Datos generales de la guía
- Datos del remitente, destino y ruta
- Contenido (tipos y cantidades de unidades)
- Estado de embarque y paquetes embarcados
- Atributos del tipo de pago
- Usuario creador
- Validaciones de estado

Es un servicio para **consulta detallada** de una guía antes o durante el proceso de embarque.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fshow"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">**`POST /show`**</span></div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1085" data-start="806"><thead data-end="850" data-start="806"><tr data-end="850" data-start="806"><th data-col-size="sm" data-end="814" data-start="806">Campo</th><th data-col-size="sm" data-end="821" data-start="814">Tipo</th><th data-col-size="sm" data-end="835" data-start="821">Obligatorio</th><th data-col-size="sm" data-end="850" data-start="835">Descripción</th></tr></thead><tbody data-end="1085" data-start="896"><tr data-end="962" data-start="896"><td data-col-size="sm" data-end="905" data-start="896">ose\_id</td><td data-col-size="sm" data-end="914" data-start="905">number</td><td data-col-size="sm" data-end="919" data-start="914">Sí</td><td data-col-size="sm" data-end="962" data-start="919">ID de la orden de servicio a consultar.</td></tr><tr data-end="1022" data-start="963"><td data-col-size="sm" data-end="972" data-start="963">cap\_id</td><td data-col-size="sm" data-end="981" data-start="972">number</td><td data-col-size="sm" data-end="986" data-start="981">Sí</td><td data-col-size="sm" data-end="1022" data-start="986">ID de carga (embarque) asociado.</td></tr><tr data-end="1085" data-start="1023"><td data-col-size="sm" data-end="1034" data-start="1023">terminal</td><td data-col-size="sm" data-end="1043" data-start="1034">string</td><td data-col-size="sm" data-end="1048" data-start="1043">No</td><td data-col-size="sm" data-end="1085" data-start="1048">Terminal desde donde se consulta.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

El servicio depende del middleware global (token/sesión del sistema).  
No hace validación explícita dentro de la función.

---

# 🧠 **Flujo del Servicio (resumen real)**

### 1. **Validación inicial**

- Verifica obligatorio `ose_id`.
- Verifica obligatorio `cap_id`.

### 2. **Obtiene datos de la orden**

Consulta principal:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-fecha%2C-monto%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`<span class="hljs-keyword">SELECT</span>    fecha, monto, guia, remitente, destinatario,    tipo_pago, origen, destino, usuario,    ose_id, estado_pago, tipo_entrega,    contenido <span class="hljs-operator">=</span> <span class="hljs-keyword">null</span>,    ruta <span class="hljs-operator">=</span> <span class="hljs-keyword">null</span>,    embarque_guia <span class="hljs-operator">=</span> <span class="hljs-string">'SIN GUIA'</span>,    cant_paq <span class="hljs-operator">=</span> <span class="hljs-number">0</span>,    cant_total <span class="hljs-operator">=</span> <span class="hljs-number">0</span>,    embarcados <span class="hljs-operator">=</span> <span class="hljs-keyword">null</span>,    cap_id <span class="hljs-operator">=</span> <span class="hljs-string">''</span><span class="hljs-keyword">FROM</span> emp_ordenservicio<span class="hljs-keyword">WHERE</span> ose_id <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>ose_id<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Si no existe → *"Orden de servicio no encontrada"*  
Si está anulada (`estado_pago = 'AN'`) → error.

---

### 3. **Obtiene nombres de terminales**

Se reemplazan los IDs de origen/destino por su nombre y alias:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-nombre%2C-alias"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> nombre, <span class="hljs-keyword">alias</span> <span class="hljs-keyword">FROM</span> emp_terminal <span class="hljs-keyword">WHERE</span> ter_id = origen<span class="hljs-keyword">SELECT</span> nombre, <span class="hljs-keyword">alias</span> <span class="hljs-keyword">FROM</span> emp_terminal <span class="hljs-keyword">WHERE</span> ter_id = destino`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Crea la ruta: `<span class="hljs-attr">ruta</span> = origen_alias + <span class="hljs-string">' - '</span> + destino_alias`

---

### 4. **Obtiene contenido de la OSE**

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-tipo%2C-cantida"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> tipo, cantidad<span class="hljs-keyword">FROM</span> emp_os_detalle<span class="hljs-keyword">WHERE</span> osd_osid <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>ose_id<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> osd_eliminado <span class="hljs-operator">=</span> <span class="hljs-number">0</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Construye:

- contenido → `"5 CAJA / 2 SOBRE / ..."`
- cant\_total → sumatoria de cantidades

---

### 5. **Obtiene estado de embarque**

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-emb_estado_gu"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`SELECT emb_estado_guia, emb_cant_paquetes_embarcadosFROM emp_embarque_historial<span class="hljs-type">WHERE</span> <span class="hljs-variable">emb_ose_id</span> <span class="hljs-operator">=</span> <ose_id>  <span class="hljs-type">AND</span> <span class="hljs-variable">emb_carg_id</span> <span class="hljs-operator">=</span> <cap_id>  <span class="hljs-type">AND</span> <span class="hljs-variable">status</span> <span class="hljs-operator">=</span> <span class="hljs-number">1</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Calcula:

- emb\_guia → `GUIA EMBARCADA` si existe algún registro con valor &gt; 0
- cant\_paq → cantidad de paquetes registrados
- embarcados → array de los paquetes embarcados

---

### 6. **Traduce tipo de pago**

Consulta atributos:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-abreviatura%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> abreviatura, valor<span class="hljs-keyword">FROM</span> emp_atributos<span class="hljs-keyword">WHERE</span> concepto <span class="hljs-operator">=</span> <span class="hljs-string">'tipospago'</span><span class="hljs-keyword">AND</span> atr_idpadre <span class="hljs-operator">=</span> <span class="hljs-number">90</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Aplica la conversión: `<span class="hljs-attr">orden.tipo_pago</span> = abreviatura del valor recibido`

---

### 7. **Obtiene nombre del remitente**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-documento%2C-no"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> documento, nombre_completo<span class="hljs-keyword">FROM</span> emp_persona<span class="hljs-keyword">WHERE</span> documento <span class="hljs-operator">=</span> orden.remitente`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 8. **Obtiene usuario creador**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-usr_alias-fro"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> usr_alias <span class="hljs-keyword">FROM</span> emp_usuario <span class="hljs-keyword">WHERE</span> usr_id <span class="hljs-operator">=</span> orden.usuario`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 9. **Devuelve respuesta final**

Incluye:

- datos completos de la OSE
- contenido
- tipo de pago traducido
- cantidades
- ruta
- paquetes embarcados

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Orden encontrada"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">152233</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-12"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"G-998877"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"remitente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMPRESA S.A."</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"destinatario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CLIENTE SAC"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"tipo_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CR"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIMA"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AREQUIPA"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"ruta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIM - AQP"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"contenido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"5 CAJA / 2 SOBRE"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cant_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">7</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"embarque_guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SIN GUIA"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cant_paq"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"jrojas"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">22</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"embarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ **Posibles Errores**

### 1. Falta ose\_id

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar un ose_id"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Falta cap\_id

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 28.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 28.6px;"><td style="height: 28.6px;">`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar un cap_id"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. OSE no encontrada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Orden de servicio no encontrada"</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. Guía anulada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"La guía se encuentra anulada."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 **Schemas (estructuras usadas)**

### **Orden de Servicio (emp\_ordenservicio)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"remitente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"destinatario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"tipo_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Detalle OSE (emp\_os\_detalle)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22tipo%22%3A-%22string%22%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"tipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Terminal (emp\_terminal)**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22nombre%22%3A-%22string%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 33.8px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 33.8px;"><td style="height: 33.8px;">`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"alias"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **Embarque Historial**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22emb_estado_guia%22%3A"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"emb_estado_guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cant_paquetes_embarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21ose_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%; height: 29.6px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 29.6px;"><td style="height: 29.6px;">`if !ose_id -> errorif !cap_id -> errororden = SELECT from emp_ordenservicioif not found -> return mensajeif anulada -> errororigen = SELECT terminaldestino = SELECT terminalorden.ruta = origen.alias + " - " + destino.aliasdetalles = SELECT detalle OSEcontenido = concatenar tipo + cantidadcant_total = sum cantidadesembarques = SELECT embarques para ose_id y cap_idcalcular emb_guia, cant_paq, embarcados[]tipo_pago = traducir via emp_atributosremitente = SELECT personausuario = SELECT usuarioreturn orden completa`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# control/embarque/eliminar - [destroy]

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/EmbarqueController.php

## 🧾 Descripción

*Este servicio elimina el **embarque** asociado a una orden de servicio (**OSE**) y un carguero (**cap\_id**).*  
*Revierte todos los estados de embarque relacionados y registra el historial de eliminación del proceso.*  
*Si aplica, también elimina el embarque en **Moova** (integración externa).*

Es un servicio crítico dentro del flujo de **desembarque / reversión de embarque**.

---

# 🚀 Endpoint

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fembarque%2Fdestr"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr"><span style="color: rgb(224, 62, 45);">***`POST /embarque/destroy`***</span></div></div>---

# 📥 Request Body

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1198" data-start="828"><thead data-end="872" data-start="828"><tr data-end="872" data-start="828"><th data-col-size="sm" data-end="836" data-start="828">Campo</th><th data-col-size="sm" data-end="843" data-start="836">Tipo</th><th data-col-size="sm" data-end="857" data-start="843">Obligatorio</th><th data-col-size="md" data-end="872" data-start="857">Descripción</th></tr></thead><tbody data-end="1198" data-start="918"><tr data-end="983" data-start="918"><td data-col-size="sm" data-end="927" data-start="918">ose\_id</td><td data-col-size="sm" data-end="936" data-start="927">number</td><td data-col-size="sm" data-end="941" data-start="936">Sí</td><td data-col-size="md" data-end="983" data-start="941">ID de la orden de servicio a revertir.</td></tr><tr data-end="1060" data-start="984"><td data-col-size="sm" data-end="994" data-start="984">usuario</td><td data-col-size="sm" data-end="1003" data-start="994">string</td><td data-col-size="sm" data-end="1008" data-start="1003">Sí</td><td data-col-size="md" data-end="1060" data-start="1008">Usuario que ejecuta la eliminación del embarque.</td></tr><tr data-end="1133" data-start="1061"><td data-col-size="sm" data-end="1072" data-start="1061">terminal</td><td data-col-size="sm" data-end="1081" data-start="1072">string</td><td data-col-size="sm" data-end="1086" data-start="1081">Sí</td><td data-col-size="md" data-end="1133" data-start="1086">Terminal desde donde se realiza el proceso.</td></tr><tr data-end="1198" data-start="1134"><td data-col-size="sm" data-end="1143" data-start="1134">cap\_id</td><td data-col-size="sm" data-end="1152" data-start="1143">number</td><td data-col-size="sm" data-end="1157" data-start="1152">Sí</td><td data-col-size="md" data-end="1198" data-start="1157">ID del carguero asociado al embarque.</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Protegido por autenticación estándar de la API (middleware Laravel).  
La función asume que ya hay un usuario validado.

---

# 🧠 Flujo del Servicio (resumen real)

### 1. **Validaciones iniciales**

Verifica que existan los campos obligatorios: `ose_id`, `usuario`, `terminal`, `cap_id`.  
Si falta alguno → responde con error inmediato.

---

### 2. **Obtiene información del carguero**

Consulta en `emp_cargprogramado` para asegurarse de que el carguero existe.

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-cap_origen%2C-c"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> cap_origen, cap_destino, cap_rutacarguero, cap_restricciones, ruta_aerea<span class="hljs-keyword">FROM</span> emp_cargprogramado<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> emp_grupos<span class="hljs-keyword">WHERE</span> cap_id <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>cap_id<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Si no existe → error: *"No se encontró el carguero."*

---

### 3. **Define estructura de reversión de OSE**

Se arma un arreglo con todos los campos de embarque en estado inicial:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_usuario_embar"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_usuario_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estadoembarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_ultimo_carprog_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_ultima_fecha_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_fecha_paquete_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_fecha_guia_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estado_guia_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_usuario_guia_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_usuario_paquete_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estado_paquete_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 4. **Valida si la OSE tuvo desembarque anterior**

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-des_id-from-e"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> des_id <span class="hljs-keyword">FROM</span> emp_desembarque_historial<span class="hljs-keyword">WHERE</span> des_ose_id <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>ose_id<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> des_carg_id <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>cap_id<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Si existen → marca `estado_os = "Desembarque"`

---

### 5. **Revierte el embarque en historial empresarial**

Actualiza `emp_embarque_historial`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-where-emb_carg_id-%3D-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-type">WHERE</span> <span class="hljs-variable">emb_carg_id</span> <span class="hljs-operator">=</span> cap_id <span class="hljs-type">AND</span> <span class="hljs-variable">emb_ose_id</span> <span class="hljs-operator">=</span> ose_id<span class="hljs-type">UPDATE</span> <span class="hljs-variable">status</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 6. **Resetea información de embarque en la OSE**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-update-emp_ordenserv"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`UPDATE emp_ordenservicio <span class="hljs-built_in">SET</span> <campos de <span class="hljs-variable">$OS</span>> <span class="hljs-built_in">WHERE</span> ose_id = <ose_id>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 7. **Revierte procesos en historial de CentOS**

Busca procesos activos en:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-emp_procesos_histori"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`emp_procesos_historial_app<span class="hljs-type">WHERE</span> <span class="hljs-variable">idose</span> <span class="hljs-operator">=</span> ose_id<span class="hljs-type">AND</span> <span class="hljs-variable">idcarguero</span> <span class="hljs-operator">=</span> cap_id<span class="hljs-type">AND</span> <span class="hljs-variable">proceso</span> <span class="hljs-operator">=</span> <span class="hljs-string">'embarque'</span>AND nombre_metodo <span class="hljs-title function_">IN</span> <span class="hljs-params">(<span class="hljs-string">'embarque_paquete'</span></span>, <span class="hljs-string">'embarque_guia'</span>)<span class="hljs-type">UPDATE</span> <span class="hljs-variable">status</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

### 8. **Registra un nuevo historial de eliminación**

Inserta un registro indicando el proceso "eliminar\_embarque".

---

### 9. **Integración con Moova (si aplica)**

Si el carguero contiene destino "523", verifica si el terminal está habilitado para Moova:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-id-from-emp_t"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> id <span class="hljs-keyword">FROM</span> emp_ter_moova<span class="hljs-keyword">WHERE</span> ter_id <span class="hljs-operator">=</span> terminal <span class="hljs-keyword">AND</span> status <span class="hljs-operator">=</span> <span class="hljs-number">1</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Si existe → Ejecuta: `<span class="hljs-title class_">MoovaController</span>::<span class="hljs-title function_ invoke__">destroy</span>(<span class="hljs-variable">$ose_id</span>)`

---

### 10. **Respuesta final**

Devuelve mensaje de éxito: `<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Embarque eliminado"</span><span class="hljs-punctuation">}</span>`

---

# 📤 Response 200 – Ejemplo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Embarque eliminado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ Posibles Errores

### 1. Falta ose\_id

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta ose_id."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Falta usuario

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta usuario."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 3. Falta terminal

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta terminal."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 4. Falta cap\_id

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta cap_id."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 5. Carguero no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--4"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el carguero."</span> <span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 Schemas (estructuras usadas)

### **emp\_cargprogramado**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_origen%22%3A-%22str"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json/string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_rutacarguero"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_restricciones"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json/string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_embarque\_historial**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22emb_ose_id%22%3A-%22num"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"emb_ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_carg_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estadoembarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_usuario_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string|null"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_procesos\_historial\_app**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22idose%22%3A-%22string%22%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"idose"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"idcarguero"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_metodo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"status"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 Lógica en pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-validar-campos-oblig"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`validar campos obligatorios: ose_id, usuario, terminal, cap_idcarguero = obtener cargueroif !carguero -> errorOS = campos en estado inicialdesembarque = buscar desembarque previoif existe -> OS.estado_os = 'Desembarque'actualizar emp_embarque_historial SET status = 0actualizar emp_ordenservicio SET OSactualizar procesos_historial_app SET status = 0insertar registro eliminar_embarquesi carguero.cap_destino contiene '523':    si terminal tiene configuración moova:        llamar MoovaController.destroy(ose_id)return success`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# Desembarques

# control/grupo/listar - [index] (1,2)

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/GrupoController.php

## 🧾 **Descripción**

Retorna una lista paginada de **grupos de cargueros de desembarque**, filtrados por terminal, nombre y fecha.  
Cada grupo incluye sus placas asociadas y el nombre legible de la terminal.

Realiza consultas en la base **empresarial**, transforma datos y enriquece la respuesta con nombres de terminales y placas de cargueros programados.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fcargueros-dese"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /cargueros-desembarque`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22terminal%22%3A-3%2C-%22pa"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pagina"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"TURNO A"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1079" data-start="769"><thead data-end="813" data-start="769"><tr data-end="813" data-start="769"><th data-col-size="sm" data-end="777" data-start="769">Campo</th><th data-col-size="sm" data-end="784" data-start="777">Tipo</th><th data-col-size="sm" data-end="798" data-start="784">Obligatorio</th><th data-col-size="md" data-end="813" data-start="798">Descripción</th></tr></thead><tbody data-end="1079" data-start="859"><tr data-end="906" data-start="859"><td data-col-size="sm" data-end="870" data-start="859">terminal</td><td data-col-size="sm" data-end="876" data-start="870">int</td><td data-col-size="sm" data-end="884" data-start="876">✔️ Sí</td><td data-col-size="md" data-end="906" data-start="884">ID de la terminal.</td></tr><tr data-end="980" data-start="907"><td data-col-size="sm" data-end="916" data-start="907">pagina</td><td data-col-size="sm" data-end="922" data-start="916">int</td><td data-col-size="sm" data-end="930" data-start="922">✔️ Sí</td><td data-col-size="md" data-end="980" data-start="930">Número de página (paginación de 15 registros).</td></tr><tr data-end="1079" data-start="981"><td data-col-size="sm" data-end="990" data-start="981">nombre</td><td data-col-size="sm" data-end="999" data-start="990">string</td><td data-col-size="sm" data-end="1013" data-start="999">✖️ Opcional</td><td data-col-size="md" data-end="1079" data-start="1013">Filtra por nombre del grupo (activa rango de fecha extendido).</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Requiere token o autenticación definida en middleware general (no se valida dentro del método).

---

# 🧠 **Flujo del Servicio (resumen real)**

### 1. Validaciones iniciales

- Si no envían `terminal` → error obligatorio.
- Se toma `pagina` para paginar.
- Se define `limit = 15`.
- Fecha mínima:
    
    
    - Por defecto: **ayer**
    - Si se envía `nombre`: se amplía rango **–10 días a +10 días** y se agrega filtro LIKE al nombre.

### 2. Construcción del filtro para la consulta

Filtros aplicados:

- terminal = enviado
- status = 1
- fecha\_creacion &gt; fechaDesde
- si existe nombre → LIKE %nombre% y fecha\_creacion &lt; fechaHasta

### 3. Consulta de grupos de desembarque

Tabla: `emp_grupo_cargueros_desembarque`

Campos retornados:

- id
- grupo (array JSON de cap\_id)
- nombre
- terminal
- cerrar\_grupo
- fecha\_creacion
- placas = null (placeholder)

Si no hay resultados → “No se encontraron grupos”.

### 4. Obtención del catálogo de terminales

Consulta `emp_terminal` y crea un arreglo tipo diccionario:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B-ter_id-%3D%3E-ter_nomb"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-selector-attr">[ ter_id => ter_nombre ]</span>`</div></div>### 5. Enriquecimiento de la data

Para cada grupo:

1. Decodifica `grupo` (lista de cap\_id).
2. Consulta placas desde:
    
    
    - **emp\_cargprogramado (cap)**
    - **emp\_carguero\_new (carg)**
    
    Campos:
    
    
    - placa1
    - codigo1
    - placa2
3. Construye lista de placas:  
    `"placa1 codigo1"`
4. Reemplaza el id de terminal por su nombre real.

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"lista de grupos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">15</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"grupo"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-number">123</span><span class="hljs-punctuation">,</span> <span class="hljs-number">124</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"TURNO A"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Terminal Callao"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cerrar"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-26 10:21:00"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"placas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>        <span class="hljs-string">"B1234 C001"</span><span class="hljs-punctuation">,</span>        <span class="hljs-string">"B2288 C002"</span>      <span class="hljs-punctuation">]</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# ❗ **Posibles Errores**

### 1. Terminal obligatorio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar una terminal"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### 2. Sin resultados

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontraron grupos"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_grupo\_cargueros\_desembarque**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-%22number%22%2C-%22g"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"grupo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json array of cap_id"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cerrar_grupo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_cargprogramado + emp\_carguero\_new**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22placa1%22%3A-%22string%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"placa1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"codigo1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"placa2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>### **emp\_terminal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ter_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_abrebiatura"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21terminal--%3E-erro"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !terminal -> errorfechaDesde = yesterdayif nombre:    fechaDesde = -10 days    fechaHasta = +10 days    add filter nombre LIKE %nombre%    add filter fecha_creacion < fechaHastaadd filter fecha_creacion > fechaDesdegrupos = SELECT from emp_grupo_cargueros_desembarque where filters, paginatedif empty -> errorterminales = SELECT all terminalesmap[ter_id] = ter_nombrefor each grupo:    ids = decode(grupo.grupo)    cargueros = SELECT placas info using ids    grupo.placas = format placas    grupo.terminal = terminales[grupo.terminal]return grupos`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>

# control/grupo/obtener - [show]

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/GrupoController.php

## 🧾 **Descripción**

Este servicio obtiene la **información detallada de un grupo de cargueros de desembarque**, incluyendo:

- Datos del grupo
- Terminal asociada
- Cargueros programados (placas/códigos)
- Información estructurada lista para visualizar en pantalla

El servicio consulta varias tablas del sistema empresarial para reconstruir toda la información relacionada al grupo.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fgrupo-desembar"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /grupo-desembarque/show`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22grp_id%22%3A-123-%7D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"grp_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">123</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="853" data-start="710"><thead data-end="754" data-start="710"><tr data-end="754" data-start="710"><th data-col-size="sm" data-end="718" data-start="710">Campo</th><th data-col-size="sm" data-end="725" data-start="718">Tipo</th><th data-col-size="sm" data-end="739" data-start="725">Obligatorio</th><th data-col-size="sm" data-end="754" data-start="739">Descripción</th></tr></thead><tbody data-end="853" data-start="800"><tr data-end="853" data-start="800"><td data-col-size="sm" data-end="809" data-start="800">grp\_id</td><td data-col-size="sm" data-end="819" data-start="809">integer</td><td data-col-size="sm" data-end="824" data-start="819">Sí</td><td data-col-size="sm" data-end="853" data-start="824">ID del grupo a consultar.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Requiere autenticación estándar del sistema (middleware).  
La función no implementa validación de permisos directamente.

---

# 🧠 **Flujo del Servicio (resumen real)**

### 1. **Validación del parámetro**

- Si no se envía `grp_id`, retorna error.

---

### 2. **Obtiene información del grupo**

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-id%2C-grupo%2C-no"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> id, grupo, nombre, terminal, cerrar_grupo <span class="hljs-keyword">AS</span> cerrar,       fecha_creacion <span class="hljs-keyword">AS</span> fecha, <span class="hljs-keyword">null</span> <span class="hljs-keyword">AS</span> placas<span class="hljs-keyword">FROM</span> emp_grupo_cargueros_desembarque<span class="hljs-keyword">WHERE</span> id = <grp_id>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>- Si no se encuentra → error *"No se encontró el grupo"*.

---

### 3. **Reemplaza el ID de terminal por su nombre**

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-ter_id%2C-ter_n"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> ter_id, ter_nombre, ter_abrebiatura<span class="hljs-keyword">FROM</span> emp_terminal<span class="hljs-keyword">WHERE</span> ter_id <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>grupo.terminal<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Actualiza: `<span class="hljs-attr">grupo.terminal</span> = <terminal.ter_nombre>`

---

### 4. **Convierte el campo grupo a JSON**

`grupo.grupo` es un JSON que contiene una lista de `cap_id`.

Ejemplo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%5B12%2C-15%2C-19%5D"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">[</span><span class="hljs-number">12</span><span class="hljs-punctuation">,</span> <span class="hljs-number">15</span><span class="hljs-punctuation">,</span> <span class="hljs-number">19</span><span class="hljs-punctuation">]</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 5. **Obtiene información de cargueros programados**

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-cap.cap_cargu"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> cap.cap_cargueroid <span class="hljs-keyword">AS</span> placa1,       carg.car_codigo <span class="hljs-keyword">AS</span> codigo1,       cap.cap_carguero_id2 <span class="hljs-keyword">AS</span> placa2<span class="hljs-keyword">FROM</span> emp_cargprogramado capLEFT <span class="hljs-keyword">JOIN</span> emp_carguero_new carg <span class="hljs-keyword">ON</span> cap.cap_cargid = carg.id<span class="hljs-keyword">WHERE</span> cap.cap_id <span class="hljs-keyword">IN</span> (<lista de cap_id>)  <span class="hljs-built_in">AND</span> cap.eliminado = <span class="hljs-number">0</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Luego construye una lista tipo: `<span class="hljs-selector-attr">[<span class="hljs-string">"PLACA001 COD001"</span></span>, <span class="hljs-string">"PLACA002 COD009"</span>, ...]`

Asignado a: `<span class="hljs-attr">grupo.placas</span> = [...]`

---

### 6. **Respuesta final**

Retorna toda la estructura ensamblada.

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Informacion de grupo"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">12</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"grupo"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span><span class="hljs-number">125</span><span class="hljs-punctuation">,</span> <span class="hljs-number">126</span><span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"GRUPO 1"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Terminal Norte"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cerrar"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-10 10:20:00"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"placas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"ABC123 COD001"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"XYZ998 COD077"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. Falta de parámetro obligatorio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar grp_id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Grupo no encontrado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró el grupo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_grupo\_cargueros\_desembarque**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-%22number%22%2C-%22g"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"grupo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json-array"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cerrar"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"placas"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"array<string>"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_terminal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ter_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_abrebiatura"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_cargprogramado + emp\_carguero\_new**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22placa1%22%3A-%22string%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"placa1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"codigo1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"placa2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21grp_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !grp_id -> errorgrupo = SELECT ... FROM emp_grupo_cargueros_desembarque WHERE id=grp_idif !grupo -> errorterminal = SELECT ... FROM emp_terminal WHERE ter_id=grupo.terminalgrupo.terminal = terminal.nombreterminales = JSON decode(grupo.grupo)grupo.grupo = terminalesif terminales not empty:    cargueros = SELECT cargueros programados WHERE cap_id IN terminales    grupo.placas = ["placa1 codigo1", ...]return grupo`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/carguero/grupo - [listarPorGrupo]

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/CargueroController.php

## 🧾 **Descripción**

Este servicio recibe un **ID de grupo de cargueros (`grp_id`)** y retorna la **lista de cargueros asociados al grupo**, incluyendo información enriquecida:

- Datos del carguero (placas, choferes, ruta, origen/destino)
- Estado de QR generado
- Datos de desembarque (paquetes desembarcados y guías desembarcadas)
- Escalas generadas dinámicamente según origen y destino

El servicio consulta varias tablas del sistema Empresarial y CentOS y consolida la información en una sola respuesta.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Flistar-por-gru"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /listar-por-grupo`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22grp_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"grp_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1110" data-start="923"><thead data-end="967" data-start="923"><tr data-end="967" data-start="923"><th data-col-size="sm" data-end="931" data-start="923">Campo</th><th data-col-size="sm" data-end="938" data-start="931">Tipo</th><th data-col-size="sm" data-end="952" data-start="938">Obligatorio</th><th data-col-size="md" data-end="967" data-start="952">Descripción</th></tr></thead><tbody data-end="1110" data-start="1013"><tr data-end="1110" data-start="1013"><td data-col-size="sm" data-end="1022" data-start="1013">grp\_id</td><td data-col-size="sm" data-end="1031" data-start="1022">number</td><td data-col-size="sm" data-end="1036" data-start="1031">Sí</td><td data-col-size="md" data-end="1110" data-start="1036">ID del grupo registrado en la tabla `emp_grupo_cargueros_desembarque`.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Protegido generalmente por autenticación de la API (token/middleware definido).  
El método no valida credenciales directamente.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Validación de entrada**
    
    
    - Verifica que `grp_id` exista; si no, retorna error.
    - Busca el grupo en `emp_grupo_cargueros_desembarque`.
    - Verifica que el grupo tenga cargueros registrados.
2. **Obtiene cargueros asociados**  
    Consulta `emp_cargprogramado` para los `cap_id` del grupo:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> fecha, cap_id, chofer1, chofer2, ruta,       origen, destino, placa1, placa2, cerrado<span class="hljs-keyword">FROM</span> emp_cargprogramado<span class="hljs-keyword">WHERE</span> eliminado = <span class="hljs-number">0</span> <span class="hljs-keyword">AND</span> cap_id <span class="hljs-keyword">IN</span> (<cap_ids>)<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> fecha <span class="hljs-keyword">DESC</span>`</div></div>
3. **Obtiene catálogo de terminales**
    
    
    - Lista nombres y abreviaturas de todas las terminales.
    - Se usa para convertir IDs de terminal en texto legible.
4. **Procesamiento por cada carguero**  
    Para cada `cap_id`:
    
    
    - Decodifica JSON de `origen` y `destino`.
    - Traduce IDs a abreviaturas de terminal:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attribute">ORIGEN</span> → <span class="hljs-string">"LIM - CHI - ARE"</span>DESTINO → <span class="hljs-string">"ARE - JUL"</span>`</div></div>
    - Verifica si tiene QR generado (consulta en CentOS).
    - Obtiene información de desembarque por guía:
        
        
        - Paquetes desembarcados
        - Total de paquetes
        - Estado de guía (DESEMBARCADA, SIN GUIA, FALTA DESEMBARCAR GUIA)
    - Calcula:
        
        
        - Total de paquetes desembarcados
        - Total de guías desembarcadas
    - Construye lista de **escalas** combinando origen + destino.
5. **Devuelve lista final de cargueros procesados**

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de cargueros"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-10 08:00:00"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">98765</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"chofer1"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1122</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"chofer2"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3344</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ruta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"RUTA-01"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIM - ARE"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ARE - JUL"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"placa1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ABC-123"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"placa2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"XYZ-789"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cerrado"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"qr_generado"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"escalas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>        <span class="hljs-string">"1 Terminal Lima"</span><span class="hljs-punctuation">,</span>        <span class="hljs-string">"2 Terminal Arequipa"</span><span class="hljs-punctuation">,</span>        <span class="hljs-string">"3 Terminal Juliaca"</span>      <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"paquetes"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">150</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"guias"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">12</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. No se envió `grp_id`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Envie grp_id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Grupo no existe

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No se encontró grupo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Grupo sin cargueros

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Agregue cargueros al grupo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. No hay cargueros coincidentes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Agregue cargueros al grupo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras utilizadas)**

### **emp\_grupo\_cargueros\_desembarque**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-number%2C-%22gru"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"grupo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (JSON array)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_cargprogramado**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-number%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_fhsalidaprogramada"</span><span class="hljs-punctuation">:</span> datetime<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_chofer1id"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_chofer2id"</span><span class="hljs-punctuation">:</span> number|<span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_rutacarguero"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"JSON array"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"JSON array"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_cargueroid"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_carguero_id2"</span><span class="hljs-punctuation">:</span> string|<span class="hljs-literal"><span class="hljs-keyword">null</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_cerrado"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_terminal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ter_id%22%3A-number%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_nombre"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_abrebiatura"</span><span class="hljs-punctuation">:</span> string<span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_desembarque\_historial + emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22des_ose_id%22%3A-numb"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"des_ose_id"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"desembarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"comma separated string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"total"</span><span class="hljs-punctuation">:</span> number<span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estadoguia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"FALTA DESEMBARCAR GUIA | SIN GUIA | GUIA DESEMBARCADA"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21grp_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !grp_id -> errorgrupo = SELECT grupo WHERE id=grp_idif !grupo -> errorcap_ids = json_decode(grupo.grupo)if empty -> errorcargueros = SELECT cargueros WHERE cap_id IN cap_idsif empty -> errorterminales = SELECT ter_id, ter_nombre, abreviaturafor each carguero:    origen_ids = json_decode(carguero.origen)    destino_ids = json_decode(carguero.destino)    traducir ids a abreviaturas    verificar QR generado    consultar historial de desembarque    calcular paquetes desembarcados y guías desembarcadas    generar escalas a partir de origen + destinoreturn cargueros procesados`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/grupo/guardar - [store]

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/GrupoController.php

## 🧾 **Descripción**

Crea un nuevo registro en **emp\_grupo\_cargueros\_desembarque**, que representa un grupo de cargueros/desembarque asociado a un terminal.

Si el usuario no envía un nombre, el sistema genera uno automáticamente usando el nombre del terminal y la fecha de creación.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fgrupo-carguero"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /grupo-cargueros-desembarque`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22nombre%22%3A-%22string-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number (requerido)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1092" data-start="694"><thead data-end="744" data-start="694"><tr data-end="744" data-start="694"><th data-col-size="sm" data-end="706" data-start="694">Campo</th><th data-col-size="sm" data-end="715" data-start="706">Tipo</th><th data-col-size="sm" data-end="729" data-start="715">Obligatorio</th><th data-col-size="md" data-end="744" data-start="729">Descripción</th></tr></thead><tbody data-end="1092" data-start="796"><tr data-end="876" data-start="796"><td data-col-size="sm" data-end="808" data-start="796">terminal</td><td data-col-size="sm" data-end="817" data-start="808">number</td><td data-col-size="sm" data-end="831" data-start="817">Sí</td><td data-col-size="md" data-end="876" data-start="831">ID del terminal donde se creará el grupo.</td></tr><tr data-end="986" data-start="877"><td data-col-size="sm" data-end="889" data-start="877">nombre</td><td data-col-size="sm" data-end="898" data-start="889">string</td><td data-col-size="sm" data-end="912" data-start="898">No</td><td data-col-size="md" data-end="986" data-start="912">Nombre personalizado del grupo. Si no se envía, el sistema genera uno.</td></tr><tr data-end="1092" data-start="987"><td data-col-size="sm" data-end="999" data-start="987">usuario</td><td data-col-size="sm" data-end="1008" data-start="999">string</td><td data-col-size="sm" data-end="1022" data-start="1008">No</td><td data-col-size="md" data-end="1092" data-start="1022">Usuario que realiza la operación (no se usa dentro de la función).</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

El método no define validación propia, pero depende del middleware o autenticación general de la API.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Obtiene los parámetros**: nombre, terminal, usuario, fecha actual.
2. **Valida que terminal sea numérico**.  
    Si no lo es → retorna:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-punctuation">{</span> <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span> <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe enviar el terminal"</span> <span class="hljs-punctuation">}</span>`</div></div>
3. **Busca datos del terminal** en `emp_terminal`:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> ter_id, ter_nombre <span class="hljs-keyword">AS</span> nombre<span class="hljs-keyword">FROM</span> emp_terminal<span class="hljs-keyword">WHERE</span> ter_id = {terminal}`</div></div>
4. **Genera nombre automáticamente** si no se envía:  
    → `<nombre_terminal> <fecha>`
5. **Inserta un nuevo grupo** en `emp_grupo_cargueros_desembarque`:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> emp_grupo_cargueros_desembarque(nombre, terminal, fecha_creacion)<span class="hljs-keyword">VALUES</span> (...)`</div></div>
6. **Retorna ID generado** mediante `insertGetId`.

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Grupo creado correctamente"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">58</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*(donde `58` es el ID del nuevo grupo)*

---

# ❗ **Posibles Errores**

### 1. Terminal no válido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Debe enviar el terminal"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*(No existen más validaciones dentro del método.)*

---

# 📚 **Schemas (estructuras usadas)**

### **emp\_terminal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ter_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_grupo\_cargueros\_desembarque**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-%22number%22%2C-%22n"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"fecha_creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-nombre-%3D-request.nom"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`nombre = request.nombreterminal = request.terminalusuario = request.usuariofecha = now()if terminal is not numeric:    return errorterminal_data = SELECT nombre FROM emp_terminal WHERE ter_id = terminalif nombre is empty:    nombre = terminal_data.nombre + " " + fechagrupo_new = INSERT INTO emp_grupo_cargueros_desembarque (nombre, terminal, fecha_creacion)return success with grupo_new id`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/grupo/carguero/agregar - [agregarCarguero]

Path: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/GrupoController.php

## 🧾 **Descripción**

Agrega un **carguero (cap\_id)** a un **grupo de cargueros de desembarque (grp\_id)**.  
El servicio valida que:

- Exista el grupo.
- El grupo tenga su lista de cargueros almacenados en formato JSON.
- El carguero no esté ya incluido en el grupo.
- Luego actualiza la tabla agregando el carguero al listado.

Este servicio modifica directamente la tabla:

**emp\_grupo\_cargueros\_desembarque**

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fagregar-cargue"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /agregar-carguero`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22grp_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"grp_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1045" data-start="833"><thead data-end="877" data-start="833"><tr data-end="877" data-start="833"><th data-col-size="sm" data-end="841" data-start="833">Campo</th><th data-col-size="sm" data-end="848" data-start="841">Tipo</th><th data-col-size="sm" data-end="862" data-start="848">Obligatorio</th><th data-col-size="md" data-end="877" data-start="862">Descripción</th></tr></thead><tbody data-end="1045" data-start="923"><tr data-end="991" data-start="923"><td data-col-size="sm" data-end="932" data-start="923">grp\_id</td><td data-col-size="sm" data-end="941" data-start="932">number</td><td data-col-size="sm" data-end="946" data-start="941">Sí</td><td data-col-size="md" data-end="991" data-start="946">ID del grupo de cargueros de desembarque.</td></tr><tr data-end="1045" data-start="992"><td data-col-size="sm" data-end="1001" data-start="992">cap\_id</td><td data-col-size="sm" data-end="1010" data-start="1001">number</td><td data-col-size="sm" data-end="1015" data-start="1010">Sí</td><td data-col-size="md" data-end="1045" data-start="1015">ID del carguero a agregar.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Protegido por autenticación del sistema (middleware).  
El servicio no valida permisos dentro de la función.

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Validación inicial de parámetros**
    
    
    - Si falta `grp_id` → retorna error.
    - Si falta `cap_id` → retorna error.
2. **Obtiene información del grupo**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> grupo<span class="hljs-keyword">FROM</span> emp_grupo_cargueros_desembarque<span class="hljs-keyword">WHERE</span> id <span class="hljs-operator">=</span> grp_id`</div></div>
    - Si no existe → error “Grupo no encontrado”.
3. **Decodifica el campo `grupo`**
    
    
    - Si el campo `grupo` tiene JSON → se convierte en array.
    - Si está vacío → se crea array vacío.
4. **Verifica si el carguero ya está en el grupo**
    
    
    - Si `cap_id` ya existe → error “El carguero ya se encuentra en el grupo”.
5. **Agrega el nuevo carguero al grupo**
    
    
    - Inserta `cap_id` dentro del array.
    - Convierte el array nuevamente a JSON.
6. **Actualiza la BD**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">UPDATE</span> emp_grupo_cargueros_desembarque<span class="hljs-keyword">SET</span> grupo <span class="hljs-operator">=</span> json_encode(arreglo_actualizado)<span class="hljs-keyword">WHERE</span> id <span class="hljs-operator">=</span> grp_id`  
      
    </div></div>
7. **Retorna éxito**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-string">"Carguero agregado al grupo"</span>`</div></div>

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Carguero agregado al grupo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. Falta `grp_id`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta cap_id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*(El mensaje es incorrecto en el código, pero lo dejamos tal cual está implementado.)*

---

### 2. Falta `cap_id`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Falta cap_id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 3. Grupo no existe

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Grupo no encontrado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

### 4. Carguero repetido

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"El carguero ya se encuentra en el grupo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras usadas)**

### Tabla: `emp_grupo_cargueros_desembarque`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22id%22%3A-%22number%22%2C-%22g"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"grupo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string(JSON array of cap_id)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Ejemplo del campo `grupo`: `<span class="hljs-punctuation">[</span><span class="hljs-string">"123"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"245"</span><span class="hljs-punctuation">,</span> <span class="hljs-string">"300"</span><span class="hljs-punctuation">]</span>`

---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21grp_id--%3E-error%28"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !grp_id -> error("Falta cap_id")if !cap_id -> error("Falta cap_id")grupo = SELECT grupo FROM tabla WHERE id = grp_idif !grupo -> error("Grupo no encontrado")grupos = decode(grupo.grupo) OR []if cap_id in grupos:    error("El carguero ya se encuentra en el grupo")grupos.append(cap_id)UPDATE tabla SET grupo = encode(grupos) WHERE id = grp_idsuccess("Carguero agregado al grupo")`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/carguero/obtener - [show]

PATH: /var/www/html/qaservicesapp/app/Http/Controllers/ShalomControl/CargueroController.php

## 🧾 **Descripción**

Este servicio devuelve **toda la información detallada** de un carguero programado (`cap_id`), incluyendo:

- Datos generales del carguero (choferes, placas, ruta, fechas).
- Orígenes y destinos estructurados con su nombre de terminal.
- Escalas calculadas (orígenes + destinos).
- Cantidad de órdenes de servicio asociadas al carguero.
- Suma de los montos finales de dichas OS.

Lee información combinada de `emp_cargprogramado`, `emp_terminal` y `emp_ordenservicio`.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fcarguero%2Fshow"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /carguero/show`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros requeridos

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1120" data-start="864"><thead data-end="908" data-start="864"><tr data-end="908" data-start="864"><th data-col-size="sm" data-end="872" data-start="864">Campo</th><th data-col-size="sm" data-end="879" data-start="872">Tipo</th><th data-col-size="sm" data-end="893" data-start="879">Obligatorio</th><th data-col-size="sm" data-end="908" data-start="893">Descripción</th></tr></thead><tbody data-end="1120" data-start="954"><tr data-end="1008" data-start="954"><td data-col-size="sm" data-end="963" data-start="954">cap\_id</td><td data-col-size="sm" data-end="972" data-start="963">number</td><td data-col-size="sm" data-end="977" data-start="972">Sí</td><td data-col-size="sm" data-end="1008" data-start="977">ID del carguero programado.</td></tr><tr data-end="1068" data-start="1009"><td data-col-size="sm" data-end="1019" data-start="1009">usuario</td><td data-col-size="sm" data-end="1028" data-start="1019">string</td><td data-col-size="sm" data-end="1033" data-start="1028">No</td><td data-col-size="sm" data-end="1068" data-start="1033">Usuario que ejecuta el proceso.</td></tr><tr data-end="1120" data-start="1069"><td data-col-size="sm" data-end="1080" data-start="1069">terminal</td><td data-col-size="sm" data-end="1089" data-start="1080">string</td><td data-col-size="sm" data-end="1094" data-start="1089">No</td><td data-col-size="sm" data-end="1120" data-start="1094">Terminal de operación.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Requiere sesión o token según la configuración del middleware (no validado en la función).

---

# 🧠 **Flujo del Servicio (resumen real)**

1. **Validación inicial**
    
    
    - Si no se envía `cap_id`, retorna error.
2. **Obtiene datos del carguero**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> fecha, cap_id, chofer1, chofer2, ruta, placa1, placa2, cerrado,       origen, destino<span class="hljs-keyword">FROM</span> emp_cargprogramado<span class="hljs-keyword">WHERE</span> cap_id <span class="hljs-operator">=</span> :cap_id`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>
3. **Obtiene datos de terminales**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> ter_id, ter_nombre <span class="hljs-keyword">FROM</span> emp_terminal`</div></div>Construye un diccionario:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`listaTerminal[<span class="hljs-built_in">id</span>] = nombre`</div></div>
4. **Procesa orígenes y destinos**
    
    
    - Decodifica JSON almacenado en BD.
    - Convierte cada id de terminal a:
        
        <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
        </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="language-xml">"<span class="hljs-tag"><<span class="hljs-name">id</span></span></span>> <span class="hljs-tag"><<span class="hljs-name">nombre</span></span>>"`</div></div>
5. **Calcula escalas**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-attr">escalas</span> = origenes ∪ destinos`</div></div>
6. **Busca órdenes de servicio asociadas al carguero**
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">SELECT</span> ose_montofinal, ose_id<span class="hljs-keyword">FROM</span> emp_ordenservicio<span class="hljs-keyword">WHERE</span> ose_ultimo_carprog_embarque = :cap_id<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> ose_ultima_fecha_embarque <span class="hljs-keyword">DESC</span>`</div></div>
7. **Calcula:**
    
    
    - `cantidad` = total de OS encontradas
    - `suma` = sumatoria de `ose_montofinal`
8. **Retorna el carguero con estructura final.**

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de cargueros"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-21 14:00:00"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">441</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"chofer1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CH00123"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"chofer2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CH00452"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"ruta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"NORTE 01"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"placa1"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"ABC-123"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"placa2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"XYZ-987"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cerrado"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">0</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">12</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"suma"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1560.50</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"escalas"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"01 LIMA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"05 CHIMBOTE"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"07 TRUJILLO"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"origenes"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"01 LIMA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-string">"05 CHIMBOTE"</span>    <span class="hljs-punctuation">]</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"destinos"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>      <span class="hljs-string">"07 TRUJILLO"</span>    <span class="hljs-punctuation">]</span>  <span class="hljs-punctuation">}</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. cap\_id no enviado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar un id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. No se encuentra carguero (si cap\_id no existe)

*(Laravel devolverá null y puede lanzar errores posteriores, según tu implementación)*  
Puedes documentarlo así:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Carguero no encontrado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>*(**Sugerencia:** en tu función no validas esto, pero debería considerarse.)*

---

# 📚 **Schemas (estructuras usadas)**

### **emp\_cargprogramado**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_fhsalidaprogramada"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_chofer1id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_chofer2id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_rutacarguero"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_cargueroid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_carguero_id2"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json[]"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"json[]"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cap_cerrado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_terminal**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ter_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ter_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ter_nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_ordenservicio**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_montofinal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"float"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_ultimo_carprog_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_ultima_fecha_embarque"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21cap_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !cap_id -> errorcarguero = SELECT carguero WHERE cap_idterminales = SELECT id, nombre FROM terminalmapaTerminal = map(id => nombre)carguero.origenes = decodeJSON(carguero.origen)carguero.destinos = decodeJSON(carguero.destino)escalas = unique(origenes + destinos)convertir ids a "<id> <nombre>" usando mapaTerminalordenes = SELECT OS WHERE os.ose_ultimo_carprog_embarque = cap_idcarguero.cantidad = count(ordenes)carguero.suma = sum(ordenes.montofinal)return carguero`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# query/validar_crear_ruta - [funct_validar_crear_ruta_module]

Path: /var/www/html/moradex-qa/app/Models/GeneralesApp.php

## 🧾 **Descripción**

Servicio que valida si un usuario o un terminal tienen permiso para acceder a un módulo específico.  
Actualmente, debido a un `return` colocado antes de la validación, **el servicio siempre devuelve acceso permitido**, pero la lógica diseñada incluye listas de usuarios y terminales autorizados.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fvalidar-crear-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /validar-crear-ruta-<span class="hljs-keyword">module</span>`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22username%22%3A-%22strin"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminalId"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="928" data-start="708"><thead data-end="752" data-start="708"><tr data-end="752" data-start="708"><th data-col-size="sm" data-end="716" data-start="708">Campo</th><th data-col-size="sm" data-end="723" data-start="716">Tipo</th><th data-col-size="sm" data-end="737" data-start="723">Obligatorio</th><th data-col-size="sm" data-end="752" data-start="737">Descripción</th></tr></thead><tbody data-end="928" data-start="798"><tr data-end="859" data-start="798"><td data-col-size="sm" data-end="809" data-start="798">username</td><td data-col-size="sm" data-end="818" data-start="809">string</td><td data-col-size="sm" data-end="823" data-start="818">Sí</td><td data-col-size="sm" data-end="859" data-start="823">DNI o identificador del usuario.</td></tr><tr data-end="928" data-start="860"><td data-col-size="sm" data-end="873" data-start="860">terminalId</td><td data-col-size="sm" data-end="882" data-start="873">string</td><td data-col-size="sm" data-end="887" data-start="882">Sí</td><td data-col-size="sm" data-end="928" data-start="887">ID del terminal desde el cual accede.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Sin validación interna adicional.  
Generalmente depende del middleware aplicado al endpoint.

---

# 🧠 **Flujo del Servicio (resumen real)**

> **IMPORTANTE:** El servicio retorna inmediatamente acceso permitido debido al primer `return`.

### Flujo implementado (real):

1. Obtiene:
    
    
    - `username` (usuario)
    - `terminalId` (terminal)
2. Retorna:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.8711%;"></col></colgroup><tbody><tr><td>`{ <span class="hljs-attr">valor:</span> <span class="hljs-literal">true</span>, <span class="hljs-attr">msn:</span> <span class="hljs-string">"Puede acceder al modulo"</span> }`</td></tr></tbody></table>
    
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

Esto interrumpe el método, haciendo que la lógica posterior nunca se ejecute.

---

### Flujo diseñado (pero actualmente inactivo por el return anticipado)

1. Verificar si el usuario está en la lista de usuarios permitidos:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">in_array</span>(<span class="hljs-variable">$user</span>, <span class="hljs-variable">$usuarios_permitidas</span>))    acceso permitido`</div></div>
2. Verificar si el terminal está en la lista de terminales permitidas:
    
    <div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
    </div></div></div><div class="overflow-y-auto p-4" dir="ltr">`<span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">in_array</span>(<span class="hljs-variable">$terminal</span>, <span class="hljs-variable">$terminales_permitidas</span>))    acceso permitido`</div></div>
3. Si no coincide con ninguna lista → acceso denegado (pero el código está incompleto y termina con `retur`).

---

# 📤 **Response – Ejemplo (actual)**

### ✔️ Acceso permitido (siempre)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Puede acceder al modulo"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores (según la lógica esperada)**

> *Actualmente NO se producen porque la función retorna antes de validar.*

### 1. Usuario NO autorizado

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Usuario no autorizado"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. Terminal NO autorizada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Terminal no autorizada"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. Petición incompleta

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Datos insuficientes (username o terminalId faltantes)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras usadas)**

### Request

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22username%22%3A-%22strin-1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"username"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"terminalId"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Response

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-%22boolean%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"boolean"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-user-%3D-post.username"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`user = POST.usernameterminal = POST.terminalIdreturn { valor: true, msn: "Puede acceder al modulo" }  // retorna siempreusuarios_permitidos = [...]terminales_permitidas = [...]if user in usuarios_permitidos:    return acceso permitidoif terminal in terminales_permitidas:    return acceso permitidoreturn acceso denegado`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>

# control/desembarque/pendientes - [pendientes]

## 🧾 **Descripción**

Este servicio retorna la lista de **órdenes de servicio (OSE)** que **aún tienen paquetes pendientes por desembarcar** en una unidad específica (`cap_id`).  
Combina información de embarques, desembarques, órdenes de servicio, detalles de OS, atributos, terminales y datos de personas.

Permite aplicar **filtro por número de guía** y soporta **paginación**.

Es un servicio crítico para la vista de **desembarques pendientes**.

---

# 🚀 **Endpoint**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-%2Fpendientes"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs">  
</div></div></div><div class="overflow-y-auto p-4" dir="ltr">`POST /pendientes`</div></div>---

# 📥 **Request Body**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22cap_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"pagina"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string (opcional)"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### Parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-tipo-obligator"><div class="group _tableWrapper_1rjym_13 flex w-fit flex-col-reverse" tabindex="-1"><table class="w-fit min-w-(--thread-content-width)" data-end="1084" data-start="807"><thead data-end="851" data-start="807"><tr data-end="851" data-start="807"><th data-col-size="sm" data-end="815" data-start="807">Campo</th><th data-col-size="sm" data-end="822" data-start="815">Tipo</th><th data-col-size="sm" data-end="836" data-start="822">Obligatorio</th><th data-col-size="sm" data-end="851" data-start="836">Descripción</th></tr></thead><tbody data-end="1084" data-start="897"><tr data-end="962" data-start="897"><td data-col-size="sm" data-end="906" data-start="897">cap\_id</td><td data-col-size="sm" data-end="915" data-start="906">number</td><td data-col-size="sm" data-end="922" data-start="915">✔ Sí</td><td data-col-size="sm" data-end="962" data-start="922">ID de la unidad de carga programada.</td></tr><tr data-end="1018" data-start="963"><td data-col-size="sm" data-end="972" data-start="963">pagina</td><td data-col-size="sm" data-end="981" data-start="972">number</td><td data-col-size="sm" data-end="988" data-start="981">✔ Sí</td><td data-col-size="sm" data-end="1018" data-start="988">Número de página a listar.</td></tr><tr data-end="1084" data-start="1019"><td data-col-size="sm" data-end="1026" data-start="1019">guia</td><td data-col-size="sm" data-end="1035" data-start="1026">string</td><td data-col-size="sm" data-end="1042" data-start="1035">✘ No</td><td data-col-size="sm" data-end="1084" data-start="1042">Filtra por número de guía del cliente.</td></tr></tbody></table>

</div></div>---

# 🔐 **Seguridad**

Requiere autenticación estándar usada en los endpoints del backend (middleware Laravel).  
No se valida explícitamente dentro del método.

---

# 🧠 **Flujo del Servicio (resumen real)**

### 1. Validación inicial

- `cap_id` es obligatorio.
- Define paginación con `limit = 15`.

---

### 2. Obtener embarques asociados al `cap_id`

Consulta tabla `emp_embarque_historial`:

- Se filtra por:
    
    
    - estado activo (`status = 1`)
    - paquete habilitado (`emb_estado_paquete = 1`)
    - carg\_id igual al cap\_id

Si no hay embarques:  
**“Aún no se ha embarcado nada en esta unidad.”**

Se arma:

- Lista de OSE (`ose_ids`)
- Información del embarque por OSE:
    
    
    - estado de guía
    - cantidad de paquetes embarcados
    - cantidad total de paquetes

---

### 3. Obtener desembarques del mismo `cap_id`

Consulta tabla `emp_desembarque_historial` similares filtros:

Se arma:

- Lista de desembarques por OSE:
    
    
    - estado de guía
    - paquetes desembarcados
    - total de paquetes

---

### 4. Obtener órdenes de servicio relacionadas

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-%28varios-campo"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-keyword">SELECT</span> (varios campos)<span class="hljs-keyword">FROM</span> emp_ordenservicio<span class="hljs-keyword">WHERE</span> ose_id <span class="hljs-keyword">IN</span> (ose_ids)<span class="hljs-keyword">AND</span> (opcional) ose_nroguiacliente = guia<span class="hljs-keyword">OFFSET</span> (pagina - <span class="hljs-number">1</span>) * <span class="hljs-number">15</span><span class="hljs-keyword">LIMIT</span> <span class="hljs-number">15</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si no encuentra OS → **“No ha embarcado nada aun”**

---

### 5. Obtener terminales (origen y destino)

Convierte IDs a:

- nombre
- alias (para construir la ruta)

---

### 6. Obtener detalle de OS

Consulta `emp_os_detalle`:

Agrupa por:

- OSE
- Tipo

Construye por OSE:

- contenido: `"cantidad tipo"`
- cantidad total sumada

---

### 7. Obtener atributos de tipo de pago

Convierte `tipo_pago` → abreviatura usando tabla `emp_atributos`.

---

### 8. Integrar datos (núcleo del servicio)

Por cada OS:

- Si existe desembarque:
    
    
    - Calcula paquetes pendientes = total – desembarcados
    - Marca guía como `"GUIA EMBARCADA"` o `"SIN GUIA"`
- Si no existe desembarque:
    
    
    - Paquetes pendientes = total del detalle
- Si cantidad pendiente es `0` → se omite del resultado final.
- Se construye:
    
    
    - contenido
    - cantidad total
    - cantidad pendiente
    - ruta origen → destino
    - nombre de terminales

Si después de filtrar no hay OS pendientes:  
→ **“No hay desembarques pendientes”**

---

### 9. Obtener nombres de remitentes

Consulta `emp_persona` usando los DNIs encontrados:

Reemplaza el DNI por nombre completo.

---

### ✔ 10. Respuesta Final

Devuelve toda la data procesada.

---

# 📤 **Response 200 – Ejemplo**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-true%2C-%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Lista de ordenes"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">202525</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-15 10:30:00"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">45.50</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"GUIA-882233"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"remitente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Carlos Gómez"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"destinatario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Empresa ABC"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"tipo_pago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"CR"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"origen"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIMA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"destino"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AREQUIPA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ruta"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"LIM - AQP"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cap_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">33112</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"contenido"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"10 CAJA, 2 SOBRE"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cant_paq"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">5</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"cant_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">12</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"desembarque_guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"SIN GUIA"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"jperez"</span>    <span class="hljs-punctuation">}</span>  <span class="hljs-punctuation">]</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# ❗ **Posibles Errores**

### 1. No envía `cap_id`

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Es obligatorio enviar un cap_id"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 2. No hay embarques

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--1"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Aun nó se ha embarcado nada en esta unidad."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 3. No hay órdenes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--2"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No ha embarcado nada aun"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### 4. No hay desembarques pendientes

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22success%22%3A-false%2C--3"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"success"</span><span class="hljs-punctuation">:</span> <span class="hljs-literal"><span class="hljs-keyword">false</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"message"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"No hay desembarques pendientes"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 📚 **Schemas (estructuras usadas)**

### **emp\_embarque\_historial**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22emb_ose_id%22%3A-%22num"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"emb_ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_estado_guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cant_paquetes_embarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"emb_cant_paquetes_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_desembarque\_historial**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22des_ose_id%22%3A-%22num"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"des_ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"des_estado_guia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"des_cant_paquetes_desembarcados"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"des_cant_paquetes_total"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_ordenservicio**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22ose_id%22%3A-%22number%22"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"ose_id"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_fhpreferenciapartida"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_nroguiacliente"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_remiteempresa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_destinaempresa"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_servpagotipo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termorigenatencion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_termdestinoentrega"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"ose_estadoPago"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_os\_detalle**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22osd_osid%22%3A-%22numbe"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"osd_osid"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"osd_tipopreciomanual"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"cantidad"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"number"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_atributos**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-%22string%22%2C"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"valor"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"abreviatura"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>### **emp\_persona**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22documento%22%3A-%22stri"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`<span class="hljs-punctuation">{</span>  <span class="hljs-attr">"documento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>---

# 🗃 **Lógica en pseudo-código**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-%21cap_id--%3E-error-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-text-secondary flex items-center gap-4 rounded-sm px-2 font-sans text-xs"><table border="1" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr><td>`if !cap_id -> errorembarques = SELECT embarques WHERE cap_id = inputif empty -> errordesembarques = SELECT desembarques WHERE cap_id = inputose_ids = embarques.ose_idordenes = SELECT OS WHERE ose_id in ose_ids FILTER guia IF EXISTS PAGINACIONif empty -> errordetalles = SELECT SUM(cantidad), tipo FROM emp_os_detalle WHERE ose_id in ose_ids GROUP BY ose_id,tipoatributos = SELECT mapa tipo_pago -> abreviaturaterminales = SELECT terminal_id -> nombre, aliasbuild lista:    para cada OS:        calcular paquetes pendientes        si 0 → excluir        traducir tipo_pago        generar ruta origen/destino        agregar contenido y totalesif lista vacía -> “No hay desembarques pendientes”buscar nombres remitente en emp_personareturn lista final`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>