openstamanager/modules/dashboard/widgets/notifiche.php

122 lines
7.3 KiB
PHP
Raw Normal View History

2019-07-30 16:50:10 +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/>.
*/
2019-07-30 16:50:10 +02:00
include_once __DIR__.'/../../../core.php';
use Carbon\Carbon;
use Models\Module;
if (!empty($is_title_request)) {
echo tr('Notifiche interne');
return;
}
$notes = collect();
$moduli = Module::getAll()->where('permission', '<>', '-');
foreach ($moduli as $modulo) {
2020-10-29 16:54:22 +01:00
$note = $modulo->notes()->whereNotNull('notification_date')->orderBy('notification_date', 'asc')->get();
2019-07-30 16:50:10 +02:00
$notes = $notes->merge($note);
}
if (!empty($is_number_request)) {
echo $notes->count();
return;
}
2020-10-29 16:54:22 +01:00
if ($notes->count() < 1) {
2019-07-30 16:50:10 +02:00
echo '
<p>'.tr('Non ci sono note da notificare').'.</p>';
return;
}
$moduli = $notes->groupBy('id_module')->sortBy('notification_date');
foreach ($moduli as $module_id => $note) {
$modulo = Module::pool($module_id);
2019-07-30 16:50:10 +02:00
echo '
<h4>'.$modulo->title.'</h4>
<table class="table table-hover">
<tr>
2023-05-30 14:36:33 +02:00
<th width="15%" >'.tr('Riferimento').'</th>
2023-08-04 14:54:28 +02:00
<th width="20%" >'.(($modulo->title == 'Fatture di acquisto' || $modulo->title == 'Ordini fornitore' || $modulo->title == 'Ddt in entrata') ? tr('Fornitore') : tr('Cliente')).'</th>
2019-07-30 16:50:10 +02:00
<th>'.tr('Contenuto').'</th>
<th width="20%" class="text-center">'.tr('Data di notifica').'</th>
2019-07-30 17:11:59 +02:00
<th class="text-center">#</th>
2019-07-30 16:50:10 +02:00
</tr>';
foreach ($note as $nota) {
$class = (strtotime($nota->notification_date) < strtotime(date('Y-m-d')) && !empty($nota->notification_date)) ? 'danger' : '';
2023-08-04 14:54:28 +02:00
2023-05-30 14:36:33 +02:00
$documento = '';
if ($modulo->title == 'Attività') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT in_interventi.codice AS numero, ragione_sociale FROM zz_notes INNER JOIN in_interventi ON (in_interventi.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Attività')zz) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = in_interventi.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Fatture di vendita') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero_esterno AS numero, ragione_sociale FROM zz_notes INNER JOIN co_documenti ON (co_documenti.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Fatture di vendita')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_documenti.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Fatture di acquisto') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero, ragione_sociale FROM zz_notes INNER JOIN co_documenti ON (co_documenti.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Fatture di acquisto')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_documenti.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Preventivi') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero, ragione_sociale FROM zz_notes INNER JOIN co_preventivi ON (co_preventivi.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Preventivi')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_preventivi.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Contratti') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero, ragione_sociale FROM zz_notes INNER JOIN co_contratti ON (co_contratti.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Contratti')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = co_contratti.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Ordini cliente') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero_esterno as numero, ragione_sociale FROM zz_notes INNER JOIN or_ordini ON (or_ordini.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Ordini cliente')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = or_ordini.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Ordini fornitore') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero, ragione_sociale FROM zz_notes INNER JOIN or_ordini ON (or_ordini.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Ordini fornitore')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = or_ordini.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Ddt in uscita') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero_esterno as numero, ragione_sociale FROM zz_notes INNER JOIN dt_ddt ON (dt_ddt.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Ddt in uscita')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = dt_ddt.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Ddt in entrata') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT numero, ragione_sociale FROM zz_notes INNER JOIN dt_ddt ON (dt_ddt.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Ddt in uscita')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = dt_ddt.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Articoli') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT codice AS numero FROM zz_notes INNER JOIN mg_articoli ON (mg_articoli.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Articoli')) WHERE zz_notes.id = ".$nota->id);
2023-08-04 14:54:28 +02:00
} elseif ($modulo->title == 'Impianti') {
2023-09-08 11:51:04 +02:00
$documento = $dbo->fetchOne("SELECT matricola AS numero, ragione_sociale FROM zz_notes INNER JOIN my_impianti ON (my_impianti.id = zz_notes.id_record AND zz_notes.id_module=(SELECT id FROM zz_modules WHERE title = 'Impianti')) INNER JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = my_impianti.idanagrafica WHERE zz_notes.id = ".$nota->id);
2023-05-30 14:36:33 +02:00
} else {
$documento['numero'] = ' ';
2023-09-15 17:06:37 +02:00
}
2019-07-30 16:50:10 +02:00
echo '
<tr class="'.$class.'">
2023-05-30 14:36:33 +02:00
<td>'.($documento['numero'] == null ? ' - ' : $documento['numero']).'</td>
<td>'.$documento['ragione_sociale'].'</td>
2019-07-30 16:50:10 +02:00
<td>
2019-07-30 17:11:59 +02:00
<span class="pull-right"></span>
2020-09-07 15:04:06 +02:00
2019-07-30 16:50:10 +02:00
'.$nota->content.'
2020-09-07 15:04:06 +02:00
2019-07-30 16:50:10 +02:00
<small>'.$nota->user->nome_completo.'</small>
</td>
2020-09-07 15:04:06 +02:00
2019-07-30 16:50:10 +02:00
<td class="text-center">
2019-07-30 17:11:59 +02:00
'.dateFormat($nota->notification_date).' ('.Carbon::parse($nota->notification_date)->diffForHumans().')
</td>
2020-09-07 15:04:06 +02:00
2019-07-30 17:11:59 +02:00
<td class="text-center">
'.Modules::link($module_id, $nota->id_record, '', null, 'class="btn btn-primary btn-xs"', true, 'tab_note').'
2019-07-30 16:50:10 +02:00
</td>
</tr>';
}
echo '
</table>';
}