début refonte gestion versements

FossilOrigin-Name: 1be54b8a985d3fb24895bae4cc5481743edf0a68dbb0eb4278580df3ce7f530d
This commit is contained in:
engel 2022-03-24 18:00:39 +00:00
parent 2e8eb26e5a
commit af7816d97f
11 changed files with 322 additions and 112 deletions

View file

@ -2,6 +2,9 @@
namespace Garradin;
use Garradin\Files\Files;
use Garradin\Entities\Files\File;
use Garradin\Plugin\RecusFiscaux\RecusHTML;
use Garradin\Plugin\RecusFiscaux\Utils;
use Garradin\Plugin\RecusFiscaux\Personne;
@ -12,21 +15,29 @@ $lesLignes = f('selected');
// filtrer les versements sélectionnés
$versementsSelectionnes = array();
foreach ($lesLignes as $ligne) {
$versementsSelectionnes[] = $_SESSION['lesVersementsTotaux'][$ligne];
$versementsSelectionnes[] = $_SESSION['lesVersements'][$ligne];
}
// cumuler les versements d'une personne : id => Personne
$totalPersonnes = cumulerVersements($versementsSelectionnes);
// informations pour les reçus
$nomAsso = Utils::getNomAsso();
$adresseAsso = Utils::getAdresseAsso();
$nomAsso = $config->get('nom_asso');
$adresseAsso = $config->get('adresse_asso');
$signature =
(null !== $plugin->getConfig('signature')) ?
\Garradin\Files\Files::get($plugin->getConfig('signature'))->fullpath() :
(null !== $plugin->getConfig('signature'))
?
Files::get($plugin->getConfig('signature'))->fullpath()
:
"";
// logo
$logo_file = Files::get(File::CONTEXT_CONFIG . '/logo.png');
$logoAsso =
(null !== $config->fileURL('logo')) ?
$config->fileURL('logo') :
\Garradin\Files\Files::get('skel/plugin/recusfiscaux/default_logo.png');
(null !== $logo_file)
?
Files::get($logo_file->path)->fullpath()
:
"";
// articles du CGI
$articlesCGI = array();
@ -36,8 +47,9 @@ foreach ($plugin->getConfig('articlesCGI') as $article)
$articlesCGI[] = $article->titre;
}
}
$listeFichiers = array(); // fichiers pdf générés
foreach ($versementsSelectionnes as $ligne)
foreach ($totalPersonnes as $idPersonne => $personne)
{
// générer un fichier par reçu
$html = new RecusHTML(
@ -53,8 +65,16 @@ foreach ($versementsSelectionnes as $ligne)
);
// extraire les montants des versements
$lesMontants[$_SESSION['taux_reduction']] = $ligne->versement/100;
$personne = $_SESSION['membresDonateurs'][$ligne->idUser];
$lesMontants = array();
foreach ($personne->versements as $versement)
{
if (array_key_exists($versement->tauxReduction, $lesMontants)) {
$lesMontants[$versement->tauxReduction] += $versement->montant;
}
else {
$lesMontants[$versement->tauxReduction] = $versement->montant;
}
}
$html->imprimer_recu(
$_SESSION['annee_recu'],
$personne->id,
@ -81,3 +101,49 @@ $fichierZip = Utils::makeArchive(
$_SESSION['annee_recu'],
PLUGIN_ROOT . "/zip"
);
/**
* Cumuler les versements de chaque personne
* @param tableau des versements triés par idUser, date
* @return tableau des versements cumulés : id => Personne
*/
function cumulerVersements($versements)
{
$totalPersonnes = array();
$idPersonneCourant = -1;
$totalVersements = 0;
foreach ($versements as $ligne)
{
if ($ligne->idUser != $idPersonneCourant)
{
// changement de personne
if ($idPersonneCourant != -1)
{
$totalPersonnes[$idPersonneCourant]->ajouterVersement(
0,
0,
$totalVersements/100,
$_SESSION['taux_reduction']
);
}
$idPersonneCourant = $ligne->idUser;
$totalVersements = $ligne->versement;
// créer les infos de la personne, sauf si elle est déjà présente
if (!array_key_exists($idPersonneCourant, $totalPersonnes))
{
$totalPersonnes["$idPersonneCourant"] = $_SESSION['membresDonateurs'][$ligne->idUser];
}
} else {
// cumuler versements
$totalVersements += $ligne->versement;
}
}
// et le dernier
$totalPersonnes[$idPersonneCourant]->ajouterVersement(
0,
0,
$totalVersements/100,
$_SESSION['taux_reduction']
);
return $totalPersonnes;
}