From 41f75cf19f23ee2e95629b21cf56354f7c05312a Mon Sep 17 00:00:00 2001 From: Pek5892 Date: Thu, 28 Mar 2024 13:03:21 +0100 Subject: [PATCH] Fix per fatture di vendita lingua inglese --- modules/fatture/actions.php | 2 +- modules/fatture/edit.php | 53 ++++++++++++++++++++++----------- modules/fatture/src/Fattura.php | 34 ++++++++++++--------- update/2_5.php | 1 + 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/modules/fatture/actions.php b/modules/fatture/actions.php index 051eec982..977f91fbb 100755 --- a/modules/fatture/actions.php +++ b/modules/fatture/actions.php @@ -37,7 +37,7 @@ use Util\XML; $module = Module::find($id_module); $op = post('op'); -if ($module->getTranslation('name') == 'Fatture di vendita') { +if ($module->getTranslation('name', \Models\Locale::getPredefined()->id) == 'Fatture di vendita') { $dir = 'entrata'; } else { $dir = 'uscita'; diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index b612aa3f5..2cac1dc33 100755 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -26,12 +26,22 @@ use Modules\Fatture\Gestori\Bollo; use Modules\Interventi\Intervento; use Modules\Iva\Aliquota; use Plugins\ExportFE\Interaction; +use Modules\Fatture\Stato as StatoFattura; +use Modules\DDT\Stato as StatoDDT; +use Modules\Ordini\Stato as StatoOrdine; include_once __DIR__.'/../../core.php'; $anagrafica_azienda = Anagrafica::find(setting('Azienda predefinita')); -$block_edit = !empty($note_accredito) || in_array($record['stato'], ['Emessa', 'Pagato', 'Parzialmente pagato']) || !$abilita_genera; +$id_stato_bozza = (new StatoFattura())->getByField('name', 'Bozza', \Models\Locale::getPredefined()->id); +$id_stato_emessa = (new StatoFattura())->getByField('name', 'Emessa', \Models\Locale::getPredefined()->id); +$id_stato_pagato = (new StatoFattura())->getByField('name', 'Pagato', \Models\Locale::getPredefined()->id); +$id_stato_parz_pagato = (new StatoFattura())->getByField('name', 'Parzialmente pagato', \Models\Locale::getPredefined()->id); +$id_stato_non_valida = (new StatoFattura())->getByField('name', 'Non valida', \Models\Locale::getPredefined()->id); +$id_stato_annullata = (new StatoFattura())->getByField('name', 'Annullata', \Models\Locale::getPredefined()->id); + +$block_edit = !empty($note_accredito) || in_array($fattura->stato->id, [$id_stato_parz_pagato, $id_stato_pagato, $id_stato_emessa]) || !$abilita_genera; if ($dir == 'entrata') { $conto = 'vendite'; @@ -155,7 +165,7 @@ if (!empty($fattura->ref_documento) && $fattura->isNota()) { } // Ricordo che si sta emettendo una fattura conto terzi -if ($dir == 'entrata' && $fattura->stato->getTranslation('name') == 'Bozza') { +if ($dir == 'entrata' && $fattura->stato->id == $id_stato_bozza) { if ($fattura->is_fattura_conto_terzi) { echo '
@@ -189,7 +199,7 @@ if ($dir == 'entrata') { $data_odierna = new DateTime(); $differenza = $data_odierna->diff($data_fattura)->days; - if ($fattura->codice_stato_fe == 'NS' && $fattura->stato->getTranslation('name') != 'Non valida' && ($differenza > setting('Giorni validità fattura scartata'))) { + if ($fattura->codice_stato_fe == 'NS' && $fattura->stato->id != $id_stato_non_valida && ($differenza > setting('Giorni validità fattura scartata'))) { echo '
'.tr('Questa fattura è stata scartata e sono trascorsi i termini di reinvio, è necessario invalidare il documento.').' @@ -277,16 +287,16 @@ if ($righe_vuote) { id).')'; +$query = 'SELECT `co_statidocumento`.*, `co_statidocumento`.`id` AS id, `colore` AS _bgcolor_, `co_statidocumento_lang`.`name` as descrizione FROM `co_statidocumento` LEFT JOIN `co_statidocumento_lang` ON (`co_statidocumento_lang`.`id_record` = `co_statidocumento`.`id` AND `co_statidocumento_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')'; if (empty($record['is_fiscale'])) { - $query .= " WHERE `name` = 'Bozza'"; + $query .= " WHERE `co_statidocumento`.`id` = '.$id_stato_bozza.'"; $plugin = $dbo->fetchArray('SELECT `zz_plugins`.`id` FROM `zz_plugins` LEFT JOIN `zz_plugins_lang` ON (`zz_plugins`.`id` = `zz_plugins_lang`.`id_record` AND `zz_plugins_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).") 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. -elseif ($record['stato'] == 'Bozza') { - $query .= " WHERE `name` IN ('Emessa', 'Bozza')"; +elseif ($fattura->stato->id == $id_stato_bozza) { + $query .= " WHERE `co_statidocumento`.`id` IN (".$id_stato_emessa.", ".$id_stato_bozza.")"; } $query .= ' ORDER BY `name`'; @@ -311,7 +321,7 @@ $query .= ' ORDER BY `name`'; ?>
> - {[ "type": "select", "label": "", "name": "codice_stato_fe", "values": "query=SELECT `codice` as id, CONCAT_WS(' - ',`codice`, `name`) as text FROM `fe_stati_documento` LEFT JOIN `fe_stati_documento_lang` ON (`fe_stati_documento_lang`.`id_record` = `fe_stati_documento`.`codice` AND `fe_stati_documento_lang`.`id_lang` = id); ?>)", "value": "$codice_stato_fe$", "disabled": , "class": "unblockable", "help": "" ]} + {[ "type": "select", "label": "", "name": "codice_stato_fe", "values": "query=SELECT `codice` as id, CONCAT_WS(' - ',`codice`, `name`) as text FROM `fe_stati_documento` LEFT JOIN `fe_stati_documento_lang` ON (`fe_stati_documento_lang`.`id_record` = `fe_stati_documento`.`codice` AND `fe_stati_documento_lang`.`id_lang` = id); ?>)", "value": "$codice_stato_fe$", "disabled": stato->id == $id_stato_bozza && $abilita_genera)); ?>, "class": "unblockable", "help": "" ]}
- {[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatodocumento", "required": 1, "values": "query='.$query.'", "value": "'.$fattura->stato->id.'", "class": "'.(($fattura->stato->getTranslation('name') != 'Bozza' && !$abilita_genera) ? '' : 'unblockable').'", "extra": "onchange=\"return cambiaStato()\"" ]} + {[ "type": "select", "label": "'.tr('Stato').'", "name": "idstatodocumento", "required": 1, "values": "query='.$query.'", "value": "'.$fattura->stato->id.'", "class": "'.(($fattura->stato->id != $id_stato_bozza && !$abilita_genera) ? '' : 'unblockable').'", "extra": "onchange=\"return cambiaStato()\"" ]}
@@ -395,7 +405,7 @@ if ($dir == 'entrata') {
- {[ "type": "select", "label": "", "name": "idtipodocumento", "required": 1, "values": "query=SELECT `co_tipidocumento`.`id`, CONCAT_WS(' - ',`codice_tipo_documento_fe`, `name`) AS descrizione FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id` = `co_tipidocumento_lang`.`id_record` AND `co_tipidocumento_lang`.`id_lang` = id); ?>) WHERE `dir`='' AND ((`reversed` = 0 AND `id_segment` ='') OR `co_tipidocumento`.`id` = ) ORDER BY `codice_tipo_documento_fe`", "value": "$idtipodocumento$", "readonly": , "help": "fetchOne('SELECT tipo FROM an_anagrafiche WHERE idanagrafica = '.prepare($record['idanagrafica']))['tipo'] == 'Ente pubblico') ? 'FPA12 - fattura verso PA (Ente pubblico)' : 'FPR12 - fattura verso soggetti privati (Azienda o Privato)'; ?>" ]} + {[ "type": "select", "label": "", "name": "idtipodocumento", "required": 1, "values": "query=SELECT `co_tipidocumento`.`id`, CONCAT_WS(' - ',`codice_tipo_documento_fe`, `name`) AS descrizione FROM `co_tipidocumento` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id` = `co_tipidocumento_lang`.`id_record` AND `co_tipidocumento_lang`.`id_lang` = id); ?>) WHERE `dir`='' AND ((`reversed` = 0 AND `id_segment` ='') OR `co_tipidocumento`.`id` = ) ORDER BY `codice_tipo_documento_fe`", "value": "$idtipodocumento$", "readonly": stato->id != $id_stato_bozza && $fattura->stato->id != $id_stato_annullata); ?>, "help": "fetchOne('SELECT tipo FROM an_anagrafiche WHERE idanagrafica = '.prepare($record['idanagrafica']))['tipo'] == 'Ente pubblico') ? 'FPA12 - fattura verso PA (Ente pubblico)' : 'FPR12 - fattura verso soggetti privati (Azienda o Privato)'; ?>" ]}
@@ -452,7 +462,7 @@ if ($dir == 'entrata') {
'; } -if ($record['stato'] != 'Bozza' && $record['stato'] != 'Annullata') { +if ($fattura->stato->id != $id_stato_bozza && $fattura->stato->id != $id_stato_annullata) { $scadenze = $fattura->scadenze; $ricalcola = true; @@ -468,7 +478,7 @@ if ($record['stato'] != 'Bozza' && $record['stato'] != 'Annullata') { '.Modules::link('Scadenzario', $scadenze[0]['id'], tr(''), '', 'class="btn btn-xs btn-primary"'); // Ricalcola scadenze disponibile solo per fatture di acquisto - if ($fattura->isFE() && $ricalcola && $module->getTranslation('name') == 'Fatture di acquisto') { + if ($fattura->isFE() && $ricalcola && $module->getTranslation('name', \Models\Locale()->getPredefined()->id) == 'Fatture di acquisto') { echo '