# Utilidades(Obtener Proceso de Descarga (1, 2, 3,4,5)) - [show]

## 🧾 Descripción

*Este servicio permite **consultar el último registro** almacenado en la tabla `historial_procesos_app` según:*

- Empleado
- Proceso
- (Opcional) Año
- (Opcional) Mes

Es usado para validar si un empleado ya realizó o no un proceso específico dentro del aplicativo.

---

# 🚀 Endpoint

**POST** `<span style="color: rgb(224, 62, 45);"><strong>/show</strong></span>`

---

# 📥 Parámetros de Entrada (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%22%3A-%22emp-0"><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">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"descargaContratoTrabajo"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2025</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">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>### 🔎 Descripción de parámetros

<div class="_tableContainer_1rjym_1" id="bkmrk-par%C3%A1metro-tipo-oblig"><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="1133" data-start="809"><thead data-end="857" data-start="809"><tr data-end="857" data-start="809"><th data-col-size="sm" data-end="821" data-start="809">Parámetro</th><th data-col-size="sm" data-end="828" data-start="821">Tipo</th><th data-col-size="sm" data-end="842" data-start="828">Obligatorio</th><th data-col-size="sm" data-end="857" data-start="842">Descripción</th></tr></thead><tbody data-end="1133" data-start="906"><tr data-end="965" data-start="906"><td data-col-size="sm" data-end="917" data-start="906">empleado</td><td data-col-size="sm" data-end="926" data-start="917">string</td><td data-col-size="sm" data-end="930" data-start="926">✔</td><td data-col-size="sm" data-end="965" data-start="930">Código del empleado a consultar</td></tr><tr data-end="1020" data-start="966"><td data-col-size="sm" data-end="976" data-start="966">proceso</td><td data-col-size="sm" data-end="985" data-start="976">string</td><td data-col-size="sm" data-end="989" data-start="985">✔</td><td data-col-size="sm" data-end="1020" data-start="989">Nombre del proceso a buscar</td></tr><tr data-end="1077" data-start="1021"><td data-col-size="sm" data-end="1028" data-start="1021">anio</td><td data-col-size="sm" data-end="1034" data-start="1028">int</td><td data-col-size="sm" data-end="1038" data-start="1034">✖</td><td data-col-size="sm" data-end="1077" data-start="1038">Año del proceso (filtrado opcional)</td></tr><tr data-end="1133" data-start="1078"><td data-col-size="sm" data-end="1084" data-start="1078">mes</td><td data-col-size="sm" data-end="1090" data-start="1084">int</td><td data-col-size="sm" data-end="1094" data-start="1090">✖</td><td data-col-size="sm" data-end="1133" data-start="1094">Mes del proceso (filtrado opcional)</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Utiliza conexión directa a la base de datos `dbapp`.  
No requiere token ERP, pero depende de la autenticación interna del backend.

---

# 🧠 Flujo del Servicio (Resumen real)

1. **Validar parámetros obligatorios**
    
    
    - Si no se envía *empleado* → retorna error
    - Si no se envía *proceso* → retorna error
2. **Construir filtros dinámicos**
    
    
    - Base: empleado + proceso
    - Si llega año → se agrega al `WHERE`
    - Si llega mes → se agrega al `WHERE`
3. **Consultar la tabla interna**  
    Query sobre:
    
    <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">`historial_procesos_app<span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> fecha <span class="hljs-keyword">DESC</span><span class="hljs-keyword">LIMIT</span> <span class="hljs-number">1</span>`</div></div>Utiliza `first()` para obtener el último registro.
4. **Validar si existe registro**
    
    
    - Si no existe, devuelve mensaje informando que no se encontró el proceso.
5. **Retornar información del proceso encontrado**  
    Incluye toda la fila obtenida desde la base de datos.

---

# 📤 Response 200 – Ejemplos

### ✅ Caso exitoso

<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">"Proceso encontrado."</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">1524</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"empleado"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"proceso"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"descargaContratoTrabajo"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">2025</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-01-03 09:32:11"</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>### ❌ Faltan parámetros

<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">"Falta empleado."</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div><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">"Falta proceso."</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 existe el proceso

<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">"No se encontró el proceso."</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 envía `empleado`**
    
    <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">"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">"Falta empleado."</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 envía `proceso`**
    
    <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">"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">"Falta proceso."</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 se encontró el registro**
    
    <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">"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">"No se encontró el proceso."</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. **Error interno de base de datos**  
    (Puede retornar error 500 desde DB, manejado por Laravel)

---

# 📚 Estructura usada (historial\_procesos\_app)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22empleado%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">"empleado"</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">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</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>---

# 🗃 Lógica en Pseudo-código

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-empleado-is-empty"><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 empleado is empty → return errorif proceso is empty → return errorwhere = [    empleado = input.empleado,    proceso  = input.proceso]if anio present:    where.year = input.anioif mes present:    where.month = input.mesresult = DB.historial_procesos_app            .where(where)            .orderBy(fecha desc)            .first()if result is null:    return error "No se encontró el proceso"return success + result`</td></tr></tbody></table>

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