2017-08-04 16:28:16 +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 />.
*/
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
use Modules\Interventi\Intervento ;
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2020-08-04 18:33:28 +02:00
// Lettura dei parametri di interesse
2020-08-04 16:29:01 +02:00
$id_anagrafica = filter ( 'idanagrafica' );
$id_sede = filter ( 'idsede' );
$richiesta = filter ( 'richiesta' );
2021-07-16 18:18:10 +02:00
$id_tipo = filter ( 'id_tipo' );
2018-08-11 15:37:38 +02:00
2020-08-04 16:29:01 +02:00
$origine_dashboard = get ( 'ref' ) !== null ;
$module_anagrafiche = Modules :: get ( 'Anagrafiche' );
2021-11-18 14:46:13 +01:00
$id_plugin_sedi = Plugins :: get ( 'Sedi' )[ 'id' ];
2017-09-18 18:11:19 +02:00
2020-08-04 16:29:01 +02:00
// Calcolo dell'orario di inizio e di fine sulla base delle informazioni fornite
$orario_inizio = filter ( 'orario_inizio' );
$orario_fine = filter ( 'orario_fine' );
if ( null == $orario_inizio || '00:00:00' == $orario_inizio ) {
$orario_inizio = date ( 'H' ) . ':00:00' ;
$orario_fine = date ( 'H' , time () + 60 * 60 ) . ':00:00' ;
}
2019-07-11 15:05:36 +02:00
2020-08-04 16:29:01 +02:00
// Un utente del gruppo Tecnici può aprire attività solo a proprio nome
2020-09-15 12:30:25 +02:00
$id_tecnico = filter ( 'id_tecnico' );
2020-08-04 16:29:01 +02:00
if ( $user [ 'gruppo' ] == 'Tecnici' && ! empty ( $user [ 'idanagrafica' ])) {
$id_tecnico = $user [ 'idanagrafica' ];
2020-10-16 08:31:10 +02:00
} elseif ( $user [ 'gruppo' ] == 'Clienti' && ! empty ( $user [ 'idanagrafica' ])) {
2020-10-06 12:29:14 +02:00
$id_cliente = $user [ 'idanagrafica' ];
2017-08-04 16:28:16 +02:00
}
2020-08-04 16:29:01 +02:00
// Stato di default associato all'attivitò
2021-09-22 11:22:03 +02:00
$stato = $dbo -> fetchArray ( " SELECT * FROM in_statiintervento WHERE codice = 'WIP' " );
2020-08-04 16:29:01 +02:00
$id_stato = $stato [ 'idstatointervento' ];
// Se è indicata un'anagrafica relativa, si carica il tipo di intervento di default impostato
if ( ! empty ( $id_anagrafica )) {
$anagrafica = $dbo -> fetchOne ( 'SELECT idtipointervento_default, idzona FROM an_anagrafiche WHERE idanagrafica=' . prepare ( $id_anagrafica ));
2021-07-19 09:40:49 +02:00
$id_tipo = $id_tipo ? : $anagrafica [ 'idtipointervento_default' ];
2020-08-04 16:29:01 +02:00
$id_zona = $anagrafica [ 'idzona' ];
2017-08-04 16:28:16 +02:00
}
2020-08-04 16:29:01 +02:00
// Gestione dell'impostazione dei Contratti
2018-10-25 13:46:16 +02:00
$id_intervento = filter ( 'id_intervento' );
2020-08-04 16:29:01 +02:00
$id_contratto = filter ( 'idcontratto' );
$id_promemoria_contratto = filter ( 'idcontratto_riga' );
2021-03-01 16:32:08 +01:00
$id_ordine = null ;
2020-08-04 16:29:01 +02:00
// Trasformazione di un Promemoria dei Contratti in Intervento
if ( ! empty ( $id_contratto ) && ! empty ( $id_promemoria_contratto )) {
$contratto = $dbo -> fetchOne ( 'SELECT *, (SELECT idzona FROM an_anagrafiche WHERE idanagrafica = co_contratti.idanagrafica) AS idzona FROM co_contratti WHERE id = ' . prepare ( $id_contratto ));
$id_anagrafica = $contratto [ 'idanagrafica' ];
$id_zona = $contratto [ 'idzona' ];
// Informazioni del Promemoria
$promemoria = $dbo -> fetchOne ( 'SELECT *, (SELECT tempo_standard FROM in_tipiintervento WHERE idtipointervento = co_promemoria.idtipointervento) AS tempo_standard FROM co_promemoria WHERE idcontratto=' . prepare ( $id_contratto ) . ' AND id = ' . prepare ( $id_promemoria_contratto ));
$id_tipo = $promemoria [ 'idtipointervento' ];
$data = ( null !== filter ( 'data' )) ? filter ( 'data' ) : $promemoria [ 'data_richiesta' ];
$richiesta = $promemoria [ 'richiesta' ];
$id_sede = $promemoria [ 'idsede' ];
$impianti_collegati = $promemoria [ 'idimpianti' ];
// Generazione dell'orario di fine sulla base del tempo standard definito dal Promemoria
if ( ! empty ( $promemoria [ 'tempo_standard' ])) {
$orario_fine = date ( 'H:i:s' , strtotime ( $orario_inizio ) + (( 60 * 60 ) * $promemoria [ 'tempo_standard' ]));
2018-06-23 18:35:08 +02:00
}
2020-08-04 16:29:01 +02:00
// Caricamento degli impianti a Contratto se non definiti in Promemoria
if ( empty ( $impianti_collegati )) {
$rs = $dbo -> fetchArray ( 'SELECT idimpianto FROM my_impianti_contratti WHERE idcontratto = ' . prepare ( $id_contratto ));
$impianti_collegati = implode ( ',' , array_column ( $rs , 'idimpianto' ));
2018-06-23 18:35:08 +02:00
}
2017-08-04 16:28:16 +02:00
}
2020-08-04 16:29:01 +02:00
// Gestione dell'aggiunta di una sessione a un Intervento senza sessioni (Promemoria intervento) da Dashboard
2018-09-20 09:21:34 +02:00
elseif ( ! empty ( $id_intervento )) {
2020-08-04 16:29:01 +02:00
$intervento = $dbo -> fetchOne ( 'SELECT *, (SELECT idcontratto FROM co_promemoria WHERE idintervento = in_interventi.id LIMIT 0,1) AS idcontratto, in_interventi.id_preventivo as idpreventivo, (SELECT tempo_standard FROM in_tipiintervento WHERE idtipointervento = in_interventi.idtipointervento) AS tempo_standard FROM in_interventi WHERE id = ' . prepare ( $id_intervento ));
$id_tipo = $intervento [ 'idtipointervento' ];
$data = ( null !== filter ( 'data' )) ? filter ( 'data' ) : $intervento [ 'data_richiesta' ];
$data_richiesta = $intervento [ 'data_richiesta' ];
$data_scadenza = $intervento [ 'data_scadenza' ];
$richiesta = $intervento [ 'richiesta' ];
$id_sede = $intervento [ 'idsede' ];
$id_anagrafica = $intervento [ 'idanagrafica' ];
$id_cliente_finale = $intervento [ 'idclientefinale' ];
$id_stato = $intervento [ 'idstatointervento' ];
$id_contratto = $intervento [ 'idcontratto' ];
$id_preventivo = $intervento [ 'idpreventivo' ];
$id_zona = $intervento [ 'idzona' ];
// Generazione dell'orario di fine sulla base del tempo standard definito dall'Intervento
if ( ! empty ( $intervento [ 'tempo_standard' ])) {
$orario_fine = date ( 'H:i:s' , strtotime ( $orario_inizio ) + (( 60 * 60 ) * $intervento [ 'tempo_standard' ]));
2018-09-20 09:21:34 +02:00
}
2020-08-04 16:29:01 +02:00
$rs = $dbo -> fetchArray ( 'SELECT idimpianto FROM my_impianti_interventi WHERE idintervento = ' . prepare ( $id_intervento ));
$impianti_collegati = implode ( ',' , array_column ( $rs , 'idimpianto' ));
2018-09-20 09:21:34 +02:00
}
2020-08-04 16:29:01 +02:00
// Selezione dei tecnici assegnati agli impianti selezionati
if ( ! empty ( $impianti_collegati )) {
$tecnici_impianti = $dbo -> fetchArray ( 'SELECT idtecnico FROM my_impianti WHERE id IN (' . prepare ( $impianti_collegati ) . ')' );
$id_tecnico = array_unique ( array_column ( $tecnici_impianti , 'idtecnico' ));
2020-02-14 11:46:44 +01:00
}
2020-08-04 16:29:01 +02:00
// Impostazione della data se mancante
2017-08-04 16:28:16 +02:00
if ( empty ( $data )) {
2020-08-04 16:29:01 +02:00
$data = filter ( 'data' );
if ( null == $data ) {
2020-02-14 11:46:44 +01:00
$data = date ( 'Y-m-d' );
2017-08-04 16:28:16 +02:00
}
}
2020-08-04 16:29:01 +02:00
// Impostazione della data di fine da Dashboard
if ( empty ( $data_fine )) {
$data_fine = filter ( 'data_fine' );
if ( null == $data_fine ) {
2021-05-17 17:35:48 +02:00
$data_fine = $data ;
2020-08-04 16:29:01 +02:00
}
}
2020-02-14 11:46:44 +01:00
$data_fine = $data_fine ? : $data ;
2020-08-04 16:29:01 +02:00
$inizio_sessione = $data . ' ' . $orario_inizio ;
$fine_sessione = $data_fine . ' ' . $orario_fine ;
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
// Calcolo del nuovo codice
$new_codice = Intervento :: getNextCodice ( $data );
2018-09-19 15:12:20 +02:00
2020-08-04 16:29:01 +02:00
echo '
< form action = " " method = " post " id = " add-form " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " op " value = " add " >
2020-08-04 16:29:01 +02:00
< input type = " hidden " name = " ref " value = " '.get('ref').' " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
2019-11-19 16:06:50 +01:00
<!-- Fix creazione da Anagrafica -->
2020-08-04 16:29:01 +02:00
< input type = " hidden " name = " id_record " value = " " > ' ;
2019-11-19 16:06:50 +01:00
2020-08-04 16:29:01 +02:00
if ( ! empty ( $id_promemoria_contratto )) {
echo '<input type="hidden" name="idcontratto_riga" value="' . $id_promemoria_contratto . '">' ;
2018-09-20 09:21:34 +02:00
}
if ( ! empty ( $id_intervento )) {
echo '<input type="hidden" name="id_intervento" value="' . $id_intervento . '">' ;
}
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
echo '
2020-08-04 18:33:28 +02:00
< div class = " row " >
< div class = " col-md-4 " >
2020-10-16 08:31:10 +02:00
{[ " type " : " select " , " label " : " '.tr('Cliente').' " , " name " : " idanagrafica " , " required " : 1 , " value " : " '.(! $id_cliente ? $id_anagrafica : $id_cliente ).' " , " ajax-source " : " clienti " , " icon-after " : " add|'. $module_anagrafiche['id'] .'|tipoanagrafica=Cliente&readonly_tipo=1 " , " readonly " : " '.((empty( $id_anagrafica ) && empty( $id_cliente )) ? 0 : 1).' " ]}
2020-08-04 18:33:28 +02:00
</ div >
2021-07-15 17:35:46 +02:00
< div class = " col-md-4 " >
2021-11-18 14:46:13 +01:00
{[ " type " : " select " , " label " : " '.tr('Sede destinazione').' " , " name " : " idsede_destinazione " , " value " : " '. $id_sede .' " , " ajax-source " : " sedi " , " icon-after " : " add|'. $module_anagrafiche['id'] .'|id_plugin='. $id_plugin_sedi .'&id_parent='. $id_anagrafica .' " ]}
2021-07-15 17:35:46 +02:00
</ div >
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Per conto di').' " , " name " : " idclientefinale " , " value " : " '. $id_cliente_finale .' " , " ajax-source " : " clienti " ]}
</ div >
2021-03-01 16:32:08 +01:00
</ div >
2020-08-04 18:33:28 +02:00
2021-03-01 16:32:08 +01:00
< div class = " row " >
2020-08-04 18:33:28 +02:00
< div class = " col-md-4 " >
2021-03-01 16:32:08 +01:00
{[ " type " : " select " , " label " : " '.tr('Preventivo').' " , " name " : " idpreventivo " , " value " : " '. $id_preventivo .' " , " ajax-source " : " preventivi " , " readonly " : " '.(empty( $id_preventivo ) ? 0 : 1).' " , " select-options " : '.json_encode([' idanagrafica ' => $id_anagrafica]).' ]}
2020-08-04 18:33:28 +02:00
</ div >
< div class = " col-md-4 " >
2021-03-01 16:32:08 +01:00
{[ " type " : " select " , " label " : " '.tr('Contratto').' " , " name " : " idcontratto " , " value " : " '. $id_contratto .' " , " ajax-source " : " contratti " , " readonly " : " '.(empty( $id_contratto ) ? 0 : 1).' " , " select-options " : '.json_encode([' idanagrafica ' => $id_anagrafica]).' ]}
2020-08-04 18:33:28 +02:00
</ div >
2021-03-01 15:01:02 +01:00
< div class = " col-md-4 " >
2021-03-01 16:32:08 +01:00
{[ " type " : " select " , " label " : " '.tr('Ordine').' " , " name " : " idordine " , " ajax-source " : " ordini-cliente " , " value " : " '. $id_ordine .' " , " select-options " : '.json_encode([' idanagrafica ' => $id_anagrafica]).' ]}
2021-03-01 15:01:02 +01:00
</ div >
2021-03-01 16:32:08 +01:00
</ div >
2021-03-01 15:01:02 +01:00
2021-03-01 16:32:08 +01:00
< div class = " row " >
2020-08-04 18:33:28 +02:00
< div class = " col-md-4 " >
{[ " type " : " timestamp " , " label " : " '.tr('Data/ora richiesta').' " , " name " : " data_richiesta " , " required " : 1 , " value " : " '.( $data_richiesta ?: '-now-').' " ]}
</ div >
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Tipo').' " , " name " : " idtipointervento " , " required " : 1 , " values " : " query=SELECT idtipointervento AS id, descrizione FROM in_tipiintervento ORDER BY descrizione ASC " , " value " : " '. $id_tipo .' " , " ajax-source " : " tipiintervento " ]}
</ div >
2021-03-01 16:32:08 +01:00
< div class = " col-md-4 " >
2020-08-04 18:33:28 +02:00
{[ " type " : " select " , " label " : " '.tr('Stato').' " , " name " : " idstatointervento " , " required " : 1 , " values " : " query=SELECT idstatointervento AS id, descrizione, colore AS _bgcolor_ FROM in_statiintervento WHERE deleted_at IS NULL " , " value " : " '. $id_stato .' " ]}
</ div >
2021-03-01 16:32:08 +01:00
</ div >
2020-08-04 18:33:28 +02:00
2021-03-01 16:32:08 +01:00
< div class = " row " >
< div class = " col-md-12 " >
2021-03-29 18:31:23 +02:00
{[ " type " : " ckeditor " , " label " : " '.tr('Richiesta').' " , " name " : " richiesta " , " id " : " richiesta_add " , " required " : 1 , " value " : " '. $richiesta .' " , " extra " : " style= \ 'max-height:80px; \ ' " ]}
2020-08-04 18:33:28 +02:00
</ div >
2020-08-04 18:37:53 +02:00
</ div > ' ;
2020-08-04 18:33:28 +02:00
2020-08-04 18:37:53 +02:00
$espandi_dettagli = setting ( 'Espandi automaticamente la sezione "Dettagli aggiuntivi"' );
echo '
2020-08-04 18:33:28 +02:00
<!-- DATI AGGIUNTIVI -->
2021-10-25 19:25:20 +02:00
< div class = " box box-info collapsable '.(empty( $espandi_dettagli ) ? 'collapsed-box' : '').' " >
2020-08-04 18:33:28 +02:00
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Dettagli aggiuntivi ').' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
2020-08-04 18:37:53 +02:00
< i class = " fa fa-'.(empty( $espandi_dettagli ) ? 'plus' : 'minus').' " ></ i >
2020-08-04 18:33:28 +02:00
</ button >
</ div >
</ div >
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
< div class = " box-body " >
2017-08-04 16:28:16 +02:00
< div class = " row " >
2020-08-04 18:33:28 +02:00
< div class = " col-md-4 " >
{[ " type " : " timestamp " , " label " : " '.tr('Data/ora scadenza').' " , " name " : " data_scadenza " , " required " : 0 , " value " : " '. $data_scadenza .' " ]}
2018-10-26 01:00:44 +02:00
</ div >
2020-08-04 18:33:28 +02:00
< div class = " col-md-4 " >
2020-08-18 09:53:58 +02:00
{[ " type " : " select " , " label " : " '.tr('Impianto').' " , " multiple " : 1 , " name " : " idimpianti[] " , " value " : " '. $impianti_collegati .' " , " ajax-source " : " impianti-cliente " , " select-options " : { " idanagrafica " : '.($id_anagrafica ?: ' " " ').' }, " icon-after " : " add|'.Modules::get('Impianti')['id'].'|id_anagrafica='. $id_anagrafica .' " ]}
2018-10-26 01:00:44 +02:00
</ div >
2020-08-04 18:33:28 +02:00
< div class = " col-md-4 " >
2020-08-04 16:29:01 +02:00
{[ " type " : " select " , " label " : " '.tr('Componenti').' " , " multiple " : 1 , " name " : " componenti[] " , " placeholder " : " '.tr('Seleziona prima un impianto').' " , " ajax-source " : " componenti " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
2020-08-04 19:04:53 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
2020-08-04 19:04:53 +02:00
if ( empty ( $id_intervento )) {
echo '
2020-08-04 18:33:28 +02:00
<!-- ASSEGNAZIONE TECNICI -->
< div class = " box box-info collapsable collapsed-box " >
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Assegnazione tecnici ').' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
< i class = " fa fa-plus " ></ i >
</ button >
</ div >
2017-08-04 16:28:16 +02:00
</ div >
2020-08-04 18:33:28 +02:00
< div class = " box-body " >
< div class = " row " >
2020-11-06 19:24:11 +01:00
< div class = " col-md-12 " >
{[ " type " : " select " , " label " : " '.tr('Tecnici assegnati').' " , " multiple " : " 1 " , " name " : " tecnici_assegnati[] " , " ajax-source " : " tecnici " , " value " : " " , " icon-after " : " add|'. $module_anagrafiche['id'] .'|tipoanagrafica=Tecnico " ]}
< div class = " row " >
< div class = " col-md-12 " >
< div class = " btn-group " >
2020-11-20 16:25:26 +01:00
< button type = " button " class = " btn btn-xs btn-primary " onclick = " assegnaTuttiTecnici() " >
2020-11-06 19:24:11 +01:00
'.tr(' Tutti ').'
</ button >
2020-11-20 16:25:26 +01:00
< button type = " button " class = " btn btn-xs btn-danger " onclick = " deassegnaTuttiTecnici() " >
< i class = " fa fa-times " ></ i >
2020-11-06 19:24:11 +01:00
</ button >
</ div >
</ div >
</ div >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
2020-08-04 18:33:28 +02:00
</ div >
2020-08-04 19:04:53 +02:00
</ div > ' ;
}
2017-08-04 16:28:16 +02:00
2020-08-04 19:04:53 +02:00
echo '
2021-10-25 19:25:20 +02:00
<!-- ORE LAVORO -->
< div class = " box box-info collapsable '.( $origine_dashboard ? '' : 'collapsed-box').' " >
2018-09-19 15:12:20 +02:00
< div class = " box-header with-border " >
2021-10-25 19:25:20 +02:00
< h3 class = " box-title " > '.tr(' Ore lavoro ').' </ h3 >
2018-09-19 15:12:20 +02:00
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
2020-08-04 16:29:01 +02:00
< i class = " fa fa-'.( $origine_dashboard ? 'minus' : 'plus').' " ></ i >
2018-09-19 15:12:20 +02:00
</ button >
</ div >
</ div >
< div class = " box-body " >
< div class = " row " >
2021-07-15 17:35:46 +02:00
< div class = " col-md-4 " >
2020-08-04 16:29:01 +02:00
{[ " type " : " timestamp " , " label " : " '.tr('Inizio attività').' " , " name " : " orario_inizio " , " required " : '.($origine_dashboard ? 1 : 0).' , " value " : " '. $inizio_sessione .' " ]}
2018-09-19 15:12:20 +02:00
</ div >
2021-07-15 17:35:46 +02:00
< div class = " col-md-4 " >
2020-08-04 16:29:01 +02:00
{[ " type " : " timestamp " , " label " : " '.tr('Fine attività').' " , " name " : " orario_fine " , " required " : '.($origine_dashboard ? 1 : 0).' , " value " : " '. $fine_sessione .' " ]}
2018-09-19 15:12:20 +02:00
</ div >
2021-07-15 17:35:46 +02:00
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Zona').' " , " name " : " idzona " , " values " : " query=SELECT id, CONCAT_WS( \ ' - \ ', nome, descrizione) AS descrizione FROM an_zone ORDER BY nome " , " placeholder " : " '.tr('Nessuna zona').' " , " help " : " '.tr('La zona viene definita automaticamente in base al cliente selezionato').'. " , " readonly " : " 1 " , " value " : " '. $id_zona .' " ]}
</ div >
2018-09-19 15:12:20 +02:00
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2020-08-04 16:29:01 +02:00
{[ " type " : " select " , " label " : " '.tr('Tecnici').' " , " multiple " : " 1 " , " name " : " idtecnico[] " , " required " : '.($origine_dashboard ? 1 : 0).' , " ajax-source " : " tecnici " , " value " : " '. $id_tecnico .' " , " icon-after " : " add|'. $module_anagrafiche['id'] .'|tipoanagrafica=Tecnico||'.(empty( $id_tecnico ) ? '' : 'disabled').' " ]}
2018-09-19 15:12:20 +02:00
</ div >
</ div >
2020-08-17 09:47:18 +02:00
2020-08-24 17:22:52 +02:00
< div id = " info-conflitti-add " ></ div >
2020-08-17 09:47:18 +02:00
2018-09-19 15:12:20 +02:00
</ div >
</ div >
2021-09-22 11:22:03 +02:00
<!-- RICORRENZA -->
2021-10-25 19:25:20 +02:00
< div class = " box box-info collapsable collapsed-box " >
2021-09-22 11:22:03 +02:00
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Ricorrenza ').' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
< i class = " fa fa-plus " ></ i >
</ button >
</ div >
</ div >
< div class = " box-body " >
< div class = " row " >
< div class = " col-md-4 " >
2021-10-25 19:25:20 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Attività ricorrente').' " , " name " : " ricorsiva " , " value " : " " ]}
2021-09-22 11:22:03 +02:00
</ div >
< div class = " col-md-4 ricorrenza " >
{[ " type " : " timestamp " , " label " : " '.tr('Data/ora inizio').' " , " name " : " data_inizio_ricorrenza " , " value " : " '.( $data_richiesta ?: '-now-').' " ]}
</ div >
< div class = " col-md-4 ricorrenza " >
{[ " type " : " number " , " label " : " '.tr('Periodicità').' " , " name " : " periodicita " , " decimals " : " 0 " , " icon-after " : " choice|period|months " , " value " : " 1 " ]}
</ div >
</ div >
< div class = " row ricorrenza " >
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Metodo fine ricorrenza').' " , " name " : " metodo_ricorrenza " , " values " : " list= \" data \" : \" Data fine \" , \" numero \" : \" Numero ricorrenze \" " ]}
</ div >
< div class = " col-md-4 " >
{[ " type " : " timestamp " , " label " : " '.tr('Data/ora fine').' " , " name " : " data_fine_ricorrenza " ]}
</ div >
< div class = " col-md-4 " >
{[ " type " : " number " , " label " : " '.tr('Numero ricorrenze').' " , " name " : " numero_ricorrenze " , " decimals " : " 0 " ]}
</ div >
</ div >
< div class = " row ricorrenza " >
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Stato ricorrenze').' " , " name " : " idstatoricorrenze " , " values " : " query=SELECT idstatointervento AS id, descrizione, colore AS _bgcolor_ FROM in_statiintervento WHERE deleted_at IS NULL AND is_completato=0 " ]}
</ div >
< div class = " col-md-4 " >
{[ " type " : " checkbox " , " label " : " '.tr('Riporta sessioni di lavoro').' " , " name " : " riporta_sessioni " , " value " : " " ]}
</ div >
</ div >
</ div >
</ div >
2021-06-28 18:44:27 +02:00
<!-- DETTAGLI CLIENTE -->
2021-10-25 19:25:20 +02:00
< div class = " box box-info collapsable collapsed-box " >
2021-06-28 18:44:27 +02:00
< div class = " box-header with-border " >
< h3 class = " box-title " > '.tr(' Dettagli cliente ').' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
< i class = " fa fa-plus " ></ i >
</ button >
</ div >
</ div >
2021-07-16 14:44:43 +02:00
< div class = " box-body " id = " dettagli_cliente " >
2021-10-25 19:25:20 +02:00
'.tr(' Seleziona prima un cliente ').' ...
2021-06-28 18:44:27 +02:00
</ div >
</ div >
2017-08-04 16:28:16 +02:00
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
2020-08-04 16:29:01 +02:00
< button type = " button " class = " btn btn-primary " onclick = " salva(this) " >
< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').'
</ button >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
2020-10-20 14:12:53 +02:00
</ form > ' ;
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
if ( ! empty ( $id_intervento )) {
echo '
2017-08-04 16:28:16 +02:00
< script type = " text/javascript " >
2020-08-04 16:29:01 +02:00
$ ( document ) . ready ( function () {
input ( " idsede_destinazione " ) . disable ();
input ( " idpreventivo " ) . disable ();
input ( " idcontratto " ) . disable ();
2021-05-17 17:31:03 +02:00
input ( " idordine " ) . disable ();
2020-08-04 16:29:01 +02:00
input ( " idimpianti " ) . disable ();
input ( " componenti " ) . disable ();
input ( " idanagrafica " ) . disable ();
input ( " idclientefinale " ) . disable ();
input ( " idzona " ) . disable ();
input ( " idtipointervento " ) . disable ();
input ( " idstatointervento " ) . disable ();
input ( " data_richiesta " ) . disable ();
});
</ script > ' ;
}
2018-09-20 09:21:34 +02:00
2020-08-04 16:29:01 +02:00
// Disabilito i campi che non devono essere modificati per poter collegare l'Intervento al Promemoria del Contratto
if ( ! empty ( $id_contratto ) && ! empty ( $id_promemoria_contratto )) {
2018-09-20 09:21:34 +02:00
echo '
2020-08-04 16:29:01 +02:00
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
input ( " idanagrafica " ) . disable ();
input ( " idclientefinale " ) . disable ();
input ( " idzona " ) . disable ();
input ( " idtipointervento " ) . disable ();
});
</ script > ' ;
2018-09-20 09:21:34 +02:00
}
2020-08-04 16:29:01 +02:00
echo '
< script type = " text/javascript " >
var anagrafica = input ( " idanagrafica " );
var sede = input ( " idsede_destinazione " );
var contratto = input ( " idcontratto " );
var preventivo = input ( " idpreventivo " );
2021-03-01 16:32:08 +01:00
var ordine = input ( " idordine " );
2020-08-04 16:29:01 +02:00
$ ( document ) . ready ( function () {
if ( ! anagrafica . get ()){
sede . disable ();
2021-03-01 16:32:08 +01:00
preventivo . disable ();
contratto . disable ();
ordine . disable ();
2020-08-04 16:29:01 +02:00
input ( " idimpianti " ) . disable ();
input ( " componenti " ) . disable ();
}
// Quando modifico orario inizio, allineo anche l\'orario fine
let orario_inizio = input ( " orario_inizio " ) . getElement ();
let orario_fine = input ( " orario_fine " ) . getElement ();
orario_inizio . on ( " dp.change " , function ( e ) {
orario_fine . data ( " DateTimePicker " ) . minDate ( e . date );
orario_fine . change ();
2017-08-04 16:28:16 +02:00
});
2018-03-24 14:24:17 +01:00
2018-03-14 11:27:58 +01:00
// Refresh modulo dopo la chiusura di una pianificazione attività derivante dalle attività
// da pianificare, altrimenti il promemoria non si vede più nella lista a destra
2018-11-13 14:51:19 +01:00
// TODO: da gestire via ajax
2020-08-04 16:29:01 +02:00
if ( $ ( " input[name=idcontratto_riga] " ) . val ()) {
$ ( " #modals > div button.close " ) . on ( " click " , function () {
2018-03-14 11:27:58 +01:00
location . reload ();
});
}
2021-09-22 11:22:03 +02:00
// Ricorrenza
$ ( " .ricorrenza " ) . addClass ( " hidden " );
2017-08-04 16:28:16 +02:00
});
2020-08-17 09:47:18 +02:00
input ( " idtecnico " ) . change ( function () {
calcolaConflittiTecnici ();
});
2020-08-04 16:29:01 +02:00
// Gestione della modifica dell\'anagrafica
anagrafica . change ( function () {
2021-07-16 14:44:43 +02:00
let value = $ ( this ) . val ();
updateSelectOption ( " idanagrafica " , value );
session_set ( " superselect,idanagrafica " , value , 0 );
2017-08-04 16:28:16 +02:00
2021-07-16 14:44:43 +02:00
let selected = ! $ ( this ) . val ();
let placeholder = selected ? " '.tr('Seleziona prima un cliente').' " : " '.tr( " Seleziona un 'opzione").' " ;
2017-08-04 16:28:16 +02:00
2021-07-16 14:44:43 +02:00
sede . setDisabled ( selected )
2020-08-04 16:29:01 +02:00
. getElement () . selectReset ( placeholder );
2017-08-04 16:28:16 +02:00
2021-07-16 14:44:43 +02:00
preventivo . setDisabled ( selected )
2021-03-01 16:32:08 +01:00
. getElement () . selectReset ( placeholder );
2021-07-16 14:44:43 +02:00
contratto . setDisabled ( selected )
2020-08-04 16:29:01 +02:00
. getElement () . selectReset ( placeholder );
2017-08-04 16:28:16 +02:00
2021-07-16 14:44:43 +02:00
ordine . setDisabled ( selected )
2020-08-04 16:29:01 +02:00
. getElement () . selectReset ( placeholder );
2017-08-04 16:28:16 +02:00
2021-07-16 14:44:43 +02:00
input ( " idimpianti " ) . setDisabled ( selected );
2018-06-23 18:35:08 +02:00
2020-08-04 16:29:01 +02:00
let data = anagrafica . getData ();
if ( data ) {
input ( " idzona " ) . set ( data . idzona ? data . idzona : " " );
// session_set("superselect,idzona", $(this).selectData().idzona, 0);
2018-02-20 16:46:23 +01:00
2020-08-04 16:29:01 +02:00
// Impostazione del tipo intervento da anagrafica
input ( " idtipointervento " ) . getElement ()
2020-08-04 18:33:28 +02:00
. selectSetNew ( data . idtipointervento , data . idtipointervento_descrizione );
2018-02-15 12:22:21 +01:00
}
2021-06-28 18:44:27 +02:00
if ( data !== undefined ) {
2021-07-16 14:44:43 +02:00
// Carico nel panel i dettagli del cliente
$ . get ( " '.base_path().'/ajax_complete.php?module=Interventi&op=dettagli&id_anagrafica= " + value , function ( data ){
$ ( " #dettagli_cliente " ) . html ( data );
2021-06-28 18:44:27 +02:00
});
2021-07-16 14:44:43 +02:00
} else {
$ ( " #dettagli_cliente " ) . html ( " '.tr('Seleziona prima un cliente').'... " );
2021-06-28 18:44:27 +02:00
}
2021-11-18 14:46:13 +01:00
plus_sede = $ ( " #idsede_destinazione " ) . parent () . find ( " .btn " );
plus_sede . attr ( " onclick " , plus_sede . attr ( " onclick " ) . replace ( / id_parent = [ 0 - 9 ] */ , " id_parent= " + value ));
plus_impianto = $ ( " #idimpianti " ) . parent () . find ( " .btn " );
plus_impianto . attr ( " onclick " , plus_impianto . attr ( " onclick " ) . replace ( / id_anagrafica = [ 0 - 9 ] */ , " id_anagrafica= " + value ));
2017-08-04 16:28:16 +02:00
});
2020-08-04 16:29:01 +02:00
// Gestione della modifica della sede selezionato
sede . change ( function () {
2020-08-17 10:57:51 +02:00
updateSelectOption ( " idsede_destinazione " , $ ( this ) . val ());
2020-08-04 16:29:01 +02:00
session_set ( " superselect,idsede_destinazione " , $ ( this ) . val (), 0 );
input ( " idimpianti " ) . getElement () . selectReset ();
let data = sede . getData ();
if ( data ) {
input ( " idzona " ) . set ( data . idzona ? data . idzona : " " );
// session_set("superselect,idzona", $(this).selectData().idzona, 0);
2018-02-15 12:22:21 +01:00
}
2017-08-04 16:28:16 +02:00
});
2021-03-01 16:32:08 +01:00
// Gestione della modifica dell\'ordine selezionato
ordine . change ( function () {
if ( ordine . get ()) {
contratto . getElement () . selectReset ();
preventivo . getElement () . selectReset ();
}
});
2020-08-04 16:29:01 +02:00
// Gestione della modifica del preventivo selezionato
preventivo . change ( function () {
2021-03-01 16:32:08 +01:00
if ( preventivo . get ()){
2020-08-04 16:29:01 +02:00
contratto . getElement () . selectReset ();
2021-03-01 16:32:08 +01:00
ordine . getElement () . selectReset ();
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
input ( " idtipointervento " ) . getElement ()
. selectSetNew ( $ ( this ) . selectData () . idtipointervento , $ ( this ) . selectData () . idtipointervento_descrizione );
2017-08-04 16:28:16 +02:00
}
});
2020-08-04 16:29:01 +02:00
// Gestione della modifica del contratto selezionato
contratto . change ( function () {
2021-03-01 16:32:08 +01:00
if ( contratto . get ()){
2020-08-04 16:29:01 +02:00
preventivo . getElement () . selectReset ();
2021-03-01 16:32:08 +01:00
ordine . getElement () . selectReset ();
2020-08-04 16:29:01 +02:00
$ ( " input[name=idcontratto_riga] " ) . val ( " " );
}
2017-08-04 16:28:16 +02:00
});
2018-06-23 18:35:08 +02:00
2020-08-04 16:29:01 +02:00
// Gestione delle modifiche agli impianti selezionati
input ( " idimpianti " ) . change ( function () {
2020-08-17 16:25:01 +02:00
updateSelectOption ( " matricola " , $ ( this ) . val ());
session_set ( " superselect,matricola " , $ ( this ) . val (), 0 );
2020-04-20 13:09:55 +02:00
2020-08-04 16:29:01 +02:00
input ( " componenti " ) . setDisabled ( ! $ ( this ) . val ())
. getElement () . selectReset ();
}); ' ;
2020-07-02 15:56:32 +02:00
2020-08-04 16:29:01 +02:00
if ( filter ( 'orario_fine' ) !== null ) {
echo '
// Automatismo del tempo standard
input ( " idtipointervento " ) . change ( function () {
let data = $ ( this ) . selectData ();
if ( data && data . tempo_standard > 0 ) {
let orario_inizio = input ( " orario_inizio " ) . get ();
if ( moment ( orario_inizio , globals . timestamp_format , globals . locale ) . isValid ()) {
let tempo_standard = data . tempo_standard * 60 ;
let nuovo_orario_fine = moment ( orario_inizio ) . add ( tempo_standard , " m " );
input ( " orario_fine " ) . set ( moment ( nuovo_orario_fine ) . format ( globals . timestamp_format ));
2020-03-10 18:58:40 +01:00
}
2018-05-21 12:33:07 +02:00
}
2020-08-04 16:29:01 +02:00
}); ' ;
}
2018-11-23 17:58:59 +01:00
2020-08-04 16:29:01 +02:00
if ( ! $origine_dashboard ) {
echo '
input ( " idtecnico " ) . change ( function () {
var value = $ ( this ) . val () > 0 ? true : false ;
input ( " orario_inizio " ) . setRequired ( value );
input ( " orario_fine " ) . setRequired ( value );
input ( " data " ) . setRequired ( value );
}); ' ;
}
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
echo '
var ref = " '.get('ref').' " ;
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
async function salva ( button ) {
// Submit attraverso ricaricamento della pagina
if ( ! ref ) {
$ ( " #add-form " ) . submit ();
return ;
}
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
// Submit dinamico tramite AJAX
2021-03-29 18:31:23 +02:00
let response = await salvaForm ( " #add-form " , {
2020-08-04 18:33:28 +02:00
id_module : " '. $id_module .' " , // Fix creazione da Dashboard
2021-03-29 18:31:23 +02:00
}, button );
2018-11-23 17:58:59 +01:00
2020-08-04 16:29:01 +02:00
// Se l\'aggiunta intervento proviene dalla scheda di pianificazione ordini di servizio della dashboard, la ricarico
if ( ref == " dashboard " ) {
$ ( " #modals > div " ) . modal ( " hide " );
2018-11-23 17:58:59 +01:00
2020-08-04 16:29:01 +02:00
// Aggiornamento elenco interventi da pianificare
$ ( " #calendar " ) . fullCalendar ( " refetchEvents " );
$ ( " #calendar " ) . fullCalendar ( " render " );
}
2017-08-04 16:28:16 +02:00
2020-08-04 16:29:01 +02:00
// Se l\'aggiunta intervento proviene dai contratti, faccio il submit via ajax e ricarico la tabella dei contratti
else if ( ref == " interventi_contratti " ) {
$ ( " #modals > div " ) . modal ( " hide " );
parent . window . location . reload ();
//TODO: da gestire via ajax
//$("#elenco_interventi > tbody").load(globals.rootdir + "/modules/contratti/plugins/contratti.pianificazioneinterventi.php?op=get_interventi_pianificati&idcontratto='.$id_contratto.'");
2017-08-04 16:28:16 +02:00
}
2020-08-04 16:29:01 +02:00
}
2020-08-17 09:47:18 +02:00
function calcolaConflittiTecnici () {
let tecnici = input ( " idtecnico " ) . get ();
2020-08-24 17:22:52 +02:00
return $ ( " #info-conflitti-add " ) . load ( " '. $module->fileurl ('occupazione_tecnici.php').' " , {
2020-08-17 09:47:18 +02:00
" id_module " : globals . id_module ,
" tecnici[] " : tecnici ,
" inizio " : input ( " orario_inizio " ) . get (),
" fine " : input ( " orario_fine " ) . get (),
});
}
2020-11-20 16:25:26 +01:00
function assegnaTuttiTecnici () {
deassegnaTuttiTecnici ();
$ . getJSON ( globals . rootdir + " /ajax_select.php?op=tecnici " , function ( response ) {
let input_tecnici = input ( " tecnici_assegnati " ) . getElement ();
$ . each ( response . results , function ( key , result ) {
input_tecnici . append ( `<option value="` + result [ " id " ] + `">` + result [ " descrizione " ] + `</option>` );
input_tecnici . find ( " option " ) . prop ( " selected " , true );
});
$ ( " #tecnici_assegnati " ) . trigger ( " change " );
});
}
function deassegnaTuttiTecnici () {
input ( " tecnici_assegnati " ) . getElement () . selectReset ();
}
2021-09-22 11:22:03 +02:00
$ ( " #ricorsiva " ) . on ( " change " , function (){
if ( $ ( this ) . is ( " :checked " )) {
$ ( " .ricorrenza " ) . removeClass ( " hidden " );
$ ( " #data_inizio_ricorrenza " ) . attr ( " required " , true );
$ ( " #metodo_ricorrenza " ) . attr ( " required " , true );
$ ( " #idstatoricorrenze " ) . attr ( " required " , true );
} else {
$ ( " .ricorrenza " ) . addClass ( " hidden " );
$ ( " #data_inizio_ricorrenza " ) . attr ( " required " , false );
$ ( " #metodo_ricorrenza " ) . attr ( " required " , false );
$ ( " #idstatoricorrenze " ) . attr ( " required " , false );
}
});
$ ( " #metodo_ricorrenza " ) . on ( " change " , function (){
if ( $ ( this ) . val () == " data " ) {
input ( " data_fine_ricorrenza " ) . enable ();
$ ( " #data_fine_ricorrenza " ) . attr ( " required " , true );
input ( " numero_ricorrenze " ) . disable ();
input ( " numero_ricorrenze " ) . set ( " " );
} else {
input ( " numero_ricorrenze " ) . enable ();
input ( " data_fine_ricorrenza " ) . disable ();
input ( " data_fine_ricorrenza " ) . set ( " " );
$ ( " #data_fine_ricorrenza " ) . attr ( " required " , false );
}
});
2020-08-04 16:29:01 +02:00
</ script > ' ;