diff --git a/templates/versements_activites.tpl b/templates/versements_activites.tpl index 068e0a0..6762f0e 100644 --- a/templates/versements_activites.tpl +++ b/templates/versements_activites.tpl @@ -10,7 +10,7 @@ -
+ {* Itération sur les versements *} {foreach from=$lesVersements key="i" item="versement"} diff --git a/templates/versements_personnes.tpl b/templates/versements_personnes.tpl index b83eae7..cae6d14 100644 --- a/templates/versements_personnes.tpl +++ b/templates/versements_personnes.tpl @@ -10,7 +10,7 @@ - + {* Itération sur les personnes *} {foreach from=$lesVersements key="i" item="versement"} diff --git a/www/admin/generer_personnes.php b/www/admin/generer_personnes.php deleted file mode 100644 index 8d3b1f7..0000000 --- a/www/admin/generer_personnes.php +++ /dev/null @@ -1,134 +0,0 @@ - Personne -$totalPersonnes = cumulerVersements($versementsSelectionnes); - -// informations pour les reçus -$nomAsso = $config->get('nom_asso'); -$adresseAsso = $config->get('adresse_asso'); -$signature = - (null !== $plugin->getConfig('signature')) - ? - Files::get($plugin->getConfig('signature'))->fullpath() - : - ""; -// logo -$logo_file = Files::get(File::CONTEXT_CONFIG . '/logo.png'); -$logoAsso = - (null !== $logo_file) - ? - Files::get($logo_file->path)->fullpath() - : - ""; - -// articles du CGI -$articlesCGI = array(); -foreach ($plugin->getConfig('articlesCGI') as $article) -{ - if ($article->valeur == 1) { - $articlesCGI[] = $article->titre; - } -} - -$listeFichiers = array(); // fichiers pdf générés -foreach ($totalPersonnes as $idPersonne => $personne) -{ - // générer un fichier par reçu - $html = new RecusHTML( - $nomAsso, - $adresseAsso, - $logoAsso, - $plugin->getConfig('objet_asso'), - $plugin->getConfig('nom_responsable'), - $plugin->getConfig('fonction_responsable'), - $plugin->getConfig('ville_asso'), - $articlesCGI, - $signature - ); - - $html->imprimer_recu( - $_SESSION['annee_recu'], - $personne->id, - $personne->nomPrenom, - $personne->versements, - $personne->adresse, - $personne->codePostal, - $personne->ville - ); - // fabriquer le fichier PDF - $nomPDF = \Garradin\Utils::filePDF($html->get()); - // changer le nom du fichier - $nom = str_replace(' ', '_', $personne->nomPrenom); - $nom = str_replace("'", "", $nom); - $nomFichier = "recu_" . $_SESSION['annee_recu'] . "_" . $nom . ".pdf"; - rename($nomPDF, $nomFichier); - // ajouter le nom du fichier à la liste pour mettre dans une archive - $listeFichiers[] = $nomFichier; -} - -// faire une archive zip -$fichierZip = Utils::makeArchive( - $listeFichiers, - $_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( - $_SESSION['taux_reduction'], - $totalVersements/100 - ); - } - $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]->clone(); - } - } else { - // cumuler versements - $totalVersements += $ligne->versement; - } - } - // et le dernier - $totalPersonnes[$idPersonneCourant]->ajouterVersement( - $_SESSION['taux_reduction'], - $totalVersements/100 - ); - return $totalPersonnes; -} diff --git a/www/admin/generer_activites.php b/www/admin/generer_recus.php similarity index 69% rename from www/admin/generer_activites.php rename to www/admin/generer_recus.php index 39e66cf..d2d3868 100644 --- a/www/admin/generer_activites.php +++ b/www/admin/generer_recus.php @@ -18,9 +18,15 @@ foreach ($lesLignes as $ligne) { $versementsSelectionnes[] = $_SESSION['lesVersements'][$ligne]; } -// cumuler les versements d'une personne : id => Personne -$totalPersonnes = cumulerVersements($versementsSelectionnes); -error_log("totalPersonnes = " . print_r($totalPersonnes, true)); +// cumuler les versements +if ($_GET['type'] == 'personne') +{ + $totalPersonnes = cumulerVersementsPersonne($versementsSelectionnes); +} +elseif ($_GET['type'] == 'activite') +{ + $totalPersonnes = cumulerVersementsTarif($versementsSelectionnes); +} // informations pour les reçus $nomAsso = $config->get('nom_asso'); @@ -46,10 +52,10 @@ foreach ($plugin->getConfig('articlesCGI') as $article) } } +// générer les reçus $listeFichiers = array(); // fichiers pdf générés foreach ($totalPersonnes as $idPersonne => $personne) { - // générer un fichier par reçu $html = new RecusHTML( $nomAsso, $adresseAsso, @@ -89,12 +95,54 @@ $fichierZip = Utils::makeArchive( 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 cumulerVersementsPersonne($versements) +{ + $totalPersonnes = array(); + $idPersonneCourant = -1; + $totalVersements = 0; + foreach ($versements as $ligne) + { + if ($ligne->idUser != $idPersonneCourant) + { + // changement de personne + if ($idPersonneCourant != -1) + { + $totalPersonnes[$idPersonneCourant]->ajouterVersement( + $_SESSION['taux_reduction'], + $totalVersements/100 + ); + } + $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]->clone(); + } + } else { + // cumuler versements + $totalVersements += $ligne->versement; + } + } + // et le dernier + $totalPersonnes[$idPersonneCourant]->ajouterVersement( + $_SESSION['taux_reduction'], + $totalVersements/100 + ); + return $totalPersonnes; +} + /** * Cumuler les versements de chaque personne par tarif * @param tableau des versements triés par idTarif, idUser, date * @return tableau des versements cumulés : id => Personne */ -function cumulerVersements($versements) +function cumulerVersementsTarif($versements) { $totalPersonnes = array(); $idTarifCourant = -1;