Skip to content

Commit 33b7c3f

Browse files
committed
feat: gestione rinnovo contratto con ore residue
1 parent 438cbee commit 33b7c3f

7 files changed

Lines changed: 401 additions & 100 deletions

File tree

include/common/importa.php

Lines changed: 111 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060

6161
$righe_totali = $documento->getRighe();
6262

63+
// Verifica se è un rinnovo di contratto
64+
$is_renewal = !empty($options['is_renewal']);
65+
6366
$id_module_interventi = Module::where('name', 'Interventi')->first()->id;
6467
$id_module_ordini_f = Module::where('name', 'Ordini fornitore')->first()->id;
6568
if ($final_module->id == $id_module_interventi) {
@@ -71,8 +74,14 @@
7174
$righe = $righe_totali;
7275
$righe_evase = collect();
7376
} else {
74-
$righe = $righe_totali->where('qta_rimanente', '>', 0);
75-
$righe_evase = $righe_totali->where('qta_rimanente', '=', 0);
77+
// Se è un rinnovo di contratto, includi tutte le righe (anche quelle evase)
78+
if ($is_renewal) {
79+
$righe = $righe_totali;
80+
$righe_evase = collect();
81+
} else {
82+
$righe = $righe_totali->where('qta_rimanente', '>', 0);
83+
$righe_evase = $righe_totali->where('qta_rimanente', '=', 0);
84+
}
7685
}
7786

7887
$link = !empty($documento_finale) ? base_path_osm().'/editor.php?id_module='.$final_module->id.'&id_record='.$documento_finale->id : base_path_osm().'/controller.php?id_module='.$final_module->id;
@@ -88,7 +97,7 @@
8897
<input type="hidden" name="is_evasione" value="1">';
8998

