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 );
$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 ();
echo generaListaComponenti ( $componenti_installati , [
'type' => 'primary' ,
'title' => tr ( 'Componenti installati' ),
'date' => 'data_installazione' ,
'date_name' => tr ( 'Installato' ),
]);
echo generaListaComponenti ( $componenti_sostituiti , [
'type' => 'warning' ,
'title' => tr ( 'Componenti sostituiti' ),
'date' => 'data_sostituzione' ,
'date_name' => tr ( 'Sostituzione' ),
]);
echo generaListaComponenti ( $componenti_rimossi , [
'type' => 'danger' ,
'title' => tr ( 'Componenti rimossi' ),
'date' => 'data_rimozione' ,
'date_name' => tr ( 'Rimosso' ),
]);
function generaListaComponenti ( $componenti , $options )
{
$type = $options [ 'type' ];
$title = $options [ 'title' ];
$date = $options [ 'date' ];
$date_name = $options [ 'date_name' ];
$database = database ();
$plugin = Plugin :: pool ( 'Componenti' );
$module = $plugin -> module ;
if ( empty ( $componenti ) || $componenti -> isEmpty ()) {
return ;
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 " >
< button type = " button " class = " btn btn-box-tool " onclick = " toggleDettagli(this) " >
< 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 " >
< td colspan = " 4 " >
< 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 " >
{[ " type " : " date " , " label " : " '.tr('Data registrazione').' " , " name " : " data_registrazione " , " id " : " data_registrazione_'. $componente->id .' " , " value " : " '. $componente['data_registrazione'] .' " ]}
</ div >
< div class = " col-md-2 " >
{[ " type " : " date " , " label " : " '.tr('Data installazione').' " , " name " : " data_installazione " , " id " : " data_installazione_'. $componente->id .' " , " value " : " '. $componente['data_installazione'] .' " ]}
</ 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 " >
< div class = " col-md-12 " >
{[ " type " : " ckeditor " , " label " : " '.tr('Note').' " , " name " : " note " , " id " : " note_'. $componente->id .' " , " value " : " '. $componente['note'] .' " ]}
</ 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 );
} else {
dettagli . hide ( 500 );
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-05 18:17:26 +02:00
redirect ( " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .'&op=delete&backto=record-edit&id_plugin='. $id_plugin .'&id= " + id_componente + " &hash=tab_'. $structure->id .' " );
2021-06-17 18:33:00 +02:00
}
}
2021-07-07 07:57:10 +02:00
</ script > ' ;