# Intento de Marcación (1) - [intentMarca]

### 🧾 Descripción

*Registra y actualiza los intentos de marcación que realiza un empleado en una agencia durante el día.*  
*Este servicio controla cuántas veces un colaborador intenta marcar asistencia, creando o actualizando un registro diario en el ERP.*

Se basa en el Doctype:

- **Intento de marcacion**

Y utiliza los campos:

- empleado
- agencia
- intento
- creacion (fecha del intento)

---

# 🚀 Endpoint

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

El servicio recibe datos desde el body mediante <span style="color: rgb(224, 62, 45);">**`Request`**</span>.

---

# 📥 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">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AG-001"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"intento"</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>### 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="1166" data-start="907"><thead data-end="951" data-start="907"><tr data-end="951" data-start="907"><th data-col-size="sm" data-end="915" data-start="907">Campo</th><th data-col-size="sm" data-end="922" data-start="915">Tipo</th><th data-col-size="sm" data-end="936" data-start="922">Obligatorio</th><th data-col-size="sm" data-end="951" data-start="936">Descripción</th></tr></thead><tbody data-end="1166" data-start="999"><tr data-end="1046" data-start="999"><td data-col-size="sm" data-end="1010" data-start="999">empleado</td><td data-col-size="sm" data-end="1019" data-start="1010">string</td><td data-col-size="sm" data-end="1023" data-start="1019">✔</td><td data-col-size="sm" data-end="1046" data-start="1023">Código del empleado</td></tr><tr data-end="1106" data-start="1047"><td data-col-size="sm" data-end="1057" data-start="1047">agencia</td><td data-col-size="sm" data-end="1066" data-start="1057">string</td><td data-col-size="sm" data-end="1070" data-start="1066">✔</td><td data-col-size="sm" data-end="1106" data-start="1070">Agencia en la que intenta marcar</td></tr><tr data-end="1166" data-start="1107"><td data-col-size="sm" data-end="1117" data-start="1107">intento</td><td data-col-size="sm" data-end="1123" data-start="1117">int</td><td data-col-size="sm" data-end="1127" data-start="1123">✔</td><td data-col-size="sm" data-end="1166" data-start="1127">Intento actual enviado desde la app</td></tr></tbody></table>

</div></div>---

# 🔐 Seguridad

Utiliza autenticación interna del ERP a través de:

- **dbErp()** para consultas SQL
- **ServiceErp()** para creación y actualización de documentos en el ERP

Requiere credenciales internas del sistema.

---

# 🧠 Flujo del Servicio (resumen real)

1. **Valida que existan los parámetros obligatorios**: empleado, agencia e intento.  
    Si falta alguno → retorna error.
2. **Determina la fecha actual (`Y-m-d`)**.  
    Este valor se usa para registrar un intento por día.
3. **Consulta si el empleado ya tiene un registro de Intento de marcacion para el día actual**:
    
    <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">`tpr.empleado <span class="hljs-operator">=</span> empleado <span class="hljs-keyword">AND</span> tpr.creacion <span class="hljs-operator">=</span> fecha_actual`</div></div>
4. Si **existe un registro previo**:
    
    
    - Se suma el intento nuevo al intento existente:
        
        <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">`<span class="hljs-attr">intento_total</span> = intento_enviado + intento_existente`</div></div>
    - Se actualiza el Doctype:
        
        <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">`<span class="hljs-type">PUT</span> resource<span class="hljs-regexp">/Intento de marcacion/</span>{name}`</div></div>
5. Si **NO existe un registro previo**:
    
    
    - Se crea un nuevo documento Intento de marcacion:
        
        <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">`<span class="hljs-attribute">POST</span> resource/Intento de marcacion`</div></div>
6. Devuelve la respuesta directa del ERP.

---

# 📤 Response 200 – Ejemplo (actualizado)

### ✔ Caso actualización

<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">"Actualizado correctamente"</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">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"INT-MAR-00045"</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">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AG-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"intento"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">3</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-10"</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>### ✔ Caso creación

<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">"Creado correctamente"</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">"name"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"INT-MAR-00046"</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">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"AG-001"</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"intento"</span><span class="hljs-punctuation">:</span> <span class="hljs-number">1</span><span class="hljs-punctuation">,</span>    <span class="hljs-attr">"creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"2025-02-10"</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. Falta de parámetros requeridos

<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">"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>### 2. Error en la consulta DB → dbErp

<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%; height: 33.8px;"><colgroup><col style="width: 99.881%;"></col></colgroup><tbody><tr style="height: 33.8px;"><td style="height: 33.8px;">`<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">"Error al consultar ERP"</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>### 3. Error en creación o actualización en ERP

<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%; 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-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">"Error al registrar intento"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"data"</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span> ...respuesta ERP... <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>---

# 📚 Doctype utilizado

## Intento de marcacion

Campos usados:

<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">"agencia"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"string"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"intento"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"int"</span><span class="hljs-punctuation">,</span>  <span class="hljs-attr">"creacion"</span><span class="hljs-punctuation">:</span> <span class="hljs-string">"date"</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-employee-%3D-request.e"><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;">`employee = request.empleadoagencia = request.agenciaintento = request.intentofecha = hoy (Y-m-d)if falta algún parámetro:    return errorconsulta = GET Intento de marcacion where empleado = employee and creacion = fechaif existe_registro:    nuevo_intento = intento + registro.intento    PUT Intento de marcacion/{name} con { empleado, agencia, intento: nuevo_intento, creacion }else:    POST Intento de marcacion con { empleado, agencia, intento, creacion }return respuesta`</td></tr></tbody></table>

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