2024-03-05 17:31:36 +01:00
< ? php
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
* Copyright ( C ) DevCode s . r . l .
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
include_once __DIR__ . '/../../core.php' ;
2024-03-06 09:23:43 +01:00
use Models\Module ;
2024-03-22 15:52:24 +01:00
use Modules\Checklists\Check ;
2024-03-05 17:31:36 +01:00
2024-06-11 16:58:27 +02:00
$id_modulo_impianti = Module :: where ( 'name' , 'Impianti' ) -> first () -> id ;
$checklist_module = Module :: where ( 'name' , 'Checklists' ) -> first ();
2024-03-05 17:31:36 +01:00
// Blocco della modifica impianti se l'intervento è completato
$dati_intervento = $dbo -> fetchArray ( 'SELECT `in_statiintervento`.`is_completato` FROM `in_statiintervento` INNER JOIN `in_interventi` ON `in_statiintervento`.`id` = `in_interventi`.`idstatointervento` WHERE `in_interventi`.`id`=' . prepare ( $id_record ));
$is_completato = $dati_intervento [ 0 ][ 'is_completato' ];
if ( $is_completato ) {
$readonly = 'readonly' ;
$disabled = 'disabled' ;
} else {
$readonly = '' ;
$disabled = '' ;
}
$where = get ( 'search' ) ? 'AND (my_impianti.matricola LIKE ' . prepare ( '%' . get ( 'search' ) . '%' ) . ' OR my_impianti.nome LIKE ' . prepare ( '%' . get ( 'search' ) . '%' ) . ')' : '' ;
$impianti_collegati = $dbo -> fetchArray ( 'SELECT * FROM my_impianti_interventi INNER JOIN my_impianti ON my_impianti_interventi.idimpianto = my_impianti.id WHERE idintervento = ' . prepare ( $id_record ) . ' ' . $where );
$n_impianti = count ( $impianti_collegati );
$impianti_non_completati = 0 ;
$impianti_completati = 0 ;
$impianti_non_previsti = 0 ;
foreach ( $impianti_collegati as $impianto ) {
2024-03-06 09:23:43 +01:00
$checks = Check :: where ( 'id_module_from' , $id_modulo_impianti ) -> where ( 'id_record_from' , $impianto [ 'id' ]) -> where ( 'id_module' , $id_module ) -> where ( 'id_record' , $id_record ) -> where ( 'id_parent' , null ) -> get ();
2024-03-05 17:31:36 +01:00
if ( sizeof ( $checks )) {
$has_checks_not_verified = $checks -> where ( 'checked_at' , null ) -> count ();
if ( $has_checks_not_verified ) {
2024-03-22 15:52:24 +01:00
++ $impianti_non_completati ;
2024-03-05 17:31:36 +01:00
} else {
2024-03-22 15:52:24 +01:00
++ $impianti_completati ;
2024-03-05 17:31:36 +01:00
}
} else {
2024-03-22 15:52:24 +01:00
++ $impianti_non_previsti ;
2024-03-05 17:31:36 +01:00
}
}
2024-08-27 09:20:20 +02:00
$percentuale_completati = $n_impianti ? round (( $impianti_completati * 100 ) / ( $n_impianti ? : 1 )) : 0 ;
$percentuale_non_completati = $n_impianti ? round (( $impianti_non_completati * 100 ) / ( $n_impianti ? : 1 )) : 0 ;
$percentuale_non_previsti = $n_impianti ? round (( $impianti_non_previsti * 100 ) / ( $n_impianti ? : 1 )) : 0 ;
2024-03-05 17:31:36 +01:00
echo '
< div class = " row " >
2024-05-17 12:11:00 +02:00
< div class = " offset-md-4 col-md-4 text-center " >
2024-08-27 09:20:20 +02:00
< h4 > '.strtoupper(tr(' Impianti ')).' : '.$n_impianti.' </ h4 >
2024-07-30 16:23:04 +02:00
< div class = " progress " style = " height:2rem; " >
2024-03-05 17:31:36 +01:00
< div class = " progress-bar progress-bar-striped progress-bar-success " role = " progressbar " style = " width:'. $percentuale_completati .'% " >< i class = " fa fa-check " ></ i > < b > '.$impianti_completati.' </ b ></ div >
< div class = " progress-bar progress-bar-striped progress-bar-danger " role = " progressbar " style = " width:'. $percentuale_non_completati .'% " >< i class = " fa fa-clock-o " ></ i > < b > '.$impianti_non_completati.' </ b ></ div >
2024-08-27 09:20:20 +02:00
< div class = " progress-bar progress-bar-striped progress-bar-warning " role = " progressbar " style = " width:'. $percentuale_non_previsti .'% " >< i class = " fa fa-times " ></ i > < b > '.$impianti_non_previsti.' </ b ></ div >
2024-03-05 17:31:36 +01:00
</ div >
</ div >
2024-07-30 16:23:04 +02:00
< div class = " col-md-1 " >
< button type = " button " class = " btn btn-default " onclick = " caricaImpianti() " style = " margin-top: 25px; " >
2024-08-27 09:20:20 +02:00
< i class = " fa fa-refresh " ></ i > '.tr(' Aggiorna ').'
2024-03-05 17:31:36 +01:00
</ button >
</ div >
</ div >
2024-07-30 16:23:04 +02:00
< hr >
< div class = " row " >
< div class = " col-md-12 " >
< div class = " card " >
< table class = " table table-hover table-condensed table-striped " >
2024-03-05 17:31:36 +01:00
< tr >
< th class = " text-center " width = " 1% " ></ th >
< th class = " text-center " width = " 10% " > '.tr(' Matricola ').' </ th >
< th class = " text-center " width = " 20% " > '.tr(' Nome ').' </ th >
< th class = " text-center " width = " 7% " > '.tr(' Data ').' </ th >
< th class = " text-center " > '.tr(' Note ').' </ th >
< th class = " text-center " width = " 25% " > '.tr("Componenti soggetti all' intervento " ).'</th>
< th class = " text-center " width = " 5% " > Checklist </ th >
< th class = " text-center " width = " 2% " ></ th >
</ tr > ' ;
foreach ( $impianti_collegati as $impianto ) {
2024-03-06 09:23:43 +01:00
$checks = Check :: where ( 'id_module_from' , $id_modulo_impianti ) -> where ( 'id_record_from' , $impianto [ 'id' ]) -> where ( 'id_module' , $id_module ) -> where ( 'id_record' , $id_record ) -> where ( 'id_parent' , null ) -> get ();
2024-03-05 17:31:36 +01:00
$type = 'warning' ;
$class = 'disabled' ;
$icon = 'circle-o' ;
$icon2 = 'remove' ;
if ( sizeof ( $checks )) {
$class = '' ;
$icon = 'plus' ;
$checks_not_verified = $checks -> where ( 'checked_at' , null ) -> count ();
$type = $checks_not_verified ? 'danger' : 'success' ;
$icon2 = $checks_not_verified ? 'clock-o' : 'check' ;
}
2024-03-22 15:52:24 +01:00
echo '
2024-03-05 17:31:36 +01:00
< tr data - id = " '. $impianto['id'] .' " >
< td class = " text-left " >
2024-04-23 17:14:56 +02:00
< button type = " button " class = " btn btn-xs btn-default '. $class .' " onclick = " loadChecklist('. $impianto['id'] .'); toggleDettagli(this); " >
2024-03-05 17:31:36 +01:00
< i class = " fa fa-'. $icon .' " ></ i >
</ button >
</ td >
< td > '.$impianto[' matricola '].' </ td >
< td > '.Modules::link(' Impianti ', $impianto[' id '], $impianto[' nome ']).' </ td >
< td class = " text-center " > '.Translator::dateToLocale($impianto[' data ']).' </ td >
< td >
{[ " type " : " textarea " , " name " : " note " , " id " : " note_imp_'. $impianto['id'] .' " , " value " : " '. $impianto['note'] .' " , " onchange " : " updateImpianto( $ (this).closest( \ 'tr \ ').data( \ 'id \ ')) " , " readonly " : " '.!empty( $readonly ).' " , " disabled " : " '.!empty( $disabled ).' " ]}
</ td >
< td > ' ;
2024-03-22 15:52:24 +01:00
$inseriti = $dbo -> fetchArray ( 'SELECT * FROM my_componenti_interventi WHERE id_intervento = ' . prepare ( $id_record ));
$ids = array_column ( $inseriti , 'id_componente' );
2024-03-05 17:31:36 +01:00
2024-03-22 15:52:24 +01:00
echo '
2024-03-05 17:31:36 +01:00
{[ " type " : " select " , " multiple " : 1 , " name " : " componenti[] " , " id " : " componenti_imp_'. $impianto['id'] .' " , " ajax-source " : " componenti " , " select-options " : { " matricola " : '.$impianto[' id '].' }, " value " : " '.implode(',', $ids ).' " , " onchange " : " updateImpianto( $ (this).closest( \ 'tr \ ').data( \ 'id \ ')) " , " readonly " : " '.!empty( $readonly ).' " , " disabled " : " '.!empty( $disabled ).' " ]}
</ form >
</ td >
< td class = " text-center " >< i class = " fa fa-'. $icon2 .' fa-2x text-'. $type .' " ></ i ></ td >
< td class = " text-center " >< button class = " btn btn-sm btn-danger '. $disabled .' " onclick = " rimuoviImpianto( $ (this).closest( \ 'tr \ ').data( \ 'id \ ')) " >< i class = " fa fa-trash " ></ i ></ button ></ td >
</ tr >
< tr style = " display: none " >
< td colspan = " 7 " >
< table class = " table " >
2024-04-23 17:14:56 +02:00
< tbody class = " sort check-impianto " data - sonof = " 0 " id = " checklist_'. $impianto['id'] .' " >
< span class = " text-muted " id = " loading-checks_'. $impianto['id'] .' " >< i class = " fa fa-spin fa-spinner " ></ i > '.tr(' Caricamento checklist ').' ...</ span >
2024-03-05 17:31:36 +01:00
</ tbody >
</ table >
</ td >
</ tr > ' ;
}
echo '
2024-07-30 16:23:04 +02:00
</ table >
</ div >
</ div >
</ div >
2024-03-05 17:31:36 +01:00
< script >
$ ( document ) . ready ( init );
function rimuoviImpianto ( id ) {
swal ({
title : " '.tr('Rimuovere questo impianto?').' " ,
html : " '.tr('Sei sicuro di volere rimuovere questo impianto dal documento?').' '.tr( " L 'operazione è irreversibile").' . " ,
type : " warning " ,
showCancelButton : true ,
confirmButtonText : " '.tr('Sì').' "
}) . then ( function () {
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
dataType : " json " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
id_plugin : '.$id_plugin.' ,
op : " delete_impianto " ,
id : id ,
},
success : function ( response ) {
renderMessages ();
caricaImpianti ();
},
error : function () {
renderMessages ();
caricaImpianti ();
}
});
}) . catch ( swal . noop );
}
function updateImpianto ( id ) {
var note = $ ( " #note_imp_ " + id ) . val ();
var componenti = $ ( " #componenti_imp_ " + id ) . val ();
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
data : {
id_module : globals . id_module ,
id_plugin : '.$id_plugin.' ,
id_record : globals . id_record ,
op : " update_impianto " ,
id_impianto : id ,
note : note ,
componenti : componenti
},
success : function ( response ) {
renderMessages ();
},
error : function () {
renderMessages ();
}
});
}
2024-04-23 17:14:56 +02:00
function delete_check ( id ){
if ( confirm ( " Eliminare questa checklist? " )){
2024-03-05 17:31:36 +01:00
$ . post ( " '. $checklist_module->fileurl ('ajax.php').' " , {
2024-04-23 17:14:56 +02:00
op : " delete_check " ,
id : id ,
}, function (){
location . reload ();
2024-03-05 17:31:36 +01:00
});
2024-04-23 17:14:56 +02:00
}
2024-03-05 17:31:36 +01:00
}
2024-04-23 17:14:56 +02:00
function edit_check ( id ){
launch_modal ( " Modifica checklist " , " '. $checklist_module->fileurl ('components/edit-check.php').'?id_record= " + id , 1 );
}
2024-03-05 17:31:36 +01:00
function saveNota ( id ) {
$ . post ( " '. $checklist_module->fileurl ('ajax.php').' " , {
op : " save_note " ,
note : $ ( " #note_ " + id ) . val (),
id : id
}, function () {
2024-04-23 17:14:56 +02:00
renderMessages ();
2024-03-05 17:31:36 +01:00
$ ( " #note_ " + id ) . parent () . parent () . parent () . find ( " .save-nota " ) . removeClass ( " btn-success " );
$ ( " #note_ " + id ) . parent () . parent () . parent () . find ( " .save-nota " ) . addClass ( " btn-default " );
});
}
2024-04-23 17:14:56 +02:00
function loadChecklist ( id ){
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " POST " ,
data : {
id_module : globals . id_module ,
id_plugin : '.$id_plugin.' ,
id_record : globals . id_record ,
op : " load_checklist " ,
id_impianto : id ,
},
success : function ( response ) {
$ ( " #loading-checks_ " + id ) . hide ();
$ ( " #checklist_ " + id ) . html ( response );
init ();
sortable ( " #tab_checks .sort " , {
axis : " y " ,
handle : " .handle " ,
cursor : " move " ,
dropOnEmpty : true ,
scroll : true ,
});
sortable_table = sortable ( " #tab_checks .sort " ) . length ;
for ( i = 0 ; i < sortable_table ; i ++ ){
sortable ( " #tab_checks .sort " )[ i ] . addEventListener ( " sortupdate " , function ( e ) {
var sonof = $ ( this ) . data ( " sonof " );
let order = $ ( this ) . find ( " .sonof_ " + sonof + " [data-id] " ) . toArray () . map ( a => $ ( a ) . data ( " id " ))
$ . post ( " '. $checklist_module->fileurl ('ajax.php').' " , {
op : " update_position " ,
order : order . join ( " , " ),
});
});
2024-03-05 17:31:36 +01:00
}
2024-04-23 17:14:56 +02:00
$ ( " textarea[name= \ 'note_checklist \ '] " ) . keyup ( function () {
$ ( this ) . parent () . parent () . parent () . find ( " .save-nota " ) . removeClass ( " btn-default " );
$ ( this ) . parent () . parent () . parent () . find ( " .save-nota " ) . addClass ( " btn-success " );
});
$ ( " .check-impianto .checkbox " ) . click ( function (){
if ( $ ( this ) . is ( " :checked " )){
$ . post ( " '. $checklist_module->fileurl ('ajax.php').' " , {
op : " save_checkbox " ,
id : $ ( this ) . attr ( " data-id " ),
}, function ( result ){
});
$ ( this ) . parent () . parent () . find ( " .text " ) . css ( " text-decoration " , " line-through " );
parent = $ ( this ) . attr ( " data-id " );
$ ( " tr.sonof_ " + parent ) . find ( " input[type=checkbox] " ) . each ( function (){
if ( ! $ ( this ) . is ( " :checked " )){
$ ( this ) . click ();
}
});
$ ( this ) . parent () . parent () . find ( " .verificato " ) . removeClass ( " hidden " );
$ ( this ) . parent () . parent () . find ( " .verificato " ) . text ( " '.tr('Verificato da _USER_ il _DATE_', [
2024-04-24 12:26:51 +02:00
'_USER_' => $user -> username ,
'_DATE_' => dateFormat ( date ( 'Y-m-d' )) . ' ' . date ( 'H:i' ),
]) . ' " );
2024-04-23 17:14:56 +02:00
} else {
$ . post ( " '. $checklist_module->fileurl ('ajax.php').' " , {
op : " remove_checkbox " ,
id : $ ( this ) . attr ( " data-id " ),
}, function ( result ){
});
$ ( this ) . parent () . parent () . find ( " .text " ) . css ( " text-decoration " , " none " );
parent = $ ( this ) . attr ( " data-id " );
$ ( " tr.sonof_ " + parent ) . find ( " input[type=checkbox] " ) . each ( function (){
if ( $ ( this ) . is ( " :checked " )){
$ ( this ) . click ();
}
});
$ ( this ) . parent () . parent () . find ( " .verificato " ) . addClass ( " hidden " );
}
})
},
error : function () {
renderMessages ();
}
});
2024-03-05 17:31:36 +01:00
}
2024-03-22 15:52:24 +01:00
</ script > ' ;