# Obtiene descarga boleta de pago (2) - [getDownloadBoletaPago]

### 🧾 Descripción

*Este servicio valida si un empleado **debe descargar obligatoriamente su boleta de pago del último mes** antes de poder realizar acciones como:*

- Registrar marcación
- Registrar solicitudes en la app
- Acceder a otros módulos operativos

*El servicio evalúa:*

1. Si está dentro del rango de validación (solo **del día 1 al 3** de cada mes).
2. La **fecha de ingreso del trabajador**.
3. Si tiene boleta generada el mes anterior.
4. Si el mes correspondiente está **habilitado para descarga**.
5. Si el empleado **ya descargó** la boleta (se revisa historial en MySQL).
6. Si el empleado está **PreActivo**, no se valida la descarga.

---

# 🚀 Endpoint

### GET /get-download-boleta-pago/{empleado}

📌 **Parámetro obligatorio:**

- **empleado** → ID del Employee (name)

---

# 🔐 Seguridad

- Requiere autenticación interna por el ERP mediante `dbErp()` y conexión MySQL interna.
- El servicio está pensado solo para uso interno de la aplicación móvil corporativa.

---

# 🧠 Flujo del Servicio (resumen)

### 1️⃣ Validación de fecha

Solo se ejecuta validación si el día actual está entre **1 y 3**.  
Si el día &gt; 3 → se omite toda validación:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%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">"status"</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">"No está dentro del rango de fecha de validación"</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️⃣ Obtener información del empleado

Consulta ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-fecha_de_ingr"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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> fecha_de_ingreso_real, status<span class="hljs-keyword">FROM</span> `tabEmployee`<span class="hljs-keyword">WHERE</span> name <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>empleado<span class="hljs-operator">></span>`</td></tr></tbody></table>

</div></div></div><div class="overflow-y-auto p-4" dir="ltr"></div></div>Si el empleado está **PreActivo**, no se valida boleta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%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">"status"</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">"No validar descarga de boleta en PreActivo"</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️⃣ Comparar fecha de ingreso vs fecha límite

Se calcula:

- Mes anterior
- Último día del mes anterior

Solo se valida si el empleado ingresó **antes del cierre del mes previo**.

---

### 4️⃣ Verificar en MySQL si ya descargó la boleta

Consulta tabla `historial_procesos_app`:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-where-empleado-%3D-%3F-a"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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">WHERE</span> empleado <span class="hljs-operator">=</span> ? <span class="hljs-keyword">AND</span> proceso <span class="hljs-operator">=</span> <span class="hljs-string">'NOMINA'</span><span class="hljs-keyword">AND</span> <span class="hljs-keyword">month</span> <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>mes_anterior<span class="hljs-operator">></span><span class="hljs-keyword">AND</span> <span class="hljs-keyword">year</span> <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>year_anterior<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 registro se sigue validación.

---

### 5️⃣ Validar si EXISTE boleta en ERP

Consulta Salary Slip del último mes:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-posting_date-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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> posting_date<span class="hljs-keyword">FROM</span> `tabSalary Slip`<span class="hljs-keyword">WHERE</span> employee <span class="hljs-operator">=</span> ?<span class="hljs-keyword">AND</span> posting_date <span class="hljs-keyword">between</span> <span class="hljs-operator"><</span>primer_día_mes_anterior<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> <span class="hljs-operator"><</span>último_día_mes_anterior<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 tiene boleta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%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">"status"</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">"No tiene boleta de pago por lo tanto 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>---

### 6️⃣ Validar si el mes está habilitado para descarga

