From 0d313930d3caee7f61c5fc49677c474baa72bc29 Mon Sep 17 00:00:00 2001 From: MatteoPistorello Date: Fri, 13 May 2022 13:24:03 +0200 Subject: [PATCH] Aggiunti controlli sulla stato documento delle fatture di vendita --- modules/fatture/controller_before.php | 80 +++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 modules/fatture/controller_before.php diff --git a/modules/fatture/controller_before.php b/modules/fatture/controller_before.php new file mode 100644 index 000000000..9bcd0dd9e --- /dev/null +++ b/modules/fatture/controller_before.php @@ -0,0 +1,80 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +use Carbon\Carbon; +use Modules\Fatture\Fattura; + +if ($module->name == 'Fatture di vendita') { + $documenti_scarto = []; + $documenti_invio = []; + $codici_scarto = ['EC02','ERR','ERVAL','NS']; + $codici_invio = ['GEN','QUEUE']; + $data_limite = (new Carbon())->subMonths(6); + $data_limite_invio = (new Carbon())->subDays(10); + + $documenti = Fattura::where('data', '>', $data_limite)->whereIn('codice_stato_fe', ['EC02','ERR','ERVAL','NS','GEN','QUEUE'])->get(); + foreach ($documenti as $documento) { + $stato_fe = $database->fetchOne('SELECT descrizione, icon FROM fe_stati_documento WHERE codice = '.prepare($documento->codice_stato_fe)); + if (in_array($documento->codice_stato_fe, $codici_scarto)) { + $documenti_scarto[] = Modules::link('Fatture di vendita', $documento->id, tr('_ICON_ Fattura numero _NUM_ del _DATE_ : _STATO_', [ + '_ICON_' => '', + '_NUM_' => $documento->numero_esterno, + '_DATE_' => dateFormat($documento->data), + '_STATO_' => $stato_fe['descrizione'], + ])); + } elseif (in_array($documento->codice_stato_fe, $codici_invio)) { + if ($documento->data_stato_fe <= $data_limite_invio) { + $documenti_invio[] = Modules::link('Fatture di vendita', $documento->id, tr('_ICON_ Fattura numero _NUM_ del _DATE_ : _STATO_', [ + '_ICON_' => '', + '_NUM_' => $documento->numero_esterno, + '_DATE_' => dateFormat($documento->data), + '_STATO_' => $stato_fe['descrizione'], + ])); + } + } + } + + if (sizeof($documenti_scarto) > 0) { + echo ' +
+ '.tr("ATTENZIONE: le seguenti fatture riscontrano i seguenti problemi").': +
'; + } + + if (sizeof($documenti_invio) > 0) { + echo ' +
+ '.tr("Le seguenti fatture sono in attesa di essere inviate").': +
'; + } +}