9099
// Creazione fattura dal documento
91-
if (!empty($options['create_document'])) {
100+
if (!empty($options['create_document']) && empty($options['tipi_attivita'])) {
92101
echo '
93102
<div class="card card-primary">
94103
<div class="card-header with-border">
@@ -422,11 +431,16 @@
422431
$qta_rimanente = $riga['qta_rimanente'];
423432
}
424433

425-
// Calcola disponibilità per questa riga
434+
// Per il rinnovo, usa la quantità totale invece di quella rimanente
435+
if ($is_renewal) {
436+
$qta_rimanente = $riga['qta'];
437+
}
438+
439+
// Calcola disponibilità per questa riga (non applicare nel rinnovo)
426440
$qta_disponibile = null;
427441
$qta_disponibile_originale = null;
428442
$qta_da_evadere = $qta_rimanente;
429-
if ($abilita_controllo_disponibilita && $riga->isArticolo() && !$riga['is_descrizione']) {
443+
if ($abilita_controllo_disponibilita && $riga->isArticolo() && !$riga['is_descrizione'] && !$is_renewal) {
430444
$id_articolo = $riga->idarticolo;
431445
$info_disponibilita = $disponibilita_articoli[$id_articolo] ?? null;
432446

@@ -457,7 +471,7 @@
457471
<input type="hidden" class="righe" name="righe" value="'.$i.'"/>
458472
<input type="hidden" id="prezzo_unitario_'.$i.'" name="subtot['.$riga['id'].']" value="'.($dir == 'entrata' ? $riga['prezzo_unitario'] : $riga['costo_unitario']).'" />
459473
<input type="hidden" id="sconto_unitario_'.$i.'" name="sconto['.$riga['id'].']" value="'.$riga['sconto_unitario'].'" />
460-
<input type="hidden" id="max_qta_'.$i.'" value="'.($options['superamento_soglia_qta'] ? '' : $riga['qta_rimanente']).'" />';
474+
<input type="hidden" id="max_qta_'.$i.'" value="'.($options['superamento_soglia_qta'] || $is_renewal ? '' : $riga['qta_rimanente']).'" />';
461475

462476
$descrizione = ($riga->isArticolo() ? $riga->articolo->codice.' - ' : '').$riga['descrizione'];
463477

@@ -571,8 +585,8 @@
571585
</div>
572586
</div>';
573587

574-
// Elenco righe evase completametne
575-
if (!$righe_evase->isEmpty()) {
588+
// Elenco righe evase completametne (non mostrare nel rinnovo)
589+
if (!$righe_evase->isEmpty() && !$is_renewal) {
576590
echo '
577591
<div class="card card-primary collapsable collapsed-card">
578592
<div class="card-header with-border">
@@ -607,6 +621,59 @@
607621
</div>';
608622
}
609623

624+
// Card Ore residue per i contratti
625+
if (!empty($options['tipi_attivita'])) {
626+
echo '
627+
<div class="card card-primary">
628+
<div class="card-header with-border">
629+
<h3 class="card-title">'.tr('Ore residue').'</h3>
630+
</div>
631+
632+
<div class="card-body p-0">
633+
<table class="table table-striped table-hover table-sm">
634+
<thead>
635+
<tr>
636+
<th width="2%"><input id="import_all_ore" type="checkbox" checked/></th>
637+
<th>'.tr('Tipo attività').'</th>
638+
<th width="15%" class="text-center">'.tr('Ore totali').'</th>
639+
<th width="15%" class="text-center">'.tr('Ore utilizzate').'</th>
640+
<th width="15%" class="text-center">'.tr('Ore residue').'</th>
641+
<th width="12%">'.tr('Q.tà da riportare').'</th>
642+
</tr>
643+
</thead>
644+
<tbody>';
645+
646+
foreach ($options['tipi_attivita'] as $i => $tipo) {
647+
$ore_residue = max(0, $tipo['ore_totali'] - $tipo['ore_utilizzate']);
648+
649+
// Visualizza solo i tipi di attività con ore totali valorizzate e ore residue disponibili
650+
if ($tipo['ore_totali'] > 0 && $ore_residue > 0) {
651+
echo '
652+
<tr data-local_id="'.$i.'">
653+
<td style="vertical-align:middle">
654+
<input class="check" type="checkbox" checked id="checked_ore_'.$i.'" name="evadere_ore['.$tipo['idtipointervento'].']" value="on" onclick="ricalcolaTotaleOre();" />
655+
<input type="hidden" class="tipi_attivita" name="tipi_attivita[]" value="'.$tipo['idtipointervento'].'"/>
656+
</td>
657+
<td style="vertical-align:middle">'.$tipo['descrizione'].'</td>
658+
<td class="text-center" style="vertical-align:middle">'.numberFormat($tipo['ore_totali'], 2).'</td>
659+
<td class="text-center" style="vertical-align:middle">'.numberFormat($tipo['ore_utilizzate'], 2).'</td>
660+
<td class="text-center '.($ore_residue > 0 ? '' : 'text-warning').'" style="vertical-align:middle">'.numberFormat($ore_residue, 2).'</td>
661+
<td class="text-center" style="vertical-align:middle; padding: 0;">
662+
<div style="display: flex; align-items: center; justify-content: center; height: 100%; padding: 8px;">
663+
{[ "type": "number", "name": "qta_da_evadere_ore['.$tipo['idtipointervento'].']", "id": "qta_ore_'.$i.'", "required": 1, "value": "'.$ore_residue.'", "decimals": "2", "min-value": "0", "extra": "onkeyup=\"ricalcolaTotaleOre();\"" ]}
664+
</div>
665+
</td>
666+
</tr>';
667+
}
668+
}
669+
670+
echo '
671+
</tbody>
672+
</table>
673+
</div>
674+
</div>';
675+
}
676+
610677
// Gestione articolo sottoscorta
611678
if ($abilita_controllo_disponibilita) {
612679
echo '
@@ -863,4 +930,40 @@ function ricalcolaTotale() {
863930
});
864931
}
865932
});
933+
934+
$("#modals #import_all_ore").click(function(){
935+
if( $(this).is(":checked") ){
936+
$(".check").each(function(){
937+
if( !$(this).is(":checked") && $(this).attr("id").indexOf("checked_ore") >= 0 ){
938+
$(this).trigger("click");
939+
}
940+
});
941+
}else{
942+
$(".check").each(function(){
943+
if( $(this).is(":checked") && $(this).attr("id").indexOf("checked_ore") >= 0 ){
944+
$(this).trigger("click");
945+
}
946+
});
947+
}
948+
ricalcolaTotaleOre();
949+
});
950+
951+
function ricalcolaTotaleOre() {
952+
let totale_ore = 0.00;
953+
let totale_qta = 0;
954+
955+
$("#modals input[name*=qta_ore_]").each(function() {
956+
let qta = $(this).val().toEnglish();
957+
let r = $(this).attr("id").replace("qta_ore_", "");
958+
959+
if (!$("#checked_ore_" + r).is(":checked") || isNaN(qta)) {
960+
qta = 0;
961+
}
962+
963+
totale_ore += qta;
964+
totale_qta += qta;
965+
});
966+
967+
$("#modals #totale").html(totale_ore.toLocale(2) + " " + globals.currency);
968+
}
866969
</script>';

0 commit comments

Comments
 (0)