2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2018-05-05 09:29:09 +02:00
// Rimuovo session usate sui select combinati (sedi, preventivi, contratti, impianti)
2017-08-04 16:28:16 +02:00
unset ( $_SESSION [ 'superselect' ][ 'idanagrafica' ]);
unset ( $_SESSION [ 'superselect' ][ 'idsede' ]);
2018-07-05 09:18:00 +02:00
unset ( $_SESSION [ 'superselect' ][ 'non_fatturato' ]);
2017-08-04 16:28:16 +02:00
2018-09-20 09:21:34 +02:00
// Calcolo del nuovo codice
$idintervento_template = setting ( 'Formato codice intervento' );
$idintervento_template = str_replace ( '#' , '%' , $idintervento_template );
2019-01-04 23:26:38 +01:00
$rs = $dbo -> fetchArray ( 'SELECT codice FROM in_interventi WHERE codice=(SELECT MAX(CAST(codice AS SIGNED)) FROM in_interventi) AND codice LIKE ' . prepare ( Util\Generator :: complete ( $idintervento_template )) . ' ORDER BY codice DESC LIMIT 0,1' );
2018-09-20 09:21:34 +02:00
if ( ! empty ( $rs [ 0 ][ 'codice' ])) {
$new_codice = Util\Generator :: generate ( setting ( 'Formato codice intervento' ), $rs [ 0 ][ 'codice' ]);
}
if ( empty ( $new_codice )) {
2019-01-04 23:26:38 +01:00
$rs = $dbo -> fetchArray ( 'SELECT codice FROM in_interventi WHERE codice LIKE ' . prepare ( Util\Generator :: complete ( $idintervento_template )) . ' ORDER BY codice DESC LIMIT 0,1' );
2018-09-20 09:21:34 +02:00
$new_codice = Util\Generator :: generate ( setting ( 'Formato codice intervento' ), $rs [ 0 ][ 'codice' ]);
}
2017-08-04 16:28:16 +02:00
// Se ho passato l'idanagrafica, carico il tipo di intervento di default
$idanagrafica = filter ( 'idanagrafica' );
$idsede = filter ( 'idsede' );
2018-06-23 18:35:08 +02:00
$idimpianto = null ;
$idzona = null ;
$idtipointervento = null ;
$idstatointervento = null ;
$richiesta = null ;
2017-09-18 18:11:19 +02:00
$impianti = [];
2018-08-11 15:37:38 +02:00
// Come tecnico posso aprire attività solo a mio nome
2018-08-11 11:08:55 +02:00
if ( $user [ 'gruppo' ] == 'Tecnici' && ! empty ( $user [ 'idanagrafica' ])) {
2018-06-26 14:30:26 +02:00
$idtecnico = $user [ 'idanagrafica' ];
} else {
$idtecnico = null ;
2018-06-25 18:25:04 +02:00
}
2017-09-18 18:11:19 +02:00
2017-08-04 16:28:16 +02:00
if ( ! empty ( $idanagrafica )) {
2018-02-23 10:01:48 +01:00
$rs = $dbo -> fetchArray ( 'SELECT idtipointervento_default, idzona FROM an_anagrafiche WHERE idanagrafica=' . prepare ( $idanagrafica ));
2017-08-04 16:28:16 +02:00
$idtipointervento = $rs [ 0 ][ 'idtipointervento_default' ];
2018-03-22 15:40:20 +01:00
$idzona = $rs [ 0 ][ 'idzona' ];
2017-08-04 16:28:16 +02:00
$idstatointervento = 'WIP' ;
$richiesta = filter ( 'richiesta' );
}
// Calcolo orario di inizio e fine di default
2017-09-18 18:11:19 +02:00
if ( null !== filter ( 'orario_inizio' ) && '00:00:00' != filter ( 'orario_inizio' )) {
2017-08-04 16:28:16 +02:00
$orario_inizio = filter ( 'orario_inizio' );
$orario_fine = filter ( 'orario_fine' );
} else {
$orario_inizio = date ( 'H' ) . ':00' ;
$orario_fine = date ( 'H' , time () + 60 * 60 ) . ':00' ;
}
// Se sto pianificando un contratto, leggo tutti i dati del contratto per predisporre l'aggiunta intervento
2018-10-25 16:17:52 +02:00
//ref (intervento,promemoria,ordine)
2018-10-25 13:46:16 +02:00
$id_intervento = filter ( 'id_intervento' );
2017-08-04 16:28:16 +02:00
$idcontratto = filter ( 'idcontratto' );
2018-10-25 16:17:52 +02:00
$idcontratto_riga = filter ( 'idcontratto_riga' );
2017-08-04 16:28:16 +02:00
$idordineservizio = filter ( 'idordineservizio' );
2018-10-25 13:46:16 +02:00
2017-08-04 16:28:16 +02:00
if ( ! empty ( $idcontratto ) && ! empty ( $idordineservizio )) {
2018-02-23 10:01:48 +01:00
$rs = $dbo -> fetchArray ( 'SELECT *, (SELECT idzona FROM an_anagrafiche WHERE idanagrafica = co_contratti.idanagrafica) AS idzona FROM co_contratti WHERE id=' . prepare ( $idcontratto ));
2017-08-04 16:28:16 +02:00
$idanagrafica = $rs [ 0 ][ 'idanagrafica' ];
2018-03-22 15:40:20 +01:00
$idzona = $rs [ 0 ][ 'idzona' ];
2017-08-04 16:28:16 +02:00
// Info riga pianificata
$rs = $dbo -> fetchArray ( 'SELECT * FROM co_ordiniservizio WHERE idcontratto=' . prepare ( $idcontratto ) . ' AND id=' . prepare ( $idordineservizio ));
$data = $rs [ 0 ][ 'data_scadenza' ];
$idimpianto = $rs [ 0 ][ 'id' ];
// Seleziono "Ordine di servizio" come tipo intervento
$rs = $dbo -> fetchArray ( " SELECT idtipointervento FROM in_tipiintervento WHERE descrizione='Ordine di servizio' " );
$idtipointervento = $rs [ 0 ][ 'idtipointervento' ];
// Spunto il tecnico di default assegnato all'impianto
$rs = $dbo -> fetchArray ( 'SELECT idtecnico FROM my_impianti WHERE id=' . prepare ( $idimpianto ));
$idtecnico = $rs [ 0 ][ 'idtecnico' ] ? : '' ;
}
// Se sto pianificando un contratto, leggo tutti i dati del contratto per predisporre l'aggiunta intervento
elseif ( ! empty ( $idcontratto ) && ! empty ( $idcontratto_riga )) {
2018-06-29 17:10:48 +02:00
$rs = $dbo -> fetchArray ( 'SELECT *, (SELECT idzona FROM an_anagrafiche WHERE idanagrafica = co_contratti.idanagrafica) AS idzona FROM co_contratti WHERE id=' . prepare ( $idcontratto ));
2017-08-04 16:28:16 +02:00
$idanagrafica = $rs [ 0 ][ 'idanagrafica' ];
2018-03-22 15:40:20 +01:00
$idzona = $rs [ 0 ][ 'idzona' ];
2018-05-21 11:14:37 +02:00
2017-08-04 16:28:16 +02:00
// Info riga pianificata
2018-08-31 11:39:38 +02:00
$rs = $dbo -> fetchArray ( 'SELECT *, (SELECT tempo_standard FROM in_tipiintervento WHERE idtipointervento = co_promemoria.idtipointervento) AS tempo_standard FROM co_promemoria WHERE idcontratto=' . prepare ( $idcontratto ) . ' AND id=' . prepare ( $idcontratto_riga ));
2017-08-04 16:28:16 +02:00
$idtipointervento = $rs [ 0 ][ 'idtipointervento' ];
2017-09-18 18:11:19 +02:00
$data = ( null !== filter ( 'data' )) ? filter ( 'data' ) : $rs [ 0 ][ 'data_richiesta' ];
2017-08-04 16:28:16 +02:00
$richiesta = $rs [ 0 ][ 'richiesta' ];
$idsede = $rs [ 0 ][ 'idsede' ];
2018-06-23 18:35:08 +02:00
$idimpianti = $rs [ 0 ][ 'idimpianti' ];
// aumento orario inizio del tempo standard definito dalla tipologia dell'intervento (PRESO DAL PROMEMORIA)
if ( ! empty ( $rs [ 0 ][ 'tempo_standard' ])) {
2018-09-20 09:21:34 +02:00
$orario_fine = date ( 'H:i:s' , strtotime ( $orario_inizio ) + (( 60 * 60 ) * $rs [ 0 ][ 'tempo_standard' ]));
2018-06-23 18:35:08 +02:00
}
// se gli impianti non sono stati definiti nel promemoria, carico tutti gli impianti a contratto
if ( empty ( $idimpianti )) {
$rs = $dbo -> fetchArray ( 'SELECT idimpianto FROM my_impianti_contratti WHERE idcontratto=' . prepare ( $idcontratto ));
$idimpianto = implode ( ',' , array_column ( $rs , 'idimpianto' ));
} else {
$idimpianto = $idimpianti ;
2018-08-11 11:08:55 +02:00
// Spunto il tecnico di default assegnato all'impianto
$rs = $dbo -> fetchArray ( 'SELECT idtecnico FROM my_impianti WHERE id=' . prepare ( $idimpianto ));
$idtecnico = $rs [ 0 ][ 'idtecnico' ] ? : '' ;
2018-06-23 18:35:08 +02:00
}
2017-08-04 16:28:16 +02:00
// Seleziono "In programmazione" come stato
2018-02-20 16:42:59 +01:00
$rs = $dbo -> fetchArray ( " SELECT * FROM in_statiintervento WHERE idstatointervento='WIP' " );
2017-08-04 16:28:16 +02:00
$idstatointervento = $rs [ 0 ][ 'idstatointervento' ];
}
2018-09-20 09:21:34 +02:00
// Intervento senza sessioni
elseif ( ! empty ( $id_intervento )) {
// Info riga pianificata
$rs = $dbo -> fetchArray ( '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 ));
$idtipointervento = $rs [ 0 ][ 'idtipointervento' ];
$data = ( null !== filter ( 'data' )) ? filter ( 'data' ) : $rs [ 0 ][ 'data_richiesta' ];
2018-09-20 16:42:35 +02:00
$data_richiesta = $rs [ 0 ][ 'data_richiesta' ];
2018-09-20 09:21:34 +02:00
$richiesta = $rs [ 0 ][ 'richiesta' ];
$idsede = $rs [ 0 ][ 'idsede' ];
$idanagrafica = $rs [ 0 ][ 'idanagrafica' ];
$idclientefinale = $rs [ 0 ][ 'idclientefinale' ];
$idstatointervento = $rs [ 0 ][ 'idstatointervento' ];
$idcontratto = $rs [ 0 ][ 'idcontratto' ];
$idpreventivo = $rs [ 0 ][ 'idpreventivo' ];
$idzona = $rs [ 0 ][ 'idzona' ];
// Aumento orario inizio del tempo standard definito dalla tipologia dell'intervento (PRESO DAL PROMEMORIA)
if ( ! empty ( $rs [ 0 ][ 'tempo_standard' ])) {
$orario_fine = date ( 'H:i:s' , strtotime ( $orario_inizio ) + (( 60 * 60 ) * $rs [ 0 ][ 'tempo_standard' ]));
}
$rs = $dbo -> fetchArray ( 'SELECT idimpianto FROM my_impianti_interventi WHERE idintervento=' . prepare ( $id_intervento ));
$idimpianto = implode ( ',' , array_column ( $rs , 'idimpianto' ));
}
2017-08-04 16:28:16 +02:00
if ( empty ( $data )) {
2017-09-18 18:11:19 +02:00
if ( null !== filter ( 'data' )) {
2017-08-04 16:28:16 +02:00
$data = filter ( 'data' );
} else {
2018-09-20 12:05:22 +02:00
$data = date ( formatter () -> getDatePattern ());
2017-08-04 16:28:16 +02:00
}
}
$_SESSION [ 'superselect' ][ 'idanagrafica' ] = $idanagrafica ;
2018-09-19 15:12:20 +02:00
$orario_inizio = $data . ' ' . $orario_inizio ;
$orario_fine = $data . ' ' . $orario_fine ;
2017-08-04 16:28:16 +02:00
?>
2018-07-02 15:41:38 +02:00
< form action = " " method = " post " id = " add-form " onsubmit = " if( $ (this).parsley().validate()) { return add_intervento(); } " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " op " value = " add " >
2018-06-23 18:35:08 +02:00
< input type = " hidden " name = " ref " value = " <?php echo get('ref'); ?> " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
2018-09-20 09:21:34 +02:00
< ? php
if ( ! empty ( $idcontratto_riga )) {
echo '<input type="hidden" name="idcontratto_riga" value="' . $idcontratto_riga . '">' ;
}
if ( ! empty ( $idordineservizio )) {
echo '<input type="hidden" name="idordineservizio" value="' . $idordineservizio . '">' ;
}
if ( ! empty ( $id_intervento )) {
echo '<input type="hidden" name="id_intervento" value="' . $id_intervento . '">' ;
}
?>
2017-08-04 16:28:16 +02:00
<!-- DATI CLIENTE -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2017-09-04 12:02:29 +02:00
< h3 class = " panel-title " >< ? php echo tr ( 'Dati cliente' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
< div class = " panel-body " >
<!-- RIGA 1 -->
< div class = " row " >
< div class = " col-md-4 " >
2018-05-23 18:05:49 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Cliente'); ?> " , " name " : " idanagrafica " , " required " : 1 , " value " : " <?php echo $idanagrafica ; ?> " , " ajax-source " : " clienti " , " icon-after " : " add|<?php echo Modules::get('Anagrafiche')['id']; ?>|tipoanagrafica=Cliente||<?php echo (empty( $idanagrafica )) ? '' : 'disabled'; ?> " , " data-heavy " : 0 ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-4 " >
2018-08-11 15:49:46 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Sede'); ?> " , " name " : " idsede " , " value " : " <?php echo $idsede ; ?> " , " placheholder " : " <?php echo tr('Seleziona prima un cliente'); ?>... " , " ajax-source " : " sedi " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-4 " >
2018-09-20 09:21:34 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Per conto di'); ?> " , " name " : " idclientefinale " , " value " : " <?php echo $idclientefinale ; ?> " , " ajax-source " : " clienti " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
<!-- RIGA 2 -->
< div class = " row " >
2018-10-26 01:00:44 +02:00
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " <?php echo tr('Zona'); ?> " , " name " : " idzona " , " values " : " query=SELECT id, CONCAT_WS( ' - ', nome, descrizione) AS descrizione FROM an_zone ORDER BY nome " , " value " : " <?php echo $idzona ; ?> " , " placeholder " : " <?php echo tr('Nessuna zona'); ?> " , " help " : " <?php echo 'La zona viene definita automaticamente in base al cliente selezionato'; ?>. " , " extra " : " readonly " , " value " : " <?php echo $idzona ; ?> " ]}
</ div >
2017-08-04 16:28:16 +02:00
< div class = " col-md-4 " >
2018-09-20 09:21:34 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Preventivo'); ?> " , " name " : " idpreventivo " , " value " : " <?php echo $idpreventivo ; ?> " < ? php echo ! empty ( $idanagrafica ) ? '' : ', "placeholder": "' . tr ( 'Seleziona prima un cliente' ) . '..."' ; ?> , "ajax-source": "preventivi" ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-4 " >
2018-07-04 18:33:27 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Contratto'); ?> " , " name " : " idcontratto " , " value " : " <?php echo $idcontratto ; ?> " < ? php echo ! empty ( $idanagrafica ) ? '' : ', "placeholder": "' . tr ( 'Seleziona prima un cliente' ) . '..."' ; ?> , "ajax-source": "contratti" ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
2018-10-26 01:00:44 +02:00
< div class = " col-md-6 " id = 'impianti' >
{[ " type " : " select " , " label " : " <?php echo tr('Impianto'); ?> " , " multiple " : 1 , " name " : " idimpianti[] " , " value " : " <?php echo $idimpianto ; ?> " < ? php echo ! empty ( $idanagrafica ) ? '' : ', "placeholder": "' . tr ( 'Seleziona prima un cliente' ) . '..."' ; ?> , "ajax-source": "impianti-cliente", "icon-after": "add|<?php echo Modules::get('MyImpianti')['id']; ?>|source=Attività|<?php echo (empty($idimpianto)) ? '' : 'disabled'; ?>", "data-heavy": 0 ]}
</ div >
< div class = " col-md-6 " >
2018-06-23 18:35:08 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Componenti'); ?> " , " multiple " : 1 , " name " : " componenti[] " , " placeholder " : " <?php echo tr('Seleziona prima un impianto'); ?>... " , " ajax-source " : " componenti " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div >
<!-- DATI INTERVENTO -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2017-09-04 12:02:29 +02:00
< h3 class = " panel-title " >< ? php echo tr ( 'Dati intervento' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
< div class = " panel-body " >
<!-- RIGA 3 -->
< div class = " row " >
2018-10-26 01:00:44 +02:00
< div class = " col-md-4 " >
2018-11-13 13:22:38 +01:00
{[ " type " : " timestamp " , " label " : " <?php echo tr('Data e ora richiesta'); ?> " , " name " : " data_richiesta " , " required " : 1 , " value " : " <?php echo $data_richiesta ?: '-now-'; ?> " ]}
2018-10-26 01:00:44 +02:00
</ div >
2017-08-04 16:28:16 +02:00
2017-09-01 12:55:48 +02:00
< div class = " col-md-4 " >
2018-07-31 19:20:19 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Tipo attività'); ?> " , " name " : " idtipointervento " , " required " : 1 , " values " : " query=SELECT idtipointervento AS id, descrizione FROM in_tipiintervento ORDER BY descrizione ASC " , " value " : " <?php echo $idtipointervento ; ?> " , " ajax-source " : " tipiintervento " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-10-26 01:00:44 +02:00
< div class = " col-md-4 " >
2018-07-31 19:20:19 +02:00
{[ " type " : " select " , " label " : " <?php echo 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 " : " <?php echo $idstatointervento ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
<!-- RIGA 5 -->
< div class = " row " >
< div class = " col-md-12 " >
2017-09-18 18:11:19 +02:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Richiesta'); ?> " , " name " : " richiesta " , " required " : 1 , " value " : " <?php echo $richiesta ; ?> " , " extra " : " style='max-height:80px; ' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div >
2018-09-19 15:12:20 +02:00
<!-- DATI INTERVENTO -->
2018-09-20 09:21:34 +02:00
< div class = " box box-primary collapsable <?php echo get('ref') ? '' : 'collapsed-box'; ?> " >
2018-09-19 15:12:20 +02:00
< div class = " box-header with-border " >
< h3 class = " box-title " >< ? php echo tr ( 'Ore di lavoro' ); ?> </h3>
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >
< i class = " fa fa-<?php echo get('ref') ? 'minus' : 'plus'; ?> " ></ i >
</ button >
</ div >
</ div >
< div class = " box-body " >
< div class = " row " >
< div class = " col-md-6 " >
{[ " type " : " timestamp " , " label " : " <?php echo tr('Inizio attività'); ?> " , " name " : " orario_inizio " , " required " : < ? php echo get ( 'ref' ) ? 1 : 0 ; ?> , "value": "<?php echo $orario_inizio; ?>" ]}
</ div >
< div class = " col-md-6 " >
{[ " type " : " timestamp " , " label " : " <?php echo tr('Fine attività'); ?> " , " name " : " orario_fine " , " required " : < ? php echo get ( 'ref' ) ? 1 : 0 ; ?> , "value": "<?php echo $orario_fine; ?>" ]}
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
{[ " type " : " select " , " label " : " <?php echo tr('Tecnici'); ?> " , " multiple " : " 1 " , " name " : " idtecnico[] " , " required " : < ? php echo get ( 'ref' ) ? 1 : 0 ; ?> , "ajax-source": "tecnici", "value": "<?php echo $idtecnico; ?>" ]}
</ div >
</ div >
</ div >
</ div >
2017-08-04 16:28:16 +02:00
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
2017-09-04 12:02:29 +02:00
< button type = " submit " class = " btn btn-primary " >< i class = " fa fa-plus " ></ i > < ? php echo tr ( 'Aggiungi' ); ?> </button>
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ form >
2017-09-18 18:11:19 +02:00
< script src = " <?php echo $rootdir ; ?>/lib/init.js " ></ script >
2017-08-04 16:28:16 +02:00
< script type = " text/javascript " >
$ ( document ) . ready ( function (){
2018-11-08 10:58:29 +01:00
if ( ! $ ( " #bs-popup #idanagrafica " ) . val ()){
$ ( " #bs-popup #idsede " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idpreventivo " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idcontratto " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idimpianti " ) . prop ( " disabled " , true );
$ ( " #bs-popup #componenti " ) . prop ( " disabled " , true );
2017-08-04 16:28:16 +02:00
< ? php
if ( ! empty ( $idcontratto ) && ( ! empty ( $idordineservizio ) || ! empty ( $idcontratto_riga ))) {
// Disabilito i campi che non devono essere modificati per poter collegare l'intervento all'ordine di servizio
echo '
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #idanagrafica " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idclientefinale " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idzona " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idtipointervento " ) . prop ( " disabled " , true );
$ ( " #bs-popup #impianti " ) . find ( " button " ) . prop ( " disabled " , true ); ' ;
2017-08-04 16:28:16 +02:00
}
?>
2018-07-04 17:56:51 +02:00
}
2018-09-20 09:21:34 +02:00
< ? php
if ( ! empty ( $id_intervento )) {
echo '
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #idsede " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idpreventivo " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idcontratto " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idimpianti " ) . prop ( " disabled " , true );
$ ( " #bs-popup #componenti " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idanagrafica " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idanagrafica " ) . find ( " button " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idclientefinale " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idzona " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idtipointervento " ) . prop ( " disabled " , true );
$ ( " #bs-popup #idstatointervento " ) . prop ( " disabled " , true );
$ ( " #bs-popup #richiesta " ) . prop ( " disabled " , true );
$ ( " #bs-popup #data_richiesta " ) . prop ( " disabled " , true );
$ ( " #bs-popup #impianti " ) . find ( " button " ) . prop ( " disabled " , true );
2018-09-20 09:21:34 +02:00
' ;
}
?>
// Quando modifico orario inizio, allineo anche l'orario fine
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #orario_inizio " ) . on ( " dp.change " , function ( e ) {
$ ( " #bs-popup #orario_fine " ) . data ( " DateTimePicker " ) . minDate ( e . date ) . format ( globals . timestampFormat );
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
2018-03-14 11:27:58 +01:00
if ( $ ( 'input[name=idcontratto_riga]' ) . val () != undefined ){
$ ( '#bs-popup button.close' ) . on ( 'click' , function (){
location . reload ();
});
}
2017-08-04 16:28:16 +02:00
});
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idanagrafica' ) . change ( function (){
2017-08-04 16:28:16 +02:00
session_set ( 'superselect,idanagrafica' , $ ( this ) . val (), 0 );
var value = ! $ ( this ) . val () ? true : false ;
2018-11-30 16:10:15 +01:00
var placeholder = ! $ ( this ) . val () ? '<?php echo tr(' Seleziona prima un cliente ... '); ?>' : '<?php echo tr("-Seleziona un\'opzione-"); ?>' ;
2017-08-04 16:28:16 +02:00
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #idsede " ) . prop ( " disabled " , value );
$ ( " #bs-popup #idsede " ) . selectReset ( placeholder );
2017-08-04 16:28:16 +02:00
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #idpreventivo " ) . prop ( " disabled " , value );
$ ( " #bs-popup #idpreventivo " ) . selectReset ( placeholder );
2017-08-04 16:28:16 +02:00
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #idcontratto " ) . prop ( " disabled " , value );
$ ( " #bs-popup #idcontratto " ) . selectReset ( placeholder );
2017-08-04 16:28:16 +02:00
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #idimpianti " ) . prop ( " disabled " , value );
$ ( " #bs-popup #impianti " ) . find ( " button " ) . prop ( " disabled " , value );
$ ( " #bs-popup #idimpianti " ) . selectReset ( placeholder );
2018-06-23 18:35:08 +02:00
2018-02-15 12:22:21 +01:00
if (( $ ( this ) . val ())) {
if (( $ ( this ) . selectData () . idzona )){
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idzona' ) . val ( $ ( this ) . selectData () . idzona ) . change ();
2018-02-20 16:46:23 +01:00
2018-02-15 12:22:21 +01:00
} else {
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idzona' ) . val ( '' ) . change ();
2018-02-15 12:22:21 +01:00
}
2018-06-23 18:35:08 +02:00
// session_set('superselect,idzona', $(this).selectData().idzona, 0);
2018-02-15 12:22:21 +01:00
}
2017-08-04 16:28:16 +02:00
});
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idsede' ) . change ( function (){
2017-08-04 16:28:16 +02:00
session_set ( 'superselect,idsede' , $ ( this ) . val (), 0 );
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #idimpianti " ) . selectReset ();
2018-02-20 16:46:23 +01:00
2018-02-15 12:22:21 +01:00
if (( $ ( this ) . val ())) {
if (( $ ( this ) . selectData () . idzona )){
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idzona' ) . val ( $ ( this ) . selectData () . idzona ) . change ();
2018-02-15 12:22:21 +01:00
} else {
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idzona' ) . val ( '' ) . change ();
2018-02-15 12:22:21 +01:00
}
2018-06-23 18:35:08 +02:00
// session_set('superselect,idzona', $(this).selectData().idzona, 0);
2018-02-15 12:22:21 +01:00
}
2017-08-04 16:28:16 +02:00
});
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idpreventivo' ) . change ( function (){
if ( $ ( '#bs-popup #idcontratto' ) . val () && $ ( this ) . val ()){
$ ( " #bs-popup #idcontratto " ) . selectReset ();
2017-08-04 16:28:16 +02:00
}
if ( $ ( this ) . val ()){
2018-11-13 15:54:40 +01:00
//TODO: disattivato perché genera problemi con il change successivo di iditpointervento per il tempo standard*
2018-11-23 17:58:59 +01:00
$ ( '#bs-popup #idtipointervento' ) . selectSetNew ( $ ( this ) . selectData () . idtipointervento , $ ( this ) . selectData () . idtipointervento_descrizione );
2017-08-04 16:28:16 +02:00
}
});
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idcontratto' ) . change ( function (){
if ( $ ( '#bs-popup #idpreventivo' ) . val () && $ ( this ) . val ()){
$ ( " #bs-popup #idpreventivo " ) . selectReset ();
2017-08-04 16:28:16 +02:00
$ ( 'input[name=idcontratto_riga]' ) . val ( '' );
}
});
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idimpianti' ) . change ( function (){
2017-08-04 16:28:16 +02:00
session_set ( 'superselect,marticola' , $ ( this ) . val (), 0 );
2018-11-08 10:58:29 +01:00
$ ( " #bs-popup #componenti " ) . prop ( " disabled " , ! $ ( this ) . val () ? true : false );
$ ( " #bs-popup #componenti " ) . selectReset ();
2017-08-04 16:28:16 +02:00
});
2018-06-23 18:35:08 +02:00
2018-11-23 17:58:59 +01:00
// tempo standard
// TODO: tempo_standard da preventivo e contratto attraverso selectData() relativi
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idtipointervento' ) . change ( function (){
2018-11-13 16:02:44 +01:00
2018-11-23 17:58:59 +01:00
if ( $ ( this ) . selectData () && (( $ ( this ) . selectData () . tempo_standard ) > 0 ) && ( '<?php echo filter(' orario_fine '); ?>' == '' )){
2018-11-13 16:02:44 +01:00
tempo_standard = $ ( this ) . selectData () . tempo_standard ;
2018-09-19 15:12:20 +02:00
2018-11-13 16:02:44 +01:00
data = moment ( $ ( '#bs-popup #orario_inizio' ) . val (), globals . timestampFormat );
2018-09-19 15:12:20 +02:00
orario_fine = data . add ( tempo_standard , 'hours' );
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #orario_fine' ) . val ( orario_fine . format ( globals . timestampFormat ));
2018-05-21 12:33:07 +02:00
}
2018-11-23 17:58:59 +01:00
2018-05-21 12:33:07 +02:00
});
2018-06-23 18:35:08 +02:00
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #idtecnico' ) . change ( function (){
2018-06-23 18:35:08 +02:00
< ? php if ( ! get ( 'ref' )) {
?>
2018-05-21 15:47:44 +02:00
var value = ( $ ( this ) . val () > 0 ) ? true : false ;
2018-11-08 10:58:29 +01:00
$ ( '#bs-popup #orario_inizio' ) . prop ( " required " , value );
$ ( '#bs-popup #orario_fine' ) . prop ( " required " , value );
$ ( '#bs-popup #data' ) . prop ( " required " , value );
2018-06-23 18:35:08 +02:00
< ? php
} ?>
});
var ref = " <?php echo get('ref'); ?> " ;
2017-08-04 16:28:16 +02:00
function add_intervento (){
// Se l'aggiunta intervento proviene dal calendario, faccio il submit via ajax e ricarico gli eventi...
if ( ref ){
$ ( '#add-form' ) . find ( '[type=submit]' ) . prop ( " disabled " , true ) . addClass ( " disabled " );
$ ( '#add-form' ) . find ( 'input:disabled, select:disabled, textarea:disabled' ) . removeAttr ( 'disabled' );
2017-09-22 15:19:59 +02:00
$ . post ( globals . rootdir + '/actions.php?id_module=<?php echo Modules::get(' Interventi ')[' id ']; ?>' , $ ( '#add-form' ) . serialize (), function ( data , response ){
2017-08-04 16:28:16 +02:00
if ( response == " success " ){
// Se l'aggiunta intervento proviene dalla scheda di pianificazione ordini di servizio della dashboard, la ricarico
if ( ref == " dashboard " ){
$ ( " #bs-popup " ) . modal ( 'hide' );
// Aggiornamento elenco interventi da pianificare
$ ( '#calendar' ) . fullCalendar ( 'refetchEvents' );
$ ( '#calendar' ) . fullCalendar ( 'render' );
}
// Se l'aggiunta intervento proviene dai contratti, faccio il submit via ajax e ricarico la tabella dei contratti
else if ( ref == " interventi_contratti " ){
2018-11-23 17:58:59 +01:00
2018-11-13 14:51:19 +01:00
$ ( " #bs-popup " ) . modal ( 'hide' );
2018-07-20 15:45:53 +02:00
parent . window . location . reload ();
2018-11-13 14:51:19 +01:00
//TODO: da gestire via ajax
//$('#elenco_interventi > tbody').load(globals.rootdir + '/modules/contratti/plugins/contratti.pianificazioneinterventi.php?op=get_interventi_pianificati&idcontratto=<?php echo $idcontratto; ?>');
2018-11-23 17:58:59 +01:00
2017-08-04 16:28:16 +02:00
}
}
});
return false ;
}
}
</ script >