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
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
WHERE an_anagrafiche . deleted_at IS NULL AND an_tipianagrafiche . descrizione = 'Tecnico' " .Modules::getAdditionalsQuery('Interventi').'
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 ) {
$_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.' >
< label for = " stato_'. $stato['id'] .' " class = " badge " style = " color:'.color_inverse( $stato['colore'] ).'; background:'. $stato['colore'] .'; " >
'.$stato[' descrizione '].' </ span >
</ 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'] .' " >
'.$tecnico[' ragione_sociale '].'
</ 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 ) {
$data = new Carbon\Carbon ( $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 ) {
$data = new Carbon\Carbon ( $mese [ 'data' ]);
$chiave = $data -> format ( 'mY' );
$testo = $data -> formatLocalized ( '%B %Y' );
2018-03-22 18:34:33 +01:00
2020-03-14 14:59:27 +01:00
echo '
< option value = " '. $chiave .' " > '.ucfirst($testo).' </ option > ' ;
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' ;
} else {
$def = 'agendaWeek' ;
}
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 = {
load_url : globals . rootdir + " /actions.php?id_module='. $id_module .' " ,
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').' " ,
};
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 () {
$ ( 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 " );
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 " ,
right : " month,agendaWeek,agendaDay "
},
timeFormat : globals . dashboard . timeFormat ,
slotLabelFormat : globals . dashboard . timeFormat ,
slotDuration : " 00:15: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-06-03 11:06:51 +02:00
allDaySlot : true ,
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 ,
select : function ( start , end , allDay ) { // info
// let start = info.start;
// let end = info.end;
2021-06-04 19:01:13 +02:00
let is_allDay = ! start . hasTime () && ! end . hasTime ();
if ( is_allDay !== true ){
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 ,
2020-11-27 17:52:44 +01:00
eventDrop : function ( event , delta , revertFunc ) { // info
2020-08-04 18:33:28 +02:00
// let event = info.event;
2021-06-04 19:01:13 +02:00
2020-08-04 18:33:28 +02:00
$ . post ( globals . dashboard . load_url , {
op : " modifica_intervento " ,
id : event . id ,
idintervento : event . idintervento ,
timeStart : moment ( event . start ) . format ( " YYYY-MM-DD HH:mm " ),
timeEnd : moment ( event . end ) . format ( " YYYY-MM-DD HH:mm " )
}, function ( data , response ) {
data = $ . trim ( data );
if ( response !== " success " || data !== " ok " ) {
2020-11-27 17:52:44 +01:00
swal ( " '.tr('Errore').' " , data , " error " );
revertFunc (); // info.revert();
2020-08-04 18:33:28 +02:00
}
});
},
eventResize : function ( event , dayDelta , minuteDelta , revertFunc ) { // info
// let event = info.event;
$ . post ( globals . dashboard . load_url , {
op : " modifica_intervento " ,
id : event . id ,
idintervento : event . idintervento ,
timeStart : moment ( event . start ) . format ( " YYYY-MM-DD HH:mm " ),
timeEnd : moment ( event . end ) . format ( " YYYY-MM-DD HH:mm " )
}, function ( data , response ) {
data = $ . trim ( data );
if ( response !== " success " || data !== " ok " ) {
2020-11-27 17:52:44 +01:00
swal ( " '.tr('Errore').' " , data , " error " );
2020-08-04 18:33:28 +02:00
revertFunc (); // info.revert();
}
2017-08-31 10:09:06 +02:00
});
},
2020-08-04 18:33:28 +02:00
// eventPositioned: function (info) {
eventAfterRender : function ( event , element ) {
// let event = info.event;
// let element = $(info.el);
element . find ( " .fc-title " ) . html ( event . title );
let id_intervento = event . idintervento ;
2021-06-04 19:01:13 +02:00
if ( globals . dashboard . tooltip == 1 && event . allDay == false ) {
2020-11-16 18:19:51 +01:00
element . tooltipster ({
content : " '.tr('Caricamento...').' " ,
animation : " grow " ,
updateAnimation : " grow " ,
contentAsHTML : true ,
hideOnClick : true ,
speed : 200 ,
delay : 300 ,
maxWidth : 400 ,
theme : " tooltipster-shadow " ,
touchDevices : true ,
trigger : " hover " ,
position : " left " ,
functionBefore : function ( instance , helper ) {
let $origin = $ ( helper . origin );
if ( $origin . data ( " loaded " ) !== true ) {
$ . post ( globals . dashboard . load_url , {
2021-06-04 18:10:00 +02:00
op : " tooltip_info " ,
2020-11-16 18:19:51 +01:00
id : id_intervento ,
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 () {
2020-11-27 17:52:44 +01:00
swal ( " '.tr('Errore').' " , globals . dashboard . error , " error " );
2020-08-04 18:33:28 +02:00
}
}
});
//calendar.render();
globals . dashboard . calendar = calendar ;
}
</ script > ' ;