|
60 | 60 |
|
61 | 61 | $righe_totali = $documento->getRighe(); |
62 | 62 |
|
| 63 | +// Verifica se è un rinnovo di contratto |
| 64 | +$is_renewal = !empty($options['is_renewal']); |
| 65 | + |
63 | 66 | $id_module_interventi = Module::where('name', 'Interventi')->first()->id; |
64 | 67 | $id_module_ordini_f = Module::where('name', 'Ordini fornitore')->first()->id; |
65 | 68 | if ($final_module->id == $id_module_interventi) { |
|
71 | 74 | $righe = $righe_totali; |
72 | 75 | $righe_evase = collect(); |
73 | 76 | } 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 | + } |
76 | 85 | } |
77 | 86 |
|
78 | 87 | $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 | 97 | <input type="hidden" name="is_evasione" value="1">'; |
89 | 98 |
|
90 | 99 | // Creazione fattura dal documento |
91 | | -if (!empty($options['create_document'])) { |
| 100 | +if (!empty($options['create_document']) && empty($options['tipi_attivita'])) { |
92 | 101 | echo ' |
93 | 102 | <div class="card card-primary"> |
94 | 103 | <div class="card-header with-border"> |
|
422 | 431 | $qta_rimanente = $riga['qta_rimanente']; |
423 | 432 | } |
424 | 433 |
|
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) |
426 | 440 | $qta_disponibile = null; |
427 | 441 | $qta_disponibile_originale = null; |
428 | 442 | $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) { |
430 | 444 | $id_articolo = $riga->idarticolo; |
431 | 445 | $info_disponibilita = $disponibilita_articoli[$id_articolo] ?? null; |
432 | 446 |
|
|
457 | 471 | <input type="hidden" class="righe" name="righe" value="'.$i.'"/> |
458 | 472 | <input type="hidden" id="prezzo_unitario_'.$i.'" name="subtot['.$riga['id'].']" value="'.($dir == 'entrata' ? $riga['prezzo_unitario'] : $riga['costo_unitario']).'" /> |
459 | 473 | <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']).'" />'; |
461 | 475 |
|
462 | 476 | $descrizione = ($riga->isArticolo() ? $riga->articolo->codice.' - ' : '').$riga['descrizione']; |
463 | 477 |
|
|
571 | 585 | </div> |
572 | 586 | </div>'; |
573 | 587 |
|
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) { |
576 | 590 | echo ' |
577 | 591 | <div class="card card-primary collapsable collapsed-card"> |
578 | 592 | <div class="card-header with-border"> |
|
607 | 621 | </div>'; |
608 | 622 | } |
609 | 623 |
|
| 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 | + |
610 | 677 | // Gestione articolo sottoscorta |
611 | 678 | if ($abilita_controllo_disponibilita) { |
612 | 679 | echo ' |
@@ -863,4 +930,40 @@ function ricalcolaTotale() { |
863 | 930 | }); |
864 | 931 | } |
865 | 932 | }); |
| 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 | + } |
866 | 969 | </script>'; |
0 commit comments