2023-03-13 22:56:37 +01:00
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
2022-07-19 19:05:56 +02:00
use Carbon\Carbon ;
2023-08-04 14:54:28 +02:00
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2021-03-29 10:07:45 +02:00
// Individuazione dati selezionabili
// Stati interventi
2024-02-05 17:07:33 +01:00
$stati_intervento = $dbo -> fetchArray ( 'SELECT `idstatointervento` AS id, `descrizione`, `colore` FROM `in_statiintervento` WHERE `deleted_at` IS NULL ORDER BY `descrizione` ASC' );
2021-03-29 10:07:45 +02:00
// Tipi intervento
2024-02-05 17:07:33 +01:00
$tipi_intervento = $dbo -> fetchArray ( 'SELECT `idtipointervento` AS id, `descrizione` FROM `in_tipiintervento` WHERE `deleted_at` IS NULL ORDER BY `descrizione` ASC' );
2021-03-29 10:07:45 +02:00
// Tecnici disponibili
2024-02-05 17:07:33 +01:00
$tecnici_disponibili = $dbo -> fetchArray ( ' SELECT
`an_anagrafiche` . `idanagrafica` AS id , `ragione_sociale` , `colore`
FROM
`an_anagrafiche`
INNER JOIN `an_tipianagrafiche_anagrafiche` ON `an_anagrafiche` . `idanagrafica` = `an_tipianagrafiche_anagrafiche` . `idanagrafica`
INNER JOIN `an_tipianagrafiche` ON `an_tipianagrafiche_anagrafiche` . `idtipoanagrafica` = `an_tipianagrafiche` . `id`
LEFT JOIN `an_tipianagrafiche_lang` ON ( `an_tipianagrafiche` . `id` = `an_tipianagrafiche_lang` . `id_record` AND `an_tipianagrafiche_lang` . `id_lang` = '.prepare(setting(' Lingua ' )) . " )
LEFT JOIN `in_interventi_tecnici` ON `in_interventi_tecnici` . `idtecnico` = `an_anagrafiche` . `idanagrafica`
INNER JOIN `in_interventi` ON `in_interventi_tecnici` . `idintervento` = `in_interventi` . `id`
WHERE
`an_anagrafiche` . `deleted_at` IS NULL AND `an_tipianagrafiche_lang` . `name` = 'Tecnico' " .Modules::getAdditionalsQuery('Interventi', null, false).'
GROUP BY
`an_anagrafiche` . `idanagrafica`
ORDER BY
`ragione_sociale` ASC ' );
2021-03-29 10:07:45 +02:00
// Zone
$zone = $dbo -> fetchArray ( '(SELECT 0 AS ordine, \'0\' AS id, \'Nessuna zona\' AS descrizione) UNION (SELECT 1 AS ordine, id, descrizione FROM an_zone) ORDER BY ordine, descrizione ASC' );
2021-03-24 12:56:29 +01:00
// Prima selezione globale per tutti i filtri
if ( ! isset ( $_SESSION [ 'dashboard' ][ 'idtecnici' ])) {
$_SESSION [ 'dashboard' ][ 'idtecnici' ] = [ " '-1' " ];
2021-03-29 10:07:45 +02:00
foreach ( $tecnici_disponibili as $tecnico ) {
2023-08-04 14:54:28 +02:00
if (( $user [ 'gruppo' ] == 'Tecnici' && $user [ 'idanagrafica' ] == $tecnico [ 'id' ]) || $user [ 'gruppo' ] != 'Tecnici' ) {
2021-10-20 16:21:14 +02:00
$_SESSION [ 'dashboard' ][ 'idtecnici' ][] = " ' " . $tecnico [ 'id' ] . " ' " ;
}
2021-03-24 12:56:29 +01:00
}
}
if ( ! isset ( $_SESSION [ 'dashboard' ][ 'idstatiintervento' ])) {
$_SESSION [ 'dashboard' ][ 'idstatiintervento' ] = [ " '-1' " ];
2021-03-29 10:07:45 +02:00
foreach ( $stati_intervento as $stato ) {
$_SESSION [ 'dashboard' ][ 'idstatiintervento' ][] = " ' " . $stato [ 'id' ] . " ' " ;
2021-03-24 12:56:29 +01:00
}
}
if ( ! isset ( $_SESSION [ 'dashboard' ][ 'idtipiintervento' ])) {
$_SESSION [ 'dashboard' ][ 'idtipiintervento' ] = [ " '-1' " ];
2021-03-29 10:07:45 +02:00
foreach ( $tipi_intervento as $tipo ) {
$_SESSION [ 'dashboard' ][ 'idtipiintervento' ][] = " ' " . $tipo [ 'id' ] . " ' " ;
2021-03-24 12:56:29 +01:00
}
}
if ( ! isset ( $_SESSION [ 'dashboard' ][ 'idzone' ])) {
$_SESSION [ 'dashboard' ][ 'idzone' ] = [ " '-1' " ];
2021-03-29 10:07:45 +02:00
foreach ( $zone as $zona ) {
$_SESSION [ 'dashboard' ][ 'idzone' ][] = " ' " . $zona [ 'id' ] . " ' " ;
2021-03-24 12:56:29 +01:00
}
}
2020-08-04 18:33:28 +02:00
echo '
<!-- Filtri -->
< div class = " row " >
<!-- STATI INTERVENTO -->
< div class = " dropdown col-md-3 " id = " dashboard_stati " >
< button type = " button " class = " btn btn-block counter_object " data - toggle = " dropdown " >
< i class = " fa fa-filter " ></ i > '.tr(' Stati attività ').'
( < span class = " selected_counter " ></ span >/< span class = " total_counter " ></ span > ) < i class = " caret " ></ i >
</ button >
< ul class = " dropdown-menu " role = " menu " > ' ;
2017-08-04 16:28:16 +02:00
// Stati intervento
2020-09-23 17:53:19 +02:00
$stati_sessione = session_get ( 'dashboard.idstatiintervento' , []);
2020-08-04 18:33:28 +02:00
foreach ( $stati_intervento as $stato ) {
2017-08-04 16:28:16 +02:00
$attr = '' ;
2020-09-22 20:28:37 +02:00
if ( in_array ( " ' " . $stato [ 'id' ] . " ' " , $stati_sessione )) {
2020-08-04 18:33:28 +02:00
$attr = 'checked="checked"' ;
2017-08-04 16:28:16 +02:00
}
2018-02-18 19:53:23 +01:00
2020-08-04 18:33:28 +02:00
echo '
< li >
< input type = " checkbox " id = " stato_'. $stato['id'] .' " class = " dashboard_stato " value = " '. $stato['id'] .' " '.$attr.' >
2022-06-15 18:33:41 +02:00
< label for = " stato_'. $stato['id'] .' " >
'.$stato[' descrizione '].' < span style = " position:relative;right:-7px;bottom:-3px;width:15px;height:15px;display:inline-block;border-radius:50%;background-color:'. $stato['colore'] .'; " ></ span >
2020-08-04 18:33:28 +02:00
</ label >
</ li > ' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
echo '
< div class = " btn-group float-right " >
< button type = " button " class = " btn btn-primary btn-sm seleziona_tutto " >
'.tr(' Tutti ').'
</ button >
< button type = " button " class = " btn btn-danger btn-sm deseleziona_tutto " >
< i class = " fa fa-times " ></ i >
</ button >
2017-08-04 16:28:16 +02:00
</ div >
</ ul >
</ div >
2020-08-04 18:33:28 +02:00
<!-- TIPI INTERVENTO -->
< div class = " dropdown col-md-3 " id = " dashboard_tipi " >
< button type = " button " class = " btn btn-block counter_object " data - toggle = " dropdown " >
< i class = " fa fa-filter " ></ i > '.tr(' Tipi attività ').'
( < span class = " selected_counter " ></ span >/< span class = " total_counter " ></ span > ) < i class = " caret " ></ i >
</ button >
< ul class = " dropdown-menu " role = " menu " > ' ;
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
// Tipi intervento
2020-09-23 17:53:19 +02:00
$tipi_sessione = session_get ( 'dashboard.idtipiintervento' , []);
2020-08-04 18:33:28 +02:00
foreach ( $tipi_intervento as $tipo ) {
2017-08-04 16:28:16 +02:00
$attr = '' ;
2020-09-22 20:28:37 +02:00
if ( in_array ( " ' " . $tipo [ 'id' ] . " ' " , $tipi_sessione )) {
2020-08-04 18:33:28 +02:00
$attr = 'checked="checked"' ;
2017-08-04 16:28:16 +02:00
}
2018-02-18 19:53:23 +01:00
2020-08-04 18:33:28 +02:00
echo '
< li >
< input type = " checkbox " id = " tipo_'. $tipo['id'] .' " class = " dashboard_tipo " value = " '. $tipo['id'] .' " '.$attr.' >
< label for = " tipo_'. $tipo['id'] .' " >
'.$tipo[' descrizione '].'
</ label >
</ li > ' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
echo '
< div class = " btn-group float-right " >
< button type = " button " class = " btn btn-primary btn-sm seleziona_tutto " >
'.tr(' Tutti ').'
</ button >
< button type = " button " class = " btn btn-danger btn-sm deseleziona_tutto " >
< i class = " fa fa-times " ></ i >
</ button >
2017-08-04 16:28:16 +02:00
</ div >
</ ul >
</ div >
2020-08-04 18:33:28 +02:00
<!-- TECNICI -->
< div class = " dropdown col-md-3 " id = " dashboard_tecnici " >
< button type = " button " class = " btn btn-block counter_object " data - toggle = " dropdown " >
< i class = " fa fa-filter " ></ i > '.tr(' Tecnici ').'
( < span class = " selected_counter " ></ span >/< span class = " total_counter " ></ span > ) < i class = " caret " ></ i >
</ button >
< ul class = " dropdown-menu " role = " menu " > ' ;
2020-09-23 17:53:19 +02:00
$tecnici_sessione = session_get ( 'dashboard.idtecnici' , []);
2020-08-04 18:33:28 +02:00
foreach ( $tecnici_disponibili as $tecnico ) {
2017-08-04 16:28:16 +02:00
$attr = '' ;
2020-09-22 20:28:37 +02:00
if ( in_array ( " ' " . $tecnico [ 'id' ] . " ' " , $tecnici_sessione )) {
2020-08-04 18:33:28 +02:00
$attr = 'checked="checked"' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
echo '
< li >
< input type = " checkbox " id = " tecnico_'. $tecnico['id'] .' " class = " dashboard_tecnico " value = " '. $tecnico['id'] .' " '.$attr.' >
< label for = " tecnico_'. $tecnico['id'] .' " >
2022-06-15 18:33:41 +02:00
'.$tecnico[' ragione_sociale '].' < span style = " position:relative;right:-7px;bottom:-3px;width:15px;height:15px;display:inline-block;border-radius:50%;background-color:'. $tecnico['colore'] .'; " ></ span >
2020-08-04 18:33:28 +02:00
</ label >
</ li > ' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
echo '
< div class = " btn-group float-right " >
< button type = " button " class = " btn btn-primary btn-sm seleziona_tutto " >
'.tr(' Tutti ').'
</ button >
< button type = " button " class = " btn btn-danger btn-sm deseleziona_tutto " >
< i class = " fa fa-times " ></ i >
</ button >
2017-08-04 16:28:16 +02:00
</ div >
</ ul >
</ div >
2020-08-04 18:33:28 +02:00
<!-- ZONE -->
< div class = " dropdown col-md-3 " id = " dashboard_zone " >
< button type = " button " class = " btn btn-block counter_object " data - toggle = " dropdown " >
< i class = " fa fa-filter " ></ i > '.tr(' Zone ').'
( < span class = " selected_counter " ></ span >/< span class = " total_counter " ></ span > ) < i class = " caret " ></ i >
</ button >
< ul class = " dropdown-menu " role = " menu " > ' ;
2017-08-04 16:28:16 +02:00
// Zone
2020-09-23 17:53:19 +02:00
$zone_sessione = session_get ( 'dashboard.idzone' , []);
2020-08-04 18:33:28 +02:00
foreach ( $zone as $zona ) {
2017-08-04 16:28:16 +02:00
$attr = '' ;
2020-09-22 20:28:37 +02:00
if ( in_array ( " ' " . $zona [ 'id' ] . " ' " , $zone_sessione )) {
2020-08-04 18:33:28 +02:00
$attr = 'checked="checked"' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
echo '
< li >
< input type = " checkbox " id = " zona_'. $zona['id'] .' " class = " dashboard_zona " value = " '. $zona['id'] .' " '.$attr.' >
< label for = " zona_'. $zona['id'] .' " >
'.$zona[' descrizione '].'
</ label >
</ li > ' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
echo '
< div class = " btn-group float-right " >
< button type = " button " class = " btn btn-primary btn-sm seleziona_tutto " >
'.tr(' Tutti ').'
</ button >
< button type = " button " class = " btn btn-danger btn-sm deseleziona_tutto " >
< i class = " fa fa-times " ></ i >
</ button >
2017-08-04 16:28:16 +02:00
</ div >
</ ul >
</ div >
</ div >
2020-08-04 18:33:28 +02:00
< br > ' ;
2023-06-12 12:36:55 +02:00
$solo_promemoria_assegnati = setting ( 'Visualizza solo promemoria assegnati' );
2020-08-04 19:04:53 +02:00
$id_tecnico = null ;
if ( $user [ 'gruppo' ] == 'Tecnici' && ! empty ( $user [ 'idanagrafica' ])) {
$id_tecnico = $user [ 'idanagrafica' ];
}
2024-02-09 12:08:55 +01:00
$query_da_programmare = ' SELECT
`data_richiesta` AS data
FROM
`co_promemoria`
INNER JOIN `co_contratti` ON `co_promemoria` . `idcontratto` = `co_contratti` . `id`
INNER JOIN `co_staticontratti` ON `co_contratti` . `idstato` = `co_staticontratti` . `id`
LEFT JOIN `co_staticontratti_lang` ON ( `co_staticontratti` . `id` = `co_staticontratti_lang` . `id_record` AND `co_staticontratti_lang` . `id_lang` = '.prepare(setting(' Lingua ')).' )
INNER JOIN `an_anagrafiche` ON `co_contratti` . `idanagrafica` = `an_anagrafiche` . `idanagrafica`
2020-03-14 14:59:27 +01:00
WHERE
2024-02-09 12:08:55 +01:00
`co_staticontratti` . `is_pianificabile` = 1 AND `idintervento` IS NULL
2020-03-14 14:59:27 +01:00
2024-02-09 12:08:55 +01:00
UNION
SELECT
IF ( `data_scadenza` IS NULL , `data_richiesta` , `data_scadenza` ) AS data
FROM
`in_interventi`
INNER JOIN `an_anagrafiche` ON `in_interventi` . `idanagrafica` = `an_anagrafiche` . `idanagrafica` ' ;
2020-08-04 19:04:53 +02:00
2020-11-06 19:24:11 +01:00
// Visualizzo solo promemoria del tecnico loggato
2020-08-04 19:04:53 +02:00
if ( ! empty ( $id_tecnico ) && ! empty ( $solo_promemoria_assegnati )) {
$query_da_programmare .= '
INNER JOIN in_interventi_tecnici_assegnati ON in_interventi . id = in_interventi_tecnici_assegnati . id_intervento AND id_tecnico = ' . prepare ( $id_tecnico );
}
$query_da_programmare .= '
2020-11-06 19:24:11 +01:00
WHERE ( SELECT COUNT ( * ) FROM in_interventi_tecnici WHERE in_interventi_tecnici . idintervento = in_interventi . id ) = 0 AND in_interventi . idstatointervento IN ( SELECT idstatointervento FROM in_statiintervento WHERE is_completato = 0 ) ' ;
2020-03-14 14:59:27 +01:00
$risultati_da_programmare = $dbo -> fetchArray ( $query_da_programmare );
if ( ! empty ( $risultati_da_programmare )) {
2017-08-04 16:28:16 +02:00
echo '
< div class = " row " >
2018-02-20 16:46:23 +01:00
< div class = " col-md-10 " > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
< div id = " calendar " ></ div > ' ;
2020-03-14 14:59:27 +01:00
if ( ! empty ( $risultati_da_programmare )) {
2017-08-04 16:28:16 +02:00
echo '
</ div >
< div id = " external-events " class = " hidden-xs hidden-sm col-md-2 " >
2018-10-23 12:50:02 +02:00
< h4 > '.tr(' Promemoria da pianificare ').' </ h4 > ' ;
2018-05-11 10:22:38 +02:00
2018-06-06 00:00:22 +02:00
// Controllo pianificazioni mesi precedenti
2020-11-06 19:24:11 +01:00
// Promemoria contratti + promemoria interventi
2020-03-14 14:59:27 +01:00
$query_mesi_precenti = ' SELECT co_promemoria . id FROM co_promemoria INNER JOIN co_contratti ON co_promemoria . idcontratto = co_contratti . id WHERE idstato IN ( SELECT id FROM co_staticontratti WHERE is_pianificabile = 1 ) AND idintervento IS NULL AND DATE_ADD ( co_promemoria . data_richiesta , INTERVAL 1 DAY ) <= NOW ()
2020-08-04 19:04:53 +02:00
UNION SELECT in_interventi . id FROM in_interventi
INNER JOIN an_anagrafiche ON in_interventi . idanagrafica = an_anagrafiche . idanagrafica ' ;
2020-11-06 19:24:11 +01:00
// Visualizzo solo promemoria del tecnico loggato
2020-08-04 19:04:53 +02:00
if ( ! empty ( $id_tecnico ) && ! empty ( $solo_promemoria_assegnati )) {
$query_mesi_precenti .= '
INNER JOIN in_interventi_tecnici_assegnati ON in_interventi . id = in_interventi_tecnici_assegnati . id_intervento AND id_tecnico = ' . prepare ( $id_tecnico );
}
$query_mesi_precenti .= '
2020-11-06 19:24:11 +01:00
WHERE ( SELECT COUNT ( * ) FROM in_interventi_tecnici WHERE in_interventi_tecnici . idintervento = in_interventi . id ) = 0 AND in_interventi . idstatointervento IN ( SELECT idstatointervento FROM in_statiintervento WHERE is_completato = 0 ) AND DATE_ADD ( IF ( in_interventi . data_scadenza IS NULL , in_interventi . data_richiesta , in_interventi . data_scadenza ), INTERVAL 1 DAY ) <= NOW () ' ;
2020-03-14 14:59:27 +01:00
$numero_mesi_precenti = $dbo -> fetchNum ( $query_mesi_precenti );
2018-05-11 10:22:38 +02:00
2020-03-14 14:59:27 +01:00
if ( $numero_mesi_precenti > 0 ) {
2020-11-06 19:24:11 +01:00
echo '<div class="alert alert-warning alert-dismissible" role="alert"><button class="close" type="button" data-dismiss="alert" aria-hidden="true"><span aria-hidden="true">× </span><span class="sr-only">' . tr ( 'Chiudi' ) . '</span></button><i class="fa fa-exclamation-triangle"></i><span class="text-sm"> ' . tr ( 'Ci sono _NUM_ promemoria scaduti' , [
2020-03-14 14:59:27 +01:00
'_NUM_' => $numero_mesi_precenti ,
2020-11-06 19:24:11 +01:00
]) . '.</span></div>' ;
2018-03-22 18:34:33 +01:00
}
2019-12-13 10:08:17 +01:00
2020-03-14 14:59:27 +01:00
// Aggiunta della data corrente per visualizzare il mese corrente
$risultati_da_programmare [] = [
'data' => date ( 'Y-m-d H:i:s' ),
];
2018-05-11 10:22:38 +02:00
2020-03-14 14:59:27 +01:00
$mesi = collect ( $risultati_da_programmare )
-> unique ( function ( $item ) {
2022-07-19 19:05:56 +02:00
$data = Carbon :: parse ( $item [ 'data' ]);
2018-05-11 10:22:38 +02:00
2020-03-14 14:59:27 +01:00
return $data -> format ( 'm-Y' );
})
-> sortBy ( 'data' );
2018-05-11 10:22:38 +02:00
2020-03-14 14:59:27 +01:00
echo '
2023-04-13 10:45:50 +02:00
< select class = " superselect openstamanager-input select-input " id = " mese-promemoria " >
< option value = " all " > '.tr(' Tutti ').' </ option > ' ;
2018-05-11 10:22:38 +02:00
2020-03-14 14:59:27 +01:00
foreach ( $mesi as $mese ) {
2022-07-19 19:05:56 +02:00
$data = Carbon :: parse ( $mese [ 'data' ]);
2020-03-14 14:59:27 +01:00
$chiave = $data -> format ( 'mY' );
$testo = $data -> formatLocalized ( '%B %Y' );
2018-03-22 18:34:33 +01:00
2023-08-04 14:54:28 +02:00
if ( checkdate ( $data -> format ( 'm' ), $data -> format ( 'd' ), $data -> format ( 'Y' ))) {
echo '
2022-07-21 10:31:28 +02:00
< option value = " '. $chiave .' " > '.ucfirst($testo).' </ option > ' ;
2022-07-19 19:05:56 +02:00
}
2017-08-31 10:09:06 +02:00
}
2018-05-11 10:22:38 +02:00
2017-08-04 16:28:16 +02:00
echo '
2020-03-14 14:59:27 +01:00
</ select >
2020-08-04 18:33:28 +02:00
< div id = " elenco-promemoria " ></ div >
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
}
2018-07-08 18:11:17 +02:00
$vista = setting ( 'Vista dashboard' );
2017-08-04 16:28:16 +02:00
if ( $vista == 'mese' ) {
2023-01-23 23:10:52 +01:00
$def = 'dayGridMonth' ;
2017-08-04 16:28:16 +02:00
} elseif ( $vista == 'giorno' ) {
2023-02-21 18:59:11 +01:00
$def = 'timeGridDay' ;
2022-03-24 11:11:36 +01:00
} elseif ( $vista == 'settimana' ) {
2023-01-27 12:42:04 +01:00
$def = 'timeGridWeek' ;
2022-03-24 11:11:36 +01:00
} else {
$def = 'listWeek' ;
2017-08-04 16:28:16 +02:00
}
2023-03-28 11:57:23 +02:00
$days = [
1 => 'Lunedì' ,
2 => 'Martedì' ,
3 => 'Mercoledì' ,
4 => 'Giovedì' ,
5 => 'Venerdì' ,
6 => 'Sabato' ,
2023-08-04 14:54:28 +02:00
0 => 'Domenica' ,
2023-03-28 11:57:23 +02:00
];
2023-08-04 14:54:28 +02:00
$working_days = explode ( ',' , setting ( 'Giorni lavorativi' ));
2023-03-28 11:57:23 +02:00
$non_working_days = [];
foreach ( $days as $key => $day ) {
if ( ! in_array ( $day , $working_days )) {
array_push ( $non_working_days , $key );
2023-08-04 14:54:28 +02:00
}
2023-03-28 11:57:23 +02:00
}
2020-08-04 18:33:28 +02:00
$modulo_interventi = Modules :: get ( 'Interventi' );
echo '
2023-01-23 23:10:52 +01:00
< script type = " text/javascript " >
2023-01-24 22:43:39 +01:00
var Draggable = FullCalendar . Draggable ;
2023-01-23 23:10:52 +01:00
globals . dashboard = {
2023-03-28 16:24:33 +02:00
load_url : " '. $structure->fileurl ('ajax.php').' " ,
2020-08-04 18:33:28 +02:00
style : " '. $def .' " ,
2020-11-27 17:48:21 +01:00
show_sunday : '.intval(setting(' Visualizzare la domenica sul calendario ')).' ,
2020-10-13 17:49:21 +02:00
start_time : " '.setting('Ora inizio sul calendario').' " ,
2020-10-16 08:31:10 +02:00
end_time : " '.((setting('Ora fine sul calendario') != '00:00:00' && !empty(setting('Ora fine sul calendario'))) ? setting('Ora fine sul calendario') : '23:59:59').' " ,
2020-11-27 17:48:21 +01:00
write_permission : '.intval($modulo_interventi->permission == ' rw ').' ,
tooltip : '.intval(setting(' Utilizzare i tooltip sul calendario ')).' ,
2020-08-04 18:33:28 +02:00
calendar : null ,
timeFormat : " H:mm " ,
select : {
title : " '.tr('Aggiungi intervento').' " ,
url : globals . rootdir + " /add.php?id_module='. $modulo_interventi->id .' " ,
},
drop : {
title : " '.tr('Pianifica intervento').' " ,
url : globals . rootdir + " /add.php?id_module='. $modulo_interventi->id .' " ,
},
error : " '.tr('Errore durante la creazione degli eventi').' " ,
2021-08-05 10:01:49 +02:00
genericError : " '.tr('Errore').' " ,
genericWarning : " '.tr('Attenzione').' " ,
informazioni_aggiuntive : '.intval(setting(' Visualizza informazioni aggiuntive sul calendario ')).' ,
2020-08-04 18:33:28 +02:00
};
function aggiorna_contatore ( counter_id ) {
2020-11-27 17:48:21 +01:00
let counter = $ ( counter_id );
2020-08-04 18:33:28 +02:00
2020-11-27 17:48:21 +01:00
let dropdown = counter . find ( " .dropdown-menu " );
let selected = dropdown . find ( " input:checked " ) . length ;
let total = dropdown . find ( " input " ) . length ;
2020-08-04 18:33:28 +02:00
counter . find ( " .selected_counter " ) . html ( selected );
counter . find ( " .total_counter " ) . html ( total );
2020-11-27 17:48:21 +01:00
let object = counter . find ( " .counter_object " );
2020-08-04 18:33:28 +02:00
if ( total === 0 ) {
object . addClass ( " btn-primary disabled " );
return ;
} else {
object . removeClass ( " btn-primary disabled " );
}
2019-07-29 13:16:55 +02:00
2020-08-04 18:33:28 +02:00
if ( selected === total ) {
object . removeClass ( " btn-warning btn-danger " ) . addClass ( " btn-success " );
} else if ( selected === 0 ) {
object . removeClass ( " btn-warning btn-success " ) . addClass ( " btn-danger " );
} else {
object . removeClass ( " btn-success btn-danger " ) . addClass ( " btn-warning " );
}
}
2019-07-29 13:16:55 +02:00
2020-08-04 18:33:28 +02:00
function carica_interventi_da_pianificare ( mese ) {
if ( mese === undefined ) {
// Seleziono il mese corrente per gli interventi da pianificare
let date = new Date ();
date . setDate ( date . getDate ());
2019-05-13 19:21:46 +02:00
2020-08-04 18:33:28 +02:00
//Note: January is 0, February is 1, and so on.
mese = ( " 0 " + ( date . getMonth () + 1 )) . slice ( - 2 ) + date . getFullYear ();
2019-05-13 19:21:46 +02:00
2020-08-04 18:33:28 +02:00
$ ( " #mese-promemoria option[value= " + mese + " ] " ) . attr ( " selected " , " selected " ) . trigger ( " change " );
}
2019-07-29 13:16:55 +02:00
2020-08-04 18:33:28 +02:00
$ ( " #elenco-promemoria " ) . html ( " <center><br><br><i class= \" fa fa-refresh fa-spin fa-2x fa-fw \" ></i></center> " );
$ . get ( globals . dashboard . load_url , {
op : " carica_interventi " ,
mese : mese
}) . done ( function ( data ) {
$ ( " #elenco-promemoria " ) . html ( data );
2019-07-29 13:16:55 +02:00
2020-08-04 18:33:28 +02:00
$ ( " #external-events .fc-event " ) . each ( function () {
2023-01-26 23:41:05 +01:00
new Draggable ( this , {
create : false ,
2018-03-22 18:34:33 +01:00
revert : true ,
2020-08-04 18:33:28 +02:00
eventData : {
title : $ . trim ( $ ( this ) . text ()),
stick : false
}
2023-01-24 22:43:39 +01:00
} );
2018-03-22 18:34:33 +01:00
});
2017-08-04 16:28:16 +02:00
});
2020-08-04 18:33:28 +02:00
}
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
$ ( document ) . ready ( function () {
// Aggiornamento contatori iniziale
aggiorna_contatore ( " #dashboard_stati " );
aggiorna_contatore ( " #dashboard_tipi " );
aggiorna_contatore ( " #dashboard_tecnici " );
aggiorna_contatore ( " #dashboard_zone " );
2018-02-20 16:46:23 +01:00
2020-08-04 18:33:28 +02:00
// Selezione di uno stato intervento
$ ( " .dashboard_stato " ) . click ( function ( event ) {
let id = $ ( this ) . val ();
2018-02-16 18:15:36 +01:00
2020-08-04 18:33:28 +02:00
session_set_array ( " dashboard,idstatiintervento " , id ) . then ( function () {
aggiorna_contatore ( " #dashboard_stati " );
2023-01-23 23:10:52 +01:00
globals . dashboard . calendar . refetchEvents ();
2018-02-20 16:46:23 +01:00
});
2017-08-04 16:28:16 +02:00
});
2020-08-04 18:33:28 +02:00
// Selezione di un tipo intervento
$ ( " .dashboard_tipo " ) . click ( function ( event ) {
let id = $ ( this ) . val ();
2018-02-20 16:46:23 +01:00
2020-08-04 18:33:28 +02:00
session_set_array ( " dashboard,idtipiintervento " , id ) . then ( function () {
aggiorna_contatore ( " #dashboard_tipi " );
2023-01-23 23:10:52 +01:00
globals . dashboard . calendar . refetchEvents ();
2017-08-04 16:28:16 +02:00
});
});
2020-08-04 18:33:28 +02:00
// Selezione di un tecnico
$ ( " .dashboard_tecnico " ) . click ( function ( event ) {
let id = $ ( this ) . val ();
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
session_set_array ( " dashboard,idtecnici " , id ) . then ( function () {
aggiorna_contatore ( " #dashboard_tecnici " );
2023-01-23 23:10:52 +01:00
globals . dashboard . calendar . refetchEvents ();
2018-02-16 18:15:36 +01:00
});
2017-08-04 16:28:16 +02:00
});
2020-08-04 18:33:28 +02:00
// Selezione di una zona
$ ( " .dashboard_zona " ) . click ( function ( event ) {
let id = $ ( this ) . val ();
2018-02-16 18:15:36 +01:00
2020-08-04 18:33:28 +02:00
session_set_array ( " dashboard,idzone " , id ) . then ( function () {
aggiorna_contatore ( " #dashboard_zone " );
2023-01-23 23:10:52 +01:00
globals . dashboard . calendar . refetchEvents ();
2018-02-16 18:15:36 +01:00
});
2017-08-04 16:28:16 +02:00
});
2020-08-04 18:33:28 +02:00
// Selezione di tutti gli elementi
$ ( " .seleziona_tutto " ) . click ( function () {
$ ( this ) . closest ( " ul " ) . find ( " input:not(:checked) " ) . each ( function () {
$ ( this ) . click ();
2018-02-16 18:15:36 +01:00
});
2017-08-04 16:28:16 +02:00
});
2020-08-04 18:33:28 +02:00
// Deselezione di tutti gli elementi
$ ( " .deseleziona_tutto " ) . click ( function () {
$ ( this ) . closest ( " ul " ) . find ( " input:checked " ) . each ( function () {
$ ( this ) . click ();
2017-08-04 16:28:16 +02:00
});
});
2020-08-04 18:33:28 +02:00
$ ( " #mese-promemoria " ) . change ( function () {
let mese = $ ( this ) . val ();
carica_interventi_da_pianificare ( mese );
2017-08-04 16:28:16 +02:00
});
2020-08-04 18:33:28 +02:00
// Caricamento interventi da pianificare
carica_interventi_da_pianificare ();
2017-08-04 16:28:16 +02:00
// Creazione del calendario
2020-08-04 18:33:28 +02:00
create_calendar ();
});
function create_calendar () {
var calendarElement = document . getElementById ( " calendar " );
2021-11-15 11:40:45 +01:00
var clickCnt = 0 ;
2018-05-11 10:22:38 +02:00
2023-01-23 23:10:52 +01:00
var calendar = new FullCalendar . Calendar ( calendarElement , {
2020-08-04 18:33:28 +02:00
/* locales: allLocales, */
locale : globals . locale ,
2020-09-02 17:25:14 +02:00
slotEventOverlap : false ,
2023-02-24 19:10:51 +01:00
weekNumbers : true ,
weekText : " W " ,
nowIndicator : true ,
2023-03-06 09:21:20 +01:00
//height: "auto",
//aspectRatio: 1.8,
2024-01-26 17:08:00 +01:00
defaultTimedEventDuration : " 00:15 " ,
2023-03-06 09:21:20 +01:00
stickyHeaderDates : true ,
expandRows : true ,
2023-03-13 22:56:37 +01:00
//themeSystem: "bootstrap5",
showNonCurrentDates : false ,
dayMaxEvents : false ,
eventMaxStack : 4 ,
2020-10-08 10:35:27 +02:00
schedulerLicenseKey : " GPL-My-Project-Is-Open-Source " ,
2020-08-04 18:33:28 +02:00
hiddenDays : globals . dashboard . show_sunday ? [] : [ 0 ],
2023-01-23 23:10:52 +01:00
headerToolbar : {
2020-08-04 18:33:28 +02:00
left : " prev,next today " ,
center : " title " ,
2023-02-21 18:33:15 +01:00
right : " dayGridMonth,timeGridWeek,timeGridDay,listWeek "
2020-08-04 18:33:28 +02:00
},
2023-01-25 20:32:29 +01:00
eventDisplay : " block " ,
2020-08-04 18:33:28 +02:00
timeFormat : globals . dashboard . timeFormat ,
slotLabelFormat : globals . dashboard . timeFormat ,
slotDuration : " 00:15:00 " ,
2022-08-01 16:51:17 +02:00
snapDuration : globals . snapDuration ,
2023-01-27 12:42:04 +01:00
initialView : globals . dashboard . style ,
2023-01-26 23:53:06 +01:00
slotMinTime : globals . dashboard . start_time ,
slotMaxTime : globals . dashboard . end_time ,
2020-08-04 18:33:28 +02:00
lazyFetching : true ,
selectMirror : true ,
eventLimit : false , // allow "more" link when too many events
2021-08-05 10:01:49 +02:00
allDaySlot : globals . dashboard . informazioni_aggiuntive ,
2023-09-01 10:08:35 +02:00
showNonCurrentDates : true ,
2018-05-11 10:22:38 +02:00
2020-08-04 18:33:28 +02:00
loading : function ( isLoading , view ) {
if ( isLoading ) {
2023-01-27 13:25:55 +01:00
$ ( " #tiny-loader " ) . show ();
2020-08-04 18:33:28 +02:00
} else {
$ ( " #tiny-loader " ) . hide ();
2018-04-16 17:49:09 +02:00
}
2020-08-04 18:33:28 +02:00
},
2018-05-11 10:22:38 +02:00
2020-08-04 18:33:28 +02:00
droppable : globals . dashboard . write_permission ,
2023-01-24 22:43:39 +01:00
drop : function ( info ) {
let date = info . date ;
2018-05-11 10:22:38 +02:00
2020-08-04 18:33:28 +02:00
let data = moment ( date ) . format ( " YYYY-MM-DD " );
let ora_dal = moment ( date ) . format ( " HH:mm " );
let ora_al = moment ( date ) . add ( 1 , " hours " ) . format ( " HH:mm " );
2018-05-11 10:22:38 +02:00
2023-01-24 22:43:39 +01:00
let ref = info . draggedEl . dataset . ref ;
2020-08-04 18:33:28 +02:00
let name ;
if ( ref === " promemoria " ) {
name = " idcontratto_riga " ;
} else {
name = " id_intervento " ;
}
2023-01-24 22:43:39 +01:00
openModal ( globals . dashboard . drop . title , globals . dashboard . drop . url + " &data= " + data + " &orario_inizio= " + ora_dal + " &orario_fine= " + ora_al + " &ref=dashboard&idcontratto= " + info . draggedEl . dataset . idcontratto + " & " + name + " = " + info . draggedEl . dataset . id + " &id_tecnico= " + info . draggedEl . dataset . id_tecnico );
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
// Ricaricamento dei dati alla chiusura del modal
$ ( " #modals > div " ) . on ( " hidden.bs.modal " , function () {
2023-01-23 23:10:52 +01:00
globals . dashboard . calendar . refetchEvents ();
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
let mese = $ ( " #mese-promemoria " ) . val ();
carica_interventi_da_pianificare ( mese );
});
},
2023-01-26 23:41:05 +01:00
eventReceive : function ( info ){
info . revert ();
},
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
selectable : globals . dashboard . write_permission ,
2023-01-23 23:10:52 +01:00
select : function ( info ) { // info
let start = info . start ;
let end = info . end ;
2021-07-23 11:37:46 +02:00
2023-06-22 17:11:45 +02:00
let data = moment ( start ) . format ( " YYYY-MM-DD " );
let data_fine = moment ( end ) . format ( " YYYY-MM-DD " );
let orario_inizio = moment ( start ) . format ( " HH:mm " );
let orario_fine = moment ( end ) . format ( " HH:mm " );
// Fix selezione di un giorno avanti per vista mensile
if ( globals . dashboard . calendar . view == " dayGridMonth " ) {
data_fine = moment ( end ) . subtract ( 1 , " days " ) . format ( " YYYY-MM-DD " );
2020-08-26 16:45:05 +02:00
}
2023-06-22 17:11:45 +02:00
openModal ( globals . dashboard . select . title , globals . dashboard . select . url + " &ref=dashboard&data= " + data + " &data_fine= " + data_fine + " &orario_inizio= " + orario_inizio + " &orario_fine= " + orario_fine );
2017-08-30 11:50:46 +02:00
},
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
editable : globals . dashboard . write_permission ,
2023-01-23 23:10:52 +01:00
eventDrop : function ( info ) { // info
let event = info . event ;
2021-07-23 11:37:46 +02:00
2021-08-05 10:01:49 +02:00
if ( event . allDay !== true ) {
2022-06-15 18:06:25 +02:00
let start = event . start ;
let end = ( event . end != null ? event . end : event . start );
2021-06-04 19:07:50 +02:00
$ . post ( globals . dashboard . load_url , {
op : " modifica_intervento " ,
id : event . id ,
2023-01-23 23:10:52 +01:00
idintervento : event . extendedProps . idintervento ,
2022-06-15 18:06:25 +02:00
timeStart : moment ( start ) . format ( " YYYY-MM-DD HH:mm " ),
timeEnd : moment ( end ) . format ( " YYYY-MM-DD HH:mm " )
2021-08-05 10:01:49 +02:00
}, function ( data , responseType ) {
2021-06-04 19:07:50 +02:00
data = $ . trim ( data );
2021-06-08 12:36:54 +02:00
2021-08-05 10:01:49 +02:00
if ( responseType === " success " && data !== " ok " ) {
swal ( globals . dashboard . genericWarning , data , " warning " );
} else if ( responseType !== " success " ) {
swal ( globals . dashboard . genericError , data , " error " );
2021-06-04 19:07:50 +02:00
}
2021-06-08 12:36:54 +02:00
2021-08-05 10:01:49 +02:00
if ( data !== " ok " ) {
2023-01-23 23:10:52 +01:00
info . revert ();
2021-07-23 11:37:46 +02:00
}
2021-06-08 12:36:54 +02:00
2021-06-04 19:07:50 +02:00
});
2021-08-05 10:01:49 +02:00
} else {
2023-01-23 23:10:52 +01:00
info . revert ();
2021-06-04 19:07:50 +02:00
}
2020-08-04 18:33:28 +02:00
},
2023-01-23 23:10:52 +01:00
eventResize : function ( info ) {
let event = info . event ;
2022-06-15 18:06:25 +02:00
let start = event . start ;
let end = ( event . end != null ? event . end : event . start );
2020-08-04 18:33:28 +02:00
$ . post ( globals . dashboard . load_url , {
op : " modifica_intervento " ,
id : event . id ,
2023-01-23 23:10:52 +01:00
idintervento : event . extendedProps . idintervento ,
2022-06-15 18:06:25 +02:00
timeStart : moment ( start ) . format ( " YYYY-MM-DD HH:mm " ),
timeEnd : moment ( end ) . format ( " YYYY-MM-DD HH:mm " )
2021-08-05 10:01:49 +02:00
}, function ( data , responseType ) {
2020-08-04 18:33:28 +02:00
data = $ . trim ( data );
2021-07-23 11:37:46 +02:00
2021-08-05 10:01:49 +02:00
if ( responseType === " success " && data !== " ok " ) {
swal ( globals . dashboard . genericWarning , data , " warning " );
} else if ( responseType !== " success " ) {
swal ( globals . dashboard . genericError , data , " error " );
2021-06-08 12:36:54 +02:00
}
2021-08-05 10:01:49 +02:00
if ( data !== " ok " ) {
2023-01-23 23:10:52 +01:00
info . revert ();
2020-08-04 18:33:28 +02:00
}
2021-06-08 12:36:54 +02:00
2017-08-31 10:09:06 +02:00
});
2021-11-15 11:40:45 +01:00
}, ' ;
2023-08-04 14:54:28 +02:00
if ( isMobile () && setting ( 'Utilizzare i tooltip sul calendario' )) {
2021-11-15 11:40:45 +01:00
echo '
eventClick : function ( info ) {
2023-01-23 23:10:52 +01:00
let link = info . event . extendedProps . link ;
2021-11-15 11:40:45 +01:00
let element = $ ( this );
2023-01-23 23:10:52 +01:00
clickCnt ++ ;
2021-11-15 11:40:45 +01:00
if ( clickCnt === 1 ) {
oneClickTimer = setTimeout ( function () {
clickCnt = 0 ;
element . trigger ( " mouseenter " );
}, 400 );
} else if ( clickCnt === 2 ) {
clearTimeout ( oneClickTimer );
clickCnt = 0 ;
location . href = link ;
}
}, ' ;
2023-08-04 14:54:28 +02:00
} else {
2021-11-15 11:40:45 +01:00
echo '
eventClick : function ( info ) {
2023-03-31 18:01:53 +02:00
if ( info . event . extendedProps . link !== undefined ) {
info . jsEvent . preventDefault ();
location . href = info . event . extendedProps . link ;
}
2021-11-15 11:40:45 +01:00
}, ' ;
}
2017-08-31 10:09:06 +02:00
2021-11-15 11:40:45 +01:00
echo '
2023-01-23 23:10:52 +01:00
eventContent : function ( info ) {
2023-01-25 20:32:29 +01:00
return { html : info . event . title };
2023-01-23 23:10:52 +01:00
},
eventDidMount : function ( info ){
let element = $ ( info . el );
2023-03-28 11:57:23 +02:00
2023-01-23 23:10:52 +01:00
let id_record = info . event . extendedProps . idintervento ;
2022-03-24 11:11:36 +01:00
2023-03-28 11:57:23 +02:00
if ( globals . dashboard . tooltip == 1 && element [ 0 ] . childElementCount > 0 ) {
2020-11-16 18:19:51 +01:00
element . tooltipster ({
2021-08-05 10:01:49 +02:00
content : globals . translations . loading + " ... " ,
2020-11-16 18:19:51 +01:00
animation : " grow " ,
updateAnimation : " grow " ,
contentAsHTML : true ,
hideOnClick : true ,
speed : 200 ,
delay : 300 ,
maxWidth : 400 ,
theme : " tooltipster-shadow " ,
touchDevices : true ,
trigger : " hover " ,
position : " left " ,
2021-08-05 10:01:49 +02:00
functionBefore : function ( instance , helper ) {
2020-11-16 18:19:51 +01:00
let $origin = $ ( helper . origin );
if ( $origin . data ( " loaded " ) !== true ) {
2021-08-05 10:01:49 +02:00
$ . post ( globals . dashboard . load_url , {
2021-06-04 18:10:00 +02:00
op : " tooltip_info " ,
2021-06-08 12:36:54 +02:00
id_record : id_record ,
2023-01-23 23:10:52 +01:00
allDay : info . event . allDay ,
2020-11-16 18:19:51 +01:00
}, function ( data , response ) {
2023-03-28 11:57:23 +02:00
if ( data !== " " ) {
instance . content ( data );
$origin . data ( " loaded " , true );
}
2020-11-16 18:19:51 +01:00
});
}
2020-01-09 19:09:49 +01:00
}
2020-11-16 18:19:51 +01:00
});
}
2020-08-04 18:33:28 +02:00
},
2023-01-23 23:10:52 +01:00
2023-03-28 18:48:42 +02:00
eventSources : [
2023-03-28 16:24:33 +02:00
{
url : globals . dashboard . load_url ,
type : " POST " ,
extraParams : {
op : " interventi_periodo " ,
id_module : " '. $id_module .' "
},
failure : function () {
swal ( globals . dashboard . genericError , globals . dashboard . error , " error " );
}
},
{
url : globals . dashboard . load_url ,
method : " POST " ,
extraParams : {
op : " calendario_eventi " ,
id_module : " '. $id_module .' "
},
failure : function () {
swal ( globals . dashboard . genericError , globals . dashboard . error , " error " );
}
2020-08-04 18:33:28 +02:00
}
2023-03-28 18:48:42 +02:00
]
2020-08-04 18:33:28 +02:00
});
2023-03-28 11:57:23 +02:00
calendar . addEvent ({
daysOfWeek : " '.implode(',', $non_working_days ).' " ,
display : " background " ,
overlap : true ,
allDay : true
});
2023-01-23 23:10:52 +01:00
calendar . render ();
2020-08-04 18:33:28 +02:00
globals . dashboard . calendar = calendar ;
}
</ script > ' ;