2018-05-08 15:55:46 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-05-08 15:55:46 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
use Carbon\Carbon;
|
2018-05-22 17:42:19 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$calendar = $_SESSION['dashboard'];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$date = $calendar['date'];
|
|
|
|
$date = new Carbon($date);
|
2018-05-22 17:42:19 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
if ($calendar['format'] == 'week') {
|
2024-05-23 11:36:25 +02:00
|
|
|
$period = explode(' ', (string) $_SESSION['dashboard']['week']);
|
2018-05-22 17:42:19 +02:00
|
|
|
|
|
|
|
$day = $period[0];
|
|
|
|
|
|
|
|
if (count($period) == 5) {
|
|
|
|
$maxmonth = $period[3];
|
|
|
|
$maxday_ = $period[2];
|
|
|
|
|
|
|
|
$month = $period[3];
|
|
|
|
$year = $period[4];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($period) == 6) {
|
|
|
|
$maxmonth = $period[1];
|
|
|
|
$maxday_ = $period[3];
|
|
|
|
|
|
|
|
$month = $period[4];
|
|
|
|
$year = $period[5];
|
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2018-08-11 15:49:46 +02:00
|
|
|
$months = ['gen' => '01', 'feb' => '02', 'mar' => '03', 'apr' => '04', 'mag' => '05', 'giu' => '06', 'lug' => '07', 'ago' => '08', 'set' => '09', 'ott' => '10', 'nov' => '11', 'dic' => '12'];
|
2018-05-22 17:42:19 +02:00
|
|
|
$month = $months[$month];
|
|
|
|
$maxmonth = $months[$maxmonth];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$title = $_SESSION['dashboard']['week'];
|
2018-05-22 17:42:19 +02:00
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
// numero di giorni nel mese
|
2018-05-22 17:42:19 +02:00
|
|
|
$maxday = cal_days_in_month(CAL_GREGORIAN, $month, $year) + 1;
|
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$min_date = $year.'-'.$month.'-'.$day;
|
|
|
|
$max_date = $year.'-'.$maxmonth.'-'.$maxday_;
|
2018-05-22 17:42:19 +02:00
|
|
|
|
2024-01-15 15:30:45 +01:00
|
|
|
// aggiungo un giorno
|
2019-11-22 16:28:03 +01:00
|
|
|
$max_date = date('Y-m-d', date(strtotime('+1 day', strtotime($max_date))));
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$where = ' (in_interventi_tecnici.orario_inizio) <= '.prepare($max_date).' AND (in_interventi_tecnici.orario_inizio) >= '.prepare($min_date).' AND ';
|
|
|
|
} else {
|
2024-04-10 14:53:26 +02:00
|
|
|
$title = $date->isoFormat('MMMM YYYY');
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$min_date = $date->copy()->startOfMonth();
|
|
|
|
$max_date = $date->copy()->endOfMonth();
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 17:33:30 +01:00
|
|
|
$where = ' (in_interventi_tecnici.orario_inizio) <= '.prepare($max_date).' AND (in_interventi_tecnici.orario_inizio) >= '.prepare($min_date).' AND ';
|
2019-11-22 16:28:03 +01:00
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$height = '80';
|
2018-05-22 17:42:19 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$stati = (array) $calendar['idstatiintervento'];
|
|
|
|
$tipi = (array) $calendar['idtipiintervento'];
|
|
|
|
$tecnici = (array) $calendar['idtecnici'];
|
|
|
|
|
2024-06-06 11:20:30 +02:00
|
|
|
$query = "
|
|
|
|
SELECT
|
2024-02-28 15:28:39 +01:00
|
|
|
DATE(`orario_inizio`) AS data,
|
|
|
|
`an_anagrafiche`.`ragione_sociale` AS anagrafica,
|
|
|
|
GROUP_CONCAT(DISTINCT `tecnico`.`ragione_sociale` SEPARATOR ', ') AS tecnico
|
|
|
|
FROM
|
|
|
|
`in_interventi_tecnici`
|
|
|
|
INNER JOIN `in_interventi` ON `in_interventi_tecnici`.`idintervento`=`in_interventi`.`id`
|
|
|
|
INNER JOIN `an_anagrafiche` ON `in_interventi`.`idanagrafica`=`an_anagrafiche`.`idanagrafica`
|
2024-06-06 11:20:30 +02:00
|
|
|
LEFT JOIN `an_anagrafiche` AS tecnico ON `in_interventi_tecnici`.`idtecnico`=`tecnico`.`idanagrafica`
|
2024-02-28 15:28:39 +01:00
|
|
|
INNER JOIN `in_statiintervento` ON `in_interventi`.`idstatointervento`=`in_statiintervento`.`id`
|
|
|
|
WHERE
|
|
|
|
".$where.'
|
|
|
|
`idtecnico` IN('.implode(',', $tecnici).') AND
|
|
|
|
`in_interventi`.`idstatointervento` IN('.implode(',', $stati).') AND
|
|
|
|
`in_interventi_tecnici`.`idtipointervento` IN('.implode(',', $tipi).') '.Modules::getAdditionalsQuery('Interventi').'
|
|
|
|
GROUP BY
|
|
|
|
`in_interventi`.`id`, data';
|
2024-06-06 11:20:30 +02:00
|
|
|
|
2018-05-08 15:55:46 +02:00
|
|
|
$sessioni = $dbo->fetchArray($query);
|
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$sessioni = collect($sessioni)->groupBy('data');
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
// Intestazione tabella
|
|
|
|
echo '
|
|
|
|
<h3 class="text-bold">'.tr('Calendario _PERIOD_', [
|
|
|
|
'_PERIOD_' => $title,
|
|
|
|
], ['upper' => true]).'</h3>';
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
// Elenco per la gestione
|
|
|
|
$list = [];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
// Filler per i giorni non inclusi della settimana iniziale
|
|
|
|
$week_start = $min_date->startOfWeek();
|
|
|
|
$current_day = $week_start;
|
|
|
|
while ($current_day->lessThan($min_date)) {
|
|
|
|
$list[] = [
|
|
|
|
'date' => $current_day->copy(),
|
|
|
|
'contents' => [],
|
|
|
|
];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$current_day->addDay();
|
|
|
|
}
|
2018-05-22 17:42:19 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
// Elenco del periodo indicato
|
|
|
|
while ($current_day->lessThan($max_date)) {
|
|
|
|
$list[] = [
|
|
|
|
'date' => $current_day->copy(),
|
|
|
|
'contents' => $sessioni[$current_day->toDateString()] ?: [],
|
|
|
|
];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$current_day->addDay();
|
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
// Filler per i giorni non inclusi della settimana finale
|
|
|
|
$week_end = $max_date->endOfWeek();
|
|
|
|
while ($current_day->lessThan($week_end)) {
|
|
|
|
$list[] = [
|
|
|
|
'date' => $current_day->copy(),
|
|
|
|
'contents' => [],
|
|
|
|
];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$current_day->addDay();
|
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
// Stampa della tabella
|
|
|
|
echo '
|
|
|
|
<table class="table table-bordered">';
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$count = count($list);
|
|
|
|
for ($i = 0; $i < $count; $i = $i + 7) {
|
|
|
|
echo '
|
|
|
|
<tr>';
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 17:33:30 +01:00
|
|
|
for ($c = 0; $c < 7; ++$c) {
|
2019-11-22 16:28:03 +01:00
|
|
|
$element = $list[$i + $c];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
echo '
|
2024-06-06 11:20:30 +02:00
|
|
|
<th>'.ucfirst($element['date']->translatedFormat('d/m')).'</th>';
|
2018-05-22 17:42:19 +02:00
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
echo '
|
|
|
|
</tr>';
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
echo '
|
|
|
|
<tr>';
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 17:33:30 +01:00
|
|
|
for ($c = 0; $c < 7; ++$c) {
|
2019-11-22 16:28:03 +01:00
|
|
|
$element = $list[$i + $c];
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$clienti = '';
|
|
|
|
foreach ($element['contents'] as $sessione) {
|
|
|
|
$clienti .= $sessione['anagrafica'].'<br>
|
|
|
|
<small>'.$sessione['tecnico'].'</small><br>';
|
2018-05-22 17:42:19 +02:00
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
$background = '#ffffff';
|
|
|
|
if (empty($clienti)) {
|
|
|
|
$background = 'lightgray';
|
2018-05-22 17:42:19 +02:00
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
echo '
|
|
|
|
<td style="height:'.$height.'px;background:'.$background.'">'.$clienti.'</td>';
|
2018-05-08 15:55:46 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
echo '
|
|
|
|
</tr>';
|
2018-05-22 17:42:19 +02:00
|
|
|
}
|
2018-05-08 15:55:46 +02:00
|
|
|
|
2019-11-22 16:28:03 +01:00
|
|
|
echo '
|
|
|
|
</table>';
|