2021-06-17 18:33:00 +02: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 />.
*/
2021-08-05 18:17:26 +02:00
use Models\Plugin ;
use Plugins\ComponentiImpianti\Componente ;
2021-06-17 18:33:00 +02:00
include_once __DIR__ . '/../../core.php' ;
2021-08-05 18:17:26 +02:00
$compontenti_impianto = Componente :: where ( 'id_impianto' , '=' , $id_record );
2021-08-06 11:06:47 +02:00
// Avviso sul numero di componenti
2021-08-06 11:14:37 +02:00
if ( $compontenti_impianto -> count () == 0 ) {
2021-08-06 11:06:47 +02:00
echo '
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i > '.tr("Nessun componente disponibile per l' impianto corrente " ).'
</ div > ' ;
}
2021-08-05 18:17:26 +02:00
$componenti_installati = ( clone $compontenti_impianto )
-> whereNull ( 'data_sostituzione' )
-> whereNull ( 'data_rimozione' )
-> get ();
$componenti_sostituiti = ( clone $compontenti_impianto )
-> whereNotNull ( 'data_sostituzione' )
-> get ();
$componenti_rimossi = ( clone $compontenti_impianto )
-> whereNotNull ( 'data_rimozione' )
-> get ();
2021-08-06 11:06:47 +02:00
$elenchi = [
[
'componenti' => $componenti_installati ,
'type' => 'primary' ,
'title' => tr ( 'Componenti installati' ),
'date' => 'data_installazione' ,
'date_name' => tr ( 'Installato' ),
],
[
'componenti' => $componenti_sostituiti ,
'type' => 'warning' ,
'title' => tr ( 'Componenti sostituiti' ),
'date' => 'data_sostituzione' ,
'date_name' => tr ( 'Sostituzione' ),
],
[
'componenti' => $componenti_rimossi ,
'type' => 'danger' ,
'title' => tr ( 'Componenti rimossi' ),
'date' => 'data_rimozione' ,
'date_name' => tr ( 'Rimosso' ),
2021-08-06 11:14:37 +02:00
],
2021-08-06 11:06:47 +02:00
];
$plugin = Plugin :: pool ( 'Componenti' );
$module = $plugin -> module ;
// Generazione elenchi HTML
2021-08-06 11:14:37 +02:00
foreach ( $elenchi as $elenco ) {
2021-08-06 11:06:47 +02:00
$componenti = $elenco [ 'componenti' ];
$type = $elenco [ 'type' ];
$title = $elenco [ 'title' ];
$date = $elenco [ 'date' ];
$date_name = $elenco [ 'date_name' ];
2021-08-05 18:17:26 +02:00
if ( empty ( $componenti ) || $componenti -> isEmpty ()) {
2021-08-06 11:06:47 +02:00
continue ;
2021-06-17 18:33:00 +02:00
}
2021-08-05 18:17:26 +02:00
echo '
< div class = " row " >
< div class = " col-md-12 text-center " >
< h4 class = " text-'. $type .' " > '.$title.' </ h4 >
</ div >
</ div >
< hr > ' ;
2021-06-17 18:33:00 +02:00
echo '
2021-08-05 18:17:26 +02:00
< div class = " box collapsed-box box-'. $type .' " >
< div class = " box-header with-border mini " >
< table class = " table " style = " margin:0; padding:0; " >
< thead >
< tr >
< th class = " text-center " > '.tr(' ID ', [], [' upper ' => true]).' </ td >
< th class = " text-center " > '.tr(' Articolo ', [], [' upper ' => true]).' </ td >
< th class = " text-center " width = " 20% " > '.tr($date_name, [], [' upper ' => true]).' </ th >
< th class = " text-center " width = " 20% " > '.tr(' Registrazione ', [], [' upper ' => true]).' </ th >
< th class = " text-center " width = " 10% " > '.tr(' Allegati ', [], [' upper ' => true]).' </ th >
</ tr >
</ thead >
< tbody > ' ;
foreach ( $componenti as $componente ) {
$articolo = $componente -> articolo ;
$numero_allegati = $database -> fetchNum ( 'SELECT id FROM zz_files WHERE id_plugin=' . prepare ( $id_plugin ) . ' AND id_record=' . $componente [ 'id' ] . ' GROUP BY id_record' );
$data = dateFormat ( $componente [ $date ]);
$icona_allegati = $numero_allegati == 0 ? 'fa fa-times text-danger' : 'fa fa-check text-success' ;
echo '
< tr class = " riga-componente " data - id = " '. $componente->id .' " >
< td class = " text-center " > #'.$componente->id.'</td>
< td class = " text-center " > '.$articolo->codice.' - '.$articolo->descrizione.' </ td >
< td class = " text-center " > '.$data.' </ td >
< td class = " text-center " > '.dateFormat($componente->data_registrazione).' </ td >
< td class = " text-center " >
< i class = " '. $icona_allegati .' fa-lg " ></ i >
< div class = " box-tools pull-right " >
2021-08-25 16:54:28 +02:00
< button type = " button " class = " btn btn-box-tool " onclick = " toggleDettagli(this) " >
2021-08-05 18:17:26 +02:00
< i class = " fa fa-plus " ></ i >
</ button >
2021-06-17 18:33:00 +02:00
</ div >
2021-08-05 18:17:26 +02:00
</ td >
</ tr >
< tr class = " dettagli-componente " data - id = " '. $componente->id .' " style = " display: none " >
2021-08-06 11:06:47 +02:00
< td colspan = " 5 " >
2021-08-05 18:17:26 +02:00
< div class = " panel panel-'. $type .' " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Dati ').' </ h3 >
2021-06-17 18:33:00 +02:00
</ div >
2021-08-05 18:17:26 +02:00
< div class = " panel-body " >
< form action = " '.base_path().'/editor.php " method = " post " role = " form " >
< input type = " hidden " name = " id_module " value = " '. $module->id .' " >
< input type = " hidden " name = " id_record " value = " '. $componente->id_impianto .' " >
< input type = " hidden " name = " id_plugin " value = " '. $plugin->id .' " >
< input type = " hidden " name = " id_componente " value = " '. $componente->id .' " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " update " >
< div class = " row " >
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Articolo').' " , " name " : " id_articolo " , " id " : " id_articolo_'. $componente->id .' " , " disabled " : " 1 " , " value " : " '. $componente->id_articolo .' " , " ajax-source " : " articoli " , " select-options " : { " permetti_movimento_a_zero " : 1 } ]}
</ div >
< div class = " col-md-2 " >
2022-02-06 11:22:53 +01:00
{[ " type " : " date " , " label " : " '.tr('Data installazione').' " , " name " : " data_installazione " , " id " : " data_installazione_'. $componente->id .' " , " value " : " '. $componente['data_installazione'] .' " ]}
2021-08-05 18:17:26 +02:00
</ div >
< div class = " col-md-2 " >
2022-02-06 11:22:53 +01:00
{[ " type " : " date " , " label " : " '.tr('Data registrazione').' " , " name " : " data_registrazione " , " id " : " data_registrazione_'. $componente->id .' " , " value " : " '. $componente['data_registrazione'] .' " ]}
2021-08-05 18:17:26 +02:00
</ div >
< div class = " col-md-2 " >
{[ " type " : " date " , " label " : " '.tr('Data rimozione').' " , " name " : " data_rimozione " , " id " : " data_rimozione_'. $componente->id .' " , " value " : " '. $componente['data_rimozione'] .' " ]}
</ div >
</ div >
< div class = " row " >
2023-02-24 13:36:37 +01:00
< div class = " col-md-12 " > ' ;
echo input ([
'type' => 'ckeditor' ,
'label' => tr ( 'Note' ),
'name' => 'note' ,
'id' => 'note_' . $componente -> id ,
'value' => $componente [ 'note' ],
]);
echo '
2021-08-05 18:17:26 +02:00
</ div >
</ div >
<!-- PULSANTI -->
< div class = " row " > ' ;
if ( empty ( $componente -> id_sostituzione )) {
echo '
< div class = " col-md-1 " >
< button type = " button " class = " btn btn-danger " onclick = " rimuoviComponente(this) " >
< i class = " fa fa-trash " ></ i > '.tr(' Rimuovi ').'
</ button >
</ div > ' ;
}
2021-06-17 18:33:00 +02:00
2021-07-07 07:57:10 +02:00
echo '
2021-08-05 18:17:26 +02:00
< div class = " col-md-1 " >
< button type = " button " class = " btn btn-default " onclick = " gestisciAllegati(this) " >
< i class = " fa fa-file-text-o " ></ i > '.tr(' Allegati ( _NUM_ ) ' , [
'_NUM_' => $numero_allegati ,
]) . '
</ button >
</ div > ' ;
if ( empty ( $componente -> id_sostituzione )) {
echo '
< div class = " col-md-9 " >
< button type = " button " class = " btn btn-warning pull-right " onclick = " sostituisciComponente(this) " >
< i class = " fa fa-cog " ></ i > '.tr(' Sostituisci ').'
</ button >
</ div > ' ;
}
echo '
< div class = " col-md-1 pull-right " >
< button type = " submit " class = " btn btn-success pull-right " >
< i class = " fa fa-check " ></ i > '.tr(' Salva ').'
</ button >
</ div >
</ div >
</ form >
2021-06-17 18:33:00 +02:00
</ div >
</ div >
2021-08-05 18:17:26 +02:00
</ td >
</ tr > ' ;
}
echo '
</ tbody >
</ table >
</ div >
</ div > ' ;
2021-06-17 18:33:00 +02:00
}
echo '
< script >
2021-08-05 18:17:26 +02:00
function toggleDettagli ( trigger ) {
const tr = $ ( trigger ) . closest ( " tr " );
const dettagli = tr . next ();
if ( dettagli . css ( " display " ) === " none " ){
dettagli . show ( 500 );
2021-08-25 16:54:28 +02:00
$ ( trigger ) . children () . removeClass ( " fa-plus " );
$ ( trigger ) . children () . addClass ( " fa-minus " );
2021-08-05 18:17:26 +02:00
} else {
dettagli . hide ( 500 );
2021-08-25 16:54:28 +02:00
$ ( trigger ) . children () . removeClass ( " fa-minus " );
$ ( trigger ) . children () . addClass ( " fa-plus " );
2021-06-17 18:33:00 +02:00
}
}
2021-08-05 18:17:26 +02:00
function gestisciAllegati ( trigger ) {
const tr = $ ( trigger ) . closest ( " tr " );
const id_componente = tr . data ( " id " );
openModal ( \ 'Aggiungi file\', \'' . $structure -> fileurl ( 'allegati.php' ) . '?id_module=' . $id_module . '&id_plugin=' . $id_plugin . 'id_record=' . $id_record . ' & id = \ ' + id_componente );
}
function sostituisciComponente ( trigger ) {
const tr = $ ( trigger ) . closest ( " tr " );
const id_componente = tr . data ( " id " );
if ( confirm ( " '.tr('Vuoi sostituire questo componente?').' " )) {
redirect ( " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=sostituisci&backto=record-edit&id_plugin='. $id_plugin .'&id_componente= " + id_componente + " &hash=tab_'. $structure->id .' " );
}
}
function rimuoviComponente ( trigger ) {
const tr = $ ( trigger ) . closest ( " tr " );
const id_componente = tr . data ( " id " );
2021-06-17 18:33:00 +02:00
if ( confirm ( " '.tr('Vuoi eliminare questo componente?').' " )){
2021-08-06 11:34:30 +02:00
redirect ( " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=rimuovi&backto=record-edit&id_plugin='. $id_plugin .'&id_componente= " + id_componente + " &hash=tab_'. $structure->id .' " );
2021-06-17 18:33:00 +02:00
}
}
2021-07-07 07:57:10 +02:00
</ script > ' ;