Consulta:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-select-name-from-%60ta"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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> name<span class="hljs-keyword">FROM</span> `tabEstado Boleta Mensual`<span class="hljs-keyword">WHERE</span> mes <span class="hljs-operator">=</span> <span class="hljs-operator"><</span>mes_texto<span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> año <span class="hljs-operator">=</span> <span class="hljs-operator"><</span><span class="hljs-keyword">year</span><span class="hljs-operator">></span> <span class="hljs-keyword">AND</span> habilitado <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 está habilitado pero **el trabajador NO la descargó**, se bloquea:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%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">"status"</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">"Para poder registrar su marcación o realizar alguna solicitud, descargar su boleta pendiente del mes"</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️⃣ Si pasa todas las validaciones → OK

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%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">"status"</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">"Se ha descargado la boleta de pago"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

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

# 📥 Request

**No usa body**, solo el parámetro de ruta: `<span class="hljs-symbol">empleado:</span> <span class="hljs-type">string</span>`

---

# 📤 Response – Ejemplos

### ✔ Caso permitido (día fuera de rango)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-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">"status"</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">"No está dentro del rango de fecha de validación"</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 en PreActivo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-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">"status"</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">"No validar descarga de boleta en PreActivo"</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 tiene boleta generada

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-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">"status"</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">"No tiene boleta de pago por lo tanto 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>### ❌ No ha descargado la boleta y es obligatoria

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-false%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">"status"</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">"Para poder registrar su marcación o realizar alguna solicitud, descargar su boleta pendiente del mes"</span><span class="hljs-punctuation">}</span>`</td></tr></tbody></table>

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

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22status%22%3A-true%2C-%22m-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">"status"</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">"Se ha descargado la boleta de pago"</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

<div class="_tableContainer_1rjym_1" id="bkmrk-error-descripci%C3%B3n-em"><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="4308" data-start="4013"><thead data-end="4036" data-start="4013"><tr data-end="4036" data-start="4013"><th data-col-size="sm" data-end="4021" data-start="4013">Error</th><th data-col-size="sm" data-end="4036" data-start="4021">Descripción</th></tr></thead><tbody data-end="4308" data-start="4060"><tr data-end="4107" data-start="4060"><td data-col-size="sm" data-end="4081" data-start="4060">Empleado no existe</td><td data-col-size="sm" data-end="4107" data-start="4081">No se encuentra en ERP</td></tr><tr data-end="4173" data-start="4108"><td data-col-size="sm" data-end="4135" data-start="4108">No tiene boleta generada</td><td data-col-size="sm" data-end="4173" data-start="4135">Salary Slip del mes anterior vacío</td></tr><tr data-end="4248" data-start="4174"><td data-col-size="sm" data-end="4213" data-start="4174">Boleta habilitada pero no descargada</td><td data-col-size="sm" data-end="4248" data-start="4213">Bloquea marcación y solicitudes</td></tr><tr data-end="4308" data-start="4249"><td data-col-size="sm" data-end="4272" data-start="4249">Error en ERP o MySQL</td><td data-col-size="sm" data-end="4308" data-start="4272">Respuesta capturada por el catch</td></tr></tbody></table>

</div></div>---

# 🧩 Tablas consultadas

### ERP (Frappe/ERPNext)

- `tabEmployee`
- `tabSalary Slip`
- `tabEstado Boleta Mensual`

### MySQL externo

- `historial_procesos_app`

---

# 🗃 Pseudocódigo del servicio

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-day-%3E-3%3A-return-o"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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">if</span> day > <span class="hljs-number">3</span>:    <span class="hljs-keyword">return</span> OK (no validar)empleado = GET Employee<span class="hljs-keyword">if</span> empleado.status == PreActivo:    <span class="hljs-keyword">return</span> OK<span class="hljs-keyword">if</span> fecha_ingreso < ultimo_dia_mes_anterior:    verificar si ya descargó boleta en MySQL    verificar si tiene boleta en ERP    <span class="hljs-keyword">if</span> no tiene:        <span class="hljs-keyword">return</span> OK    verificar si mes habilitado    <span class="hljs-keyword">if</span> habilitado y no descargado:        bloquear<span class="hljs-keyword">return</span> OK`</td></tr></tbody></table>

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