Aggiunto plugin Regole pagamenti in Anagrafiche

This commit is contained in:
MatteoPistorello 2022-03-14 10:41:07 +01:00
parent 7ee71b8fde
commit 7c2fee847f
8 changed files with 299 additions and 3 deletions

View File

@ -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) {

View File

@ -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"

View File

@ -0,0 +1,60 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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;
}

View File

@ -0,0 +1,77 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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 '
<form action="" method="post" role="form">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="addpagamento">
<!-- Fix creazione da Anagrafica -->
<input type="hidden" name="id_record" value="">
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Mese da posticipare').'", "name": "mese", "values": '.json_encode($mesi_pagamento).', "required": "1" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Giorno riprogrammazione scadenza').'", "name": "giorno_fisso", "values": '.json_encode($giorni_pagamento).', "required": "1" ]}
</div>
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary"><i class="fa fa-plus"></i> '.tr('Aggiungi').'</button>
</div>
</div>
</form>';

View File

@ -0,0 +1,25 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
echo '
<div class="alert alert-info text-center">
'.tr("Questo plugin permette di posticipare le scadenze delle fatture collegate all'anagrafica al mese successivo impostando il giorno di riprogrammazione").'
</div>';

View File

@ -0,0 +1,98 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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 '
<form action="" method="post" role="form" id="form_sedi">
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
<input type="hidden" name="id_parent" value="'.$id_parent.'">
<input type="hidden" name="id_record" value="'.$record['id'].'">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="updatepagamento">
<div class="row">
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Mese da posticipare').'", "name": "mese", "values": '.json_encode($mesi_pagamento).', "value": "'.$record['mese'].'", "required": "1" ]}
</div>
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Giorno riprogrammazione scadenza').'", "name": "giorno_fisso", "values": '.json_encode($giorni_pagamento).', "value": "'.$record['giorno_fisso'].'", "required": "1" ]}
</div>
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12">
<button type="button" class="btn btn-danger '.$disabled.'" onclick="rimuoviPagamento(this)">
<i class="fa fa-trash"></i> '.tr('Elimina').'
</button>
<button type="submit" class="btn btn-primary pull-right"><i class="fa fa-edit"></i> '.tr('Modifica').'</button>
</div>
</div>
</form>
<script>
function rimuoviPagamento(button) {
let hash = window.location.href.split("#")[1];
confirmDelete(button).then(function () {
redirect(globals.rootdir + "/editor.php", {
backto: "record-edit",
hash: hash,
op: "deletepagamento",
id: "'.$record['id'].'",
id_plugin: "'.$id_plugin.'",
id_module: "'.$id_module.'",
id_parent: "'.$id_parent.'",
});
}).catch(swal.noop);
}
</script>';

View File

@ -0,0 +1,25 @@
<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
if (isset($id_record)) {
$record = $dbo->fetchOne('SELECT * FROM an_pagamenti_anagrafiche WHERE id='.prepare($id_record));
}

View File

@ -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`));