2018-08-30 18:20:30 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$plugin = Plugins :: get ( $id_plugin );
$id_module = Modules :: get ( 'Contratti' )[ 'id' ];
2018-08-31 09:41:43 +02:00
$is_add = filter ( 'add' ) ? true : false ;
2018-08-30 18:20:30 +02:00
// Informazioni contratto
$contratto = $dbo -> fetchOne ( 'SELECT * FROM `co_contratti` WHERE `id` = :id' , [
':id' => $id_parent ,
]);
2018-11-09 11:34:27 +01:00
$data_accettazione = $contratto [ 'data_accettazione' ];
2018-08-30 18:20:30 +02:00
$data_conclusione = $contratto [ 'data_conclusione' ];
$id_anagrafica = $contratto [ 'idanagrafica' ];
// Impianti del contratto
$impianti = $dbo -> fetchArray ( 'SELECT `idimpianto` FROM `my_impianti_contratti` WHERE `idcontratto` = :id' , [
':id' => $id_parent ,
]);
$id_impianti = array_column ( $impianti , 'idimpianto' );
// solo se ho selezionato un solo impianto nel contratto, altrimenti non so quale sede e tecnico prendere
if ( count ( $id_impianti ) == 1 ) {
$id_sede = $dbo -> fetchOne ( 'SELECT idsede FROM my_impianti WHERE id = ' . prepare ( $id_impianti [ 0 ]))[ 'idsede' ];
$id_tecnico = $dbo -> fetchOne ( 'SELECT idtecnico FROM my_impianti WHERE id = ' . prepare ( $id_impianti [ 0 ]))[ 'idtecnico' ];
}
// Informazioni del promemoria
2018-08-31 11:39:38 +02:00
$record = $dbo -> fetchOne ( 'SELECT *, (SELECT descrizione FROM in_tipiintervento WHERE idtipointervento=co_promemoria.idtipointervento) AS tipointervento, (SELECT tempo_standard FROM in_tipiintervento WHERE idtipointervento = co_promemoria.idtipointervento) AS tempo_standard FROM co_promemoria WHERE id = :id' , [
2018-08-30 18:20:30 +02:00
':id' => $id_record ,
]);
2018-09-07 17:43:52 +02:00
$data_richiesta = $record [ 'data_richiesta' ] ? : date ( 'Y-m-d' );
2018-08-30 18:20:30 +02:00
$id_sede = $record [ 'idsede' ];
$tempo_standard = $record [ 'tempo_standard' ];
$idtipointervento = $record [ 'idtipointervento' ];
if ( ! empty ( $id_sede )) {
$id_impianti = explode ( ',' , trim ( $record [ 'idimpianti' ]));
}
$pianificazione = [
2018-08-31 09:41:43 +02:00
[
'id' => 0 ,
'text' => tr ( 'Pianificare a partire da questo promemoria _DATE_' , [
'_DATE_' => $data_richiesta ,
]),
],
[
'id' => 1 ,
'text' => tr ( 'Pianificare a partire da oggi _DATE_' , [
'_DATE_' => date ( 'Y-m-d' ),
]),
],
2018-08-30 18:20:30 +02:00
];
// orari inizio fine interventi (8h standard)
$orario_inizio = '09:00' ;
$orario_fine = ! empty ( $tempo_standard ) ? date ( 'H:i' , strtotime ( $orario_inizio ) + (( 60 * 60 ) * $tempo_standard )) : '17:00' ;
echo '
2019-03-20 10:16:14 +01:00
< form id = " add_form " action = " '. $rootdir .'/controller.php " method = " post " role = " form " >
< input type = " hidden " name = " id_plugin " value = " '. $id_plugin .' " >
< input type = " hidden " name = " id_parent " value = " '. $id_parent .' " >
< input type = " hidden " name = " id_record " value = " '. $id_record .' " >
2018-08-30 18:20:30 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
2018-08-31 09:41:43 +02:00
< input type = " hidden " name = " op " value = " '.(!empty( $is_add ) ? 'edit-promemoria' : 'pianificazione').' " > ' ;
2018-08-30 18:20:30 +02:00
echo '
<!-- DATI PROMEMORIA -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Dati ').' </ h3 >
</ div >
< div class = " panel-body " >
< div class = " row " >
< div class = " col-md-6 " >
2018-11-13 13:22:38 +01:00
{[ " type " : " date " , " label " : " '.tr('Data promemoria').' " , " name " : " data_richiesta " , " required " : 1 , " value " : " '. $data_accettazione .' " , " readonly " : '.intval(empty($is_add)).' , " min-date " : " '. $data_accettazione .' " , " max-date " : " '. $data_conclusione .' " ]}
2018-08-30 18:20:30 +02:00
</ div >
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Tipo intervento').' " , " name " : " idtipointervento " , " required " : 1 , " id " : " idtipointervento_ " , " value " : " '. $record['idtipointervento'] .' " , " readonly " : '.intval(empty($is_add)).' , " ajax-source " : " tipiintervento " , " value " : " '. $idtipointervento .' " ]}
</ div >
</ div >
< div class = " row " >
< div class = " col-md-6 " >
{[ " type " : " select " , " label " : " '.tr('Sede').' " , " name " : " idsede_c " , " values " : " query=SELECT 0 AS id, \ 'Sede legale \ ' AS descrizione UNION SELECT id, CONCAT( CONCAT_WS( \ ' ( \ ', CONCAT_WS( \ ', \ ', `nomesede`, `citta`), `indirizzo` ), \ ') \ ') AS descrizione FROM an_sedi WHERE idanagrafica='. $id_anagrafica .' " , " value " : " '. $id_sede .' " , " readonly " : '.intval(empty($is_add)).' , " required " : " 1 " ]}
</ div >
< div class = " col-md-6 " >
{[ " type " : " select " , " multiple " : " 1 " , " label " : " '.tr('Impianti a contratto').' " , " name " : " idimpianti[] " , " help " : " '.tr('Impianti sede selezionata').' " , " values " : " query=SELECT my_impianti.id AS id, my_impianti.nome AS descrizione FROM my_impianti_contratti INNER JOIN my_impianti ON my_impianti_contratti.idimpianto = my_impianti.id WHERE my_impianti_contratti.idcontratto = '. $id_parent .' ORDER BY descrizione " , " value " : " '.implode(',', $id_impianti ).' " , " readonly " : '.intval(empty($is_add)).' ]}
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
{[ " type " : " textarea " , " label " : " '.tr('Descrizione').' " , " name " : " richiesta " , " id " : " richiesta_ " , " readonly " : '.intval(empty($is_add)).' , " value " : " '. $record['richiesta'] .' " ]}
</ div >
</ div >
</ div >
</ div > ' ;
echo '
<!-- ARTICOLI -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Materiale da utilizzare ').' </ h3 >
</ div >
< div class = " panel-body " >
< div id = " articoli " > ' ;
include $plugin -> filepath ( 'ajax_articoli.php' );
echo '
</ div > ' ;
if ( ! empty ( $is_add )) {
echo '
< button type = " button " class = " btn btn-primary " data - title = " '.tr('Aggiungi articolo').' " data - target = " #bs-popup2 " data - toggle = " modal " data - href = " '. $plugin->fileurl ('add_articolo.php').'?id_plugin='. $id_plugin .'&id_record='. $id_record .'&add='. $is_add .' " >< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi articolo ').' ...</ button > ' ;
}
echo '
</ div >
</ div > ' ;
echo '
<!-- SPESE AGGIUNTIVE -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Altre spese previste ').' </ h3 >
</ div >
< div class = " panel-body " >
< div id = " righe " > ' ;
include $plugin -> filepath ( 'ajax_righe.php' );
echo '
</ div > ' ;
if ( ! empty ( $is_add )) {
echo '
< button type = " button " class = " btn btn-primary " data - title = " '.tr('Aggiungi altre spese').' " data - target = " #bs-popup2 " data - toggle = " modal " data - href = " '. $plugin->fileurl ('add_righe.php').'?id_plugin='. $id_plugin .'&id_record='. $id_record .'&add='. $is_add .' " >< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi altre spese ').' ...</ button > ' ;
}
echo '
</ div >
</ div > ' ;
echo '{( "name": "filelist_and_upload", "id_record": "' . $id_record . '", "id_module": "' . $id_module . '", "id_plugin": "' . $id_plugin . '", "readonly": ' . intval ( empty ( $is_add )) . ' )}' ;
echo '
<!-- PIANIFICAZIONE CICLICA -->
< div class = " panel panel-primary '.(!empty( $is_add ) ? 'hide' : '').' " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Promemoria ciclico ? ').' </ h3 >
</ div >
< div class = " panel-body " >
<!-- div class = " col-md-8 " >
{[ " type " : " checkbox " , " label " : " '.tr('Pianifica anche date passate').' " , " name " : " date_passate " , " value " : " 0 " , " placeholder " : " '.tr('Pianificare promemoria anche con date precedenti ad oggi: ').date('d/m/Y').' " ]}
</ div -->
< div class = " row " >
2018-11-13 13:22:38 +01:00
< div class = " col-md-4 " >
2018-11-30 16:10:15 +01:00
{[ " type " : " checkbox " , " label " : " '.tr('Promemoria ciclico').' " , " name " : " pianifica_promemoria " , " value " : " 0 " , " placeholder " : " '.tr('Pianificare promemoria ciclici').' " , " help " : " '.tr('Pianificare ciclicamente altri promemoria identici a questo').' " ]}
2018-11-13 13:22:38 +01:00
</ div >
2018-08-30 18:20:30 +02:00
< div class = " col-md-2 " >
2018-11-13 13:22:38 +01:00
{[ " type " : " number " , " label " : " '.tr('Intervallo').' " , " name " : " intervallo " , " decimals " : 0 , " required " : 1 , " icon-after " : " GG " , " min-value " : " 1 " , " maxlength " : " 3 " , " disabled " : " 1 " ]}
2018-08-30 18:20:30 +02:00
</ div >
2018-11-13 13:22:38 +01:00
< div class = " col-md-3 " >
{[ " type " : " date " , " label " : " '.tr('Inizio pianificazione').' " , " help " : " '.tr('Intervallo compreso dalla data accettazione contratto fino alla data di conclusione').' " , " name " : " data_inizio " , " value " : " '. $data_accettazione .' " , " disabled " : " 1 " , " min-date " : " '. $data_accettazione .' " , " max-date " : " '. $data_conclusione .' " ]}
2018-08-30 18:20:30 +02:00
</ div >
2018-11-13 13:22:38 +01:00
2018-08-30 18:20:30 +02:00
< div class = " col-md-3 " >
2018-11-09 11:34:27 +01:00
{[ " type " : " date " , " label " : " '.tr('Fine pianificazione').' " , " help " : " '.tr('Data conclusione contratto').' " , " name " : " data_conclusione " , " extra " : " readonly " , " value " : " '. $data_conclusione .' " ]}
2018-08-30 18:20:30 +02:00
</ div >
</ div >
</ div >
</ div > ' ;
echo '
<!-- PIANIFICARE INTERVENTI -->
< div class = " panel panel-primary '.(!empty( $is_add ) ? 'hide' : '').' " >
< div class = " panel-heading " >
< h3 class = " panel-title " > '.tr(' Pianificare interventi ? ').' </ h3 >
</ div >
< div class = " panel-body " >
< div class = " row " >
< div class = " col-md-4 " >
2018-11-13 13:22:38 +01:00
{[ " type " : " checkbox " , " label " : " '.tr( " Pianifica anche l 'intervento").' " , " name " : " pianifica_intervento " , " value " : " 0 " , " placeholder " : " '.tr("Pianificare già l' intervento " ).' " , " disabled " : " 1 " ]}
2018-08-30 18:20:30 +02:00
</ div >
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Tecnici').' " , " multiple " : " 1 " , " name " : " idtecnico[] " , " ajax-source " : " tecnici " , " disabled " : " 1 " , " value " : " '. $id_tecnico .' " ]}
</ div >
< div class = " col-xs-6 col-md-2 " >
{[ " type " : " time " , " label " : " '.tr('Orario inizio').' " , " name " : " orario_inizio " , " value " : " '. $orario_inizio .' " , " disabled " : " 1 " ]}
</ div >
< div class = " col-xs-6 col-md-2 " >
{[ " type " : " time " , " label " : " '.tr('Orario fine').' " , " name " : " orario_fine " , " value " : " '. $orario_fine .' " , " disabled " : " 1 " ]}
</ div >
</ div >
</ div >
</ div > ' ;
echo '
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
2018-11-13 13:22:38 +01:00
< button type = " submit " class = " btn btn-primary " '.(empty($is_add) ? ' disabled ' : ' ').' >< i class = " fa fa-plus " ></ i > '.tr(' Pianifica ').' </ button >
2018-08-30 18:20:30 +02:00
</ div >
</ div >
</ form > ' ;
echo '
2019-07-26 18:05:19 +02:00
< script > $ ( document ) . ready ( init ) </ script > ' ;
2018-08-30 18:20:30 +02:00
echo '
< script >
$ ( document ) . ready ( function () {
if ( $ ( " #idtipointervento_ " ) . val () == null ){
$ ( " #add_form .panel-primary .panel-primary " ) . hide ();
$ ( " #bs-popup .btn-primary " ) . hide ();
};
$ ( " #idtipointervento_ " ) . change ( function (){
if (( $ ( this ) . val () != " " )){
$ ( " #add_form .panel-primary .panel-primary " ) . show ();
$ ( " #bs-popup .btn-primary " ) . show ();
} else {
$ ( " #add_form .panel-primary .panel-primary " ) . hide ();
$ ( " #bs-popup .btn-primary " ) . hide ();
}
});
2018-11-13 13:22:38 +01:00
$ ( " #pianifica_promemoria " ) . click ( function () {
if ( $ ( this ) . is ( " :checked " )){
$ ( " #intervallo " ) . removeAttr ( " disabled " );
$ ( " #data_inizio " ) . removeAttr ( " disabled " );
$ ( " #pianifica_intervento " ) . removeAttr ( " disabled " );
$ ( " #bs-popup .btn-primary " ) . removeAttr ( " disabled " );
} else {
$ ( " #intervallo " ) . prop ( " disabled " , true );
$ ( " #data_inizio " ) . prop ( " disabled " , true );
$ ( " #pianifica_intervento " ) . prop ( " checked " , false );
$ ( " #pianifica_intervento " ) . prop ( " disabled " , true );
$ ( " #bs-popup .btn-primary " ) . prop ( " disabled " , true );
$ ( " #idtecnico " ) . prop ( " disabled " , true );
$ ( " #idtecnico " ) . removeAttr ( " required " );
$ ( " #orario_inizio " ) . prop ( " disabled " , true );
$ ( " #orario_fine " ) . prop ( " disabled " , true );
$ ( " #orario_inizio " ) . removeAttr ( " required " );
$ ( " #orario_fine " ) . removeAttr ( " required " );
}
});
2018-08-30 18:20:30 +02:00
$ ( " #pianifica_intervento " ) . click ( function () {
if ( $ ( this ) . is ( " :checked " )){
$ ( " #idtecnico " ) . removeAttr ( " disabled " );
$ ( " #idtecnico " ) . prop ( " required " , true );
$ ( " #orario_inizio " ) . removeAttr ( " disabled " );
$ ( " #orario_fine " ) . removeAttr ( " disabled " );
$ ( " #orario_inizio " ) . prop ( " required " , true );
$ ( " #orario_fine " ) . prop ( " required " , true );
} else {
$ ( " #idtecnico " ) . prop ( " disabled " , true );
$ ( " #idtecnico " ) . removeAttr ( " required " );
$ ( " #orario_inizio " ) . prop ( " disabled " , true );
$ ( " #orario_fine " ) . prop ( " disabled " , true );
$ ( " #orario_inizio " ) . removeAttr ( " required " );
$ ( " #orario_fine " ) . removeAttr ( " required " );
}
});
});
function refreshArticoli ( id ){
$ ( " #articoli " ) . load ( " '. $plugin->fileurl ('ajax_articoli.php').'?id_plugin='. $id_plugin .'&id_record= " + id + " &add='. $is_add .' " );
}
function refreshRighe ( id ){
$ ( " #righe " ) . load ( " '. $plugin->fileurl ('ajax_righe.php').'?id_plugin='. $id_plugin .'&id_record= " + id + " &add='. $is_add .' " );
}
</ script > ' ;