From 2f8f472fe8090555556f8bafd94dbdb40dc0f57a Mon Sep 17 00:00:00 2001 From: Dasc3er Date: Fri, 17 Sep 2021 17:54:35 +0200 Subject: [PATCH] Inizio revisione modulo Scadenzario --- modules/fatture/edit.php | 2 +- modules/fatture/src/Fattura.php | 9 +- modules/fatture/src/Gestori/Scadenze.php | 33 +++- modules/scadenzario/edit.php | 215 +++++++++++------------ modules/scadenzario/src/Gruppo.php | 2 +- update/scadenze.sql | 1 + 6 files changed, 139 insertions(+), 123 deletions(-) diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index e2fdeb863..933ec2bd1 100755 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -334,7 +334,7 @@ elseif ($record['stato'] == 'Bozza') {

'.tr('Scadenze').'

- '.Modules::link('Scadenzario', $fattura->gruppoScadenze->id, tr(''), '', 'class="btn btn-xs btn-primary"'); + '.Modules::link('Scadenzario', $fattura->getGruppoScadenze()->id, tr(''), '', 'class="btn btn-xs btn-primary"'); // Ricalcola scadenze disponibile solo per fatture di acquisto if ($fattura->isFE() && $ricalcola && $module['name'] == 'Fatture di acquisto') { diff --git a/modules/fatture/src/Fattura.php b/modules/fatture/src/Fattura.php index e73aa71fc..734faf705 100755 --- a/modules/fatture/src/Fattura.php +++ b/modules/fatture/src/Fattura.php @@ -444,14 +444,15 @@ class Fattura extends Document return $this->hasOne(Components\Riga::class, 'iddocumento')->where('id', $this->id_riga_bollo); } - public function gruppoScadenze() + public function getGruppoScadenze() { - return $this->hasOne(Gruppo::class, 'id_documento'); + return $this->gestoreScadenze->getGruppo(); } public function scadenze() { - return $this->gruppoScadenze->scadenze() + return $this->getGruppoScadenze() + ->scadenze() ->orderBy('scadenza'); } @@ -608,7 +609,7 @@ class Fattura extends Document || $options[0] == 'forza_emissione' ) { // Correzione descrizione per Gruppo Scadenze di riferimento - $gruppo = $this->gruppoScadenze; + $gruppo = $this->gestoreScadenze->getGruppo(); $gruppo->descrizione = $this->getReference(); $gruppo->save(); diff --git a/modules/fatture/src/Gestori/Scadenze.php b/modules/fatture/src/Gestori/Scadenze.php index 96c570902..3ef6e73f4 100644 --- a/modules/fatture/src/Gestori/Scadenze.php +++ b/modules/fatture/src/Gestori/Scadenze.php @@ -32,20 +32,35 @@ use Util\XML; */ class Scadenze { + /** + * @var Fattura + */ private $fattura; + /** + * @var Gruppo + */ + private $gruppo; + public function __construct(Fattura $fattura) { $this->fattura = $fattura; } public function getGruppo(){ - // Generazione Gruppo Scadenze di riferimento - if (empty($this->fattura->gruppoScadenze)) { - $gruppo = Gruppo::build($this->fattura->getReference(), $this->fattura); + if (isset($this->gruppo)){ + return $this->gruppo; } - return $this->fattura->gruppoScadenze; + // Ricerca Gruppo Scadenza associato alla Fattura + $this->gruppo = Gruppo::where('id_documento', '=', $this->fattura->id)->first(); + + // Generazione Gruppo Scadenza associato alla Fattura + if (empty($this->gruppo)){ + $this->gruppo = Gruppo::build($this->fattura->getReference(), $this->fattura); + } + + return $this->gruppo; } /** @@ -87,7 +102,7 @@ class Scadenze $importo = -$ritenuta_acconto; - self::registraScadenza($this->fattura, $importo, $scadenza, $is_pagato, 'ritenutaacconto'); + $this->registraScadenza($importo, $scadenza, $is_pagato, 'ritenutaacconto'); } } @@ -107,9 +122,9 @@ class Scadenze * @param bool $is_pagato * @param string $tipo */ - protected static function registraScadenza(Fattura $fattura, $importo, $data_scadenza, $is_pagato, $tipo = 'fattura') + protected function registraScadenza($importo, $data_scadenza, $is_pagato, $tipo = 'fattura') { - return Scadenza::build($fattura->getGruppo(), $importo, $data_scadenza, $tipo, $is_pagato); + return Scadenza::build($this->getGruppo(), $importo, $data_scadenza, $tipo, $is_pagato); } /** @@ -140,7 +155,7 @@ class Scadenze $scadenza = !empty($rata['DataScadenzaPagamento']) ? FatturaElettronicaImport::parseDate($rata['DataScadenzaPagamento']) : $this->fattura->data; $importo = $this->fattura->isNota() ? $rata['ImportoPagamento'] : -$rata['ImportoPagamento']; - self::registraScadenza($this->fattura, $importo, $scadenza, $is_pagato); + $this->registraScadenza($importo, $scadenza, $is_pagato); } } @@ -166,7 +181,7 @@ class Scadenze $scadenza = $rata['scadenza']; $importo = $direzione == 'uscita' ? -$rata['importo'] : $rata['importo']; - self::registraScadenza($this->fattura, $importo, $scadenza, $is_pagato); + $this->registraScadenza($importo, $scadenza, $is_pagato); } } } diff --git a/modules/scadenzario/edit.php b/modules/scadenzario/edit.php index b613e5eb3..c25fca2e4 100755 --- a/modules/scadenzario/edit.php +++ b/modules/scadenzario/edit.php @@ -35,55 +35,50 @@ echo '

- '.tr('Dettagli scadenza').' - + '.tr('Gruppo Scadenze').'

-
-
- - -
'; +
'; if (!empty($documento)) { echo ' - - - - - +
+
+

' . tr('Documento') . '

+ ' . Modules::link($documento->getModule(), $documento->id, $documento->getReference()) . ' +
-
- - - +
+

' . ($documento->direzione == 'entrata' ? tr('Cliente') : tr('Fornitore')) . '

+ ' . Modules::link('Anagrafiche', $documento->anagrafica->id, $documento->anagrafica->ragione_sociale) . ' +
- - - - +
+

' . tr('Netto a pagare') . '

+ ' . moneyFormat($documento->netto) . ' +
+ - - - - +
+
'; +} + echo ' +
+
+ {[ "type": "text", "label": "'.tr('Descrizione').'", "name": "descrizione", "value": "'.$gruppo['descrizione'].'" ]} +
-
- - - +
+ {[ "type": "date", "label": "'.tr('Data di emissione').'", "name": "data_emissione", "value": "'.$gruppo['data_emissione'].'" ]} +
+ - - - - +
+
+ {[ "type": "ckeditor", "label": "'.tr('Note').'", "name": "note", "value": "'.$gruppo['note'].'" ]} +
+
'; @@ -125,96 +120,96 @@ if (!empty($documento)) { } echo ' - + + - -
-
'.($dir == 'entrata' ? tr('Cliente') : tr('Fornitore')).': - '.Modules::link('Anagrafiche', $documento->anagrafica->id, $documento->anagrafica->ragione_sociale).' -
'.tr('Documento').':'.$documento->tipo->descrizione.'
'.tr('Numero').':'.$numero.'
'.tr('Data').':'.Translator::dateToLocale($documento->data).'
'.tr('Netto a pagare').':'.moneyFormat($documento->netto).'
'.tr('Note').': - {[ "type": "textarea", "name": "note", "value": "'.$record['note'].'" ]} -
'.tr('Distinta').':
- - - - - - - - + +
+
+

'.tr('Elenco scadenza').'

+
+ +
+
-
'; +
+
'.tr('Data').''.tr('Importo').''.tr('Pagato').''.tr('Data concordata').'
+ + + + + + + + + -foreach ($scadenze as $i => $scadenza) { + '; + + foreach ($scadenze as $i => $scadenza) { if ($scadenza['da_pagare'] == $scadenza['pagato']) { - $class = 'success'; + $class = 'success'; } elseif (abs($scadenza['pagato']) == 0) { - $class = 'danger'; + $class = 'danger'; } elseif (abs($scadenza['pagato']) <= abs($scadenza['da_pagare'])) { - $class = 'warning'; + $class = 'warning'; } else { - $class = 'danger'; + $class = 'danger'; } echo ' - - + + - + - + - + - - '; -} + -echo ' - - - - - - - - - -
'.tr('Data').''.tr('Importo').''.tr('Pagato').''.tr('Data concordata').''.tr('Note').'
- {[ "type": "date", "name": "scadenza['.$i.']", "value": "'.$scadenza['scadenza'].'" ]} - + {[ "type": "date", "name": "scadenza['.$i.']", "value": "'.$scadenza['scadenza'].'" ]} + - {[ "type": "number", "name": "da_pagare['.$i.']", "decimals": 2, "value": "'.numberFormat($scadenza['da_pagare'], 2).'", "onchange": "controlloTotale()" ]} - + {[ "type": "number", "name": "da_pagare['.$i.']", "decimals": 2, "value": "'.numberFormat($scadenza['da_pagare'], 2).'", "onchange": "controlloTotale()" ]} + - {[ "type": "number", "name": "pagato['.$i.']", "decimals": 2, "value": "'.numberFormat($scadenza['pagato']).'" ]} - + {[ "type": "number", "name": "pagato['.$i.']", "decimals": 2, "value": "'.numberFormat($scadenza['pagato']).'" ]} + - {[ "type": "date", "name": "data_concordata['.$i.']", "value": "'.$scadenza['data_concordata'].'" ]} -
+ {[ "type": "date", "name": "data_concordata['.$i.']", "value": "'.$scadenza['data_concordata'].'" ]} +
'.tr('Totale').''.numberFormat($totale_da_pagare).'
'; + + {[ "type": "textarea", "name": "note['.$i.']", "value": "'.$scadenza['note'].'" ]} + + '; + } -if ($totale_da_pagare != 0) { echo ' - + + + + '.tr('Totale').' + '.numberFormat($totale_da_pagare).' + + + + + -
-
'; -} -?> +
'.tr('Il totale da pagare non corrisponde con il totale della fattura che è pari a _MONEY_', [ + '_MONEY_' => ''.moneyFormat($totale_da_pagare).'', + ]); ?>.
'', + '_CURRENCY_' => currency(), + ]).'. +
-
''.moneyFormat($totale_da_pagare).'', - ]); ?>.
'', - '_CURRENCY_' => currency(), - ]); ?>. -
- - -
-
+
- +'; - - + {[ "type": "date", "name": "scadenza[-id-]" ]} @@ -253,9 +248,13 @@ echo ' {[ "type": "number", "name": "pagato[-id-]", "decimals": 2 ]} - + {[ "type": "date", "name": "data_concordata[-id-]" ]} + + + {[ "type": "textarea", "name": "note[-id-]" ]} + diff --git a/modules/scadenzario/src/Gruppo.php b/modules/scadenzario/src/Gruppo.php index b7057da0d..0e04eb667 100644 --- a/modules/scadenzario/src/Gruppo.php +++ b/modules/scadenzario/src/Gruppo.php @@ -66,7 +66,7 @@ class Gruppo extends Model * Da utilizzare per le Fatture. */ public function rimuoviScadenze() { - $this->scadenze->delete(); + $this->scadenze()->delete(); } public function delete() diff --git a/update/scadenze.sql b/update/scadenze.sql index 855e0b1f4..781e0639f 100644 --- a/update/scadenze.sql +++ b/update/scadenze.sql @@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS `co_gruppi_scadenze` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_documento` int(11) DEFAULT NULL, `descrizione` varchar(255) NOT NULL, + `note` TEXT, `data_emissione` date DEFAULT NULL, `totale_pagato` decimal(12, 6) NOT NULL, `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,