nouvelle version des structures de données

FossilOrigin-Name: ff5fc2aff4eab5aa2817d5b6183a5ab842bc701609fb255e97728a2a95e19c14
This commit is contained in:
engel 2022-02-10 16:05:24 +00:00
parent 2a7f5ad834
commit 341afe6a7b
9 changed files with 263 additions and 109 deletions

View File

@ -10,8 +10,8 @@ class Personne
public $id; public $id;
public $nomPrenom; public $nomPrenom;
public $adresse; public $adresse;
public $ville;
public $codePostal; public $codePostal;
public $ville;
public $courriel; public $courriel;
public $versements; // tableau des versements totaux par activité/tarif public $versements; // tableau des versements totaux par activité/tarif
@ -19,19 +19,31 @@ class Personne
$id, $id,
$nomPrenom, $nomPrenom,
$adresse, $adresse,
$ville,
$codePostal, $codePostal,
$courriel $ville,
$courriel = ""
) { ) {
$this->id = $id; $this->id = $id;
$this->nomPrenom = $nomPrenom; $this->nomPrenom = $nomPrenom;
$this->adresse = $adresse; $this->adresse = $adresse;
$this->ville = $ville;
$this->codePostal = $codePostal; $this->codePostal = $codePostal;
$this->ville = $ville;
$this->courriel = $courriel; $this->courriel = $courriel;
$this->versements = array(); $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 * ajouter un versement pour une activité et un tarif donnés
*/ */

View File

@ -135,8 +135,8 @@ class RecusPDF extends tFPDF
$nom, $nom,
$lesMontants, $lesMontants,
$adresse, $adresse,
$ville, $code_postal,
$code_postal) $ville)
{ {
$this->AddPage(); $this->AddPage();

View File

@ -7,10 +7,79 @@ use KD2\ZipWriter;
class Utils 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 * @return liste des activités
*/ */
public static function getActivites() public static function getToutesActivites()
{ {
return DB::getInstance()->get( return DB::getInstance()->get(
"SELECT "SELECT
@ -26,7 +95,7 @@ class Utils
* @return liste des tarifs d'une activité * @return liste des tarifs d'une activité
* @param $activite : identifiant de l'activité * @param $activite : identifiant de l'activité
*/ */
public static function getTarifs($activite) public static function getTarifsActivite($activite)
{ {
return DB::getInstance()->get( return DB::getInstance()->get(
"SELECT "SELECT

View File

@ -7,6 +7,7 @@ class Versement
public $idActivite; public $idActivite;
public $idTarif; public $idTarif;
public $montant; public $montant;
public $tauxReduction;
public function __construct( public function __construct(
$idActivite, $idActivite,

View File

@ -3,7 +3,6 @@
<h2>Liste des versements par activité et tarif</h2> <h2>Liste des versements par activité et tarif</h2>
{* TODO : vérifier le détail de ce div *}
<div class="year-header noprint"> <div class="year-header noprint">
<button type="button" data-icon="↓" class="icn-btn" id="open_details">Déplier toutes les activités</button> <button type="button" data-icon="↓" class="icn-btn" id="open_details">Déplier toutes les activités</button>
<button type="button" data-icon="↑" class="icn-btn" id="close_details">Replier toutes les activités</button> <button type="button" data-icon="↑" class="icn-btn" id="close_details">Replier toutes les activités</button>
@ -16,67 +15,46 @@
<label for="check_global">Cliquer pour cocher toutes les lignes</label> <label for="check_global">Cliquer pour cocher toutes les lignes</label>
</fieldset> </fieldset>
{* Itération sur les activités *} {* Itération sur les versements *}
{foreach from=$listeParActiviteEtTarif item="activite"} {foreach from=$lesVersements key="i" item="versement"}
{if $i == 0}
{* Itération sur les tarifs de l'activité *} {* premier versement *}
{foreach from=$activite->tarifs item="tarif"} <?php
$tarifCourant = $versement->idTarif;
<details open="open"> $personneCourante = $versement->idUser;
<summary class="activite"> ?>
<h3>Activité « {$activite->label} »</h3> {afficher_debut_tarif versement=$versement}
{if !empty($activite->description)} {afficher_debut_personne versement=$versement}
<h4>{$activite->description}</h4> {afficher_versement versement=$versement rang=$i}
{/if} {else}
<h4>tarif « {$tarif->titreTarif} », montant : {* autre versement *}
{if $tarif->montantTarif > 0}{$tarif->montantTarif|raw|money} {if $versement.idTarif != $tarifCourant}
{else}libre {* changement de tarif *}
{/if} </fieldset> {* fin versements d'une personne *}
</h4> </details>
</summary> <?php
$tarifCourant = $versement->idTarif;
{* $personneCourante = $versement->idUser;
Itération sur les versements d'un tarif d'une activité ?>
présentation : une table pour les versements d'une personne {afficher_debut_tarif versement=$versement}
*} {afficher_debut_personne versement=$versement}
<?php $currentUser = -1; $firstUser = true; ?> {afficher_versement versement=$versement rang=$i}
{foreach from=$lesVersements key="rang" item="versement"} {elseif $versement->idUser != $personneCourante}
{if $versement.idActivite == $activite->idActivite && {* changement de personne *}
$versement.idTarif == $tarif->idTarif} </fieldset>
{if $versement.idUser != $currentUser} <?php
{* changement de personne *} $personneCourante = $versement->idUser;
{if $firstUser} ?>
<?php $firstUser = false; ?> {afficher_debut_personne versement=$versement}
{else} {afficher_versement versement=$versement rang=$i}
{* fermer le tableau précédent *} {else}
</fieldset> {* même personne *}
{/if} {afficher_versement versement=$versement rang=$i}
{* Afficher les infos de la personne *} {/if}
<?php $idVersements = $versement->idTarif."_".$versement->idUser; ?> {/if}
<h3 class="personne">Versements de {$versement.nom} : <span id="total_{$idVersements}">0,00 €</span></h3> {/foreach} {* Itération sur les versements *}
<fieldset class="versements" id="versements_{$idVersements}"> </fieldset>
<input type="checkbox" class="check_{$idVersements}" id="check_{$idVersements}" </details>
onclick="cocherDecocherPersonne(check_{$idVersements}, total_{$idVersements})" />
<label for="check_{$idVersements}">Cliquer pour cocher toutes les lignes</label>
<br />
<hr>
<?php $currentUser = $versement->idUser; ?>
{/if}
{* afficher les infos du versement de la personne*}
<div {if $rang%2==0}class="pair" {else}class="impair" {/if}>
<input type="checkbox" class="check_{$idVersements}" id="check_{$idVersements}_{$rang}"
name="selected[]" value={$rang}
onclick="cocherDecocherVersement(check_{$idVersements}_{$rang}, total_{$idVersements})" />
<label for=check_{$idVersements}_{$rang}></label>
<span class="montant">{$versement.versement|raw|money}</span>
<span>{$versement.date|date_format:"%d/%m/%Y"}</span>
</div>
{/if}
{/foreach} {* Itération sur les versements *}
</fieldset>
</details>
{/foreach} {* Itération sur les tarifs de l'activité *}
{/foreach} {* Itération sur les activités *}
<input type="submit" value="Générer les reçus" onclick="return verifierChoix(this.form)"> <input type="submit" value="Générer les reçus" onclick="return verifierChoix(this.form)">
</form> </form>

View File

@ -17,8 +17,8 @@
<th>Nom Prénom</th> <th>Nom Prénom</th>
<th>Montant</th> <th>Montant</th>
<th>Adresse</th> <th>Adresse</th>
<th>Ville</th>
<th>Code postal</th> <th>Code postal</th>
<th>Ville</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -34,8 +34,8 @@
<td>{$versement.nom}</td> <td>{$versement.nom}</td>
<td class="montant">{$versement.montant|raw|money}</td> <td class="montant">{$versement.montant|raw|money}</td>
<td>{$versement.adresse}</td> <td>{$versement.adresse}</td>
<td>{$versement.ville}</td>
<td>{$versement.codePostal}</td> <td>{$versement.codePostal}</td>
<td>{$versement.ville}</td>
</tr> </tr>
{/foreach} {/foreach}
</tbody> </tbody>

View File

@ -14,7 +14,6 @@ $versementsSelectionnes = array();
foreach ($lesLignes as $indice => $ligne) { foreach ($lesLignes as $indice => $ligne) {
$versementsSelectionnes[] = $_SESSION['lesVersements'][$ligne]; $versementsSelectionnes[] = $_SESSION['lesVersements'][$ligne];
} }
// cumuler les versements d'une personne // cumuler les versements d'une personne
$totalPersonnes = cumulerVersements($versementsSelectionnes); $totalPersonnes = cumulerVersements($versementsSelectionnes);
@ -51,8 +50,8 @@ foreach ($totalPersonnes as $idPersonne => $personne) {
$personne->nomPrenom, $personne->nomPrenom,
$lesMontants, $lesMontants,
$personne->adresse, $personne->adresse,
$personne->ville, $personne->codePostal,
$personne->codePostal $personne->ville
); );
// fabriquer le nom du fichier PDF // fabriquer le nom du fichier PDF
$nom = str_replace(' ', '_', $personne->nomPrenom); $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 * @param tableau des versements
* @return tableau des versements cumulés * @return tableau des versements cumulés
*/ */
function cumulerVersements($versements) function cumulerVersements($versements)
{ {
$totalPersonnes = array(); $totalPersonnes = array();
$idActivite_courant = -1;
$idTarif_courant = -1; $idTarif_courant = -1;
$idPersonne_courant = -1; $idPersonne_courant = -1;
$totalVersements = 0; $totalVersements = 0;
foreach ($versements as $ligne) { foreach ($versements as $ligne) {
if ( if (
$ligne->idActivite != $idActivite_courant ||
$ligne->idTarif != $idTarif_courant || $ligne->idTarif != $idTarif_courant ||
$ligne->idUser != $idPersonne_courant $ligne->idUser != $idPersonne_courant
) { ) {
if ($idActivite_courant != -1) { if ($idTarif_courant != -1) {
$totalPersonnes["$idPersonne_courant"]->ajouterVersement( $totalPersonnes["$idPersonne_courant"]->ajouterVersement(
$idActivite_courant, $_SESSION['lesTarifs'][$idTarif_courant]->idActivite,
$idTarif_courant, $idTarif_courant,
$totalVersements/100 $totalVersements/100
); );
} }
$idActivite_courant = $ligne->idActivite;
$idTarif_courant = $ligne->idTarif; $idTarif_courant = $ligne->idTarif;
$idPersonne_courant = $ligne->idUser; $idPersonne_courant = $ligne->idUser;
$totalVersements = $ligne->versement; $totalVersements = $ligne->versement;
// créer les infos de la personne, sauf si elle est déjà présente // créer les infos de la personne, sauf si elle est déjà présente
if (!array_key_exists($idPersonne_courant, $totalPersonnes)) { if (!array_key_exists($idPersonne_courant, $totalPersonnes))
$totalPersonnes["$idPersonne_courant"] = new Personne( {
$ligne->idUser, $totalPersonnes["$idPersonne_courant"] =
$ligne->nom, Personne::copier($_SESSION['membresDonateurs'][$ligne->idUser]);
$ligne->adresse,
$ligne->ville,
$ligne->codePostal,
$ligne->courriel
);
} }
} else { } else {
// cumuler versements // cumuler versements
@ -119,7 +110,7 @@ function cumulerVersements($versements)
} }
// et le dernier // et le dernier
$totalPersonnes["$idPersonne_courant"]->ajouterVersement( $totalPersonnes["$idPersonne_courant"]->ajouterVersement(
$idActivite_courant, $_SESSION['lesTarifs'][$idTarif_courant]->idActivite,
$idTarif_courant, $idTarif_courant,
$totalVersements/100 $totalVersements/100
); );

View File

@ -45,8 +45,8 @@ foreach ($versementsSelectionnes as $idPersonne => $personne) {
$personne->nom, $personne->nom,
array($personne->montant/100), array($personne->montant/100),
$personne->adresse, $personne->adresse,
$personne->ville, $personne->codePostal,
$personne->codePostal $personne->ville
); );
// fabriquer le nom du fichier PDF // fabriquer le nom du fichier PDF
$nom = str_replace(' ', '_', $personne->nom); $nom = str_replace(' ', '_', $personne->nom);

View File

@ -2,41 +2,144 @@
namespace Garradin; namespace Garradin;
use Garradin\Plugin\RecusFiscaux\Activite;
use Garradin\Plugin\RecusFiscaux\Personne;
use Garradin\Plugin\RecusFiscaux\Tarif;
use Garradin\Plugin\RecusFiscaux\Utils; use Garradin\Plugin\RecusFiscaux\Utils;
// vérifier si l'année a bien été sélectionnée au préalable // vérifier si l'année a bien été sélectionnée au préalable
$_SESSION['annee_recu'] = f('annee_recu'); $_SESSION['annee_recu'] = f('annee_recu');
// error_log("va.php::annee_recu = (" .$_SESSION['annee_recu'] . ")");
if (! isset($_SESSION['annee_recu']) || $_SESSION['annee_recu'] == "") { if (! isset($_SESSION['annee_recu']) || $_SESSION['annee_recu'] == "") {
\Garradin\Utils::redirect(PLUGIN_URL . 'index.php'); \Garradin\Utils::redirect(PLUGIN_URL . 'index.php');
} }
// récupérer les infos du formulaire // récupérer les infos du formulaire
$lesTarifs = f('tarifs') ?: []; $tarifsSelectionnes = f('tarifs') ?: [];
// taux de réduction associés // taux de réduction associés
$lesTaux = array(); $tauxSelectionnes = array();
foreach ($lesTarifs as $idTarif) { foreach ($tarifsSelectionnes as $idTarif) {
$nomRadio = "taux_reduction_" . $idTarif; $nomRadio = "taux_reduction_" . $idTarif;
$valRadio = f("$nomRadio"); $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"); // obtenir les instances de tarifs correspondant à la sélection
// error_log("Réducs = " . print_r($lesTaux, true) . "\n"); $lesTarifs = array();
foreach (Utils::getTarifs($tarifsSelectionnes) as $ot) {
$lesTarifs[$ot->id] = Tarif::copier($ot);
}
$_SESSION['lesTarifs'] = $lesTarifs;
// liste des versements correspondants // activités correspondants aux tarifs sélectionnés
$_SESSION['lesVersements'] = Utils::getVersementsActivite($_SESSION['annee_recu'], $lesTarifs); $lesActivites = array();
foreach (Utils::getActivites($tarifsSelectionnes) as $activite) {
$lesActivites[$activite->id] = Activite::copier($activite);
}
$_SESSION['lesActivites'] = $lesActivites;
// liste des activités // versements correspondants aux tarifs sélectionnés
$activites = Utils::getActivites(); $_SESSION['lesVersements'] = Utils::getVersementsTarifs($_SESSION['annee_recu'], $tarifsSelectionnes);
foreach ($activites as $num => $activite)
// 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é $versement = $params['versement'];
$activite->{'tarifs'} = Utils::getTarifs($activite->{'idActivite'}); $idTarif = $versement->idTarif;
} $tarif = $_SESSION['lesTarifs'][$idTarif];
$idActivite = $tarif->idActivite;
$activite = $_SESSION['lesActivites'][$idActivite];
$out = '<details open="open">
<summary class="activite">';
$out .= sprintf('
<h3>Activité « %s »</h3>', $activite->label);
if (!empty($activite->description)) {
$out .= sprintf('
<h4>%s</h4>', $activite->description);
}
$out .= sprintf('
<h4>tarif « %s »', $tarif->label);
if ($tarif->montant > 0) {
$out .= sprintf(' montant : %.2f €', $tarif->montant/100);
} else {
$out .= ' montant : libre';
}
$out .= '</h4>
</summary>';
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('<h3 class="personne">Versements de %s : <span id="total_%s">0,00 €</span></h3>',
$personne->nomPrenom,
$idVersement);
$out .= sprintf('
<fieldset class="versements" id="versements_%s">',
$idVersement);
$out .= sprintf('
<input type="checkbox" class="check_%s" id="check_%s"',
$idVersement,
$idVersement);
$out .= sprintf(' onclick="cocherDecocherPersonne(check_%s, total_%s)" />',
$idVersement,
$idVersement);
$out .= sprintf('
<label for="check_%s">Cliquer pour cocher toutes les lignes</label>',
$idVersement);
$out .= '<br />
<hr>';
return $out;
});
// afficher un versement
$tpl->register_function('afficher_versement', function ($params)
{
$versement = $params['versement'];
$rang = $params['rang'];
$idVersement = $versement->idTarif . "_" . $versement->idUser;
$out = '<div class="';
$out .= ($rang%2==0) ? 'pair">' : 'impair">';
$out .= sprintf('
<input type="checkbox" class="check_%s" id="check_%s_%s"
name="selected[]" value="%s"
onclick="cocherDecocherVersement(check_%s_%s, total_%s)" />
<label for="check_%s_%s"></label>
<span class="montant">%.2f</span>
<span>%s</span>
</div>',
$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 // préparation de l'affichage
$tpl->assign('lesActivites', $lesActivites);
$tpl->assign('lesTarifs', $lesTarifs);
$tpl->assign('lesVersements', $_SESSION['lesVersements']); $tpl->assign('lesVersements', $_SESSION['lesVersements']);
$tpl->assign('listeParActiviteEtTarif', $activites);
$tpl->assign('plugin_css', ['style.css']); $tpl->assign('plugin_css', ['style.css']);
// envoyer au template // envoyer au template