From 68e6afed118b8320281dc4223bccff65234f3945 Mon Sep 17 00:00:00 2001 From: engel <> Date: Wed, 18 May 2022 10:29:19 +0000 Subject: [PATCH] =?UTF-8?q?int=C3=A9gration=20comptes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FossilOrigin-Name: d81e13438cbc9ed585e76b36e2950615b8da359697f2c577673c77460b59064d --- lib/Utils.php | 413 +++++++++++++++-------------- templates/index.tpl | 271 ++++++++++++------- templates/versements_activites.tpl | 24 +- templates/versements_personnes.tpl | 58 +++- www/admin/action.php | 89 +++++-- www/admin/index.php | 31 ++- www/admin/style.css | 11 +- www/admin/versements_activites.php | 53 ++-- www/admin/versements_personnes.php | 80 +----- 9 files changed, 609 insertions(+), 421 deletions(-) diff --git a/lib/Utils.php b/lib/Utils.php index 7d7dc29..d3cf3cf 100644 --- a/lib/Utils.php +++ b/lib/Utils.php @@ -8,35 +8,139 @@ use KD2\ZipWriter; class Utils { /** - * @return tarifs demandés - * @param array $tarifs + * @return informations sur les tarifs */ - public static function getTarifs($tarifs) + public static function getTarifs() { $db = DB::getInstance(); $sql = sprintf( - 'SELECT id, id_service as idActivite, label, description, amount as montant - FROM services_fees - WHERE services_fees.%s', - $db->where('id', $tarifs)); + 'SELECT + id, + id_service as idActivite, + label, + description, + amount as montant + FROM services_fees'); + return Utils::toAssoc($db->get($sql), 'id'); + } + + /** + * @return informations sur les activités + */ + public static function getActivites() + { + $db = DB::getInstance(); + $sql = sprintf( + 'SELECT + services.id, + services.label, + services.description + FROM services'); + return Utils::toAssoc($db->get($sql), 'id'); + } + + /** + * @return comptes sur lesquels des versements de membres ont été faits + * @param string $annee + * @param $op : opérateur de combinaison des comptes + * @param array $comptes + */ + public static function getComptes($annee, $op, $comptes) + { + $db = DB::getInstance(); + $sql = sprintf( + 'SELECT + acc_accounts.id, + acc_accounts.code as codeCompte, + acc_accounts.label as nomCompte + FROM acc_transactions_users + INNER JOIN membres + ON acc_transactions_users.id_user = membres.id + INNER JOIN acc_transactions + ON acc_transactions_users.id_transaction = acc_transactions.id + INNER JOIN acc_transactions_lines + ON acc_transactions_lines.id_transaction = acc_transactions.id + INNER JOIN acc_accounts + ON acc_transactions_lines.id_account = acc_accounts.id + WHERE + (strftime(%s, acc_transactions.date) = "%d" + AND + acc_accounts.%s + ) + GROUP by acc_accounts.id + ORDER by acc_accounts.id', + '"%Y"', + $annee, + $db->where('code', $op, $comptes) + ); + return Utils::toAssoc($db->get($sql), 'id'); + } + + /** + * @return tarifs des activités et comptes ayant des versements de + * membres dans l'année + * @param string $annee + * @param $op : opérateur de combinaison des comptes + * @param array $comptes + */ + public static function getTarifsComptes($annee, $op, $comptes) + { + $db = DB::getInstance(); + $sql = sprintf( + ' + SELECT + services_users.id_fee as idTarif, + acc_accounts.id as idCompte, + acc_accounts.code as codeCompte + FROM acc_transactions_users + INNER JOIN acc_transactions + ON acc_transactions_users.id_transaction = acc_transactions.id + INNER JOIN services_users + ON acc_transactions_users.id_service_user = services_users.id + INNER JOIN services_fees + ON services_users.id_fee = services_fees.id + INNER JOIN acc_transactions_lines + ON acc_transactions_lines.id_transaction = acc_transactions.id + INNER JOIN acc_accounts + ON acc_transactions_lines.id_account = acc_accounts.id + WHERE + (strftime(%s, acc_transactions.date) = "%d" + AND + acc_accounts.%s + ) + GROUP BY services_fees.id,acc_accounts.id + ', + '"%Y"', + $annee, + $db->where('code', $op, $comptes) + ); return $db->get($sql); } /** - * @return activités correspondant aux tarifs demandés - * @param array $tarifs + * faire un tableau associatif avec le résultat d'une requête */ - public static function getActivites($tarifs) + static function toAssoc($array, $nomCle) { - $db = DB::getInstance(); - $sql = sprintf( - 'SELECT services.id, services.label, services.description - FROM services - LEFT JOIN services_fees ON services_fees.id_service = services.id - WHERE services_fees.%s - GROUP BY services.id', - $db->where('id', $tarifs)); - return $db->get($sql); + $assoc = array(); + foreach ($array as $elem) + { + $ro = new \ReflectionObject($elem); + $proprietes = $ro->getProperties(); + $obj = new \stdClass(); + foreach ($proprietes as $p) + { + $pname = $p->getName(); + if ($pname == $nomCle) { + $key = $p->getValue($elem); + } + else { + $obj->$pname = $p->getValue($elem); + } + } + $assoc[$key] = $obj; + } + return $assoc; } /** @@ -44,88 +148,60 @@ class Utils * @param $annee * @param array $champsNom : liste non vide des champs de nom/prénom */ - public static function getVersementsPersonnes($annee, $champsNom) + public static function getVersementsPersonnes($annee, $op, $comptes, $champsNom) { $db = DB::getInstance(); $tri = Utils::combinerTri($champsNom); $sql = sprintf( 'SELECT membres.id as idUser, + acc_accounts.id as idCompte, + acc_accounts.code as codeCompte, acc_transactions_lines.credit as versement, acc_transactions.date FROM acc_transactions_users - INNER JOIN membres on acc_transactions_users.id_user = membres.id - INNER JOIN acc_transactions on acc_transactions_users.id_transaction = acc_transactions.id - INNER JOIN services_users on acc_transactions_users.id_service_user = services_users.id - INNER JOIN acc_transactions_lines on acc_transactions_lines.id_transaction = acc_transactions.id + INNER JOIN membres + ON acc_transactions_users.id_user = membres.id + INNER JOIN acc_transactions + ON acc_transactions_users.id_transaction = acc_transactions.id + INNER JOIN acc_transactions_lines + ON acc_transactions_lines.id_transaction = acc_transactions.id + INNER JOIN acc_accounts + ON acc_transactions_lines.id_account = acc_accounts.id WHERE (strftime(%s, acc_transactions.date) = "%d" AND - acc_transactions_lines.credit > 0) - ORDER by %s, acc_transactions.date', + acc_accounts.%s + ) + ORDER by %s, acc_accounts.id, acc_transactions.date', '"%Y"', $annee, + $db->where('code', $op, $comptes), $tri ); return $db->get($sql); } /** - * @return versements correspondants à l'année et aux tarifs donnés - * triés par tarif, nom, date - * @param $annee - * @param array $tarifs + * @return versements correspondants à : + * @param $annee : année fiscale + * @param $tarifs : tarifs sélectionnés + * @param array $comptes : comptes associés aux tarifs * @param array $champsNom : liste non vide des champs de nom/prénom + * @remarks tri par tarif, nom, compte, date */ - public static function getVersementsTarifs($annee, $tarifs, $champsNom) - { - $db = DB::getInstance(); - $tri = Utils::combinerTri($champsNom); - $sql = sprintf( - 'SELECT - services_fees.id as idTarif, - membres.id as idUser, - acc_transactions_lines.credit as versement, - acc_transactions.date - FROM acc_transactions_users - INNER JOIN membres on acc_transactions_users.id_user = membres.id - INNER JOIN acc_transactions on acc_transactions_users.id_transaction = acc_transactions.id - INNER JOIN services_users on acc_transactions_users.id_service_user = services_users.id - INNER JOIN services_fees on services_users.id_fee = services_fees.id - INNER JOIN acc_transactions_lines on acc_transactions_lines.id_transaction = acc_transactions.id - WHERE - (strftime(%s, acc_transactions.date) = "%d" - AND - services_fees.%s - AND - acc_transactions_lines.credit > 0) - ORDER by services_fees.id, %s, acc_transactions.date', - '"%Y"', - $annee, - $db->where('id', $tarifs), - $tri - ); - return $db->get($sql); - } - - /** - * @return versements correspondants à l'année et aux comptes donnés - * @param $annee - * @param $op : opérateur de combinaison des comptes - * @param array $comptes - * @param array $champsNom : liste non vide des champs de nom/prénom - * exemples : - * op = 'in', comptes = ['706', '7780', '756'] - * op = 'like', comptes = '7%' - */ - public static function getVersementsComptes($annee, $op, $comptes, $champsNom) + public static function getVersementsTarifsComptes($annee, + $tarifs, + $comptes, + $champsNom) { $db = DB::getInstance(); $tri = Utils::combinerTri($champsNom); $sql = sprintf( 'SELECT services_fees.id as idTarif, - acc_accounts.code as compte, + acc_accounts.id as idCompte, + acc_accounts.code as codeCompte, membres.id as idUser, acc_transactions_lines.credit as versement, acc_transactions.date @@ -145,13 +221,62 @@ class Utils WHERE (strftime(%s, acc_transactions.date) = "%d" AND - acc_accounts.%s + services_fees.%s AND - acc_transactions_lines.credit > 0) - ORDER by %s, acc_transactions.date', + acc_accounts.%s + ) + ORDER by services_fees.id, %s, acc_accounts.id, acc_transactions.date', '"%Y"', $annee, - $db->where('code', $op, $comptes), + $db->where('id', 'in', $tarifs), + $db->where('id', 'in', $comptes), + $tri + ); + return $db->get($sql); + } + + /** + * @return versements correspondants à : + * @param $annee année fiscale + * @param $comptesIsoles comptes NON associés à un tarif + * @param array $champsNom : liste non vide des champs de nom/prénom + * @remarks tri par nom, compte, date + */ + public static function getVersementsComptes($annee, + $comptesIsoles, + $champsNom) + { + $db = DB::getInstance(); + $tri = Utils::combinerTri($champsNom); + $sql = sprintf( + ' + SELECT + 0 as idTarif, + acc_accounts.id as idCompte, + acc_accounts.code as codeCompte, + membres.id as idUser, + acc_transactions_lines.credit as versement, + acc_transactions.date + FROM acc_transactions_users + INNER JOIN membres + ON acc_transactions_users.id_user = membres.id + INNER JOIN acc_transactions + ON acc_transactions_users.id_transaction = acc_transactions.id + INNER JOIN acc_transactions_lines + ON acc_transactions_lines.id_transaction = acc_transactions.id + INNER JOIN acc_accounts + ON acc_transactions_lines.id_account = acc_accounts.id + WHERE + (strftime(%s, acc_transactions.date) = "%d" + AND + acc_accounts.%s + ) + + ORDER by %s, acc_accounts.id, acc_transactions.date + ', + '"%Y"', + $annee, + $db->where('id', 'in', $comptesIsoles), $tri ); return $db->get($sql); @@ -184,8 +309,6 @@ class Utils ON acc_transactions_lines.id_transaction = acc_transactions.id WHERE ( strftime(%s, acc_transactions.date) = "%d" - AND - acc_transactions_lines.credit > 0 AND acc_transactions_users.id_transaction = acc_transactions.id AND @@ -199,7 +322,6 @@ class Utils '"%Y"', $annee ); - // error_log("getDonateurs = " . print_r($sql, true)); $donateurs = array(); foreach (DB::getInstance()->iterate($sql) as $personne) { @@ -239,121 +361,6 @@ class Utils return $tri; } - /** OBSOLETE - * 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, $champsNom) - { - $tri = Utils::combinerTri($champsNom); - $sql = sprintf( - 'SELECT - membres.id as idUser, - sum(acc_transactions_lines.credit) AS versement - FROM - acc_transactions_users, - membres, - acc_transactions - INNER JOIN acc_transactions_lines - ON acc_transactions_lines.id_transaction = acc_transactions.id - WHERE ( - strftime(%s, acc_transactions.date) = "%d" - AND - acc_transactions_lines.credit > 0 - AND - acc_transactions_users.id_transaction = acc_transactions.id - AND - acc_transactions_users.id_user = membres.id - ) - GROUP by acc_transactions_users.id_user - ORDER by %s COLLATE U_NOCASE', - '"%Y"', - $annee, - $tri); - return DB::getInstance()->get($sql); - } - - public static function getDonateurs_old($annee, $champsNom) : array - { - // concaténer les champs nom/prénoms pour la sélection - $nom = 'trim(' . Utils::combinerChamps($champsNom) . ') as nom,'; - // et pour le tri - $tri = Utils::combinerTri($champsNom); - $sql = - "SELECT - membres.id as idUser, - " . - $nom . " - membres.adresse as adresse, - membres.code_postal as codePostal, - membres.ville as ville - FROM - acc_transactions_users, - membres, - acc_transactions - INNER JOIN acc_transactions_lines - ON acc_transactions_lines.id_transaction = acc_transactions.id - WHERE ( - strftime('%Y', acc_transactions.date) = ? - AND - acc_transactions_lines.credit > 0 - AND - acc_transactions_users.id_transaction = acc_transactions.id - AND - acc_transactions_users.id_user = membres.id - ) - GROUP by membres.id - ORDER by " . $tri . " COLLATE U_NOCASE - "; - $donateurs = array(); - foreach (DB::getInstance()->iterate($sql, $annee) as $personne) - { - $donateurs[$personne->idUser] = new Personne($personne->idUser, - $personne->nom, - $personne->adresse, - $personne->codePostal, - $personne->ville); - } - return $donateurs; - } - - public static function getLignesReduction($lesTaux) - { - foreach ($lesTaux as $elem) - { - $lignes[$elem->taux] = $elem->remarque; - } - return $lignes; - } - - public static function getLigneReduction($taux) - { - return $_SESSION['ligneReduction'][$taux]; - } - - /** - * @return liste de toutes les activités, tarifs et comptes associés - */ - public static function getActivitesTarifsEtComptes() - { - return DB::getInstance()->get( - "SELECT - services.id as idActivite, - services.label as titreActivite, - services.description as descActivite, - services_fees.id as idTarif, - services_fees.label as titreTarif, - services_fees.description as descTarif, - acc_accounts.code as numeroCpt, - acc_accounts.label as nomCpt - FROM services - LEFT JOIN services_fees ON services_fees.id_service = services.id - LEFT JOIN acc_accounts ON services_fees.id_account = acc_accounts.id - ORDER BY services.label" - ); - } - /** * @return liste des années fiscales */ @@ -371,11 +378,25 @@ class Utils return $anneesFiscales; } + public static function getLignesReduction($lesTaux) + { + foreach ($lesTaux as $elem) + { + $lignes[$elem->taux] = $elem->remarque; + } + return $lignes; + } + + public static function getLigneReduction($taux) + { + return $_SESSION['ligneReduction'][$taux]; + } + /** * récupérer dans la config du plugin les champs des membres * utilisés pour le nom et le prénom ; ajouter/supprimer les * modifications par rapport à la config garradin - * @return tableau des champs : clé = nom, valeur = { titre, position } + * @return array tableau des champs : clé = nom, valeur = { titre, position } */ public static function getChampsNom($config, $plugin) : array { diff --git a/templates/index.tpl b/templates/index.tpl index 4292f15..abd3ba6 100644 --- a/templates/index.tpl +++ b/templates/index.tpl @@ -1,67 +1,55 @@ {include file="%s/templates/_nav.tpl"|args:$plugin_root current_nav="index"} -
-

Choisir une méthode de génération des reçus

+

Sélectionner les versements pour les reçus

{* Choisir une des méthodes *} -
+
- {* Toutes les personnes *} -