# Documento de Ingresos (Registrar Proceso de Descarga (1)) - [registerProcessApp]

## 🧾 Descripción

*Registra en la tabla `historial_procesos_app` cada evento o proceso realizado por un usuario dentro de la aplicación móvil.*  
*Además, dependiendo del tipo de proceso, realiza validaciones adicionales como:*

- Validación de renovación de contrato
- Validación de cambio de modalidad
- Creación automática de usuario conductor en sistema externo
- Validación de existencia del empleado en ERP

Este servicio funciona como logger centralizado de acciones críticas del trabajador.

---

## 🚀 Endpoint

**POST** <span style="color: rgb(224, 62, 45);">**`/register-process-app`**</span>

---

## 📥 Parámetros de Entrada (Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%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">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><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">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"latitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"longitude"</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">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</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>`</td></tr></tbody></table>

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

## 🔐 Seguridad

- Acceso interno del sistema
- Requiere conexión válida a BD secundaria (`mysql2`)
- Valida datos contra API ERP mediante `dbErp` y `ServiceErp`

---

## 🧠 Flujo del Servicio (Resumen Real)

### 1️⃣ Obtiene parámetros principales del request:

- usuario
- empleado
- agencia
- lat/long
- proceso
- month / year

---

### 2️⃣ Si el proceso es **descargaContratoReingreso**

- Ejecuta validación de renovación del contrato:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Evalidateproce"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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-variable language_">$this</span>-><span class="hljs-title function_ invoke__">validateProcessContractRenovation</span>(<span class="hljs-variable">$request</span>, <span class="hljs-variable">$connection</span>);`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>- Ejecuta validación de cambio de modalidad:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%24this-%3Evalidateproce-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-variable language_">$this</span>-><span class="hljs-title function_ invoke__">validateProcessContractChangeModality</span>(<span class="hljs-variable">$request</span>,<span class="hljs-variable">$connection</span>);`</td></tr></tbody></table>

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

### 3️⃣ Si el proceso es **descargaContratoTrabajo**

#### a) Obtiene datos del empleado en el ERP

(Documento, sucursal, nombre y puesto)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-passport_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-keyword">SELECT</span> passport_number, id_sucursal, nombre_completo, designation <span class="hljs-keyword">FROM</span> `tabEmployee``</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>#### b) Si el puesto contiene la palabra **CONDUCTOR**

El sistema crea un **usuario conductor** en un sistema externo:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-post-empresarial%2Fapi"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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-string">POST</span> <span class="hljs-string">EMPRESARIAL/api/crearUsuarioConductor</span>{   <span class="hljs-attr">documento:</span> <span class="hljs-string">DNI</span>,   <span class="hljs-attr">ter_id:</span> <span class="hljs-string">id_sucursal</span>,   <span class="hljs-attr">nombre:</span> <span class="hljs-string">nombre_completo</span>}`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr">  
</div></div>Cualquier error en este paso retorna:

<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">"Ocurrio un error al registrar 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️⃣ Inserta el registro del proceso en `historial_procesos_app`

Campos insertados:

<div class="_tableContainer_1rjym_1" id="bkmrk-campo-descripci%C3%B3n-us"><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="2783" data-start="2443"><thead data-end="2466" data-start="2443"><tr data-end="2466" data-start="2443"><th data-col-size="sm" data-end="2451" data-start="2443">Campo</th><th data-col-size="sm" data-end="2466" data-start="2451">Descripción</th></tr></thead><tbody data-end="2783" data-start="2491"><tr data-end="2535" data-start="2491"><td data-col-size="sm" data-end="2501" data-start="2491">usuario</td><td data-col-size="sm" data-end="2535" data-start="2501">Usuario que ejecuta el proceso</td></tr><tr data-end="2570" data-start="2536"><td data-col-size="sm" data-end="2547" data-start="2536">empleado</td><td data-col-size="sm" data-end="2570" data-start="2547">Código del empleado</td></tr><tr data-end="2601" data-start="2571"><td data-col-size="sm" data-end="2581" data-start="2571">agencia</td><td data-col-size="sm" data-end="2601" data-start="2581">ID de la agencia</td></tr><tr data-end="2624" data-start="2602"><td data-col-size="sm" data-end="2613" data-start="2602">latitude</td><td data-col-size="sm" data-end="2624" data-start="2613">Latitud</td></tr><tr data-end="2649" data-start="2625"><td data-col-size="sm" data-end="2637" data-start="2625">longitude</td><td data-col-size="sm" data-end="2649" data-start="2637">Longitud</td></tr><tr data-end="2692" data-start="2650"><td data-col-size="sm" data-end="2660" data-start="2650">proceso</td><td data-col-size="sm" data-end="2692" data-start="2660">Nombre del proceso ejecutado</td></tr><tr data-end="2724" data-start="2693"><td data-col-size="sm" data-end="2701" data-start="2693">fecha</td><td data-col-size="sm" data-end="2724" data-start="2701">Fecha y hora actual</td></tr><tr data-end="2752" data-start="2725"><td data-col-size="sm" data-end="2734" data-start="2725">estado</td><td data-col-size="sm" data-end="2752" data-start="2734">1 (registrado)</td></tr><tr data-end="2768" data-start="2753"><td data-col-size="sm" data-end="2761" data-start="2753">month</td><td data-col-size="sm" data-end="2768" data-start="2761">Mes</td></tr><tr data-end="2783" data-start="2769"><td data-col-size="sm" data-end="2776" data-start="2769">year</td><td data-col-size="sm" data-end="2783" data-start="2776">Año</td></tr></tbody></table>

</div></div>---

### 5️⃣ Devuelve respuesta exitosa

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

## 📤 Respuestas

### ✔ **200 – Éxito**

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22ms-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">true</span></span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"msn"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Proceso registrado 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>---

### ❗ Error al insertar registro

<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">"Ocurrio un error al registrar 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>---

### ❗ Empleado no encontrado

<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ó al 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>---

### ❗ Error de creación de usuario conductor

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-false%2C-%22m-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">"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">"Ocurrio un error al registrar 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>---

## 📚 Estructuras utilizadas

### Tabla: historial\_procesos\_app

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22usuario%22%3A-%22string-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">"usuario"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><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">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"latitude"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"longitude"</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">"fecha"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"estado"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</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">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

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

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22passport_number%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">"passport_number"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"id_sucursal"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"nombre_completo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"designation"</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 Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-leer-usuario%2C-emplea"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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>`leer usuario, empleado, proceso, month, year, lat, longsi proceso == "descargaContratoReingreso":    validar renovación de contrato    validar cambio de modalidadsi proceso == "descargaContratoTrabajo":    traer datos del empleado    si puesto incluye "CONDUCTOR":        crear usuario conductor en sistema externoinsertar registro en historial_procesos_appsi inserción falla:    retornar errorretornar éxito`</td></tr></tbody></table>

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