diff --git a/lib/Personne.php b/lib/Personne.php index 14a40d7..2497586 100644 --- a/lib/Personne.php +++ b/lib/Personne.php @@ -10,8 +10,8 @@ class Personne public $id; public $nomPrenom; public $adresse; - public $ville; public $codePostal; + public $ville; public $courriel; public $versements; // tableau des versements totaux par activité/tarif @@ -19,19 +19,31 @@ class Personne $id, $nomPrenom, $adresse, - $ville, $codePostal, - $courriel + $ville, + $courriel = "" ) { $this->id = $id; $this->nomPrenom = $nomPrenom; $this->adresse = $adresse; - $this->ville = $ville; $this->codePostal = $codePostal; + $this->ville = $ville; $this->courriel = $courriel; $this->versements = array(); } + public static function copier($p) + { + return new Personne( + $p->id, + $p->nomPrenom, + $p->adresse, + $p->codePostal, + $p->ville, + $p->courriel); + } + + /* * ajouter un versement pour une activité et un tarif donnés */ diff --git a/lib/RecusPDF.php b/lib/RecusPDF.php index bc4d70e..87d1f41 100644 --- a/lib/RecusPDF.php +++ b/lib/RecusPDF.php @@ -135,8 +135,8 @@ class RecusPDF extends tFPDF $nom, $lesMontants, $adresse, - $ville, - $code_postal) + $code_postal, + $ville) { $this->AddPage(); diff --git a/lib/Utils.php b/lib/Utils.php index d392ac7..5b2a348 100644 --- a/lib/Utils.php +++ b/lib/Utils.php @@ -7,10 +7,79 @@ use KD2\ZipWriter; class Utils { + // ------------------------------------------------------------ + // test nouvelle organisation + /** + * @return tarifs demandés + * @param array $tarifs + */ + public static function getTarifs($tarifs) + { + $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)); + return $db->get($sql); + } + + /** + * @return activités correspondant aux tarifs demandés + * @param array $tarifs + */ + public static function getActivites($tarifs) + { + $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); + } + + /** + * @return versements correspondants à l'année et aux tarifs donnés + * @param $annee + * @param array $tarifs + */ + public static function getVersementsTarifs($annee, $tarifs) + { + $db = DB::getInstance(); + $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, membres.id, acc_transactions.date', + '"%Y"', + $annee, + $db->where('id', $tarifs)); + return $db->get($sql); + } + + // ------------------------------------------------------------ + /** * @return liste des activités */ - public static function getActivites() + public static function getToutesActivites() { return DB::getInstance()->get( "SELECT @@ -26,7 +95,7 @@ class Utils * @return liste des tarifs d'une activité * @param $activite : identifiant de l'activité */ - public static function getTarifs($activite) + public static function getTarifsActivite($activite) { return DB::getInstance()->get( "SELECT diff --git a/lib/Versement.php b/lib/Versement.php index c5d0145..0a4a5bf 100644 --- a/lib/Versement.php +++ b/lib/Versement.php @@ -7,6 +7,7 @@ class Versement public $idActivite; public $idTarif; public $montant; + public $tauxReduction; public function __construct( $idActivite, diff --git a/templates/versements_activites.tpl b/templates/versements_activites.tpl index 3137e9c..36b8a26 100644 --- a/templates/versements_activites.tpl +++ b/templates/versements_activites.tpl @@ -3,7 +3,6 @@

Liste des versements par activité et tarif

