Commit Graph

3 Commits

Author SHA1 Message Date
BFLOWS
3021792c31 feat(v2): verbale istruttoria PDF con tranche N/M + custom_checks + 5 voci Cecilia + storico
B6 routers/verbale.py:
- _build_context arricchito con custom_checks_merged (schema+values da RemissionCustomCheckValue)
- previous_tranches: elenco tranche APPROVED precedenti con cumulative progressivo
- max_tranches_snapshot letto dallo schema_snapshot.gate_rules.max_tranches
- filename include _t{sequence_number}.pdf

B6 templates_jinja/verbale_istruttoria.html:
- Header: 'Tranche N/M' + period_label dopo numero pratica
- Meta-grid: riga 'Tranche / fase' quando max_tranches > 1
- Nuova sezione 'Controlli aggiuntivi' (dopo verifica documenti):
  tabella label, obbligatorio, dichiarato SI/NO, doc allegato SI/NO, validazione, note
- Sezione 'Storico tranches precedenti' (solo se sequence > 1):
  tabella con cumulativo progressivo
- Box totali riscritto con **5 VOCI UFFICIALI CECILIA**:
  (1) Importo massimo ammissibile (cap globale) + gia approvato tranche precedenti
  (2) Richiesto pre-controllo = pre_check_admissible
  (3) Ammesso post-controllo = remission_due
  (4) Importo finanziamento erogato + tranches count/max
  (5) Residuo da restituire = erogato - approvato_prec - ammesso
- Box 'REMISSIONE APPROVATA PER QUESTA TRANCHE' evidenziato quando APPROVED

Test E2E: verbale T1 APPROVED 29.3KB con tutte sezioni presenti.
Verbale T2 simulata con storico T1 e cap tranche 2 correttamente calcolato.
2026-04-18 17:53:04 +02:00
BFLOWS
25215f388b feat(v2): multi-tranche DB schema + gate cumulativo 5 voci Cecilia
A1 migrations.py:
- remission_practice DROP uq_application + ADD sequence_number/period_label/suggested_instructor_id
- UNIQUE composita (application_id, sequence_number)
- partial index idx_remission_practice_unassigned su assigned_instructor_id NULL
- nuova tabella remission_custom_check_value (storage_path/mime/size/sha256 allineata adapter)

A2 models.py + templates.py:
- RemissionPractice: UniqueConstraint composita, campi multi-tranche, relationship custom_checks
- classe RemissionCustomCheckValue
- RESTART_TEMPLATE schema_version=2, max_tranches=2, custom_checks esempio
  (antiriciclaggio required no-doc, polizza_fidejussoria optional con-doc)
- upgrade_schema_to_v2 idempotente per snapshot v1 esistenti

A3 _compute_gate_check(db, practice) CUMULATIVO:
- max_remission_global = min(cap_pct * erogato, cap_abs)
- already_approved = func.sum(approved_remission) su tranche APPROVED precedenti
  dello stesso application_id con sequence_number < corrente
- max_remission_this_tranche = max(0, global - already_approved)
- pre_check_admissible = min(grand_total_declared, this_tranche)  [voce 2 Cecilia]
- remission_due = min(effective_total, this_tranche)
- residuo_da_restituire = erogato - already_approved - remission_due (cumulativo)
- output totals esteso: sequence_number, tranches_count, tranches_max
- signature (db, practice) - aggiornati 6 call site in practices/instructor/verbale

Test su NAPOLI SAS: erogato 17K, cap 8500, tranche 1 approvata 467.14EUR,
tranche 2 vuota -> residuo disponibile 8032.86EUR, residuo_da_restituire 16532.86EUR.
2026-04-18 17:35:56 +02:00
BFLOWS
23a2b525a4 feat(verbale): export PDF verbale istruttoria via weasyprint
- Dockerfile: dipendenze sistema libpango/libgdk-pixbuf/libcairo/shared-mime-info +
  fonts-dejavu per rendering WeasyPrint su debian slim
- requirements: weasyprint==61.2 + pydyf==0.10.0 (vincolo compatibilita,
  weasyprint 62.x ha bug con pydyf 0.11 su stream.transform) + jinja2==3.1.3
- templates_jinja/verbale_istruttoria.html: layout A4 professionale con
  intestazione Gepafin, dati pratica, tabelle fatture raggruppate per categoria
  (dichiarato vs ammesso con motivazione rettifica), ULA, documenti,
  soccorsi istruttori, totali, checklist finale, note istruttore, blocco firma
- routers/verbale: endpoint /verbale.html (debug preview) e /verbale.pdf
  (weasyprint on-the-fly) — solo ruoli istruttore/superadmin
- main: include router verbale, version bump 0.3.0

Testato E2E: PDF 27KB generato su pratica UNDER_REVIEW, magic bytes PDF-1.7 OK.
2026-04-18 16:54:35 +02:00