openstamanager/modules/dashboard/edit.php

800 lines
30 KiB
PHP
Raw Normal View History

2023-03-13 22:56:37 +01: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/>.
*/
use Carbon\Carbon;
2023-08-04 14:54:28 +02:00
include_once __DIR__.'/../../core.php';
// 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');
// 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');
// 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');
// 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');
// Prima selezione globale per tutti i filtri
if (!isset($_SESSION['dashboard']['idtecnici'])) {
$_SESSION['dashboard']['idtecnici'] = ["'-1'"];
foreach ($tecnici_disponibili as $tecnico) {
2023-08-04 14:54:28 +02:00
if (($user['gruppo'] == 'Tecnici' && $user['idanagrafica'] == $tecnico['id']) || $user['gruppo'] != 'Tecnici') {
$_SESSION['dashboard']['idtecnici'][] = "'".$tecnico['id']."'";
}
}
}
if (!isset($_SESSION['dashboard']['idstatiintervento'])) {
$_SESSION['dashboard']['idstatiintervento'] = ["'-1'"];
foreach ($stati_intervento as $stato) {
$_SESSION['dashboard']['idstatiintervento'][] = "'".$stato['id']."'";
}
}
if (!isset($_SESSION['dashboard']['idtipiintervento'])) {
$_SESSION['dashboard']['idtipiintervento'] = ["'-1'"];
foreach ($tipi_intervento as $tipo) {
$_SESSION['dashboard']['idtipiintervento'][] = "'".$tipo['id']."'";
}
}
if (!isset($_SESSION['dashboard']['idzone'])) {
$_SESSION['dashboard']['idzone'] = ["'-1'"];
foreach ($zone as $zona) {
$_SESSION['dashboard']['idzone'][] = "'".$zona['id']."'";
}
}
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">';
// Stati intervento
$stati_sessione = session_get('dashboard.idstatiintervento', []);
foreach ($stati_intervento as $stato) {
$attr = '';
if (in_array("'".$stato['id']."'", $stati_sessione)) {
$attr = 'checked="checked"';
}
2018-02-18 19:53:23 +01: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>
</label>
</li>';
}
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>
</div>
</ul>
</div>
<!-- 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">';
// Tipi intervento
$tipi_sessione = session_get('dashboard.idtipiintervento', []);
foreach ($tipi_intervento as $tipo) {
$attr = '';
if (in_array("'".$tipo['id']."'", $tipi_sessione)) {
$attr = 'checked="checked"';
}
2018-02-18 19:53:23 +01: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>';
}
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>
</div>
</ul>
</div>
<!-- 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">';
$tecnici_sessione = session_get('dashboard.idtecnici', []);
foreach ($tecnici_disponibili as $tecnico) {
$attr = '';
if (in_array("'".$tecnico['id']."'", $tecnici_sessione)) {
$attr = 'checked="checked"';
}
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>
</label>
</li>';
}
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>
</div>
</ul>
</div>
<!-- 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">';
// Zone
$zone_sessione = session_get('dashboard.idzone', []);
foreach ($zone as $zona) {
$attr = '';
if (in_array("'".$zona['id']."'", $zone_sessione)) {
$attr = 'checked="checked"';
}
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>';
}
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>
</div>
</ul>
</div>
</div>
<br>';
2023-06-12 12:36:55 +02:00
$solo_promemoria_assegnati = setting('Visualizza solo promemoria assegnati');
$id_tecnico = null;
if ($user['gruppo'] == 'Tecnici' && !empty($user['idanagrafica'])) {
$id_tecnico = $user['idanagrafica'];
}
$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
`co_staticontratti`.`is_pianificabile` = 1 AND `idintervento` IS NULL
2020-03-14 14:59:27 +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`';
// Visualizzo solo promemoria del tecnico loggato
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 .= '
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)) {
echo '
<div class="row">
2018-02-20 16:46:23 +01:00
<div class="col-md-10">';
}
echo '
<div id="calendar"></div>';
2020-03-14 14:59:27 +01:00
if (!empty($risultati_da_programmare)) {
echo '
</div>
<div id="external-events" class="hidden-xs hidden-sm col-md-2">
<h4>'.tr('Promemoria da pianificare').'</h4>';
2018-05-11 10:22:38 +02:00
// Controllo pianificazioni mesi precedenti
// 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()
UNION SELECT in_interventi.id FROM in_interventi
INNER JOIN an_anagrafiche ON in_interventi.idanagrafica=an_anagrafiche.idanagrafica';
// Visualizzo solo promemoria del tecnico loggato
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 .= '
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) {
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,
]).'.</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 = 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 '
<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) {
$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>';
}
}
2018-05-11 10:22:38 +02:00
echo '
2020-03-14 14:59:27 +01:00
</select>
<div id="elenco-promemoria"></div>
</div>
</div>';
}
2018-07-08 18:11:17 +02:00
$vista = setting('Vista dashboard');
if ($vista == 'mese') {
2023-01-23 23:10:52 +01:00
$def = 'dayGridMonth';
} elseif ($vista == 'giorno') {
$def = 'timeGridDay';
} elseif ($vista == 'settimana') {
2023-01-27 12:42:04 +01:00
$def = 'timeGridWeek';
} else {
$def = 'listWeek';
}
$days = [
1 => 'Lunedì',
2 => 'Martedì',
3 => 'Mercoledì',
4 => 'Giovedì',
5 => 'Venerdì',
6 => 'Sabato',
2023-08-04 14:54:28 +02:00
0 => 'Domenica',
];
2023-08-04 14:54:28 +02:00
$working_days = explode(',', setting('Giorni lavorativi'));
$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
}
}
$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').'",
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')).',
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')).',
};
function aggiorna_contatore(counter_id) {
2020-11-27 17:48:21 +01:00
let counter = $(counter_id);
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;
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");
if (total === 0) {
object.addClass("btn-primary disabled");
return;
} else {
object.removeClass("btn-primary disabled");
}
2019-07-29 13:16:55 +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
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());
//Note: January is 0, February is 1, and so on.
mese = ("0" + (date.getMonth() + 1)).slice(-2) + date.getFullYear();
$("#mese-promemoria option[value=" + mese + "]").attr("selected", "selected").trigger("change");
}
2019-07-29 13:16:55 +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
$("#external-events .fc-event").each(function () {
new Draggable( this, {
create: false,
2018-03-22 18:34:33 +01:00
revert: true,
eventData: {
title: $.trim($(this).text()),
stick: false
}
2023-01-24 22:43:39 +01:00
} );
2018-03-22 18:34:33 +01: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
// Selezione di uno stato intervento
$(".dashboard_stato").click(function (event) {
let id = $(this).val();
2018-02-16 18:15:36 +01: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
});
});
// Selezione di un tipo intervento
$(".dashboard_tipo").click(function (event) {
let id = $(this).val();
2018-02-20 16:46:23 +01: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();
});
});
// Selezione di un tecnico
$(".dashboard_tecnico").click(function (event) {
let id = $(this).val();
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
});
});
// Selezione di una zona
$(".dashboard_zona").click(function (event) {
let id = $(this).val();
2018-02-16 18:15:36 +01: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
});
});
// 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
});
});
// Deselezione di tutti gli elementi
$(".deseleziona_tutto").click(function () {
$(this).closest("ul").find("input:checked").each(function () {
$(this).click();
});
});
$("#mese-promemoria").change(function () {
let mese = $(this).val();
carica_interventi_da_pianificare(mese);
});
// Caricamento interventi da pianificare
carica_interventi_da_pianificare();
// Creazione del calendario
create_calendar();
});
function create_calendar() {
var calendarElement = document.getElementById("calendar");
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, {
/* locales: allLocales, */
locale: globals.locale,
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,
schedulerLicenseKey: "GPL-My-Project-Is-Open-Source",
hiddenDays: globals.dashboard.show_sunday ? [] : [0],
2023-01-23 23:10:52 +01:00
headerToolbar: {
left: "prev,next today",
center: "title",
right: "dayGridMonth,timeGridWeek,timeGridDay,listWeek"
},
2023-01-25 20:32:29 +01:00
eventDisplay: "block",
timeFormat: globals.dashboard.timeFormat,
slotLabelFormat: globals.dashboard.timeFormat,
slotDuration: "00:15: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,
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,
showNonCurrentDates: true,
2018-05-11 10:22:38 +02:00
loading: function (isLoading, view) {
if (isLoading) {
2023-01-27 13:25:55 +01:00
$("#tiny-loader").show();
} else {
$("#tiny-loader").hide();
}
},
2018-05-11 10:22:38 +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
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;
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);
// 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();
let mese = $("#mese-promemoria").val();
carica_interventi_da_pianificare(mese);
});
},
eventReceive: function(info){
info.revert();
},
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;
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");
}
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);
},
editable: globals.dashboard.write_permission,
2023-01-23 23:10:52 +01:00
eventDrop: function (info) {// info
let event = info.event;
2021-08-05 10:01:49 +02:00
if (event.allDay !== true) {
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,
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-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-08-05 10:01:49 +02:00
if (data !== "ok") {
2023-01-23 23:10:52 +01:00
info.revert();
}
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
}
},
2023-01-23 23:10:52 +01:00
eventResize: function (info) {
let event = info.event;
let start = event.start;
let end = (event.end!=null ? event.end : event.start);
$.post(globals.dashboard.load_url, {
op: "modifica_intervento",
id: event.id,
2023-01-23 23:10:52 +01:00
idintervento: event.extendedProps.idintervento,
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) {
data = $.trim(data);
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-08-05 10:01:49 +02:00
if (data !== "ok") {
2023-01-23 23:10:52 +01:00
info.revert();
}
});
},';
2023-08-04 14:54:28 +02:00
if (isMobile() && setting('Utilizzare i tooltip sul calendario')) {
echo '
eventClick: function(info) {
2023-01-23 23:10:52 +01:00
let link = info.event.extendedProps.link;
let element = $(this);
2023-01-23 23:10:52 +01:00
clickCnt++;
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 {
echo '
eventClick: function(info) {
if (info.event.extendedProps.link !== undefined) {
info.jsEvent.preventDefault();
location.href = info.event.extendedProps.link;
}
},';
}
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-01-23 23:10:52 +01:00
let id_record = info.event.extendedProps.idintervento;
if (globals.dashboard.tooltip == 1 && element[0].childElementCount > 0 ) {
element.tooltipster({
2021-08-05 10:01:49 +02:00
content: globals.translations.loading + "...",
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) {
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",
id_record: id_record,
2023-01-23 23:10:52 +01:00
allDay: info.event.allDay,
}, function (data, response) {
if (data !== "") {
instance.content(data);
$origin.data("loaded", true);
}
});
}
}
});
}
},
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");
}
}
2023-03-28 18:48:42 +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();
globals.dashboard.calendar = calendar;
}
</script>';