From a3aa6fa2000350363839fa6960bc65b224c1a82d Mon Sep 17 00:00:00 2001 From: engel <> Date: Fri, 18 Mar 2022 19:39:02 +0000 Subject: [PATCH] =?UTF-8?q?prise=20en=20compte=20de=20diff=C3=A9rents=20ch?= =?UTF-8?q?amps=20nom=20et=20pr=C3=A9nom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FossilOrigin-Name: 2895a7a5054d102c3262500e9e67557129592b607830a406d30fd3596cdfe6a9 --- lib/Utils.php | 66 ++++++++++++---- templates/config.tpl | 97 ++++++++++++++++-------- templates/index.tpl | 118 +++++++++++++++-------------- www/admin/config.php | 42 +++++++++- www/admin/index.php | 12 +++ www/admin/style.css | 5 ++ www/admin/versements_activites.php | 20 ++++- www/admin/versements_personnes.php | 19 ++++- 8 files changed, 271 insertions(+), 108 deletions(-) diff --git a/lib/Utils.php b/lib/Utils.php index 14e414d..0df1fb7 100644 --- a/lib/Utils.php +++ b/lib/Utils.php @@ -43,10 +43,12 @@ class Utils * @return versements correspondants à l'année et aux tarifs donnés * @param $annee * @param array $tarifs + * @param array $champsNom : liste non vide des champs de nom/prénom */ - public static function getVersementsTarifs($annee, $tarifs) + public static function getVersementsTarifs($annee, $tarifs, $champsNom) { $db = DB::getInstance(); + $tri = Utils::combinerTri($champsNom); $sql = sprintf( 'SELECT services_fees.id as idTarif, @@ -65,21 +67,25 @@ class Utils services_fees.%s AND acc_transactions_lines.credit > 0) - ORDER by services_fees.id, membres.nom, acc_transactions.date', + ORDER by services_fees.id, %s, acc_transactions.date', '"%Y"', $annee, - $db->where('id', $tarifs)); + $db->where('id', $tarifs), + $tri + ); return $db->get($sql); } /** * Versements totaux par personne pour une année donnée * @param année + * @param array $champsNom : liste non vide des champs de nom/prénom */ - public static function getVersementsTotaux($annee) + public static function getVersementsTotaux($annee, $champsNom) { - $sql = - "SELECT + $tri = Utils::combinerTri($champsNom); + $sql = sprintf( + 'SELECT membres.id as idUser, sum(acc_transactions_lines.credit) AS versement FROM @@ -89,7 +95,7 @@ class Utils INNER JOIN acc_transactions_lines ON acc_transactions_lines.id_transaction = acc_transactions.id WHERE ( - strftime('%Y', acc_transactions.date) = ? + strftime(%s, acc_transactions.date) = "%d" AND acc_transactions_lines.credit > 0 AND @@ -98,21 +104,55 @@ class Utils acc_transactions_users.id_user = membres.id ) GROUP by acc_transactions_users.id_user - ORDER by membres.nom COLLATE U_NOCASE; - "; - return DB::getInstance()->get($sql, $annee); + ORDER by %s COLLATE U_NOCASE', + '"%Y"', + $annee, + $tri); + return DB::getInstance()->get($sql); + } + + /** + * combiner les champs avec un opérateur + * @param array $champs : liste (non vide) de champs + * @return chaîne combinée + */ + private static function combinerChamps($champs) + { + $op = ' || " " || '; + $result = 'ifnull(membres.' . $champs[0] . ', "")'; + for ($i = 1; $i < count($champs); ++$i) + { + $result .= $op . 'ifnull(membres.' . $champs[$i] . ', "")'; + } + return $result; + } + + private static function combinerTri($champs) + { + $tri = 'membres.' . $champs[0]; + for ($i = 1; $i < count($champs); ++$i) + { + $tri .= ', membres.' . $champs[$i]; + } + return $tri; } /** * @return personnes ayant versé des dons pour une année donnée * @param $annee + * @param array $champsNom : champs qui définissent le nom et le prénom d'une personne */ - public static function getDonateurs($annee) + public static function getDonateurs($annee, $champsNom) { + // concaténer les champs nom/prénoms pour la sélection + $nom = Utils::combinerChamps($champsNom) . ' as nom,'; + // et pour le tri + $tri = Utils::combinerTri($champsNom); $sql = "SELECT membres.id as idUser, - membres.nom as nom, + " . + $nom . " membres.adresse as adresse, membres.code_postal as codePostal, membres.ville as ville @@ -132,7 +172,7 @@ class Utils acc_transactions_users.id_user = membres.id ) GROUP by membres.id - ORDER by membres.nom COLLATE U_NOCASE; + ORDER by " . $tri . " COLLATE U_NOCASE "; return DB::getInstance()->get($sql, $annee); } diff --git a/templates/config.tpl b/templates/config.tpl index df61059..79029a4 100644 --- a/templates/config.tpl +++ b/templates/config.tpl @@ -13,47 +13,41 @@
-{* - Objet (but) de l'association -*}
(obligatoire)
{input type="textarea" name="objet_asso" source=$plugin.config label="" required="required" cols="50" rows="4" maxlength=300}
-{* -
-
- Droit à la réduction d'impôt -*}
- (obligatoire ; sélectionnez tous les articles qui s'appliquent à l'asociation) + (obligatoire ; sélectionnez tous les articles qui s'appliquent à + l'asociation)
{foreach from=$plugin_config->articlesCGI key="key" item="article"} -{* - À VÉRIFIER : {input : checked ne fonctionne pas si l'attribut name est un tableau... + {* + À VÉRIFIER : {input : checked ne fonctionne pas si l'attribut name est un tableau... {input type="checkbox" name="articlesCGI[]" value=$key label=$article.titre} *} -
- +
+ -
+
{/foreach}
- (obligatoire ; sélectionnez tous les taux qui s'appliquent à l'asociation) + (obligatoire ; sélectionnez tous les taux qui s'appliquent à + l'asociation)
{foreach from=$plugin_config->reduction key="key" item="taux"} -
- - {/if} -
+
+ + {/if} +
{/foreach}
@@ -72,25 +66,42 @@
-

L'image de la signature doit être d'une taille « raisonnable » et avoir un fond transparent

- {if $plugin_config.signature != ''} - - {else} - - {/if} - {linkbutton shape="upload" label="Changer de signature" target="_dialog" href="upload.php?p=%s"|args:$path} +

L'image de la signature doit être d'une taille « raisonnable » et avoir un fond transparent

+ {if $plugin_config.signature != ''} + + {else} + + {/if} + {linkbutton shape="upload" label="Changer de signature" target="_dialog" href="upload.php?p=%s"|args:$path}
Autres informations -
+

Précède la date sur le formulaire

{input type="text" name="ville_asso" source=$plugin.config label="" maxlength=50}
-
+ {* les champs de nom *} + +
+
+

Sélectionnez et classez le(s) champ(s) qui représente(nt) le nom et le prénom du donateur

+ +
+ {foreach from=$nomChamps key="nom" item="champ"} +
+ + +
+
+
+ {/foreach} +
+
+

N'oubliez pas d'enregistrer, sinon les modifications ne seront pas prises en compte !

@@ -98,4 +109,26 @@ {csrf_field key="recusfiscaux_config"} {button type="submit" name="save" label="Enregistrer" shape="right" class="main"}

-
\ No newline at end of file + + +{literal} + +{/literal} \ No newline at end of file diff --git a/templates/index.tpl b/templates/index.tpl index 97a05d9..356628d 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -28,7 +28,8 @@ Tous les versements des membres font l'objet d'un reçu, sans tenir compte des activités et tarifs -

Choisissez cette option si vous voulez sélectionner tous les versements d'une, plusieurs ou toutes les personnes

+

Choisissez cette option si vous voulez sélectionner tous les versements d'une, plusieurs + ou toutes les personnes

@@ -44,8 +45,8 @@

Choisissez cette option si vous voulez sélectionner :

@@ -58,19 +59,20 @@

Choisir le taux de réduction

{if $nbTaux == 0} -

Vous devez d'abord sélectionner au moins un taux de réduction dans l'onglet de configuration

- {else} +

Vous devez d'abord sélectionner au moins un taux de réduction dans l'onglet de + configuration

+ {/if} + {if $nbChamps == 0} +

Vous devez d'abord sélectionner au moins un champ pour le nom et le prénom dans l'onglet + de configuration

+ {/if} + {if $nbTaux > 0 && $nbChamps > 0} {foreach from=$plugin_config->reduction item="reduc"} {if $reduc->valeur == 1} - - + + {/if} {/foreach} @@ -88,10 +90,13 @@ @@ -161,24 +163,24 @@ {literal} + } + }); + } + {/literal} diff --git a/www/admin/config.php b/www/admin/config.php index ea4b386..ec15380 100644 --- a/www/admin/config.php +++ b/www/admin/config.php @@ -5,8 +5,27 @@ use Garradin\Files\Files; use Garradin\Entities\Files\File; $session->requireAccess($session::SECTION_CONFIG, $session::ACCESS_ADMIN); -$art_sel=f('articlesCGI') ? : []; +$art_sel = f('articlesCGI') ? : []; $taux_sel = f('tauxReduction') ? : []; +$noms_sel = f('champsNom') ? : []; + +$confNoms = $plugin->getConfig('nomChamps'); +if (! isset($confNoms)) +{ + // récupérer les champs des membres utilisés pour le nom et le prénom + $nomChamps = array(); + foreach ($config->get('champs_membres')->listAssocNames() as $name => $title) + { + if (stristr($title, 'nom')) + { + $champ = new \stdClass(); + $champ->titre = $title; + $champ->position = 0; + $nomChamps[$name] = $champ; + } + } + $plugin->setConfig('nomChamps', $nomChamps); +} $path = qg('path') ?: File::CONTEXT_CONFIG; $context = Files::getContext($path); @@ -63,6 +82,19 @@ if (f('save') && $form->check('recusfiscaux_config')) // ville $plugin->setConfig('ville_asso', trim(f('ville_asso'))); + // champs pour le nom et prénom + $confNoms = (array)$plugin->getConfig('nomChamps'); + foreach ($confNoms as $nom => $champ) + { + $champ->position = 0; + } + $i = -count($noms_sel); + foreach ($noms_sel as $nom) + { + $confNoms[$nom]->position = $i++; + } + $plugin->setConfig('nomChamps', $confNoms); + \Garradin\Utils::redirect(PLUGIN_URL . 'config.php?ok'); } catch (UserException $e) @@ -71,9 +103,17 @@ if (f('save') && $form->check('recusfiscaux_config')) } } +// trier les champs de nom pour l'affichage +$nomChamps = (array) $plugin->getConfig('nomChamps'); +uasort($nomChamps, function ($a, $b) +{ + return $a->position - $b->position; +}); + $tpl->assign('ok', qg('ok') !== null); $tpl->assign('path', $path); $tpl->assign('default_signature', \Garradin\WWW_URL . "plugin/recusfiscaux/default_signature.png"); $tpl->assign('plugin_config', $plugin->getConfig()); +$tpl->assign('nomChamps', $nomChamps); $tpl->assign('plugin_css', ['style.css']); $tpl->display(PLUGIN_ROOT . '/templates/config.tpl'); diff --git a/www/admin/index.php b/www/admin/index.php index 48559e8..1dc3f17 100644 --- a/www/admin/index.php +++ b/www/admin/index.php @@ -13,6 +13,7 @@ if ($anneesFiscales[0] < $anneeCourante) { // libellés pour les taux de réduction $_SESSION['ligneReduction'] = Utils::getLignesReduction($plugin->getConfig('reduction')); + // compter le nombre de taux de réduction activés $nbTaux = 0; foreach ($plugin->getConfig('reduction') as $taux) @@ -20,6 +21,16 @@ foreach ($plugin->getConfig('reduction') as $taux) if ($taux->valeur == 1) { ++$nbTaux; } } +// idem avec les champs nom/prénom +$nbChamps = 0; +if (null !== $plugin->getConfig('nomChamps')) +{ + foreach ($plugin->getConfig('nomChamps') as $nom => $champ) + { + if ($champ->position != 0) { ++$nbChamps; } + } +} + // liste des activités, cotisations et comptes associés $activitesTarifsComptes = Utils::getActivitesTarifsEtComptes(); @@ -30,6 +41,7 @@ $tpl->assign('activitesTarifsComptes', $activitesTarifsComptes); $tpl->assign('nbTarifs', count($activitesTarifsComptes)); $tpl->assign('plugin_config', $plugin->getConfig()); $tpl->assign('nbTaux', $nbTaux); +$tpl->assign('nbChamps', $nbChamps); $tpl->assign('plugin_css', ['style.css']); // envoyer au template diff --git a/www/admin/style.css b/www/admin/style.css index 4e37b73..7247f39 100644 --- a/www/admin/style.css +++ b/www/admin/style.css @@ -39,3 +39,8 @@ div.explications ul { list-style : initial; } + +div.actions +{ + display : inline; +} diff --git a/www/admin/versements_activites.php b/www/admin/versements_activites.php index 4f263c1..8828415 100644 --- a/www/admin/versements_activites.php +++ b/www/admin/versements_activites.php @@ -12,6 +12,19 @@ $_SESSION['annee_recu'] = f('annee_recu'); if (! isset($_SESSION['annee_recu']) || $_SESSION['annee_recu'] == "") { \Garradin\Utils::redirect(PLUGIN_URL . 'index.php'); } + +// champs pour le nom et prénom +$confNoms = (array) $plugin->getConfig('nomChamps'); +uasort($confNoms, function ($a, $b) +{ + return $a->position - $b->position; +}); +$champsNom = array(); +foreach ($confNoms as $nom => $champ) +{ + if ($champ->position != 0) { $champsNom[] = $nom; } +} + // récupérer les infos du formulaire $tarifsSelectionnes = f('tarifs') ?: []; @@ -39,11 +52,14 @@ foreach (Utils::getActivites($tarifsSelectionnes) as $activite) { $_SESSION['lesActivites'] = $lesActivites; // versements correspondants aux tarifs sélectionnés -$_SESSION['lesVersements'] = Utils::getVersementsTarifs($_SESSION['annee_recu'], $tarifsSelectionnes); +$_SESSION['lesVersements'] = Utils::getVersementsTarifs($_SESSION['annee_recu'], + $tarifsSelectionnes, + $champsNom); // membres donateurs +$versementsMembres = Utils::getDonateurs($_SESSION['annee_recu'], + $champsNom); $membresDonateurs = array(); -$versementsMembres = Utils::getDonateurs($_SESSION['annee_recu']); foreach ($versementsMembres as $versement) { $membresDonateurs[$versement->idUser] = new Personne($versement->idUser, $versement->nom, diff --git a/www/admin/versements_personnes.php b/www/admin/versements_personnes.php index 496a76f..b7ebd0e 100644 --- a/www/admin/versements_personnes.php +++ b/www/admin/versements_personnes.php @@ -12,12 +12,27 @@ if (! isset($_SESSION['annee_recu']) || $_SESSION['annee_recu'] == "") { } $_SESSION['taux_reduction'] = $_POST['taux_reduction']; +// champs pour le nom et prénom +$confNoms = (array) $plugin->getConfig('nomChamps'); +uasort($confNoms, function ($a, $b) +{ + return $a->position - $b->position; +}); +$champsNom = array(); +foreach ($confNoms as $nom => $champ) +{ + if ($champ->position != 0) { $champsNom[] = $nom; } +} + // versements totaux par personne -$_SESSION['lesVersementsTotaux'] = Utils::getVersementsTotaux($_SESSION['annee_recu']); +$_SESSION['lesVersementsTotaux'] = + Utils::getVersementsTotaux($_SESSION['annee_recu'], + $champsNom); // membres donateurs +$versementsMembres = Utils::getDonateurs($_SESSION['annee_recu'], + $champsNom); $membresDonateurs = array(); -$versementsMembres = Utils::getDonateurs($_SESSION['annee_recu']); foreach ($versementsMembres as $versement) { $membresDonateurs[$versement->idUser] = new Personne($versement->idUser, $versement->nom,