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' ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
use Models\Plugin ;
2018-08-30 18:20:30 +02:00
2024-03-05 16:01:45 +01:00
$plugin = Plugin :: find ( $id_plugin );
2024-04-18 17:44:05 +02:00
$id_module = ( new Module ()) -> getByField ( 'title' , 'Contratti' , Models\Locale :: getPredefined () -> id );
2020-02-17 13:18:25 +01:00
$block_edit = filter ( 'add' ) ? false : true ;
2024-04-22 12:32:48 +02:00
$id_module_interventi = ( new Module ()) -> getByField ( 'title' , 'Attività' , Models\Locale :: getPredefined () -> id );
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
2023-11-08 14:56:01 +01:00
$impianti = $dbo -> fetchArray ( 'SELECT `idimpianti` FROM `co_promemoria` WHERE `id` = ' . $id_record . ' AND `idcontratto` = :id' , [
2018-08-30 18:20:30 +02:00
':id' => $id_parent ,
]);
2023-11-08 14:56:01 +01:00
$id_impianti = explode ( ',' , $impianti [ 0 ][ 'idimpianti' ]);
2018-08-30 18:20:30 +02:00
// 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
2024-04-18 17:44:05 +02:00
$record = $dbo -> fetchOne ( 'SELECT *, `in_tipiintervento_lang`.`title` AS tipointervento, `in_tipiintervento`.`tempo_standard` FROM `co_promemoria` INNER JOIN `in_tipiintervento` ON `in_tipiintervento`.`id` = `co_promemoria`.`idtipointervento` LEFT JOIN `in_tipiintervento_lang` ON (`in_tipiintervento`.`id` = `in_tipiintervento_lang`.`id_record` AND `in_tipiintervento_lang`.`id_lang` = ' . prepare ( Models\Locale :: getDefault () -> id ) . ') WHERE `co_promemoria`.`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 '
2020-02-17 13:18:25 +01:00
< form id = " add_form " action = " " method = " post " role = " form " >
2019-03-20 10:16:14 +01:00
< 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 .' " >
2020-02-14 17:02:16 +01:00
2018-08-30 18:20:30 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
2020-02-17 13:18:25 +01:00
< input type = " hidden " name = " op " value = " '.(! $block_edit ? 'edit-promemoria' : 'pianificazione').' " > ' ;
2018-08-30 18:20:30 +02:00
2024-01-15 15:30:45 +01:00
echo '
2018-08-30 18:20:30 +02:00
<!-- DATI PROMEMORIA -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Dati ').' </ h3 >
2018-08-30 18:20:30 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2018-08-30 18:20:30 +02:00
< div class = " row " >
2022-11-28 09:27:25 +01:00
< div class = " col-md-4 " >
2024-01-19 15:26:12 +01:00
{[ " type " : " date " , " label " : " '.tr('Data promemoria').' " , " name " : " data_richiesta " , " required " : 1 , " value " : " '. $data_richiesta .' " , " readonly " : '.intval($block_edit).' , " min-date " : " '. $data_accettazione .' " , " max-date " : " '. $data_conclusione .' " ]}
2018-08-30 18:20:30 +02:00
</ div >
2022-11-28 09:27:25 +01:00
< div class = " col-md-4 " >
2020-02-17 13:18:25 +01:00
{[ " type " : " select " , " label " : " '.tr('Tipo intervento').' " , " name " : " idtipointervento " , " required " : 1 , " id " : " idtipointervento_ " , " value " : " '. $record['idtipointervento'] .' " , " readonly " : '.intval($block_edit).' , " ajax-source " : " tipiintervento " , " value " : " '. $idtipointervento .' " ]}
2018-08-30 18:20:30 +02:00
</ div >
2022-11-28 09:27:25 +01:00
< div class = " col-md-4 " >
2024-03-05 16:01:45 +01:00
{[ " type " : " select " , " label " : " '.tr('Sezionale').' " , " name " : " id_segment " , " required " : 1 , " ajax-source " : " segmenti " , " select-options " : '.json_encode([' id_module ' => $id_module_interventi, ' is_sezionale ' => 1]).' , " value " : " '. $_SESSION['module_'.$id_module_interventi] ['id_segment'].' " ]}
2022-11-28 09:27:25 +01:00
</ div >
2018-08-30 18:20:30 +02:00
</ div >
< div class = " row " >
2024-01-29 16:00:59 +01:00
< div class = " col-md-3 " >
{[ " type " : " timestamp " , " label " : " '.tr('Data/ora scadenza').' " , " name " : " data_scadenza " , " value " : " '. $record['data_scadenza'] .' " , " readonly " : '.intval($block_edit).' ]}
</ div >
< div class = " col-md-3 " >
2020-02-17 13:18:25 +01:00
{[ " 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($block_edit).' , " required " : " 1 " ]}
2018-08-30 18:20:30 +02:00
</ div >
< div class = " col-md-6 " >
2020-09-25 11:03:39 +02:00
{[ " type " : " select " , " multiple " : " 1 " , " label " : " '.tr('Impianti a contratto').' " , " name " : " idimpianti[] " , " help " : " '.tr('Impianti della sede selezionata per il Contratto').' " , " 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($block_edit).' ]}
2018-08-30 18:20:30 +02:00
</ div >
</ div >
2024-01-29 16:00:59 +01:00
< div class = " row " >
< div class = " col-md-12 " >
{[ " type " : " select " , " label " : " '.tr('Tecnici assegnati').' " , " multiple " : " 1 " , " name " : " idtecnici[] " , " ajax-source " : " tecnici " , " value " : " '. $record['idtecnici'] .' " , " readonly " : '.intval($block_edit).' ]}
</ div >
</ div >
2018-08-30 18:20:30 +02:00
< div class = " row " >
2023-05-12 09:53:26 +02:00
< div class = " col-md-12 " > ' ;
2024-01-15 15:30:45 +01:00
echo input ([
'type' => 'ckeditor' ,
'label' => tr ( 'Richiesta' ),
'name' => 'richiesta' ,
'required' => 1 ,
'readonly' => $record [ 'flag_completato' ],
'extra' => 'rows="5"' ,
'value' => $record [ 'richiesta' ],
]);
echo '
2023-05-12 09:53:26 +02:00
</ div >
2018-08-30 18:20:30 +02:00
</ div >
</ div >
</ div > ' ;
echo '
2020-02-17 13:18:25 +01:00
<!-- RIGHE -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Righe ').' </ h3 >
2018-08-30 18:20:30 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2020-02-17 13:18:25 +01:00
< div class = " row " >
< div class = " col-md-12 " > ' ;
2024-01-15 15:30:45 +01:00
if ( ! $block_edit ) {
echo '
2024-05-16 18:02:50 +02:00
< a class = " btn btn-sm btn-primary " data - href = " '. $structure->fileurl ('row-add.php').'?id_module='. $id_module .'&id_plugin='. $id_plugin .'&id_record='. $id_record .'&is_articolo " data - widget = " tooltip " data - title = " '.tr('Aggiungi articolo').' " >
2020-02-17 13:18:25 +01:00
< i class = " fa fa-plus " ></ i > '.tr(' Articolo ').'
</ a > ' ;
2024-01-15 15:30:45 +01:00
echo '
2024-05-16 18:02:50 +02:00
< a class = " btn btn-sm btn-primary " data - href = " '. $structure->fileurl ('row-add.php').'?id_module='. $id_module .'&id_plugin='. $id_plugin .'&id_record='. $id_record .'&is_riga " data - widget = " tooltip " data - title = " '.tr('Aggiungi riga').' " >
2020-02-17 13:18:25 +01:00
< i class = " fa fa-plus " ></ i > '.tr(' Riga ').'
</ a > ' ;
2024-01-15 15:30:45 +01:00
}
2020-09-25 11:03:39 +02:00
2024-01-15 15:30:45 +01:00
echo '
2020-02-17 13:18:25 +01:00
</ div >
2018-08-30 18:20:30 +02:00
</ div >
2020-09-25 11:03:39 +02:00
< div class = " clearfix " ></ div >
< br >
< div id = " righe_promemoria " > ' ;
2018-08-30 18:20:30 +02:00
2020-02-17 13:18:25 +01:00
include $structure -> filepath ( 'row-list.php' );
2018-08-30 18:20:30 +02:00
2024-01-15 15:30:45 +01:00
echo '
2020-02-17 13:18:25 +01:00
</ div >
2018-08-30 18:20:30 +02:00
</ div >
</ div > ' ;
2020-02-17 13:18:25 +01:00
echo '{( "name": "filelist_and_upload", "id_record": "' . $id_record . '", "id_module": "' . $id_module . '", "id_plugin": "' . $id_plugin . '", "readonly": ' . intval ( $block_edit ) . ' )}' ;
2018-08-30 18:20:30 +02:00
echo '
<!-- PIANIFICAZIONE CICLICA -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary '.(! $block_edit ? 'hide' : '').' " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Promemoria ciclico ? ').' </ h3 >
2018-08-30 18:20:30 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2018-08-30 18:20:30 +02:00
<!-- 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 " >
2020-02-14 17:02:16 +01:00
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 >
2020-02-14 17:02:16 +01:00
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 >
2020-02-14 17:02:16 +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 -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary '.(! $block_edit ? 'hide' : '').' " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Pianificare interventi ? ').' </ h3 >
2018-08-30 18:20:30 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2018-08-30 18:20:30 +02:00
< 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 " >
2020-02-17 13:18:25 +01:00
< button type = " submit " class = " btn btn-primary " '.($block_edit ? ' 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 ){
2024-05-16 18:02:50 +02:00
$ ( " #add_form .card-primary .card-primary " ) . hide ();
2020-02-05 12:40:44 +01:00
$ ( " #modals > div .btn-primary " ) . hide ();
2018-08-30 18:20:30 +02:00
};
$ ( " #idtipointervento_ " ) . change ( function (){
if (( $ ( this ) . val () != " " )){
2024-05-16 18:02:50 +02:00
$ ( " #add_form .card-primary .card-primary " ) . show ();
2020-02-05 12:40:44 +01:00
$ ( " #modals > div .btn-primary " ) . show ();
2018-08-30 18:20:30 +02:00
} else {
2024-05-16 18:02:50 +02:00
$ ( " #add_form .card-primary .card-primary " ) . hide ();
2020-02-05 12:40:44 +01:00
$ ( " #modals > div .btn-primary " ) . hide ();
2018-08-30 18:20:30 +02:00
}
});
2020-02-14 17:02:16 +01:00
2018-11-13 13:22:38 +01:00
$ ( " #pianifica_promemoria " ) . click ( function () {
if ( $ ( this ) . is ( " :checked " )){
2020-08-24 15:05:29 +02:00
$ ( " #intervallo " ) . removeAttr ( " disabled " )
. prop ( " disabled " , false );
$ ( " #data_inizio " ) . removeAttr ( " disabled " )
. prop ( " disabled " , false );
input ( " pianifica_intervento " ) . setDisabled ( false );
2020-02-14 17:02:16 +01:00
2020-02-05 12:40:44 +01:00
$ ( " #modals > div .btn-primary " ) . removeAttr ( " disabled " );
2018-11-13 13:22:38 +01:00
} else {
$ ( " #intervallo " ) . prop ( " disabled " , true );
$ ( " #data_inizio " ) . prop ( " disabled " , true );
2020-08-24 15:05:29 +02:00
input ( " pianifica_intervento " ) . setDisabled ( true );
2018-11-13 13:22:38 +01:00
$ ( " #pianifica_intervento " ) . prop ( " checked " , false );
2020-02-14 17:02:16 +01:00
2020-08-24 15:05:29 +02:00
$ ( " #modals > div .btn-primary " ) . prop ( " disabled " , true );
2020-02-14 17:02:16 +01:00
2020-08-24 15:05:29 +02:00
$ ( " #idtecnico " ) . prop ( " disabled " , true )
. removeAttr ( " required " );
$ ( " #orario_inizio " ) . prop ( " disabled " , true )
. removeAttr ( " required " );
$ ( " #orario_fine " ) . prop ( " disabled " , true )
. removeAttr ( " required " );
2018-11-13 13:22:38 +01:00
}
});
2020-02-14 17:02:16 +01:00
2018-08-30 18:20:30 +02:00
$ ( " #pianifica_intervento " ) . click ( function () {
if ( $ ( this ) . is ( " :checked " )){
2020-08-24 15:05:29 +02:00
$ ( " #idtecnico " ) . removeAttr ( " disabled " )
. prop ( " required " , true );
$ ( " #orario_inizio " ) . removeAttr ( " disabled " )
. prop ( " required " , true );
$ ( " #orario_fine " ) . removeAttr ( " disabled " )
. prop ( " required " , true );
2018-08-30 18:20:30 +02:00
} else {
2020-08-24 15:05:29 +02:00
$ ( " #idtecnico " ) . prop ( " disabled " , true )
. removeAttr ( " required " );
$ ( " #orario_inizio " ) . prop ( " disabled " , true )
. removeAttr ( " required " );
$ ( " #orario_fine " ) . removeAttr ( " required " )
. prop ( " disabled " , true );
2018-08-30 18:20:30 +02:00
}
});
2024-01-29 16:00:59 +01:00
content_was_modified = false ;
2018-08-30 18:20:30 +02:00
});
2020-09-25 11:03:39 +02:00
function refreshRighe ( id ) {
$ ( " #righe_promemoria " ) . load ( " '. $plugin->fileurl ('row-list.php').'?id_plugin='. $id_plugin .'&id_record= " + id + " &add='. $block_edit .' " );
2018-08-30 18:20:30 +02:00
}
</ script > ' ;