# Otros descuentos de Nomina (1, 2) - [listar]

🧾 **Descripción**

*Obtiene y lista los otros descuentos de nómina registrados para un empleado en un año y mes específicos.*  
*El servicio consulta la información en el ERP (Doctype: **Otros Descuentos Nomina**) y devuelve únicamente los registros que coinciden con el mes y año enviados.*

*Permite también filtrar por **todos los meses del año** enviando `"TODOS"` en el parámetro `month`.*

---

# 🚀 Endpoint

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

---

# 📥 Parámetros (Request Body)

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22employee%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">"employee"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"EMP-0001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"year"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"month"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marzo"</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="1129" data-start="793"><thead data-end="845" data-start="793"><tr data-end="845" data-start="793"><th data-col-size="sm" data-end="807" data-start="793">Campo</th><th data-col-size="sm" data-end="816" data-start="807">Tipo</th><th data-col-size="sm" data-end="830" data-start="816">Obligatorio</th><th data-col-size="md" data-end="845" data-start="830">Descripción</th></tr></thead><tbody data-end="1129" data-start="899"><tr data-end="960" data-start="899"><td data-col-size="sm" data-end="913" data-start="899">employee</td><td data-col-size="sm" data-end="922" data-start="913">string</td><td data-col-size="sm" data-end="937" data-start="922">✔️ Sí</td><td data-col-size="md" data-end="960" data-start="937">Código del empleado</td></tr><tr data-end="1016" data-start="961"><td data-col-size="sm" data-end="975" data-start="961">year</td><td data-col-size="sm" data-end="984" data-start="975">string</td><td data-col-size="sm" data-end="999" data-start="984">✔️ Sí</td><td data-col-size="md" data-end="1016" data-start="999">Año a filtrar</td></tr><tr data-end="1129" data-start="1017"><td data-col-size="sm" data-end="1031" data-start="1017">month</td><td data-col-size="sm" data-end="1040" data-start="1031">string</td><td data-col-size="sm" data-end="1055" data-start="1040">✔️ Sí</td><td data-col-size="md" data-end="1129" data-start="1055">Mes a filtrar. Si se envía `"TODOS"` devuelve todos los meses del año.</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Requiere token válido del ERP.  
La comunicación se realiza mediante **ServiceErp()**, usando cabeceras internas de autenticación.

---

# 🧠 Flujo del Servicio (Resumen real)

1. **Valida que el parámetro employee exista.**
2. **Valida que el parámetro year exista.**
3. Consulta al ERP:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-get-otros-descuentos"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><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-variable constant_">GET</span> <span class="hljs-title class_">Otros</span> <span class="hljs-title class_">Descuentos</span> <span class="hljs-title class_">Nomina</span>/<employee><span class="hljs-string">?f</span>ields=[<span class="hljs-string">"table_22"</span>]`</div></div>4. Verifica que exista información.
5. Recorre la tabla interna `table_22` (donde vienen los descuentos mensuales):
    
    
    - Compara:
        
        
        - `item.mes` == mes enviado
        - `item.ano` == año enviado
    - Si `month == "TODOS"`, ignora el filtro del mes.
6. Para cada coincidencia arma un objeto con:
    
    
    - motivo
    - monto
    - año
    - mes
    - creation (en formato `"d de Mes"`)
7. Si no hay coincidencias, retorna "Sin Descuentos".
8. Si hay registros, los devuelve ordenados por creación.

---

# 📤 Response 200 – Ejemplo exitoso

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22valor%22%3A-true%2C-%22da"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-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">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Adelanto"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">150.00</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marzo"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"05 de Marzo"</span>    <span class="hljs-punctuation">}</span><span class="hljs-punctuation">,</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Descuento EPS"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">35.00</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"Marzo"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"anio"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2024"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"12 de Marzo"</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>---

# ⚠️ Respuestas de Error

### 1. Falta employee

<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 employee"</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 año

<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">"Ingrese un año"</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. El ERP no devuelve información

<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">"Sin Descuentos"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"error"</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>### 4. No existen descuentos para el filtro solicitado

<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">"Sin Descuentos"</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 usadas (Schemas)

### **Otros Descuentos Nomina**

Campos usados:

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-%7B-%22table_22%22%3A-%5B-%7B-%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">"table_22"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">[</span>    <span class="hljs-punctuation">{</span>      <span class="hljs-attr">"motivo"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"monto"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"float"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"mes"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"ano"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>      <span class="hljs-attr">"creation"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"datetime"</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>---

# 🧩 Pseudocódigo

<div class="contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary" id="bkmrk-if-employee-is-null-"><div class="sticky top-9"><div class="absolute end-0 bottom-0 flex h-9 items-center pe-2"><div class="bg-token-bg-elevated-secondary text-token-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 employee <span class="hljs-keyword">is</span> <span class="hljs-keyword">null</span> → errorif <span class="hljs-keyword">year</span> <span class="hljs-keyword">is</span> <span class="hljs-keyword">null</span> → errorotros_desc <span class="hljs-operator">=</span> <span class="hljs-keyword">GET</span> Otros Descuentos Nomina<span class="hljs-operator">/</span>employeeif <span class="hljs-keyword">no</span> data → errorforeach item <span class="hljs-keyword">in</span> table_22:    if (mes <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-keyword">month</span> <span class="hljs-keyword">AND</span> ano <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-keyword">year</span>) <span class="hljs-keyword">OR</span> (<span class="hljs-keyword">month</span> <span class="hljs-operator">=</span><span class="hljs-operator">=</span> "TODOS" <span class="hljs-keyword">AND</span> ano <span class="hljs-operator">=</span><span class="hljs-operator">=</span> <span class="hljs-keyword">year</span>):        agregar item a listaif lista vacía → error<span class="hljs-keyword">return</span> lista formateada`</td></tr></tbody></table>

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