# 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>