1
0
mirror of https://github.com/devcode-it/openstamanager.git synced 2024-12-13 08:56:08 +01:00
openstamanager/modules/interventi/widgets/interventi_da_pianificare.php

112 lines
4.5 KiB
PHP
Raw Normal View History

<?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 Modules\Interventi\Intervento;
include_once __DIR__.'/../../../core.php';
// Interventi da pianificare NON completati
$interventi_da_pianificare = Intervento::doesntHave('sessioni')
->orderByRaw('IF(data_scadenza IS NULL, data_richiesta, data_scadenza)')
2020-08-26 10:15:36 +02:00
->whereHas('stato', function ($query) {
return $query->where('is_completato', '=', 0);
})
->get();
$raggruppamenti = $interventi_da_pianificare->groupBy(function ($item, $key) {
$data = $item->data_scadenza ?: $item->data_richiesta;
2020-03-14 14:59:27 +01:00
return ucfirst($data->formatLocalized('%B %Y'));
});
$counter = 0;
foreach ($raggruppamenti as $mese => $raggruppamento) {
++$counter;
// Se cambia il mese ricreo l'intestazione della tabella
if ($counter == 1) {
$attr = '';
$class = 'fa-minus-circle';
} else {
$attr = 'style="display:none;"';
$class = 'fa-plus-circle';
}
echo "
<h4>
2020-04-20 11:23:01 +02:00
<a class='clickable' onclick=\"if( $('#interventi_pianificare_".$counter."').css('display') == 'none' ){ $(this).children('i').removeClass('fa-plus-circle'); $(this).children('i').addClass('fa-minus-circle'); }else{ $(this).children('i').addClass('fa-plus-circle'); $(this).children('i').removeClass('fa-minus-circle'); } $('#interventi_pianificare_".$counter."').slideToggle();\">
<i class='fa ".$class."'></i> ".$mese.'
</a>
</h4>';
echo '
2020-04-20 11:23:01 +02:00
<div id="interventi_pianificare_'.$counter.'" '.$attr.'>
<table class="table table-hover table-striped">
<thead>
<tr>
2020-04-20 11:23:01 +02:00
<th width="70">'.tr('Codice').'</th>
<th width="120">'.tr('Cliente').'</th>
<th width="70"><small>'.tr('Data richiesta').'</small></th>
<th width="200">'.tr('Tipo intervento').'</th>
<th width="200">'.tr('Stato intervento').'</th>
<th>'.tr('Descrizione').'</th>
</tr>
</thead>
<tbody>';
// Elenco interventi da pianificare
foreach ($raggruppamento as $r) {
echo '
<tr id="int_'.$r['id'].'">
<td><a target="_blank" >'.Modules::link(Modules::get('Interventi')['id'], $r['id'], $r['codice']).'</a></td>
2020-11-09 20:03:47 +01:00
<td><a target="_blank" >'.Modules::link(Modules::get('Anagrafiche')['id'], $r['idanagrafica'], $dbo->fetchOne('SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica='.prepare($r['idanagrafica']))['ragione_sociale']).'<br><small>Presso: ';
// Sede promemoria
if ($r['idsede'] == '-1') {
echo '- '.('Nessuna').' -';
} elseif (empty($r['idsede'])) {
echo tr('Sede legale');
} else {
$rsp2 = $dbo->fetchArray("SELECT id, CONCAT( CONCAT_WS( ' (', CONCAT_WS(', ', nomesede, citta), indirizzo ), ')') AS descrizione FROM an_sedi WHERE id=".prepare($r['idsede']));
2020-11-09 20:03:47 +01:00
echo $rsp2[0]['descrizione'];
}
echo '
</small>
</td>
2020-11-09 20:03:47 +01:00
<td>'.Translator::dateToLocale($r['data_richiesta']).' '.((empty($r['data_scadenza'])) ? '' : '<br><small>Entro il '.Translator::dateToLocale($r['data_scadenza']).'</small>').'</td>
<td>'.$dbo->fetchOne("SELECT CONCAT_WS(' - ', codice,descrizione) AS descrizione FROM in_tipiintervento WHERE idtipointervento=".prepare($r['idtipointervento']))['descrizione'].'</td>
<td>'.$dbo->fetchOne("SELECT CONCAT_WS(' - ', codice,descrizione) AS descrizione FROM in_statiintervento WHERE idstatointervento=".prepare($r['idstatointervento']))['descrizione'].'</td>
<td>'.nl2br($r['richiesta']).'</td>
';
echo '
</tr>';
}
echo '
</tbody>
</table>
</div>';
}
if ($raggruppamenti->isEmpty()) {
echo '
<p>'.tr('Non ci sono interventi da pianificare').'.</p>';
}