-{* TODO : vérifier le détail de ce div *}
@@ -16,67 +15,46 @@ - {* Itération sur les activités *} - {foreach from=$listeParActiviteEtTarif item="activite"} - - {* Itération sur les tarifs de l'activité *} - {foreach from=$activite->tarifs item="tarif"} - -
- -

Activité « {$activite->label} »

- {if !empty($activite->description)} -

{$activite->description}

- {/if} -

tarif « {$tarif->titreTarif} », montant : - {if $tarif->montantTarif > 0}{$tarif->montantTarif|raw|money} - €{else}libre - {/if} -

-
- - {* - Itération sur les versements d'un tarif d'une activité - présentation : une table pour les versements d'une personne - *} - - {foreach from=$lesVersements key="rang" item="versement"} - {if $versement.idActivite == $activite->idActivite && - $versement.idTarif == $tarif->idTarif} - {if $versement.idUser != $currentUser} - {* changement de personne *} - {if $firstUser} - - {else} - {* fermer le tableau précédent *} - - {/if} - {* Afficher les infos de la personne *} - idTarif."_".$versement->idUser; ?> -

Versements de {$versement.nom} : 0,00 €

-
- - -
-
- idUser; ?> - {/if} - {* afficher les infos du versement de la personne*} -
- - - {$versement.versement|raw|money} - {$versement.date|date_format:"%d/%m/%Y"} -
- {/if} - {/foreach} {* Itération sur les versements *} -
-
- {/foreach} {* Itération sur les tarifs de l'activité *} - {/foreach} {* Itération sur les activités *} + {* Itération sur les versements *} + {foreach from=$lesVersements key="i" item="versement"} + {if $i == 0} + {* premier versement *} + idTarif; + $personneCourante = $versement->idUser; + ?> + {afficher_debut_tarif versement=$versement} + {afficher_debut_personne versement=$versement} + {afficher_versement versement=$versement rang=$i} + {else} + {* autre versement *} + {if $versement.idTarif != $tarifCourant} + {* changement de tarif *} + {* fin versements d'une personne *} + + idTarif; + $personneCourante = $versement->idUser; + ?> + {afficher_debut_tarif versement=$versement} + {afficher_debut_personne versement=$versement} + {afficher_versement versement=$versement rang=$i} + {elseif $versement->idUser != $personneCourante} + {* changement de personne *} + + idUser; + ?> + {afficher_debut_personne versement=$versement} + {afficher_versement versement=$versement rang=$i} + {else} + {* même personne *} + {afficher_versement versement=$versement rang=$i} + {/if} + {/if} + {/foreach} {* Itération sur les versements *} + + diff --git a/templates/versements_personnes.tpl b/templates/versements_personnes.tpl index 1feb389..fffcf07 100644 --- a/templates/versements_personnes.tpl +++ b/templates/versements_personnes.tpl @@ -17,8 +17,8 @@ Nom Prénom Montant Adresse - Ville Code postal + Ville @@ -34,8 +34,8 @@ {$versement.nom} {$versement.montant|raw|money} {$versement.adresse} - {$versement.ville} {$versement.codePostal} + {$versement.ville} {/foreach} diff --git a/www/admin/generer_activites.php b/www/admin/generer_activites.php index cd68d1d..80bb472 100644 --- a/www/admin/generer_activites.php +++ b/www/admin/generer_activites.php @@ -14,7 +14,6 @@ $versementsSelectionnes = array(); foreach ($lesLignes as $indice => $ligne) { $versementsSelectionnes[] = $_SESSION['lesVersements'][$ligne]; } - // cumuler les versements d'une personne $totalPersonnes = cumulerVersements($versementsSelectionnes); @@ -51,8 +50,8 @@ foreach ($totalPersonnes as $idPersonne => $personne) { $personne->nomPrenom, $lesMontants, $personne->adresse, - $personne->ville, - $personne->codePostal + $personne->codePostal, + $personne->ville ); // fabriquer le nom du fichier PDF $nom = str_replace(' ', '_', $personne->nomPrenom); @@ -73,44 +72,36 @@ $fichierZip = Utils::makeArchive( ); /** - * Cumuler les versements de chaque personne par tarif et activité + * Cumuler les versements de chaque personne par tarif * @param tableau des versements * @return tableau des versements cumulés */ function cumulerVersements($versements) { $totalPersonnes = array(); - $idActivite_courant = -1; $idTarif_courant = -1; $idPersonne_courant = -1; $totalVersements = 0; foreach ($versements as $ligne) { if ( - $ligne->idActivite != $idActivite_courant || $ligne->idTarif != $idTarif_courant || $ligne->idUser != $idPersonne_courant ) { - if ($idActivite_courant != -1) { + if ($idTarif_courant != -1) { $totalPersonnes["$idPersonne_courant"]->ajouterVersement( - $idActivite_courant, + $_SESSION['lesTarifs'][$idTarif_courant]->idActivite, $idTarif_courant, $totalVersements/100 ); } - $idActivite_courant = $ligne->idActivite; $idTarif_courant = $ligne->idTarif; $idPersonne_courant = $ligne->idUser; $totalVersements = $ligne->versement; // créer les infos de la personne, sauf si elle est déjà présente - if (!array_key_exists($idPersonne_courant, $totalPersonnes)) { - $totalPersonnes["$idPersonne_courant"] = new Personne( - $ligne->idUser, - $ligne->nom, - $ligne->adresse, - $ligne->ville, - $ligne->codePostal, - $ligne->courriel - ); + if (!array_key_exists($idPersonne_courant, $totalPersonnes)) + { + $totalPersonnes["$idPersonne_courant"] = + Personne::copier($_SESSION['membresDonateurs'][$ligne->idUser]); } } else { // cumuler versements @@ -119,7 +110,7 @@ function cumulerVersements($versements) } // et le dernier $totalPersonnes["$idPersonne_courant"]->ajouterVersement( - $idActivite_courant, + $_SESSION['lesTarifs'][$idTarif_courant]->idActivite, $idTarif_courant, $totalVersements/100 ); diff --git a/www/admin/generer_personnes.php b/www/admin/generer_personnes.php index 2086886..d153e8b 100644 --- a/www/admin/generer_personnes.php +++ b/www/admin/generer_personnes.php @@ -45,8 +45,8 @@ foreach ($versementsSelectionnes as $idPersonne => $personne) { $personne->nom, array($personne->montant/100), $personne->adresse, - $personne->ville, - $personne->codePostal + $personne->codePostal, + $personne->ville ); // fabriquer le nom du fichier PDF $nom = str_replace(' ', '_', $personne->nom); diff --git a/www/admin/versements_activites.php b/www/admin/versements_activites.php index c844b87..9d2a32f 100644 --- a/www/admin/versements_activites.php +++ b/www/admin/versements_activites.php @@ -2,41 +2,144 @@ namespace Garradin; +use Garradin\Plugin\RecusFiscaux\Activite; +use Garradin\Plugin\RecusFiscaux\Personne; +use Garradin\Plugin\RecusFiscaux\Tarif; use Garradin\Plugin\RecusFiscaux\Utils; // vérifier si l'année a bien été sélectionnée au préalable $_SESSION['annee_recu'] = f('annee_recu'); -// error_log("va.php::annee_recu = (" .$_SESSION['annee_recu'] . ")"); if (! isset($_SESSION['annee_recu']) || $_SESSION['annee_recu'] == "") { \Garradin\Utils::redirect(PLUGIN_URL . 'index.php'); } // récupérer les infos du formulaire -$lesTarifs = f('tarifs') ?: []; +$tarifsSelectionnes = f('tarifs') ?: []; // taux de réduction associés -$lesTaux = array(); -foreach ($lesTarifs as $idTarif) { +$tauxSelectionnes = array(); +foreach ($tarifsSelectionnes as $idTarif) { $nomRadio = "taux_reduction_" . $idTarif; $valRadio = f("$nomRadio"); - $lesTaux[] = $valRadio ? $valRadio: $plugin->getConfig()->reduction[0]->taux; + $tauxSelectionnes[] = $valRadio ? $valRadio: $plugin->getConfig()->reduction[0]->taux; } -// error_log("Tarifs = " . print_r($lesTarifs, true) . "\n"); -// error_log("Réducs = " . print_r($lesTaux, true) . "\n"); +// obtenir les instances de tarifs correspondant à la sélection +$lesTarifs = array(); +foreach (Utils::getTarifs($tarifsSelectionnes) as $ot) { + $lesTarifs[$ot->id] = Tarif::copier($ot); +} +$_SESSION['lesTarifs'] = $lesTarifs; -// liste des versements correspondants -$_SESSION['lesVersements'] = Utils::getVersementsActivite($_SESSION['annee_recu'], $lesTarifs); +// activités correspondants aux tarifs sélectionnés +$lesActivites = array(); +foreach (Utils::getActivites($tarifsSelectionnes) as $activite) { + $lesActivites[$activite->id] = Activite::copier($activite); +} +$_SESSION['lesActivites'] = $lesActivites; -// liste des activités -$activites = Utils::getActivites(); -foreach ($activites as $num => $activite) +// versements correspondants aux tarifs sélectionnés +$_SESSION['lesVersements'] = Utils::getVersementsTarifs($_SESSION['annee_recu'], $tarifsSelectionnes); + +// membres donateurs +$membresDonateurs = array(); +$versementsMembres = Utils::getVersementsTotaux($_SESSION['annee_recu']); +foreach ($versementsMembres as $versement) { + $membresDonateurs[$versement->idUser] = new Personne($versement->idUser, + $versement->nom, + $versement->adresse, + $versement->codePostal, + $versement->ville); +} +$_SESSION['membresDonateurs'] = $membresDonateurs; + +// ------------------------------------------------------------------------ +// fonctions pour l'affichage + +// afficher les informations d'une activité et d'un tarif +$tpl->register_function('afficher_debut_tarif', function ($params) { - // ajouter les tarifs de l'activité - $activite->{'tarifs'} = Utils::getTarifs($activite->{'idActivite'}); -} + $versement = $params['versement']; + $idTarif = $versement->idTarif; + $tarif = $_SESSION['lesTarifs'][$idTarif]; + $idActivite = $tarif->idActivite; + $activite = $_SESSION['lesActivites'][$idActivite]; + + $out = '
+ '; + $out .= sprintf(' +

Activité « %s »

', $activite->label); + if (!empty($activite->description)) { + $out .= sprintf(' +

%s

', $activite->description); + } + $out .= sprintf(' +

tarif « %s »', $tarif->label); + if ($tarif->montant > 0) { + $out .= sprintf(' montant : %.2f €', $tarif->montant/100); + } else { + $out .= ' montant : libre'; + } + $out .= '

+
'; + return $out; +}); + +// afficher les informations d'une personne +$tpl->register_function('afficher_debut_personne', function ($params) +{ + $versement = $params['versement']; + $idUser = $versement->idUser; + $personne = $_SESSION['membresDonateurs'][$idUser]; + $idVersement = $versement->idTarif . "_" . $versement->idUser; + $out = sprintf('

Versements de %s : 0,00 €

', + $personne->nomPrenom, + $idVersement); + $out .= sprintf(' +
', + $idVersement); + $out .= sprintf(' + ', + $idVersement, + $idVersement); + $out .= sprintf(' + ', + $idVersement); + $out .= '
+
'; + return $out; +}); + +// afficher un versement +$tpl->register_function('afficher_versement', function ($params) +{ + $versement = $params['versement']; + $rang = $params['rang']; + $idVersement = $versement->idTarif . "_" . $versement->idUser; + $out = '
' : 'impair">'; + $out .= sprintf(' + + + %.2f + %s +
', + $idVersement, $idVersement, + $rang, $rang, + $idVersement, $rang, $idVersement, $idVersement, $rang, + $versement->versement/100, + date_format(date_create($versement->date),"d/m/Y")); + return $out; +}); +// ------------------------------------------------------------------------ // préparation de l'affichage +$tpl->assign('lesActivites', $lesActivites); +$tpl->assign('lesTarifs', $lesTarifs); $tpl->assign('lesVersements', $_SESSION['lesVersements']); -$tpl->assign('listeParActiviteEtTarif', $activites); $tpl->assign('plugin_css', ['style.css']); // envoyer au template