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 ;
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
$stati_intervento = $dbo -> fetchArray ( 'SELECT idstatointervento AS id, descrizione, colore FROM in_statiintervento WHERE deleted_at IS NULL ORDER BY descrizione ASC' );
// Tipi intervento
$tipi_intervento = $dbo -> fetchArray ( 'SELECT idtipointervento AS id, descrizione FROM in_tipiintervento ORDER BY descrizione ASC' );
// Tecnici disponibili
$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 . idtipoanagrafica
LEFT OUTER JOIN in_interventi_tecnici ON in_interventi_tecnici . idtecnico = an_anagrafiche . idanagrafica
INNER JOIN in_interventi ON in_interventi_tecnici . idintervento = in_interventi . id
2021-09-17 11:05:27 +02:00
WHERE an_anagrafiche . deleted_at IS NULL AND an_tipianagrafiche . descrizione = 'Tecnico' " .Modules::getAdditionalsQuery('Interventi', null, false).'
2021-03-29 10:07:45 +02:00
GROUP BY an_anagrafiche . idanagrafica
ORDER BY ragione_sociale ASC ' );
// 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 ) {
2021-10-20 16:21:14 +02:00
if (( $user [ 'gruppo' ] == 'Tecnici' && $user [ 'idanagrafica' ] == $tecnico [ 'id' ]) || $user [ 'gruppo' ] != 'Tecnici' ){
$_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 > ' ;
2020-08-04 19:04:53 +02:00
$solo_promemoria_assegnati = setting ( 'Mostra promemoria attività ai soli Tecnici assegnati' );
$id_tecnico = null ;
if ( $user [ 'gruppo' ] == 'Tecnici' && ! empty ( $user [ 'idanagrafica' ])) {
$id_tecnico = $user [ 'idanagrafica' ];
}
2020-03-14 14:59:27 +01:00
$query_da_programmare = ' SELECT data_richiesta AS data FROM co_promemoria
2020-08-04 19:04:53 +02:00
INNER JOIN co_contratti ON co_promemoria . idcontratto = co_contratti . id
INNER JOIN an_anagrafiche ON co_contratti . idanagrafica = an_anagrafiche . idanagrafica
2020-03-14 14:59:27 +01:00
WHERE
idcontratto IN ( SELECT id FROM co_contratti WHERE idstato IN ( SELECT id FROM co_staticontratti WHERE is_pianificabile = 1 ))
AND idintervento IS NULL
UNION SELECT IF ( data_scadenza IS NULL , data_richiesta , data_scadenza ) AS data FROM in_interventi
2020-08-04 19:04:53 +02:00
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_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 '
2020-10-12 09:04:05 +02:00
< select class = " superselect openstamanager-input select-input " id = " mese-promemoria " > ' ;
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
2022-07-19 19:05:56 +02:00
if ( checkdate ( $data -> format ( 'm' ), $data -> format ( 'd' ), $data -> format ( 'Y' ))){
2022-07-21 10:31:28 +02:00
echo '
< 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' ) {
$def = 'month' ;
} elseif ( $vista == 'giorno' ) {
$def = 'agendaDay' ;
2022-03-24 11:11:36 +01:00
} elseif ( $vista == 'settimana' ) {
2017-08-04 16:28:16 +02:00
$def = 'agendaWeek' ;
2022-03-24 11:11:36 +01:00
} else {
$def = 'listWeek' ;
2017-08-04 16:28:16 +02:00
}
2020-08-04 18:33:28 +02:00
$modulo_interventi = Modules :: get ( 'Interventi' );
echo '
2017-08-04 16:28:16 +02:00
< script type = " text/javascript " >
2020-08-04 18:33:28 +02:00
globals . dashboard = {
2021-07-23 11:37:46 +02:00
load_url : " '. $structure->fileurl ('ajax.php').'?id_module='. $id_module .' " ,
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 : {
hour : " 2-digit " ,
minute : " 2-digit " ,
hour12 : false
}, */
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 () {
2021-08-05 10:01:49 +02:00
$ ( this ) . draggable ({
2018-03-22 18:34:33 +01:00
zIndex : 999 ,
revert : true ,
2020-08-04 18:33:28 +02:00
revertDuration : 0 ,
eventData : {
title : $ . trim ( $ ( this ) . text ()),
stick : false
}
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 " );
globals . dashboard . calendar . fullCalendar ( " refetchEvents " ); //.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 " );
globals . dashboard . calendar . fullCalendar ( " refetchEvents " ); //.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 " );
globals . dashboard . calendar . fullCalendar ( " refetchEvents " ); //.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 " );
globals . dashboard . calendar . fullCalendar ( " refetchEvents " ); //.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
2020-08-04 18:33:28 +02:00
var calendar = $ ( calendarElement ) . fullCalendar ({
/* plugins: [interactionPlugin, dayGridPlugin, timeGridPlugin], */
/* locales: allLocales, */
locale : globals . locale ,
2020-09-02 17:25:14 +02:00
slotEventOverlap : false ,
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 ],
header : {
left : " prev,next today " ,
center : " title " ,
2022-03-24 11:11:36 +01:00
right : " month,agendaWeek,agendaDay,listWeek "
2020-08-04 18:33:28 +02:00
},
timeFormat : globals . dashboard . timeFormat ,
slotLabelFormat : globals . dashboard . timeFormat ,
slotDuration : " 00:15:00 " ,
2022-06-10 08:35:51 +02:00
snapDuration : " '.setting('Tempo predefinito di snap attività sul calendario').' " ,
2020-08-04 18:33:28 +02:00
defaultView : globals . dashboard . style ,
minTime : globals . dashboard . start_time ,
maxTime : globals . dashboard . end_time ,
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 ,
2018-05-11 10:22:38 +02:00
2020-08-04 18:33:28 +02:00
loading : function ( isLoading , view ) {
if ( isLoading ) {
$ ( " #tiny-loader " ) . fadeIn ();
} 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 ,
drop : function ( date ) { // 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
2020-08-04 18:33:28 +02:00
let ref = $ ( this ) . data ( " ref " );
let name ;
if ( ref === " promemoria " ) {
name = " idcontratto_riga " ;
} else {
name = " id_intervento " ;
}
2020-09-15 12:30:25 +02:00
openModal ( globals . dashboard . drop . title , globals . dashboard . drop . url + " &data= " + data + " &orario_inizio= " + ora_dal + " &orario_fine= " + ora_al + " &ref=dashboard&idcontratto= " + $ ( this ) . data ( " idcontratto " ) + " & " + name + " = " + $ ( this ) . data ( " id " ) + " &id_tecnico= " + $ ( this ) . data ( " 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
$ ( this ) . remove ();
$ ( " #modals > div " ) . on ( " hidden.bs.modal " , function () {
globals . dashboard . calendar . fullCalendar ( " refetchEvents " ); //.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 );
});
},
2017-08-04 16:28:16 +02:00
2020-08-04 18:33:28 +02:00
selectable : globals . dashboard . write_permission ,
2021-08-05 10:01:49 +02:00
select : function ( start , end , allDay ) { // info
2020-08-04 18:33:28 +02:00
// let start = info.start;
// let end = info.end;
2021-07-23 11:37:46 +02:00
2021-08-05 10:01:49 +02:00
let intero_giorno = ! start . hasTime () && ! end . hasTime ();
2021-09-29 15:56:10 +02:00
if ( intero_giorno !== true || globals . dashboard . informazioni_aggiuntive == 0 ) {
2021-06-04 19:01:13 +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 . fullCalendar ( " getView " ) . name == " month " ) {
data_fine = moment ( end ) . subtract ( 1 , " days " ) . format ( " YYYY-MM-DD " );
}
2017-08-04 16:28:16 +02:00
2021-06-04 19:01:13 +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 );
2020-08-26 16:45:05 +02:00
}
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 ,
2021-08-05 10:01:49 +02:00
eventDrop : function ( event , delta , revertFunc ) { // info
2020-08-04 18:33:28 +02:00
// 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 ,
idintervento : event . 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 " ) {
2021-06-08 12:36:54 +02:00
revertFunc (); // 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 {
2021-06-04 19:07:50 +02:00
revertFunc ();
}
2020-08-04 18:33:28 +02:00
},
2021-08-05 10:01:49 +02:00
eventResize : function ( event , delta , revertFunc ) { // info
2020-08-04 18:33:28 +02:00
// 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 ,
idintervento : event . 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 " ) {
2020-08-04 18:33:28 +02:00
revertFunc (); // info.revert();
}
2021-06-08 12:36:54 +02:00
2017-08-31 10:09:06 +02:00
});
2021-11-15 11:40:45 +01:00
}, ' ;
if ( isMobile () && setting ( 'Utilizzare i tooltip sul calendario' )){
echo '
eventClick : function ( info ) {
let link = info . link ;
let element = $ ( this );
clickCnt ++ ;
if ( clickCnt === 1 ) {
oneClickTimer = setTimeout ( function () {
clickCnt = 0 ;
element . trigger ( " mouseenter " );
}, 400 );
} else if ( clickCnt === 2 ) {
clearTimeout ( oneClickTimer );
clickCnt = 0 ;
location . href = link ;
}
}, ' ;
} else {
echo '
eventClick : function ( info ) {
let link = info . link ;
location . href = link ;
}, ' ;
}
2017-08-31 10:09:06 +02:00
2021-11-15 11:40:45 +01:00
echo '
2020-08-04 18:33:28 +02:00
// eventPositioned: function (info) {
2021-08-05 10:01:49 +02:00
eventAfterRender : function ( event , element ) {
2020-08-04 18:33:28 +02:00
// let event = info.event;
// let element = $(info.el);
2022-03-24 11:11:36 +01:00
element . find ( " .fc-title, .fc-list-item-title " ) . html ( event . title );
2021-06-08 12:36:54 +02:00
let id_record = event . idintervento ;
2022-03-24 11:11:36 +01:00
2021-06-08 12:36:54 +02:00
if ( globals . dashboard . tooltip == 1 ) {
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 ,
2021-06-04 19:01:13 +02:00
allDay : event . allDay ,
2020-11-16 18:19:51 +01:00
}, function ( data , response ) {
instance . content ( data );
$origin . data ( " loaded " , true );
});
}
2020-01-09 19:09:49 +01:00
}
2020-11-16 18:19:51 +01:00
});
}
2020-08-04 18:33:28 +02:00
},
2017-09-01 12:55:48 +02:00
events : {
2020-08-04 18:33:28 +02:00
url : globals . dashboard . load_url + " &op=interventi_periodo " ,
type : " GET " ,
error : function () {
2021-08-05 10:01:49 +02:00
swal ( globals . dashboard . genericError , globals . dashboard . error , " error " );
2020-08-04 18:33:28 +02:00
}
}
});
//calendar.render();
globals . dashboard . calendar = calendar ;
}
</ script > ' ;