2018-08-30 18:20:30 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* 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 />.
*/
2018-08-30 18:20:30 +02:00
include_once __DIR__ . '/../../core.php' ;
2020-02-17 13:18:25 +01:00
use Modules\Contratti\Contratto ;
use Modules\Contratti\Stato ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
2018-08-30 18:20:30 +02:00
2020-02-17 13:18:25 +01:00
$contratto = Contratto :: find ( $id_record );
2020-03-31 20:34:31 +02:00
if ( empty ( $contratto )) {
return ;
}
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
$is_pianificabile = $contratto -> stato -> is_pianificabile && ! empty ( $contratto [ 'data_accettazione' ]); // Contratto permette la pianificazione
$elenco_promemoria = $contratto -> promemoria -> sortBy ( 'data_richiesta' );
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
$stati_pianificabili = Stato :: where ( 'is_pianificabile' , 1 ) -> get ();
2024-03-01 11:32:13 +01:00
$elenco_stati = $stati_pianificabili -> implode ( 'name' , ', ' );
2018-08-31 09:41:43 +02:00
2020-03-31 20:34:31 +02:00
echo '
< p > '.tr(' Puoi < b > pianificare dei " promemoria " o direttamente gli interventi </ b > da effettuare entro determinate scadenze ').' . '.tr(' 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 : _LINK_ ' , [
'_LINK_' => '<b>' . $elenco_stati . '</b>' ,
]) . '
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
< 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 > ' ;
2020-02-17 13:18:25 +01:00
2020-03-31 20:34:31 +02:00
echo '
< hr >
< div class = " row " >
< div class = " col-md-9 " >
{[ " type " : " select " , " placeholder " : " '.tr('Tipo di promemoria').' " , " name " : " id_tipo_promemoria " , " required " : 1 , " ajax-source " : " tipiintervento " , " class " : " unblockable " ]}
2020-02-17 13:18:25 +01:00
</ div >
2020-03-31 20:34:31 +02:00
< div class = " col-md-3 " >
< button type = " button " '.(!empty($is_pianificabile) ? ' ' : ' disabled ').' title = " Aggiungi un nuovo promemoria da pianificare. " data - toggle = " tooltip " class = " btn btn-primary btn-block tip " id = " add_promemoria " >
< i class = " fa fa-plus " ></ i > '.tr(' Nuovo promemoria ').'
</ button >
</ div >
</ div >
< hr > ' ;
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
// Nessun intervento pianificato
if ( ! $elenco_promemoria -> isEmpty ()) {
echo '
< 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 > ' ;
// Elenco promemoria
foreach ( $elenco_promemoria as $promemoria ) {
// Sede
if ( $promemoria [ 'idsede' ] == '-1' ) {
echo '- ' . tr ( 'Nessuna' ) . ' -' ;
} elseif ( empty ( $promemoria [ 'idsede' ])) {
$info_sede = tr ( 'Sede legale' );
} else {
$info_sede = $dbo -> fetchOne ( " SELECT id, CONCAT( CONCAT_WS( ' (', CONCAT_WS(', ', nomesede, citta), indirizzo ), ')') AS descrizione FROM an_sedi WHERE id= " . prepare ( $promemoria -> idsede ))[ 'descrizione' ];
}
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
// Intervento svolto
$intervento = $promemoria -> intervento ;
if ( ! empty ( $intervento )) {
$info_intervento = Modules :: link ( 'Interventi' , $intervento [ 'id' ], tr ( 'Intervento num. _NUM_ del _DATE_' , [
'_NUM_' => $intervento -> codice ,
'_DATE_' => dateFormat ( $intervento -> data_richiesta ),
]));
$disabled = 'disabled' ;
$title = 'Per eliminare il promemoria, eliminare prima l\'intervento associato.' ;
} else {
2024-01-15 15:30:45 +01:00
$info_intervento = '- Nessuno -' ;
2020-03-31 20:34:31 +02:00
$disabled = '' ;
$title = 'Elimina promemoria...' ;
}
2020-03-31 20:10:18 +02:00
2020-03-31 20:34:31 +02:00
// Informazioni sugli impianti
$info_impianti = '' ;
if ( ! empty ( $promemoria [ 'idimpianti' ])) {
2024-01-15 15:30:45 +01:00
$impianti = $dbo -> fetchArray ( 'SELECT id, matricola, nome FROM my_impianti WHERE id IN (' . $promemoria [ 'idimpianti' ] . ')' );
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
foreach ( $impianti as $impianto ) {
$info_impianti .= Modules :: link ( 'MyImpianti' , $impianto [ 'id' ], tr ( '_NOME_ (_MATRICOLA_)' , [
'_NOME_' => $impianto [ 'nome' ],
'_MATRICOLA_' => $impianto [ 'matricola' ],
])) . '<br>' ;
2018-08-30 18:20:30 +02:00
}
2020-03-31 20:34:31 +02:00
}
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
// Informazioni sulle righe
$info_righe = '' ;
$righe = $promemoria -> getRighe ();
foreach ( $righe as $riga ) {
$info_righe .= tr ( '_QTA_ _UM_ x _DESC_' , [
'_DESC_' => ( $riga -> isArticolo () ? Modules :: link ( 'Articoli' , $riga [ 'idarticolo' ], $riga [ 'descrizione' ]) : $riga [ 'descrizione' ]),
'_QTA_' => Translator :: numberToLocale ( $riga [ 'qta' ]),
'_UM_' => $riga [ 'um' ],
]) . '<br>' ;
2018-08-30 18:20:30 +02:00
}
2020-03-31 20:34:31 +02:00
// Informazioni sugli allegati
$info_allegati = '' ;
$allegati = $promemoria -> uploads ();
foreach ( $allegati as $allegato ) {
$info_allegati .= tr ( ' _NOME_ (_ORIGINAL_)' , [
'_ORIGINAL_' => $allegato [ 'original_name' ],
'_NOME_' => $allegato [ 'name' ],
]) . '<br>' ;
2018-08-30 18:20:30 +02:00
}
2020-03-31 20:34:31 +02:00
2018-08-30 18:20:30 +02:00
echo '
2020-03-31 20:34:31 +02:00
< tr >
< td > '.Translator::dateToLocale($promemoria[' data_richiesta ']).' </ td >
2024-03-20 11:13:28 +01:00
< td > '.$promemoria->tipo->getTranslation(' name ').' </ td >
2020-03-31 20:34:31 +02:00
< td > '.nl2br($promemoria[' richiesta ']).' </ td >
< td > '.$info_intervento.' </ td >
< td > '.$info_sede.' </ td >
< td > '.$info_impianti.' </ td >
< td > '.$info_righe.' </ td >
< td > '.$info_allegati.' </ td >
2020-07-06 13:19:20 +02:00
< td class = " text-right " >
2020-03-31 20:34:31 +02:00
< button type = " button " class = " btn btn-warning btn-sm " title = " Pianifica... " data - toggle = " tooltip " onclick = " launch_modal( \ 'Pianifica \ ', \ ''. $structure->fileurl ('pianificazione.php').'?id_module='. $id_module .'&id_plugin='. $structure['id'] .'&id_parent='. $id_record .'&id_record='. $promemoria['id'] .' \ '); " '.((!empty($is_pianificabile)) ? ' ' : ' disabled ').' >
< i class = " fa fa-clock-o " ></ i >
</ button >
2024-03-20 11:13:28 +01:00
< button type = " button " '.$disabled.' class = " btn btn-primary btn-sm '. $disabled .' " title = " Pianifica intervento ora... " data - toggle = " tooltip " onclick = " launch_modal( \ 'Pianifica intervento \ ', \ ''.base_path().'/add.php?id_module='.(new Module())->getByField('name', 'Interventi').'&ref=interventi_contratti&idcontratto='. $id_record .'&idcontratto_riga='. $promemoria['id'] .' \ '); " '.(!empty($is_pianificabile) ? ' ' : ' disabled ').' >
2020-03-31 20:34:31 +02:00
< i class = " fa fa-calendar " ></ i >
</ button >
< button type = " button " '.$disabled.' title = " '. $title .' " class = " btn btn-danger btn-sm ask '. $disabled .' " data - op = " delete-promemoria " data - id = " '. $promemoria['id'] .' " data - id_plugin = " '. $id_plugin .' " data - backto = " record-edit " >
< i class = " fa fa-trash " ></ i >
</ button >
</ td >
</ tr > ' ;
2018-08-30 18:20:30 +02:00
}
2020-03-31 20:34:31 +02:00
echo '
</ tbody >
</ table > ' ;
2018-08-30 18:20:30 +02:00
2020-03-31 20:34:31 +02:00
if ( ! empty ( $promemorias )) {
echo '
< 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 > ' ;
}
} else {
2018-08-30 18:20:30 +02:00
echo '
2020-03-31 20:34:31 +02:00
< div class = " alert alert-info " >
< i class = " fa fa-warning " ></ i > '.tr(' Nessun promemoria pianificato per il contratto corrente ').' .
</ div > ' ;
}
echo '
< script type = " text/javascript " >
$ ( " #add_promemoria " ) . click ( function () {
var id_tipo = $ ( " #id_tipo_promemoria " ) . val ();
if ( ! id_tipo ){
swal ( " '.tr('Nessun tipo di promemoria selezionato!').' " , " '.tr('Per continuare devi selezionare una tipologia per il promemoria!').' " , " error " );
return ;
}
2020-03-31 20:10:18 +02:00
2020-03-31 20:34:31 +02:00
var restore = buttonLoading ( " #add_promemoria " );
$ . post ( globals . rootdir + " /actions.php?id_plugin='. $structure['id'] .'&id_parent='. $id_record .' " , {
op : " add-promemoria " ,
2020-08-04 16:29:01 +02:00
data_richiesta : " '. $contratto->data_accettazione .' " ,
2020-03-31 20:34:31 +02:00
idtipointervento : id_tipo ,
}) . done ( function ( data ) {
launch_modal ( " Nuovo promemoria " , globals . rootdir + " /plugins/'. $structure['directory'] .'/pianificazione.php?id_plugin='. $structure['id'] .'&id_parent='. $id_record .'&id_record= " + data + " &add=1 " );
2020-03-31 20:10:18 +02:00
2020-03-31 20:34:31 +02:00
buttonRestore ( " #add_promemoria " , restore );
2020-02-17 13:18:25 +01:00
});
2020-03-31 20:34:31 +02:00
});
</ script > ' ;