openstamanager/templates/dashboard/body.php

185 lines
5.3 KiB
PHP
Raw Normal View History

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') {
$period = explode(' ', $_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
//numero di giorni nel mese
$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
//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 {
$title = $date->formatLocalized('%B %Y');
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'];
2020-03-16 10:32:35 +01:00
$query = "SELECT
2019-11-22 16:28:03 +01:00
DATE(orario_inizio) AS data,
(SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=in_interventi.idanagrafica) AS anagrafica,
2019-11-22 17:33:30 +01:00
GROUP_CONCAT((SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=in_interventi_tecnici.idtecnico) SEPARATOR ', ') AS tecnico
2019-11-22 16:28:03 +01:00
FROM in_interventi_tecnici
INNER JOIN in_interventi ON in_interventi_tecnici.idintervento=in_interventi.id
LEFT OUTER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento
2020-03-16 10:32:35 +01:00
WHERE ".$where.'
2019-11-22 16:28:03 +01:00
idtecnico IN('.implode(',', $tecnici).') AND
in_interventi.idstatointervento IN('.implode(',', $stati).') AND
2019-11-22 17:33:30 +01:00
in_interventi_tecnici.idtipointervento IN('.implode(',', $tipi).') '.Modules::getAdditionalsQuery('Interventi').'
GROUP BY in_interventi.id, data';
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 '
2020-03-16 10:32:35 +01:00
<th>'.ucfirst($element['date']->formatLocalized('%A %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>';