# Set Factura Exenta v1 - EVENTSUD - SOK

**Identificador del Set SII:** `4841005`
**Tipo de Set:** SET FACTURA EXENTA - Version 2 (3er intento exitoso)
**RUT Emisor:** `78073481-7`
**Track ID final:** `0249679178`
**NUM_ATENCION:** `132980`
**Fecha:** 2026-05-26
**Estado SII envio:** EPR + 8/8 aceptados + 0 reparos.
**Estado SII revision del set:** `SOK - SET DE PRUEBA CORRECTO`

## DTEs incluidos

| # | Caso | Tipo | Folio | MntExe | MntTotal | Descripcion |
|---|---|---|---|---|---|---|
| 1 | 4841005-1 | 34 | 7 | 8.250 | 8.250 | Factura exenta 1 item HORAS PROGRAMADOR cant 3 @ 2750 |
| 2 | 4841005-2 | 61 | 29 | 1.032 | 1.032 | NC MODIFICA MONTO ref f7: HORAS PROGRAMADOR cant 3 @ 344 |
| 3 | 4841005-3 | 34 | 8 | 386.511 | 386.511 | Factura exenta 2 items consultoria (187543 + 198968) |
| 4 | 4841005-4 | 61 | 30 | 0 | 0 | NC CORRIGE GIRO ref f8 (fe de erratas) |
| 5 | 4841005-5 | 56 | 12 | 0 | 0 | ND ANULA NC ref f30 (anula caso 4) |
| 6 | 4841005-6 | 34 | 9 | 450.865 | 450.865 | Factura exenta 2 items capacitacion (CIGUEÑALES + PLC's CNC) |
| 7 | 4841005-7 | 61 | 31 | 138.145 | 138.145 | NC MODIFICA MONTO ref f9: CAPACITACION USO CIGUEÑALES @ 138145 |
| 8 | 4841005-8 | 56 | 13 | 34.915 | 34.915 | ND MODIFICA MONTO ref f9: CAPACITACION USO PLC's CNC @ 34915 |

## Historial de intentos hasta SOK

| Intento | TrackID | Resultado | Diagnostico |
|---|---|---|---|
| v1 | 0249678772 | EPR 5/8 + 3 reparos | RLV HED-1-844: 3 facturas tipo 34 sin GiroRecep. Mi DataMapper omitia GiroRecep para tipo 34 |
| v2 | 0249678930 | EPR 8/8 + 0 reparos | Pero SRH del set: caso 2 NC encabezado/linea no cuadraban (cantidad=1 cuando factura tenia cantidad=3); caso 6 factura nombres sin Ñ ni apostrofe |
| **v3** | **0249679178** | **EPR 8/8 + 0 reparos** | **SOK** |

## Fixes incorporados al motor para este caso

1. **fix(dte): orden XSD QtyItem<UnmdItem** (commit `f8c8818`)
   - `DteXmlBuilder.buildDetalle` ordenaba `UnmdItem` ANTES de `QtyItem`.
     XSD `DTE_v10` exige `NmbItem -> DscItem -> QtyItem -> UnmdItem -> PrcItem
     -> MontoItem`. Salida v0 fallida: STATUS=7 Esquema XML invalido.
   - Validamos localmente con `xmllint --schema EnvioDTE_v10.xsd` antes del
     envio para detectar errores XSD sin gastar folios.

2. **fix(dte): GiroRecep en tipo 34** (commit `f8c8818`)
   - `DataMapper.buildReceptor` no incluia `<GiroRecep>` para tipo 34 (factura
     exenta). Reparo HED-1-844 "DTE Sin Giro del Receptor" en v1.
   - Fix: agregar 34 a la lista `[33, 34, 52, 56, 61]` que llevan GiroRecep.

3. **fix(dte): --solo-firmar para batch** (commit `f8c8818`)
   - El comando `dte:emitir-set-pruebas` ahora soporta `--solo-firmar` para
     batches: envuelve en transaccion con rollback al final. Permite validar
     el envelope localmente sin gastar folios.

4. **Reglas de negocio (no codigo) descubiertas en este set:**
   - **NC MODIFICA MONTO** sobre una factura: la NC debe usar la **misma
     cantidad** que la factura referenciada, con el nuevo precio unitario.
     Modificar el monto NO significa cantidad=1.
   - **Nombres de items exactos:** el SII verifica nombre vs el especificado
     en el set. `CIGUEÑALES` con Ñ tilde; `PLC's CNC` con apostrofe. No
     normalizar.

## Como reproducir

```bash
php artisan dte:emitir-set-pruebas tests/Fixtures/SetPruebasSII/casos_exito/set_exenta_v1_eventsud_input.json
```

Requiere CAFs activos tipo 34, 61, 56 en `dte_cafs`.

## Notas operacionales

- **Facturas exentas (tipo 34):** NO se debe señalar TasaIVA ni IVA en Totales.
  Solo MntExe y MntTotal (mi `DteXmlBuilder.calcularTotales` ya respeta esta
  regla cuando todos los items tienen IndExe=1).
- **NC/ND ref a factura exenta:** los items de la NC/ND tambien son exentos
  (`IndExe=1`).
- **Fe-de-erratas** (CORRIGE GIRO, ANULA NC): item solo con `NmbItem` +
  `MontoItem=0`, sin QtyItem ni PrcItem.
