@@ -746,7 +756,7 @@ if ($dir == 'entrata' && !empty($fattura->dichiarazione)) {
$descrizione_iva_accettata .= '
';
}
- if ($fattura->stato->getTranslation('name') == 'Bozza') {
+ if ($fattura->stato->id == $id_stato_bozza) {
echo '
'.tr("La fattura è collegata ad una dichiarazione d'intento con diponibilità residura pari a _MONEY_.", ['_MONEY_' => moneyFormat($diff)]).'
'.tr('Per collegare una riga alla dichiarazione è sufficiente specificare come IVA
', ['_IVA_' => $descrizione_iva_accettata]).'
@@ -807,6 +817,10 @@ if (!$block_edit) {
$contratti = $dbo->fetchArray($contr_query)[0]['tot'];
}
+ $id_stato_evaso = (new StatoDDT())->getByField('name', 'Evaso', \Models\Locale::getPredefined()->id);
+ $id_stato_parz_evaso = (new StatoDDT())->getByField('name', 'Parziale evaso', \Models\Locale::getPredefined()->id);
+ $id_stato_parz_fatt = (new StatoDDT())->getByField('name', 'Parziale fatturato', \Models\Locale::getPredefined()->id);
+
// Lettura ddt (entrata o uscita)
$ddt_query = 'SELECT
COUNT(*) AS tot
@@ -819,13 +833,18 @@ if (!$block_edit) {
INNER JOIN `dt_righe_ddt` ON `dt_righe_ddt`.`idddt` = `dt_ddt`.`id`
WHERE
`idanagrafica`='.prepare($record['idanagrafica']).'
- AND `dt_statiddt_lang`.`name` IN ("Evaso", "Parzialmente evaso", "Parzialmente fatturato")
+ AND `dt_statiddt`.`id` IN ('.prepare($id_stato_evaso).','.prepare($id_stato_parz_evaso).','.prepare($id_stato_parz_fatt).')
AND `dt_tipiddt`.`dir` = '.prepare($dir).'
AND `dt_causalet`.`is_importabile` = 1
AND (`dt_righe_ddt`.`qta` - `dt_righe_ddt`.`qta_evasa`) > 0';
$ddt = $dbo->fetchArray($ddt_query)[0]['tot'];
// Lettura ordini (cliente o fornitore)
+ $id_stato_accettato = (new StatoOrdine())->getByField('name', 'Accettato', \Models\Locale::getPredefined()->id);
+ $id_stato_evaso = (new StatoOrdine())->getByField('name', 'Evaso', \Models\Locale::getPredefined()->id);
+ $id_stato_parz_evaso = (new StatoOrdine())->getByField('name', 'Parziale evaso', \Models\Locale::getPredefined()->id);
+ $id_stato_parz_fatt = (new StatoOrdine())->getByField('name', 'Parziale fatturato', \Models\Locale::getPredefined()->id);
+
$ordini_query = 'SELECT
COUNT(*) AS tot
FROM
@@ -836,7 +855,7 @@ if (!$block_edit) {
INNER JOIN `or_tipiordine` ON `or_tipiordine`.`id` = `or_ordini`.`idtipoordine`
WHERE
idanagrafica='.prepare($record['idanagrafica']).'
- AND `name` IN(\'Accettato\', \'Evaso\', \'Parzialmente evaso\', \'Parzialmente fatturato\'))
+ AND `or_statiordine`.`id` IN ('.prepare($id_stato_accettato).','.prepare($id_stato_evaso).','.prepare($id_stato_parz_evaso).','.prepare($id_stato_parz_fatt).')
AND `dir`='.prepare($dir).')
AND (`or_righe_ordini`.`qta` - `or_righe_ordini`.`qta_evasa`) > 0';
$ordini = $dbo->fetchArray($ordini_query)[0]['tot'];
diff --git a/modules/fatture/src/Fattura.php b/modules/fatture/src/Fattura.php
index ca4e028e7..4014fbb5a 100755
--- a/modules/fatture/src/Fattura.php
+++ b/modules/fatture/src/Fattura.php
@@ -96,7 +96,7 @@ class Fattura extends Document
$database = database();
// Individuazione dello stato predefinito per il documento
- $stato_documento = (new Stato())->getByField('name', 'Bozza', \Models\Locale::getPredefined()->id);
+ $id_stato_attuale_documento = (new Stato())->getByField('name', 'Bozza', \Models\Locale::getPredefined()->id);
$direzione = $tipo_documento->dir;
// Conto predefinito sulla base del flusso di denaro
@@ -111,7 +111,7 @@ class Fattura extends Document
// Informazioni di base
$model->anagrafica()->associate($anagrafica);
$model->tipo()->associate($tipo_documento);
- $model->stato()->associate($stato_documento);
+ $model->stato()->associate($id_stato_attuale_documento);
$model->save();
@@ -573,8 +573,15 @@ class Fattura extends Document
public function save(array $options = [])
{
// Informazioni sul cambio dei valori
- $stato_precedente = Stato::find($this->original['idstatodocumento']);
- $stato_precedente = $stato_precedente ? $stato_precedente->getTranslation('name') : null;
+ $id_stato_precedente = $this->original['idstatodocumento'];
+ $id_stato_attuale = $this->stato['id'];
+
+ $id_stato_bozza = (new Stato())->getByField('name', 'Bozza', \Models\Locale::getPredefined()->id);
+ $id_stato_emessa = (new Stato())->getByField('name', 'Emessa', \Models\Locale::getPredefined()->id);
+ $id_stato_annullata = (new Stato())->getByField('name', 'Annullata', \Models\Locale::getPredefined()->id);
+ $id_stato_non_valida = (new Stato())->getByField('name', 'Non valida', \Models\Locale::getPredefined()->id);
+ $id_stato_pagato = (new Stato())->getByField('name', 'Pagato', \Models\Locale::getPredefined()->id);
+
$dichiarazione_precedente = Dichiarazione::find($this->original['id_dichiarazione_intento']);
$is_fiscale = $this->isFiscale();
@@ -589,9 +596,8 @@ class Fattura extends Document
// Fix dei campi statici
$this->id_riga_bollo = $this->gestoreBollo->manageRigaMarcaDaBollo();
- $stato = Stato::find($this->stato['id']);
// Generazione numero fattura se non presente (Bozza -> Emessa)
- if ((($stato_precedente == 'Bozza' && $stato->getTranslation('name') == 'Emessa') or (!$is_fiscale)) && empty($this->numero_esterno)) {
+ if ((($id_stato_precedente == $id_stato_bozza && $id_stato_attuale == $id_stato_emessa) or (!$is_fiscale)) && empty($this->numero_esterno)) {
$this->numero_esterno = self::getNextNumeroSecondario($this->data, $this->direzione, $this->id_segment);
}
@@ -601,17 +607,17 @@ class Fattura extends Document
// Operazioni al cambiamento di stato
// Bozza o Annullato -> Stato diverso da Bozza o Annullato
if (
- (in_array($stato_precedente, ['Bozza', 'Annullata'])
- && !in_array($stato->getTranslation('name'), ['Bozza', 'Annullata', 'Non valida']))
+ (in_array($id_stato_precedente, [$id_stato_bozza, $id_stato_annullata])
+ && !in_array($id_stato_attuale, [$id_stato_bozza, $id_stato_annullata, $id_stato_non_valida]))
|| $options[0] == 'forza_emissione'
) {
// Registrazione scadenze
- $this->registraScadenze($stato->getTranslation('name') == 'Pagato');
+ $this->registraScadenze($id_stato_attuale == $id_stato_pagato);
// Registrazione movimenti
$this->gestoreMovimenti->registra();
} // Stato qualunque -> Bozza o Annullato
- elseif (in_array($stato->getTranslation('name'), ['Bozza', 'Annullata', 'Non valida'])) {
+ elseif (in_array($id_stato_attuale, [$id_stato_bozza, $id_stato_annullata, $id_stato_non_valida])) {
// Rimozione delle scadenza
$this->rimuoviScadenze();
@@ -622,7 +628,7 @@ class Fattura extends Document
$this->movimentiContabili()->delete();
}
- if ($this->changes['data_competenza'] && !in_array($stato->getTranslation('name'), ['Bozza', 'Annullata', 'Non valida'])) {
+ if ($this->changes['data_competenza'] && !in_array($id_stato_attuale, [$id_stato_bozza, $id_stato_annullata, $id_stato_non_valida])) {
$movimenti = Movimento::where('iddocumento', $this->id)->where('primanota', 0)->get();
foreach ($movimenti as $movimento) {
$movimento->data = $this->data_competenza;
@@ -645,7 +651,7 @@ class Fattura extends Document
}
// Operazioni automatiche per le Fatture Elettroniche
- if ($this->direzione == 'entrata' && $stato_precedente == 'Bozza' && $stato->getTranslation('name') == 'Emessa') {
+ if ($this->direzione == 'entrata' && $id_stato_precedente == $id_stato_bozza && $id_stato_attuale == $id_stato_emessa) {
$stato_fe = StatoFE::find($this->codice_stato_fe);
$abilita_genera = empty($this->codice_stato_fe) || intval($stato_fe['is_generabile']);
@@ -721,8 +727,8 @@ class Fattura extends Document
$new->id_ricevuta_principale = null;
// Spostamento dello stato
- $stato = (new Stato())->getByField('name', 'Bozza', \Models\Locale::getPredefined()->id);
- $new->stato()->associate($stato);
+ $id_stato_attuale = (new Stato())->getByField('name', 'Bozza', \Models\Locale::getPredefined()->id);
+ $new->stato()->associate($id_stato_attuale);
return $new;
}
diff --git a/update/2_5.php b/update/2_5.php
index 69e28fb54..01d18cf6e 100644
--- a/update/2_5.php
+++ b/update/2_5.php
@@ -68,6 +68,7 @@ $tables = [
'dt_tipiddt_lang',
'em_lists_lang',
'em_templates_lang',
+ 'fe_stati_documento_lang',
'in_fasceorarie_lang',
'in_statiintervento_lang',
'in_tipiintervento_lang',