2018-08-30 18:20:30 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$id_module = Modules :: get ( 'Contratti' )[ 'id' ];
$plugin = Plugins :: get ( $id_plugin );
$contratto = $dbo -> fetchOne ( 'SELECT * FROM co_contratti WHERE id = :id' , [
':id' => $id_record ,
]);
2018-08-31 11:39:38 +02:00
$records = $dbo -> fetchArray ( 'SELECT *, (SELECT descrizione FROM in_tipiintervento WHERE idtipointervento=co_promemoria.idtipointervento) AS tipointervento FROM co_promemoria WHERE idcontratto=' . prepare ( $id_record ) . ' ORDER BY data_richiesta ASC' );
2018-08-30 18:20:30 +02:00
// Intervento/promemoria pianificabile
2019-03-22 11:35:26 +01:00
$pianificabile = $dbo -> fetchOne ( 'SELECT is_pianificabile FROM co_staticontratti WHERE id = :id' , [
2018-08-30 18:20:30 +02:00
':id' => $contratto [ 'idstato' ],
2019-03-22 11:35:26 +01:00
])[ 'is_pianificabile' ];
2018-11-30 16:10:15 +01:00
if ( $pianificabile ) {
$pianificabile = ( date ( 'Y' , strtotime ( $contratto [ 'data_accettazione' ])) > 1970 and date ( 'Y' , strtotime ( $contratto [ 'data_conclusione' ])) > 1970 ) ? true : false ;
2018-11-13 13:22:38 +01:00
}
2018-08-30 18:20:30 +02:00
2019-03-22 11:35:26 +01:00
$stati_pianificabili = $dbo -> fetchOne ( 'SELECT GROUP_CONCAT(`descrizione` SEPARATOR ", ") AS stati_pianificabili FROM `co_staticontratti` WHERE `is_pianificabile` = 1' )[ 'stati_pianificabili' ];
2018-08-30 18:20:30 +02:00
echo '
2018-08-31 09:41:43 +02:00
2018-11-13 13:22:38 +01:00
< p > '.tr(' Puoi < b > pianificare dei " promemoria " o direttamente gli interventi </ b > da effettuare entro determinate scadenze . Per poter pianificare i promemoria , il contratto deve avere < b > data accettazione </ b > e < b > data conclusione </ b > definita ed essere in uno dei seguenti stati : < b > '.$stati_pianificabili.' </ b > ').' .
< span class = " tip " title = " '.tr( " I promemoria verranno visualizzati sulla 'Dashboard' e serviranno per semplificare la pianificazione del giorno dell 'intervento, ad esempio nel caso di interventi con cadenza mensile").' " >
< i class = " fa fa-question-circle-o " ></ i >
</ span ></ p > ' ;
2018-08-30 18:20:30 +02:00
// Nessun intervento pianificato
if ( ! empty ( $records )) {
echo '
2018-08-31 09:41:43 +02:00
< br >
< h5 > '.tr(' Lista promemoria ed eventuali interventi associati ').' :</ h5 >
< table class = " table table-condensed table-striped table-hover " >
< thead >
< tr >
< th > '.tr(' Data ').' </ th >
< th > '.tr(' Tipo intervento ').' </ th >
< th > '.tr(' Descrizione ').' </ th >
< th > '.tr(' Intervento ').' </ th >
< th > '.tr(' Sede ').' </ th >
< th > '.tr(' Impianti ').' </ th >
< th > '.tr(' Materiali ').' </ th >
< th > '.tr(' Allegati ').' </ th >
< th class = " text-right " > '.tr(' Opzioni ').' </ th >
</ tr >
</ thead >
< tbody > ' ;
2018-08-30 18:20:30 +02:00
// Elenco promemoria
foreach ( $records as $record ) {
// Sede
if ( $record [ 'idsede' ] == '-1' ) {
2018-08-31 09:41:43 +02:00
echo '- ' . tr ( 'Nessuna' ) . ' -' ;
2018-08-30 18:20:30 +02:00
} elseif ( empty ( $record [ 'idsede' ])) {
$info_sede = tr ( 'Sede legale' );
} else {
2019-05-24 20:27:43 +02:00
$info_sede = $dbo -> fetchOne ( " SELECT id, CONCAT( CONCAT_WS( ' (', CONCAT_WS(', ', nomesede, citta), indirizzo ), ')') AS descrizione FROM an_sedi WHERE id= " . prepare ( $record [ 'idsede' ]))[ 'descrizione' ];
2018-08-30 18:20:30 +02:00
}
// Intervento svolto
if ( ! empty ( $record [ 'idintervento' ])) {
2019-02-07 18:27:15 +01:00
$intervento = $dbo -> fetchOne ( 'SELECT id, codice, IFNULL((SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE idintervento = in_interventi.id), data_richiesta) AS data FROM in_interventi WHERE id = ' . prepare ( $record [ 'idintervento' ]));
2018-08-30 18:20:30 +02:00
2019-02-07 18:27:15 +01:00
$info_intervento = Modules :: link ( 'Interventi' , $intervento [ 'id' ], tr ( 'Intervento num. _NUM_ del _DATE_' , [
'_NUM_' => $intervento [ 'codice' ],
'_DATE_' => Translator :: dateToLocale ( $intervento [ 'data' ]),
2018-08-30 18:20:30 +02:00
]));
$disabled = 'disabled' ;
$title = 'Per eliminare il promemoria, eliminare prima l\'intervento associato.' ;
} else {
$info_intervento = '- ' . ( 'Nessuno' ) . ' -' ;
$disabled = '' ;
$title = 'Elimina promemoria...' ;
}
// data_conclusione contratto
if ( date ( 'Y' , strtotime ( $contratto [ 'data_conclusione' ])) < 1971 ) {
$contratto [ 'data_conclusione' ] = '' ;
}
// info impianti
$info_impianti = '' ;
if ( ! empty ( $record [ 'idimpianti' ])) {
$impianti = $dbo -> fetchArray ( 'SELECT id, matricola, nome FROM my_impianti WHERE id IN (' . ( $record [ 'idimpianti' ]) . ')' );
foreach ( $impianti as $impianto ) {
$info_impianti .= Modules :: link ( 'MyImpianti' , $impianto [ 'id' ], tr ( '_NOME_ (_MATRICOLA_)' , [
'_NOME_' => $impianto [ 'nome' ],
'_MATRICOLA_' => $impianto [ 'matricola' ],
])) . '<br>' ;
}
}
// Info materiali/articoli
2018-08-31 11:39:38 +02:00
$materiali = $dbo -> fetchArray ( 'SELECT id, descrizione,qta,um,prezzo_vendita, \'\' AS idarticolo FROM co_promemoria_righe WHERE id_promemoria = ' . prepare ( $record [ 'id' ]) . '
UNION SELECT id , descrizione , qta , um , prezzo_vendita , idarticolo FROM co_promemoria_articoli WHERE id_promemoria = '.prepare($record[' id ' ]));
2018-08-30 18:20:30 +02:00
$info_materiali = '' ;
foreach ( $materiali as $materiale ) {
$info_materiali .= tr ( ' _QTA_ _UM_ x _DESC_' , [
'_DESC_' => (( ! empty ( $materiale [ 'idarticolo' ])) ? Modules :: link ( 'Articoli' , $materiale [ 'idarticolo' ], $materiale [ 'descrizione' ]) : $materiale [ 'descrizione' ]),
'_QTA_' => Translator :: numberToLocale ( $materiale [ 'qta' ]),
'_UM_' => $materiale [ 'um' ],
'_PREZZO_' => $materiale [ 'prezzo_vendita' ],
]) . '<br>' ;
}
// Info allegati
2018-08-31 11:39:38 +02:00
$allegati = Uploads :: get ([
'id_plugin' => $id_plugin ,
'id_record' => $record [ 'id' ],
]);
2018-08-30 18:20:30 +02:00
$info_allegati = '' ;
foreach ( $allegati as $allegato ) {
$info_allegati .= tr ( ' _NOME_ (_ORIGINAL_)' , [
'_ORIGINAL_' => $allegato [ 'original' ],
2018-08-31 11:39:38 +02:00
'_NOME_' => $allegato [ 'name' ],
2018-08-30 18:20:30 +02:00
]) . '<br>' ;
}
echo '
2018-08-31 09:41:43 +02:00
< tr >
< td > '.Translator::dateToLocale($record[' data_richiesta ']).' <!-- br >< small > '.Translator::dateToLocale($contratto[' data_conclusione ']).' </ small --></ td >
< td > '.$record[' tipointervento '].' </ td >
< td > '.nl2br($record[' richiesta ']).' </ td >
< td > '.$info_intervento.' </ td >
< td > '.$info_sede.' </ td >
< td > '.$info_impianti.' </ td >
< td > '.$info_materiali.' </ td >
< td > '.$info_allegati.' </ td >
< td align = " right " >
2018-11-13 13:22:38 +01:00
< button type = " button " class = " btn btn-warning btn-sm " title = " Pianifica... " data - toggle = " tooltip " onclick = " launch_modal( \ 'Pianifica \ ', \ ''. $plugin->fileurl ('pianficazione.php').'?id_module='. $id_module .'&id_plugin='. $plugin['id'] .'&id_parent='. $id_record .'&id_record='. $record['id'] .' \ '); " '.((!empty($pianificabile)) ? ' ' : ' disabled ').' >
2018-08-31 09:41:43 +02:00
< i class = " fa fa-clock-o " ></ i >
</ button >
< button type = " button " '.$disabled.' class = " btn btn-primary btn-sm '. $disabled .' " title = " Pianifica intervento ora... " data - toggle = " tooltip " onclick = " launch_modal( \ 'Pianifica intervento \ ', \ ''. $rootdir .'/add.php?id_module='.Modules::get('Interventi')['id'].'&ref=interventi_contratti&idcontratto='. $id_record .'&idcontratto_riga='. $record['id'] .' \ '); " '.(!empty($pianificabile) ? ' ' : ' disabled ').' >
< i class = " fa fa-calendar " ></ i >
</ button >
2018-09-26 17:40:04 +02:00
< button type = " button " '.$disabled.' title = " '. $title .' " class = " btn btn-danger btn-sm ask '. $disabled .' " data - op = " delete-promemoria " data - id = " '. $record['id'] .' " data - id_plugin = " '. $id_plugin .' " data - backto = " record-edit " >
2018-08-31 09:41:43 +02:00
< i class = " fa fa-trash " ></ i >
</ button >
</ td >
</ tr > ' ;
2018-08-30 18:20:30 +02:00
}
echo '
2018-08-31 09:41:43 +02:00
</ tbody >
</ table > ' ;
2018-08-30 18:20:30 +02:00
if ( ! empty ( $records )) {
echo '
2018-08-31 09:41:43 +02:00
< br >
< div class = " pull-right " >
< button type = " button " title = " Elimina tutti i promemoria non associati ad intervento " class = " btn btn-danger ask tip " data - op = " delete-non-associati " data - id_plugin = " '. $id_plugin .' " data - backto = " record-edit " >
< i class = " fa fa-trash " ></ i > '.tr(' Elimina promemoria ').'
</ button >
</ div > ' ;
2018-08-30 18:20:30 +02:00
}
}
2018-11-30 16:10:15 +01:00
echo '
2018-11-13 13:22:38 +01:00
< button type = " button " '.((!empty($pianificabile)) ? ' ' : ' disabled ').' title = " Aggiungi un nuovo promemoria da pianificare. " data - toggle = " tooltip " class = " btn btn-primary tip " id = " add_promemoria " >
2018-08-31 09:41:43 +02:00
< i class = " fa fa-plus " ></ i > '.tr(' Nuovo promemoria ').'
</ button > ' ;
2018-11-30 16:10:15 +01:00
2019-08-26 10:25:19 +02:00
$options = $dbo -> fetchArray ( 'SELECT co_contratti_tipiintervento.*, in_tipiintervento.descrizione FROM in_tipiintervento INNER JOIN co_contratti_tipiintervento ON in_tipiintervento.idtipointervento=co_contratti_tipiintervento.idtipointervento WHERE idcontratto=' . prepare ( $id_record ) . ' ORDER BY in_tipiintervento.descrizione' );
2018-08-30 18:20:30 +02:00
echo '
< script type = " text/javascript " >
function askTipoIntervento () {
swal ({
title : " '.tr('Aggiungere un nuovo promemoria?').' " ,
type : " info " ,
showCancelButton : true ,
confirmButtonText : " '.tr('Aggiungi').' " ,
confirmButtonClass : " btn btn-lg btn-success " ,
input : " select " ,
inputOptions : { ' ;
foreach ( $options as $option ) {
echo '
" '. $option['idtipointervento'] .' " : " '. $option['descrizione'] .' " , ' ;
}
echo '
},
inputPlaceholder : " '.tr('Tipo intervento').' " ,
inputValidator : function ( value ) {
return new Promise (( resolve ) => {
if ( value === " " ) {
2019-07-08 18:10:52 +02:00
alert ( " '.tr('Seleziona un tipo intervento').' " );
2018-08-30 18:20:30 +02:00
$ ( " .swal2-select " ) . attr ( " disabled " , false );
$ ( " .swal2-confirm " ) . attr ( " disabled " , false );
$ ( " .swal2-cancel " ) . attr ( " disabled " , false );
} else {
resolve ();
}
})
}
}) . then (
function ( result ) {
2018-09-19 09:57:30 +02:00
var restore = buttonLoading ( " #add_promemoria " );
2018-08-30 18:20:30 +02:00
$ . post ( globals . rootdir + " /actions.php?id_plugin='. $plugin['id'] .'&id_parent='. $id_record .' " , {
op : " add-promemoria " ,
2018-11-13 13:22:38 +01:00
data_richiesta : " '. $contratto['data_accettazione'] .' " ,
2018-08-30 18:20:30 +02:00
idtipointervento : $ ( " .swal2-select " ) . val ()
}) . done ( function ( data ) {
launch_modal ( " Nuovo promemoria " , globals . rootdir + " /plugins/'. $plugin['directory'] .'/pianficazione.php?id_plugin='. $plugin['id'] .'&id_parent='. $id_record .'&id_record= " + data + " &add=1 " );
2018-09-19 09:57:30 +02:00
buttonRestore ( " #add_promemoria " , restore );
2018-08-30 18:20:30 +02:00
});
},
function ( dismiss ) {}
);
}
$ ( " #add_promemoria " ) . click ( function () {
askTipoIntervento ();
});
</ script > ' ;