diff --git a/modules/fatture/src/Gestori/Scadenze.php b/modules/fatture/src/Gestori/Scadenze.php index 2846263cd..fac9f9d43 100644 --- a/modules/fatture/src/Gestori/Scadenze.php +++ b/modules/fatture/src/Gestori/Scadenze.php @@ -157,7 +157,7 @@ class Scadenze $netto = $this->fattura->isNota() ? -$netto : $netto; // Calcolo delle rate - $rate = $this->fattura->pagamento->calcola($netto, $this->fattura->data); + $rate = $this->fattura->pagamento->calcola($netto, $this->fattura->data, $this->fattura->idanagrafica); $direzione = $this->fattura->tipo->dir; foreach ($rate as $rata) { diff --git a/modules/pagamenti/src/Pagamento.php b/modules/pagamenti/src/Pagamento.php index c89a07d8d..a1c3c21cb 100755 --- a/modules/pagamenti/src/Pagamento.php +++ b/modules/pagamenti/src/Pagamento.php @@ -39,7 +39,7 @@ class Pagamento extends Model return $this->hasMany(Pagamento::class, 'descrizione', 'descrizione'); } - public function calcola($importo, $data) + public function calcola($importo, $data, $id_anagrafica) { $rate = $this->rate->sortBy('num_giorni'); $number = count($rate); @@ -99,7 +99,14 @@ class Pagamento extends Model $date->setDate($date->format('Y'), $date->format('m'), $day); } - // Comversione della data in stringa standard + // Posticipo la scadenza in base alle regole pagamenti dell'anagrafica + $regola_pagamento = database()->selectOne('an_pagamenti_anagrafiche', '*', ['idanagrafica' => $id_anagrafica, 'mese' => $date->format('m')]); + if (!empty($regola_pagamento)) { + $date->modify('last day of this month'); + $date->addDay( $regola_pagamento['giorno_fisso'] ); + } + + // Conversione della data in stringa standard $scadenza = $date->format('Y-m-d'); // All'ultimo ciclo imposto come cifra da pagare il totale della fattura meno gli importi già inseriti in scadenziario per evitare di inserire cifre arrotondate "male" diff --git a/plugins/pagamenti_anagrafiche/actions.php b/plugins/pagamenti_anagrafiche/actions.php new file mode 100644 index 000000000..69cb0a9ce --- /dev/null +++ b/plugins/pagamenti_anagrafiche/actions.php @@ -0,0 +1,60 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +$operazione = filter('op'); + +switch ($operazione) { + case 'addpagamento': + if (count($dbo->selectOne('an_pagamenti_anagrafiche', 'id', ['idanagrafica' => $id_parent, 'mese' => post('mese')])) == 0) { + $dbo->insert('an_pagamenti_anagrafiche', [ + 'idanagrafica' => $id_parent, + 'mese' => post('mese'), + 'giorno_fisso' => post('giorno_fisso'), + ]); + $id_record = $dbo->lastInsertedID(); + + flash()->info(tr('Aggiunta una nuova regola pagamento!')); + } else { + flash()->warning(tr('Esiste già una regola con lo stesso mese!')); + } + + break; + + case 'updatepagamento': + $opt_out_newsletter = post('disable_newsletter'); + + $dbo->update('an_pagamenti_anagrafiche', [ + 'mese' => post('mese'), + 'giorno_fisso' => post('giorno_fisso'), + ], ['id' => $id_record]); + + flash()->info(tr('Salvataggio completato!')); + + break; + + case 'deletepagamento': + $id = filter('id'); + $dbo->query('DELETE FROM `an_pagamenti_anagrafiche` WHERE `id` = '.prepare($id).''); + + flash()->info(tr('Regola pagamento eliminata!')); + + break; +} diff --git a/plugins/pagamenti_anagrafiche/add.php b/plugins/pagamenti_anagrafiche/add.php new file mode 100644 index 000000000..e17776143 --- /dev/null +++ b/plugins/pagamenti_anagrafiche/add.php @@ -0,0 +1,77 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +$mesi = [ + '01' => 'Gennaio', + '02' => 'Febbraio', + '03' => 'Marzo', + '04' => 'Aprile', + '05' => 'Maggio', + '06' => 'Giugno', + '07' => 'Luglio', + '08' => 'Agosto', + '09' => 'Settembre', + '11' => 'Ottobre', + '11' => 'Novembre', + '12' => 'Dicembre', +]; + +foreach ($mesi as $id => $mese) { + $mesi_pagamento[] = [ + 'id' => $id, + 'text' => $mese, + ]; +} + +$giorni_pagamento = []; +for ($i = 1; $i <= 31; ++$i) { + $giorni_pagamento[] = [ + 'id' => $i, + 'text' => $i, + ]; +} + +echo ' +
+ + + + + + + +
+
+ {[ "type": "select", "label": "'.tr('Mese da posticipare').'", "name": "mese", "values": '.json_encode($mesi_pagamento).', "required": "1" ]} +
+ +
+ {[ "type": "select", "label": "'.tr('Giorno riprogrammazione scadenza').'", "name": "giorno_fisso", "values": '.json_encode($giorni_pagamento).', "required": "1" ]} +
+
+ + +
+
+ +
+
+
'; diff --git a/plugins/pagamenti_anagrafiche/controller_before.php b/plugins/pagamenti_anagrafiche/controller_before.php new file mode 100644 index 000000000..1ed6b16f2 --- /dev/null +++ b/plugins/pagamenti_anagrafiche/controller_before.php @@ -0,0 +1,25 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +echo ' +
+ '.tr("Questo plugin permette di posticipare le scadenze delle fatture collegate all'anagrafica al mese successivo impostando il giorno di riprogrammazione").' +
'; diff --git a/plugins/pagamenti_anagrafiche/edit.php b/plugins/pagamenti_anagrafiche/edit.php new file mode 100644 index 000000000..5b6775974 --- /dev/null +++ b/plugins/pagamenti_anagrafiche/edit.php @@ -0,0 +1,98 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +$mesi = [ + '01' => 'Gennaio', + '02' => 'Febbraio', + '03' => 'Marzo', + '04' => 'Aprile', + '05' => 'Maggio', + '06' => 'Giugno', + '07' => 'Luglio', + '08' => 'Agosto', + '09' => 'Settembre', + '11' => 'Ottobre', + '11' => 'Novembre', + '12' => 'Dicembre', +]; + +foreach ($mesi as $id => $mese) { + $mesi_pagamento[] = [ + 'id' => $id, + 'text' => $mese, + ]; +} + +$giorni_pagamento = []; +for ($i = 1; $i <= 31; ++$i) { + $giorni_pagamento[] = [ + 'id' => $i, + 'text' => $i, + ]; +} + +echo ' +
+ + + + + + +
+
+ {[ "type": "select", "label": "'.tr('Mese da posticipare').'", "name": "mese", "values": '.json_encode($mesi_pagamento).', "value": "'.$record['mese'].'", "required": "1" ]} +
+ +
+ {[ "type": "select", "label": "'.tr('Giorno riprogrammazione scadenza').'", "name": "giorno_fisso", "values": '.json_encode($giorni_pagamento).', "value": "'.$record['giorno_fisso'].'", "required": "1" ]} +
+
+ + +
+
+ + + +
+
+
+ +'; \ No newline at end of file diff --git a/plugins/pagamenti_anagrafiche/init.php b/plugins/pagamenti_anagrafiche/init.php new file mode 100644 index 000000000..b9c5f73cb --- /dev/null +++ b/plugins/pagamenti_anagrafiche/init.php @@ -0,0 +1,25 @@ +. + */ + +include_once __DIR__.'/../../core.php'; + +if (isset($id_record)) { + $record = $dbo->fetchOne('SELECT * FROM an_pagamenti_anagrafiche WHERE id='.prepare($id_record)); +} + diff --git a/update/2_4_31.sql b/update/2_4_31.sql index 88b4e0732..905fbf937 100644 --- a/update/2_4_31.sql +++ b/update/2_4_31.sql @@ -98,3 +98,7 @@ DELETE FROM `zz_widgets` WHERE `zz_widgets`.`name` = 'Stampa riepilogo'; INSERT INTO `zz_prints` (`id`, `id_module`, `is_record`, `name`, `title`, `filename`, `directory`, `previous`, `options`, `icon`, `version`, `compatibility`, `order`, `predefined`, `default`, `enabled`) VALUES (NULL, (SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `zz_modules`.`name` = 'Prima nota'), (SELECT `zz_modules`.`id` FROM `zz_modules` WHERE `zz_modules`.`name` = 'Prima nota'), 'Prima nota', 'Prima nota', 'Prima nota del {data}', 'prima_nota', 'idmastrino', '', 'fa fa-print', '', '', '0', '1', '1', '1'); + +-- Aggiunto plugin Regole pagamenti +INSERT INTO `zz_plugins` (`id`, `name`, `title`, `idmodule_from`, `idmodule_to`, `position`, `script`, `enabled`, `default`, `order`, `compatibility`, `version`, `options2`, `options`, `directory`, `help`) VALUES (NULL, 'Regole pagamenti', 'Regole pagamenti', (SELECT `id` FROM `zz_modules` WHERE `name` = 'Anagrafiche'), (SELECT `id` FROM `zz_modules` WHERE `name` = 'Anagrafiche'), 'tab', '', '1', '1', '0', '', '', NULL, '{ \"main_query\": [ { \"type\": \"table\", \"fields\": \"Mese da posticipare, Giorno riprogrammazione scadenza\", \"query\": \"SELECT id, IF(mese=\'01\', \'Gennaio\', IF(mese=\'02\', \'Febbraio\',IF(mese=\'03\', \'Marzo\',IF(mese=\'04\', \'Aprile\',IF(mese=\'05\', \'Maggio\', IF(mese=\'06\', \'Giugno\', IF(mese=\'07\', \'Luglio\',IF(mese=\'08\', \'Agosto\',IF(mese=\'09\', \'Settembre\', IF(mese=\'10\', \'Ottobre\', IF(mese=\'11\', \'Novembre\',\'Dicembre\'))))))))))) AS `Mese da posticipare`, giorno_fisso AS `Giorno riprogrammazione scadenza` FROM an_pagamenti_anagrafiche WHERE 1=1 AND idanagrafica=|id_parent| GROUP BY id HAVING 2=2 ORDER BY an_pagamenti_anagrafiche.mese ASC\"} ]}', 'pagamenti_anagrafiche', ''); +CREATE TABLE `an_pagamenti_anagrafiche` ( `id` INT NOT NULL AUTO_INCREMENT , `mese` INT NOT NULL , `giorno_fisso` INT NOT NULL , `idanagrafica` INT NOT NULL , PRIMARY KEY (`id`)); \ No newline at end of file