openstamanager/plugins/pianificazione_interventi/widgets/promemoria_da_pianificare.php

132 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/>.
*/
2021-11-08 12:09:49 +01:00
use Carbon\Carbon;
2024-03-06 10:56:09 +01:00
use Models\Module;
2024-03-22 15:52:24 +01:00
use Plugins\PianificazioneInterventi\Promemoria;
include_once __DIR__.'/../../../core.php';
$elenco_promemoria = Promemoria::doesntHave('intervento')->orderByraw('data_richiesta ASC')->get();
2021-03-17 18:51:25 +01:00
$array_promemoria = [];
foreach ($elenco_promemoria as $promemoria) {
2021-03-17 18:51:25 +01:00
$data_pro = new Carbon($promemoria->data_richiesta);
$array_promemoria[$data_pro->format('Y-m')][] = $promemoria;
2021-03-17 18:51:25 +01:00
}
if ($elenco_promemoria->isEmpty()) {
echo '
<p>'.tr('Non ci sono promemoria da pianificare').'.</p>';
return;
}
2024-04-09 12:18:08 +02:00
$raggruppamenti = $elenco_promemoria->groupBy(fn ($item) => $item->data_richiesta->format('Y-m'));
$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';
}
$nome_mese = new Carbon($mese.'-01');
2021-03-17 18:51:25 +01:00
echo "
<h4>
<a class='clickable' onclick=\"if( $('#promemoria_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'); } $('#promemoria_pianificare_".$counter."').slideToggle();\">
<i class='fa ".$class."'></i> ".ucfirst($nome_mese->isoFormat('MMMM YYYY')).'
</a>
</h4>';
echo '
<div id="promemoria_pianificare_'.$counter.'" '.$attr.'>
<table class="table table-hover table-striped">
<thead>
<tr>
<th width="200">'.tr('Cliente').'</th>
<th width="300">'.tr('Contratto').'</th>
<th width="70">'.tr('Entro').'</th>
<th width="200">'.tr('Tipo attività').'</th>
<th>'.tr('Descrizione').'</th>
<th width="20"></th>
</tr>
</thead>
<tbody>';
// Elenco promemoria da pianificare
2021-03-17 18:51:25 +01:00
foreach ($array_promemoria[$mese] as $promemoria) {
$contratto = $promemoria->contratto;
$anagrafica = $contratto->anagrafica;
echo '
<tr>
<td>
'.Modules::link('Anagrafiche', $anagrafica->id, nl2br($anagrafica->ragione_sociale)).'<br><small>Presso: ';
2020-11-09 20:03:47 +01:00
// Sede promemoria
if ($promemoria->idsede == '-1') {
2024-01-15 15:30:45 +01:00
echo '- Nessuna -';
2020-11-09 20:03:47 +01:00
} elseif (empty($promemoria->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($promemoria->idsede));
echo $rsp2[0]['descrizione'];
}
echo ' </small>
</td>
<td>
'.reference($contratto).'
</td>
<td>'.dateFormat($promemoria->data_richiesta).'</td>
2024-04-18 17:44:05 +02:00
<td>'.$promemoria->tipo->getTranslation('title').'</td>
<td>'.nl2br($promemoria->richiesta).'</td>
<td>
</td>';
// Pulsanti
echo '
<td>
2024-06-11 16:58:27 +02:00
<button type="button" class="btn btn-primary btn-sm" title="Pianifica intervento ora..." data-widget="tooltip" onclick="launch_modal(\'Pianifica intervento\', \''.base_path().'/add.php?id_module='.Module::where('name', 'Interventi')->first()->id.'&ref=interventi_contratti&idcontratto='.$contratto->id.'&idcontratto_riga='.$promemoria->id.'\');">
<i class="fa fa-calendar"></i>
</button>
</td>
</tr>';
}
echo '
</tbody>
</table>
</div>';
}