From 954930d7dcea56e07a2154f71623d487fce35d58 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 8 Sep 2020 10:38:27 +0200 Subject: [PATCH 1/7] Aggiunto modal per la gestione delle ricevute --- lib/functions.php | 2 +- modules/fatture/src/Fattura.php | 18 ++++ plugins/exportFE/actions.php | 33 ++++--- plugins/exportFE/edit.php | 21 ++-- plugins/exportFE/notifiche.php | 136 ++++++++++++++++++++++++++ plugins/receiptFE/actions.php | 33 +------ plugins/receiptFE/src/ReceiptHook.php | 11 +-- plugins/receiptFE/src/Ricevuta.php | 118 +++++++++++++++++----- update/2_4_18.sql | 10 ++ 9 files changed, 298 insertions(+), 84 deletions(-) create mode 100644 plugins/exportFE/notifiche.php diff --git a/lib/functions.php b/lib/functions.php index 8cbce7bad..c728e66e8 100755 --- a/lib/functions.php +++ b/lib/functions.php @@ -62,7 +62,7 @@ function sanitizeFilename($filename) /** * Elimina i file indicati. * - * @param array $files + * @param array|string $files * * @return bool */ diff --git a/modules/fatture/src/Fattura.php b/modules/fatture/src/Fattura.php index b2b2f64a2..08913e21e 100755 --- a/modules/fatture/src/Fattura.php +++ b/modules/fatture/src/Fattura.php @@ -24,6 +24,7 @@ use Carbon\Carbon; use Common\Components\Description; use Common\Document; use Illuminate\Database\Eloquent\Builder; +use Models\Upload; use Modules\Anagrafiche\Anagrafica; use Modules\Fatture\Gestori\Bollo as GestoreBollo; use Modules\Fatture\Gestori\Movimenti as GestoreMovimenti; @@ -460,6 +461,23 @@ class Fattura extends Document })->sortBy('created_at'); } + /** + * Restituisce la ricevuta principale, impostata attraverso il campo aggiuntivo id_ricevuta_principale. + * + * @return Upload|null + */ + public function getRicevutaPrincipale() + { + if (empty($this->id_ricevuta_principale)) { + return null; + } + + return $this->getModule() + ->uploads($this->id) + ->where('id', $this->id_ricevuta_principale) + ->first(); + } + /** * Controlla se la fattura di acquisto è elettronica. * diff --git a/plugins/exportFE/actions.php b/plugins/exportFE/actions.php index dd522e2d4..ba2c35f36 100755 --- a/plugins/exportFE/actions.php +++ b/plugins/exportFE/actions.php @@ -20,7 +20,6 @@ include_once __DIR__.'/init.php'; use Plugins\ExportFE\Interaction; -use Plugins\ReceiptFE\Interaction as RecepitInteraction; use Plugins\ReceiptFE\Ricevuta; switch (filter('op')) { @@ -62,23 +61,27 @@ switch (filter('op')) { } // Importazione ultima ricevuta individuata - RecepitInteraction::getReceipt($last_recepit); - - $fattura = null; - try { - $receipt = new Ricevuta($last_recepit); - $receipt->save(); - - $fattura = $receipt->getFattura()->numero_esterno; - - $receipt->delete(); - - RecepitInteraction::processReceipt($name); - } catch (UnexpectedValueException $e) { - } + $fattura = Ricevuta::process($last_recepit); + $numero_esterno = $fattura ? $fattura->numero_esterno : null; echo json_encode([ 'file' => $last_recepit, + 'fattura' => $numero_esterno, + ]); + + break; + + case 'gestione_ricevuta': + $name = filter('name'); + $type = filter('type'); + + $cambia_stato = $type != 'download'; + $fattura = Ricevuta::process($name, false); + + $numero_esterno = $fattura ? $fattura->numero_esterno : null; + + echo json_encode([ + 'file' => $name, 'fattura' => $fattura, ]); diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php index f324874a4..8a8021136 100755 --- a/plugins/exportFE/edit.php +++ b/plugins/exportFE/edit.php @@ -119,8 +119,8 @@ echo ' echo '

'; -// Messaggio esito invio -$ultima_ricevuta = $fattura->getRicevute()->last(); +// Messaggio informativo sulla ricevuta principale impostata +$ricevuta_principale = $fattura->getRicevutaPrincipale(); if (!empty($record['codice_stato_fe'])) { if ($record['codice_stato_fe'] == 'GEN') { echo ' @@ -141,9 +141,9 @@ if (!empty($record['codice_stato_fe'])) {
'.Translator::timestampToLocale($record['data_stato_fe']); - if (!empty($ultima_ricevuta)) { + if (!empty($ricevuta_principale)) { echo ' - + '.tr('Visualizza ricevuta').' '; } @@ -156,8 +156,8 @@ if (!empty($record['codice_stato_fe'])) {
'; // Lettura della ricevuta - if (!empty($ultima_ricevuta) && $stato_fe['codice'] == 'NS') { - $contenuto_ricevuta = \Util\XML::readFile($ultima_ricevuta->filepath); + if (!empty($ricevuta_principale) && $stato_fe['codice'] == 'NS') { + $contenuto_ricevuta = \Util\XML::readFile($ricevuta_principale->filepath); $lista_errori = $contenuto_ricevuta['ListaErrori']; if (!empty($lista_errori)) { @@ -193,7 +193,7 @@ if (!empty($record['codice_stato_fe'])) { echo ' '; diff --git a/plugins/receiptFE/actions.php b/plugins/receiptFE/actions.php index 798ade2f4..e40cb2b12 100755 --- a/plugins/receiptFE/actions.php +++ b/plugins/receiptFE/actions.php @@ -29,24 +29,12 @@ switch (filter('op')) { $results = []; foreach ($list as $element) { $name = $element['name']; - Interaction::getReceipt($name); - - $fattura = null; - try { - $receipt = new Ricevuta($name); - $receipt->save(); - - $fattura = $receipt->getFattura()->numero_esterno; - - $receipt->delete(); - - Interaction::processReceipt($name); - } catch (UnexpectedValueException $e) { - } + $fattura = Ricevuta::process($name); + $numero_esterno = $fattura ? $fattura->numero_esterno : null; $results[] = [ 'file' => $name, - 'fattura' => $fattura, + 'fattura' => $numero_esterno, ]; } @@ -63,20 +51,9 @@ switch (filter('op')) { // no break case 'prepare': $name = $name ?: get('name'); - Interaction::getReceipt($name); + $fattura = Ricevuta::process($name); - $fattura = null; - try { - $receipt = new Ricevuta($name); - $receipt->save(); - - $fattura = $receipt->getFattura()->numero_esterno; - - $receipt->delete(); - - Interaction::processReceipt($name); - } catch (UnexpectedValueException $e) { - } + $numero_esterno = $fattura ? $fattura->numero_esterno : null; echo json_encode([ 'file' => $name, diff --git a/plugins/receiptFE/src/ReceiptHook.php b/plugins/receiptFE/src/ReceiptHook.php index 47f56f883..e8ef57efe 100755 --- a/plugins/receiptFE/src/ReceiptHook.php +++ b/plugins/receiptFE/src/ReceiptHook.php @@ -69,18 +69,11 @@ class ReceiptHook extends Manager // Importazione ricevuta $name = $element['name']; - Interaction::getReceiptList($name); - - try { - $receipt = new Ricevuta($name); - $receipt->save(); - - $receipt->delete(); - Interaction::processReceipt($name); + $fattura = Ricevuta::process($name); + if (!empty($fattura)) { $completed[] = $element; unset($todo[$i]); - } catch (UnexpectedValueException $e) { } } diff --git a/plugins/receiptFE/src/Ricevuta.php b/plugins/receiptFE/src/Ricevuta.php index 48638debd..5438fc918 100755 --- a/plugins/receiptFE/src/Ricevuta.php +++ b/plugins/receiptFE/src/Ricevuta.php @@ -19,11 +19,10 @@ namespace Plugins\ReceiptFE; -use Modules; +use Models\Upload; use Modules\Fatture\Fattura; use Plugins; use UnexpectedValueException; -use Uploads; use Util\XML; use Util\Zip; @@ -48,6 +47,7 @@ class Ricevuta { $file = static::getImportDirectory().'/'.$name; + // Estrazione implicita per il formato ZIP if (ends_with($name, '.zip')) { $original_file = $file; @@ -79,6 +79,42 @@ class Ricevuta } } + /** + * Funzione per gestire in modo autonomo il download, l'importazione e il salvataggio di una specifica ricevuta identificata tramite nome. + * + * @param string $name + * @param bool $cambia_stato + * + * @return Fattura|null + */ + public static function process($name, $cambia_stato = true) + { + Interaction::getReceipt($name); + + $fattura = null; + try { + $receipt = new Ricevuta($name); + $receipt->save($cambia_stato); + + $fattura = $receipt->getFattura(); + + $receipt->cleanup(); + + Interaction::processReceipt($name); + } catch (UnexpectedValueException $e) { + } + + return $fattura; + } + + /** + * Salva il file indicato nella cartella temporanea per una futura elaborazione. + * + * @param string $filename + * @param string $content + * + * @return string + */ public static function store($filename, $content) { $directory = static::getImportDirectory(); @@ -90,6 +126,11 @@ class Ricevuta return $filename; } + /** + * Restituisce la cartella temporanea utilizzabile per il salvataggio della ricevuta. + * + * @return string|null + */ public static function getImportDirectory() { if (!isset(self::$directory)) { @@ -101,32 +142,51 @@ class Ricevuta return self::$directory; } + /** + * @param string $codice + * + * @return Upload|null + */ public function saveAllegato($codice) { - $module = Modules::get('Fatture di vendita'); + $filename = basename($this->file); + $fattura = $this->getFattura(); - $info = [ + // Controllo sulla presenza della stessa ricevuta + $upload_esistente = $fattura->getModule() + ->uploads($fattura->id) + ->where('original', $filename) + ->first(); + if (!empty($upload_esistente)) { + return $upload_esistente; + } + + // Registrazione del file XML come allegato + $upload = Upload::build($this->file, [ 'category' => tr('Fattura Elettronica'), 'id_module' => $module->id, - 'id_record' => $this->fattura->id, - ]; - - // Registrazione XML come allegato - Uploads::upload($this->file, array_merge($info, [ + 'id_record' => $fattura->id, 'name' => tr('Ricevuta _TYPE_', [ '_TYPE_' => $codice, ]), - 'original' => basename($this->file), - ])); + 'original' => $filename, + ]); + + return $upload; } - public function saveStato($codice) + /** + * Aggiorna lo stato della fattura relativa alla ricevuta in modo tale da rispecchiare i dati richiesti. + * + * @param $codice + * @param $id_allegato + */ + public function saveStato($codice, $id_allegato) { $fattura = $this->getFattura(); // Modifica lo stato solo se la fattura non è già stata consegnata (per evitare problemi da doppi invii) - // In realtà per le PA potrebbe esserci lo stato NE (che può contenere un esito positivo EC01 o negativo EC02) successivo alla RC, - // quindi aggiungo eccezione nel caso il nuovo codice della ricevuta sia NE. + // In realtà per le PA potrebbe esserci lo stato NE (che può contenere un esito positivo EC01 o negativo EC02) successivo alla RC, quindi aggiungo eccezione nel caso il nuovo codice della ricevuta sia NE. if ($fattura->codice_stato_fe == 'RC' && ($codice != 'EC01' || $codice != 'EC02')) { return; } @@ -138,11 +198,15 @@ class Ricevuta $fattura->data_stato_fe = $data ? date('Y-m-d H:i:s', strtotime($data)) : ''; $fattura->codice_stato_fe = $codice; $fattura->descrizione_ricevuta_fe = $descrizione; + $fattura->id_ricevuta_principale = $id_allegato; $fattura->save(); } - public function save() + /** + * Effettua le operazioni di salvataggio della ricevuta nella fattura relativa. + */ + public function save($cambia_stato = true) { $name = basename($this->file); $filename = explode('.', $name)[0]; @@ -157,22 +221,32 @@ class Ricevuta $codice_nome = $codice_nome.' - '.$errore['Errore']['Codice']; } - $this->saveAllegato($codice_nome); + $upload = $this->saveAllegato($codice_nome); - // In caso di Notifica Esito il codice è definito dal nodo della ricevuta - if ($codice_stato == 'NE') { - $codice_stato = $this->xml['EsitoCommittente']['Esito']; + if ($cambia_stato) { + // In caso di Notifica Esito il codice è definito dal nodo della ricevuta + if ($codice_stato == 'NE') { + $codice_stato = $this->xml['EsitoCommittente']['Esito']; + } + + $this->saveStato($codice_stato, $upload->id); } - - $this->saveStato($codice_stato); } + /** + * Restituisce la fattura identificata per la ricevuta. + * + * @return Fattura|null + */ public function getFattura() { return $this->fattura; } - public function delete() + /** + * Rimuove i file temporanei relativi alla ricevuta. + */ + public function cleanup() { delete($this->file); } diff --git a/update/2_4_18.sql b/update/2_4_18.sql index 858a30170..7634a6738 100644 --- a/update/2_4_18.sql +++ b/update/2_4_18.sql @@ -88,3 +88,13 @@ UPDATE `zz_views` SET `query` = 'CONCAT(UCASE(LEFT(tipo_movimento, 1)), SUBSTRIN -- Aggiornamento versione API services UPDATE `zz_settings` SET `valore` = 'v3' WHERE `nome` = 'OSMCloud Services API Version'; +-- Aggiunto collegamento con allegato per impostare la ricevuta principale +ALTER TABLE `co_documenti` ADD `id_ricevuta_principale` INT(11); +UPDATE `co_documenti` SET `co_documenti`.`id_ricevuta_principale` = ( + SELECT `zz_files`.`id` FROM `zz_files` WHERE `zz_files`.`id_module` = ( + SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `zz_modules`.`name` = 'Fatture di vendita' + ) AND `zz_files`.`id_record` = `co_documenti`.`id` + AND `zz_files`.`name` LIKE 'Ricevuta%' + ORDER BY `zz_files`.`created_at` + LIMIT 1 +); From bab428df94f585eef10fe03f78cfc5be3192e765 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 8 Sep 2020 10:56:18 +0200 Subject: [PATCH 2/7] Correzioni minori --- plugins/exportFE/edit.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php index 8a8021136..d0ed4ef45 100755 --- a/plugins/exportFE/edit.php +++ b/plugins/exportFE/edit.php @@ -19,11 +19,14 @@ include_once __DIR__.'/init.php'; +use Models\Upload; use Plugins\ExportFE\FatturaElettronica; use Plugins\ExportFE\Interaction; +use Util\XML; -/* per le PA EC02 e EC01 sono dei stati successivi a NE il quale a sua volta è successivo a RC. EC01 e EC02 sono definiti all'interno della ricevuta di NE che di fatto indica il rifiuto o l'accettazione.*/ +/* Per le PA EC02 e EC01 sono dei stati successivi a NE il quale a sua volta è successivo a RC. EC01 e EC02 sono definiti all'interno della ricevuta di NE che di fatto indica il rifiuto o l'accettazione. */ $abilita_genera = empty($fattura->codice_stato_fe) || in_array($fattura->codice_stato_fe, ['GEN', 'NS', 'EC02', 'ERR']); +$ricevuta_principale = $fattura->getRicevutaPrincipale(); if (!empty($fattura_pa)) { $disabled = false; @@ -80,7 +83,9 @@ echo ' '; - $file = $generated ? Models\Upload::where('filename', $fattura_pa->getFilename())->where('id_record', $id_record)->first() : null; + $file = $generated ? Upload::where('filename', $fattura_pa->getFilename()) + ->where('id_record', $id_record) + ->first() : null; echo ' @@ -120,7 +125,6 @@ echo ' echo '

'; // Messaggio informativo sulla ricevuta principale impostata -$ricevuta_principale = $fattura->getRicevutaPrincipale(); if (!empty($record['codice_stato_fe'])) { if ($record['codice_stato_fe'] == 'GEN') { echo ' @@ -156,8 +160,8 @@ if (!empty($record['codice_stato_fe'])) { '; // Lettura della ricevuta - if (!empty($ricevuta_principale) && $stato_fe['codice'] == 'NS') { - $contenuto_ricevuta = \Util\XML::readFile($ricevuta_principale->filepath); + if (!empty($ricevuta_principale)) { + $contenuto_ricevuta = XML::readFile($ricevuta_principale->filepath); $lista_errori = $contenuto_ricevuta['ListaErrori']; if (!empty($lista_errori)) { From b76c2937fac3a24f685050f5aafb021b980b5977 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 8 Sep 2020 11:38:25 +0200 Subject: [PATCH 3/7] Correzioni sul blocco fattura per Fattura Elettronica --- modules/fatture/edit.php | 36 ++++--- modules/fatture/init.php | 8 +- modules/fatture/modutil.php | 6 +- plugins/exportFE/edit.php | 102 ++++++++++---------- plugins/exportFE/src/FatturaElettronica.php | 1 + update/2_4_18.sql | 15 +++ 6 files changed, 97 insertions(+), 71 deletions(-) diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index 557fe4ee3..bffdd1caf 100755 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -21,11 +21,7 @@ use Modules\Iva\Aliquota; include_once __DIR__.'/../../core.php'; -$block_edit = !empty($note_accredito) || $record['stato'] == 'Emessa' || $record['stato'] == 'Pagato' || $record['stato'] == 'Parzialmente pagato'; - -$rs = $dbo->fetchArray('SELECT co_tipidocumento.descrizione, dir FROM co_tipidocumento INNER JOIN co_documenti ON co_tipidocumento.id=co_documenti.idtipodocumento WHERE co_documenti.id='.prepare($id_record)); -$dir = $rs[0]['dir']; -$tipodoc = $rs[0]['descrizione']; +$block_edit = !empty($note_accredito) || in_array($record['stato'], ['Emessa', 'Pagato', 'Parzialmente pagato']) || !$abilita_genera; if ($dir == 'entrata') { $conto = 'vendite'; @@ -164,7 +160,7 @@ if (empty($record['is_fiscale'])) { $plugin = $dbo->fetchArray("SELECT id FROM zz_plugins WHERE name='Fatturazione Elettronica' AND idmodule_to = ".prepare($id_module)); echo ''; } -//Forzo il passaggio della fattura da Bozza ad Emessa per il corretto calcolo del numero. +// Forzo il passaggio della fattura da Bozza ad Emessa per il corretto calcolo del numero. elseif ($record['stato'] == 'Bozza') { $query .= " WHERE descrizione IN ('Emessa', 'Bozza')"; } @@ -195,19 +191,17 @@ elseif ($record['stato'] == 'Bozza') { -
- - {[ "type": "select", "label": "", "name": "idstatodocumento", "required": 1, "values": "query=", "value": "$idstatodocumento$", "class": "unblockable", "extra": " onchange = \"if ($('#idstatodocumento option:selected').text()=='Pagato' || $('#idstatodocumento option:selected').text()=='Parzialmente pagato' ){if( confirm('') ){ return true; }else{ $('#idstatodocumento').selectSet(); }}\" " ]} + echo ' +
+ + {[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatodocumento", "required": 1, "values": "query='.$query.'", "value": "$idstatodocumento$", "class": "'.(!$abilita_genera ? '' : 'unblockable').'", "extra": "onchange=\"return cambiaStato()\"" ]}
- @@ -337,7 +331,7 @@ elseif ($record['stato'] == 'Bozza') {
@@ -410,7 +404,7 @@ echo '
'; -if ($tipodoc == 'Fattura accompagnatoria di vendita') { +if ($record['descrizione_tipo'] == 'Fattura accompagnatoria di vendita') { echo '
@@ -884,4 +878,16 @@ $(document).ready(function () { } }); }); + +function cambiaStato() { + let testo = $("#idstatodocumento option:selected").text(); + + if (testo == "Pagato" || testo == "Parzialmente pagato") { + if(confirm("'.tr('Sicuro di voler impostare manualmente la fattura come pagata senza aggiungere il movimento in prima nota?').'")) { + return true; + } else { + $("#idstatodocumento").selectSet('.$record['idstatodocumento'].'); + } + } +} '; diff --git a/modules/fatture/init.php b/modules/fatture/init.php index b1af4e9f7..cd62c998b 100755 --- a/modules/fatture/init.php +++ b/modules/fatture/init.php @@ -29,6 +29,7 @@ if ($module['name'] == 'Fatture di vendita') { if (isset($id_record)) { $fattura = Fattura::with('tipo', 'stato')->find($id_record); + $dir = $fattura->direzione; $is_fiscale = false; if (!empty($fattura)) { @@ -44,7 +45,7 @@ if (isset($id_record)) { co_documenti.id AS iddocumento, co_documenti.split_payment AS split_payment, co_statidocumento.descrizione AS `stato`, - co_tipidocumento.descrizione AS `descrizione_tipodoc`, + co_tipidocumento.descrizione AS `descrizione_tipo`, co_pagamenti.riba AS `riba`, (SELECT is_fiscale FROM zz_segments WHERE id = id_segment) AS is_fiscale, (SELECT descrizione FROM co_ritenutaacconto WHERE id=idritenutaacconto) AS ritenutaacconto_desc, @@ -57,5 +58,10 @@ if (isset($id_record)) { LEFT JOIN co_pagamenti ON co_documenti.idpagamento=co_pagamenti.id WHERE co_tipidocumento.dir = '.prepare($dir).' AND co_documenti.id='.prepare($id_record)); + // Note di credito collegate $note_accredito = $dbo->fetchArray("SELECT co_documenti.id, IF(numero_esterno != '', numero_esterno, numero) AS numero, data FROM co_documenti JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE reversed = 1 AND ref_documento=".prepare($id_record)); + + // Blocco gestito dallo stato della Fattura Elettronica + $stato_fe = $database->fetchOne('SELECT * FROM fe_stati_documento WHERE codice = '.prepare($fattura->codice_stato_fe)); + $abilita_genera = empty($fattura->codice_stato_fe) || intval($stato_fe['is_generabile']); } diff --git a/modules/fatture/modutil.php b/modules/fatture/modutil.php index c6b9e1ae0..53f4eaef0 100755 --- a/modules/fatture/modutil.php +++ b/modules/fatture/modutil.php @@ -237,7 +237,7 @@ function aggiungi_movimento($iddocumento, $dir, $primanota = 0) } // Lettura info fattura - $query = 'SELECT *, co_documenti.data_competenza, co_documenti.note, co_documenti.idpagamento, co_documenti.id AS iddocumento, co_statidocumento.descrizione AS `stato`, co_tipidocumento.descrizione AS `descrizione_tipodoc` FROM ((co_documenti LEFT OUTER JOIN co_statidocumento ON co_documenti.idstatodocumento=co_statidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica) INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_documenti.id='.prepare($iddocumento); + $query = 'SELECT *, co_documenti.data_competenza, co_documenti.note, co_documenti.idpagamento, co_documenti.id AS iddocumento, co_statidocumento.descrizione AS `stato`, co_tipidocumento.descrizione AS `descrizione_tipo` FROM ((co_documenti LEFT OUTER JOIN co_statidocumento ON co_documenti.idstatodocumento=co_statidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica) INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id WHERE co_documenti.id='.prepare($iddocumento); $rs = $dbo->fetchArray($query); $n = sizeof($rs); $data = $rs[0]['data_competenza']; @@ -256,9 +256,9 @@ function aggiungi_movimento($iddocumento, $dir, $primanota = 0) // Abbreviazioni contabili dei movimenti $tipodoc = ''; - if ($rs[0]['descrizione_tipodoc'] == 'Nota di credito') { + if ($rs[0]['descrizione_tipo'] == 'Nota di credito') { $tipodoc = 'Nota di credito'; - } elseif ($rs[0]['descrizione_tipodoc'] == 'Nota di debito') { + } elseif ($rs[0]['descrizione_tipo'] == 'Nota di debito') { $tipodoc = 'Nota di debito'; } else { $tipodoc = 'Fattura'; diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php index d0ed4ef45..01b093d02 100755 --- a/plugins/exportFE/edit.php +++ b/plugins/exportFE/edit.php @@ -25,15 +25,14 @@ use Plugins\ExportFE\Interaction; use Util\XML; /* Per le PA EC02 e EC01 sono dei stati successivi a NE il quale a sua volta è successivo a RC. EC01 e EC02 sono definiti all'interno della ricevuta di NE che di fatto indica il rifiuto o l'accettazione. */ -$abilita_genera = empty($fattura->codice_stato_fe) || in_array($fattura->codice_stato_fe, ['GEN', 'NS', 'EC02', 'ERR']); +$stato_fe = $database->fetchOne('SELECT * FROM fe_stati_documento WHERE codice = '.prepare($fattura->codice_stato_fe)); +$abilita_genera = empty($fattura->codice_stato_fe) || intval($stato_fe['is_generabile']); $ricevuta_principale = $fattura->getRicevutaPrincipale(); if (!empty($fattura_pa)) { - $disabled = false; - $generated = $fattura_pa->isGenerated(); + $generata = $fattura_pa->isGenerated(); } else { - $disabled = true; - $generated = false; + $generata = false; } $checks = FatturaElettronica::controllaFattura($fattura); @@ -78,12 +77,12 @@ echo ' - '; - $file = $generated ? Upload::where('filename', $fattura_pa->getFilename()) + $file = $generata ? Upload::where('filename', $fattura_pa->getFilename()) ->where('id_record', $id_record) ->first() : null; @@ -91,17 +90,17 @@ echo ' - + '.tr('Visualizza').' '; // Scelgo quando posso inviarla - $send = Interaction::isEnabled() && $generated && in_array($record['codice_stato_fe'], ['GEN', 'ERVAL', 'ERR']); + $inviabile = Interaction::isEnabled() && $generata && intval($stato_fe['is_inviabile']); echo ' - + '.tr('Scarica').' '; @@ -109,11 +108,11 @@ echo ' - '; -$verify = Interaction::isEnabled() && $generated; +$verify = Interaction::isEnabled() && $generata; echo ' @@ -125,47 +124,47 @@ echo ' echo '

'; // Messaggio informativo sulla ricevuta principale impostata -if (!empty($record['codice_stato_fe'])) { - if ($record['codice_stato_fe'] == 'GEN') { - echo ' -
'.tr("La fattura è stata generata ed è pronta per l'invio").'.
'; - } else { - $stato_fe = database()->fetchOne('SELECT codice, descrizione, icon FROM fe_stati_documento WHERE codice='.prepare($record['codice_stato_fe'])); - - if (in_array($stato_fe['codice'], ['EC01', 'RC'])) { - $class = 'success'; - } elseif (in_array($stato_fe['codice'], ['ERVAL', 'GEN', 'MC', 'WAIT', 'NE'])) { - $class = 'warning'; - } else { - $class = 'danger'; - } - - echo ' -
+if (!empty($fattura->codice_stato_fe)) { + echo ' +
- '.Translator::timestampToLocale($record['data_stato_fe']); + '.timestampFormat($record['data_stato_fe']); - if (!empty($ricevuta_principale)) { - echo ' + if (!empty($ricevuta_principale)) { + echo ' '.tr('Visualizza ricevuta').' '; - } + } - echo ' + echo '
- - '.$stato_fe['codice'].' - '.$stato_fe['descrizione'].' '.(!empty($record['descrizione_ricevuta_fe']) ? '
'.tr('Note', [], ['upper' => true]).': '.$record['descrizione_ricevuta_fe'] : '').' + + + '.$stato_fe['codice'].' - '.$stato_fe['descrizione'].' + '; + + if (!empty($record['descrizione_ricevuta_fe'])) { + echo ' +
'.tr('Note', [], ['upper' => true]).': '.$record['descrizione_ricevuta_fe']; + } + + if ($fattura->codice_stato_fe == 'GEN') { + echo ' +
'.tr("La fattura è stata generata ed è pronta per l'invio").'.'; + } + + echo '
'; - // Lettura della ricevuta - if (!empty($ricevuta_principale)) { - $contenuto_ricevuta = XML::readFile($ricevuta_principale->filepath); - $lista_errori = $contenuto_ricevuta['ListaErrori']; + // Lettura della ricevuta + if (!empty($ricevuta_principale)) { + $contenuto_ricevuta = XML::readFile($ricevuta_principale->filepath); + $lista_errori = $contenuto_ricevuta['ListaErrori']; - if (!empty($lista_errori)) { - echo ' + if (!empty($lista_errori)) { + echo '

'.tr('Elenco degli errori').'

@@ -176,20 +175,19 @@ if (!empty($record['codice_stato_fe'])) { '; - $lista_errori = $lista_errori[0] ? $lista_errori : [$lista_errori]; - foreach ($lista_errori as $errore) { - $errore = $errore['Errore']; - echo ' + $lista_errori = $lista_errori[0] ? $lista_errori : [$lista_errori]; + foreach ($lista_errori as $errore) { + $errore = $errore['Errore']; + echo ' '; - } + } - echo ' + echo '
'.$errore['Codice'].' '.$errore['Descrizione'].'
'; - } } } } @@ -212,7 +210,7 @@ echo ' buttonRestore(btn, restore); data = JSON.parse(data); - if (data.code == "200") { + if (data.code === "200") { swal("'.tr('Fattura inviata!').'", data.message, "success"); $(btn).attr("disabled", true).addClass("disabled"); @@ -220,7 +218,7 @@ echo ' swal("'.tr('Invio fallito').'", data.code + " - " + data.message, "error"); } }, - error: function(data) { + error: function() { swal("'.tr('Errore').'", "'.tr('Errore durante il salvataggio').'", "error"); buttonRestore(btn, restore); @@ -269,7 +267,7 @@ echo ' salvaForm(this, "#edit-form").then(function(valid) { if (valid) {'; -if ($generated) { +if ($generata) { echo ' swal({ title: "'.tr('Sei sicuro di rigenerare la fattura?').'", diff --git a/plugins/exportFE/src/FatturaElettronica.php b/plugins/exportFE/src/FatturaElettronica.php index 86de15ae5..b58dd82e4 100755 --- a/plugins/exportFE/src/FatturaElettronica.php +++ b/plugins/exportFE/src/FatturaElettronica.php @@ -301,6 +301,7 @@ class FatturaElettronica database()->update('co_documenti', [ 'progressivo_invio' => $this->getDocumento()['progressivo_invio'], 'codice_stato_fe' => 'GEN', + 'id_ricevuta_principale' => null, 'data_stato_fe' => date('Y-m-d H:i:s'), ], ['id' => $this->getDocumento()['id']]); diff --git a/update/2_4_18.sql b/update/2_4_18.sql index 7634a6738..777f0ca47 100644 --- a/update/2_4_18.sql +++ b/update/2_4_18.sql @@ -98,3 +98,18 @@ UPDATE `co_documenti` SET `co_documenti`.`id_ricevuta_principale` = ( ORDER BY `zz_files`.`created_at` LIMIT 1 ); + +ALTER TABLE `fe_stati_documento` ADD `is_generabile` BOOLEAN DEFAULT FALSE, + ADD `is_inviabile` BOOLEAN DEFAULT FALSE, + ADD `tipo` varchar(255) NOT NULL; + +UPDATE `fe_stati_documento` SET `is_generabile` = '1', `is_inviabile` = '1' WHERE `codice` = 'ERVAL'; +UPDATE `fe_stati_documento` SET `is_generabile` = '1', `is_inviabile` = '1' WHERE `codice` = 'ERR'; +UPDATE `fe_stati_documento` SET `is_generabile` = '1', `is_inviabile` = '1' WHERE `codice` = 'GEN'; +UPDATE `fe_stati_documento` SET `is_generabile` = '1' WHERE `codice` = 'NS'; +UPDATE `fe_stati_documento` SET `is_generabile` = '1' WHERE `codice` = 'EC02'; + +UPDATE `fe_stati_documento` SET `tipo` = 'danger'; +UPDATE `fe_stati_documento` SET `tipo` = 'warning' WHERE `codice` IN ('ERVAL', 'MC', 'WAIT', 'NE'); +UPDATE `fe_stati_documento` SET `tipo` = 'success' WHERE `codice` IN ('EC01', 'RC'); +UPDATE `fe_stati_documento` SET `tipo` = 'info' WHERE `codice` IN ('GEN'); From b97d181050df39e58ec399b43e12d4b56da4a8be Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 8 Sep 2020 11:45:52 +0200 Subject: [PATCH 4/7] Fix minori --- modules/fatture/edit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index bffdd1caf..9b6a65373 100755 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -186,7 +186,7 @@ elseif ($record['stato'] == 'Bozza') { ?>
> - {[ "type": "select", "label": "", "name": "codice_stato_fe", "required": 0, "values": "query=SELECT codice as id, CONCAT_WS(' - ',codice,descrizione) as text FROM fe_stati_documento", "value": "$codice_stato_fe$", "disabled": , "class": "unblockable", "help": "" ]} + {[ "type": "select", "label": "", "name": "codice_stato_fe", "required": 0, "values": "query=SELECT codice as id, CONCAT_WS(' - ',codice,descrizione) as text FROM fe_stati_documento", "value": "$codice_stato_fe$", "disabled": , "class": "unblockable", "help": "" ]}
Date: Tue, 8 Sep 2020 15:01:59 +0200 Subject: [PATCH 5/7] Miglioramento della selezione principale per le notifiche --- plugins/exportFE/notifiche.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/exportFE/notifiche.php b/plugins/exportFE/notifiche.php index 35a82de8e..16be48587 100644 --- a/plugins/exportFE/notifiche.php +++ b/plugins/exportFE/notifiche.php @@ -42,6 +42,9 @@ foreach ($recepits as $nome) { $pieces = explode('_', $filename); $codice_stato = $pieces[2]; + // Informazioni sullo stato indicato + $stato_fe = $database->fetchOne('SELECT * FROM fe_stati_documento WHERE codice = '.prepare($codice_stato)); + echo ' '.$nome.' @@ -67,10 +70,17 @@ foreach ($recepits as $nome) { '; } - echo ' - '; + } elseif ($upload->id == $documento->id_ricevuta_principale) { + echo ' + '; + } echo ' From 1c2f0680d0f73849d5c66541ffecffc30d58c9e3 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 8 Sep 2020 15:11:04 +0200 Subject: [PATCH 6/7] Miglioramento JS per generazione FE --- plugins/exportFE/edit.php | 83 ++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php index 01b093d02..d2340d397 100755 --- a/plugins/exportFE/edit.php +++ b/plugins/exportFE/edit.php @@ -26,7 +26,7 @@ use Util\XML; /* Per le PA EC02 e EC01 sono dei stati successivi a NE il quale a sua volta è successivo a RC. EC01 e EC02 sono definiti all'interno della ricevuta di NE che di fatto indica il rifiuto o l'accettazione. */ $stato_fe = $database->fetchOne('SELECT * FROM fe_stati_documento WHERE codice = '.prepare($fattura->codice_stato_fe)); -$abilita_genera = empty($fattura->codice_stato_fe) || intval($stato_fe['is_generabile']); +$abilita_genera = (empty($fattura->codice_stato_fe) && $fattura->stato->descrizione != 'Bozza') || intval($stato_fe['is_generabile']); $ricevuta_principale = $fattura->getRicevutaPrincipale(); if (!empty($fattura_pa)) { @@ -77,7 +77,7 @@ echo ' - '; @@ -108,7 +108,7 @@ echo ' - '; @@ -116,7 +116,7 @@ $verify = Interaction::isEnabled() && $generata; echo ' -
'; @@ -194,43 +194,45 @@ if (!empty($fattura->codice_stato_fe)) { echo ' '; From b48eaea47b0150cb308bc9038e9d2a48fc948e65 Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Tue, 8 Sep 2020 16:51:43 +0200 Subject: [PATCH 7/7] Fix minori --- modules/fatture/edit.php | 1 + plugins/exportFE/edit.php | 6 ++++-- plugins/importFE/generate.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index 9b6a65373..7c7a551a9 100755 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -174,6 +174,7 @@ elseif ($record['stato'] == 'Bozza') {
> {[ "type": "date", "label": "", "name": "data_registrazione", "required": 0, "value": "$data_registrazione$", "help": "" ]}
+
> {[ "type": "date", "class":"data_competenza) < dateFormat($fattura->data)) ? 'unblockable' : ''; ?>", "label": "", "name": "data_competenza", "required": 1, "value": "$data_competenza$", "min-date": "$data_registrazione$", "help": "" ]} diff --git a/plugins/exportFE/edit.php b/plugins/exportFE/edit.php index d2340d397..10d56a3f2 100755 --- a/plugins/exportFE/edit.php +++ b/plugins/exportFE/edit.php @@ -201,6 +201,7 @@ echo ' $.ajax({ url: globals.rootdir + "/actions.php", type: "post", + dataType: "json", data: { op: "send", id_module: "'.$id_module.'", @@ -209,12 +210,13 @@ echo ' }, success: function(data) { buttonRestore(button, restore); - data = JSON.parse(data); - if (data.code === "200") { + if (data.code === 200) { swal("'.tr('Fattura inviata!').'", data.message, "success"); $(button).attr("disabled", true).addClass("disabled"); + } else if (data.code === 301) { + swal("'.tr('Invio già effettuato').'", data.code + " - " + data.message, "error"); } else { swal("'.tr('Invio fallito').'", data.code + " - " + data.message, "error"); } diff --git a/plugins/importFE/generate.php b/plugins/importFE/generate.php index fc12c0261..586ee5aa0 100755 --- a/plugins/importFE/generate.php +++ b/plugins/importFE/generate.php @@ -371,7 +371,7 @@ if (!empty($righe)) {
- {[ "type": "select", "name": "selezione_riferimento['.$key.']", "ajax-source": "riferimenti-fe", "select-options": '.json_encode(['id_anagrafica' => $anagrafica ? $anagrafica->id : '']).', "required": 1, "label": "'.tr('Riferimento').'", "icon-after": '.json_encode('').' ]} + {[ "type": "select", "name": "selezione_riferimento['.$key.']", "ajax-source": "riferimenti-fe", "select-options": '.json_encode(['id_anagrafica' => $anagrafica ? $anagrafica->id : '']).', "label": "'.tr('Riferimento').'", "icon-after": '.json_encode('').' ]}
';