diff --git a/lib/Personne.php b/lib/Personne.php index 31b4344..8037c1a 100644 --- a/lib/Personne.php +++ b/lib/Personne.php @@ -30,7 +30,7 @@ class Personne $this->adresse = $adresse; $this->codePostal = $codePostal; $this->ville = $ville; - $this->versements = array(); // clé = tarif, valeur = montant + $this->versements = array(); // clé = tarif, valeur = Versement } /** @@ -51,19 +51,24 @@ class Personne * ajouter un versement * @param $tauxReduction * @param $montant + * @param $dateMin + * @param $dateMax */ public function ajouterVersement( $tauxReduction, - $montant + $montant, + $dateMin, + $dateMax ) { if (array_key_exists($tauxReduction, $this->versements)) { - $this->versements[$tauxReduction] += $montant; + $this->versements[$tauxReduction]->ajouter($montant, $dateMin, $dateMax); } else { - $this->versements[$tauxReduction] = $montant; + $this->versements[$tauxReduction] = new Versement($montant, $dateMin, $dateMax); } } + } diff --git a/lib/Versement.php b/lib/Versement.php index 3ac3f07..e52f98c 100644 --- a/lib/Versement.php +++ b/lib/Versement.php @@ -4,21 +4,37 @@ namespace Garradin\Plugin\RecusFiscaux; class Versement { - public $idActivite; - public $idTarif; - public $montant; - public $tauxReduction; + public $montant; + public $dateMin; // estampille + public $dateMax; // estampille public function __construct( - $idActivite, - $idTarif, $montant, - $tauxReduction + $dateMin, + $dateMax ) { - $this->idActivite = $idActivite; - $this->idTarif = $idTarif; $this->montant = $montant; - $this->tauxReduction = $tauxReduction; + $this->dateMin = $dateMin; + $this->dateMax = $dateMax; } + + /** + * ajouter un versement en fixant les dates min et max + * @param $montant + * @param $dateMin + * @param $dateMax + */ + public function ajouter($montant, $dateMin, $dateMax) + { + $this->montant += $montant; + if ($dateMin < $this->dateMin) + { + $this->dateMin = $dateMin; + } + if ($dateMax > $this->dateMax) + { + $this->dateMax = $dateMax; + } + } } diff --git a/templates/recu.skel b/templates/recu.skel index 8638f19..fd203ef 100644 --- a/templates/recu.skel +++ b/templates/recu.skel @@ -117,7 +117,14 @@ {{if $libelle != ""}} ({{$libelle}}) {{/if}} +
date des versements : + {{if $dateMin == $dateMax}} + le {{$dateMin}} + {{else}} + du {{$dateMin}} au {{$dateMax}} + {{/if}} +
{{/versements}} diff --git a/www/admin/generer_recus.php b/www/admin/generer_recus.php index 760fd0b..9a852bf 100644 --- a/www/admin/generer_recus.php +++ b/www/admin/generer_recus.php @@ -93,17 +93,18 @@ foreach ($totalPersonnes as $idPersonne => $personne) $tpl->registerSection('versements', function () use($personne, $libelles_taux) { - foreach ($personne->versements as $taux => $montant) + foreach ($personne->versements as $taux => $versement) { - $ligne['montant'] = $montant; + $ligne['montant'] = $versement->montant; $ligne['libelle'] = $libelles_taux[$taux]; + $ligne['dateMin'] = date("d/m/Y", $versement->dateMin); + $ligne['dateMax'] = date("d/m/Y", $versement->dateMax); yield $ligne; } }); // mentions complémentaires $donnees = array( - 'Date des versements : ' => "année " . $_SESSION['annee_recu'], 'Nature du don : ' => "Numéraire", 'Mode de versement : ' => "chèque et/ou virement" ); @@ -162,6 +163,8 @@ function cumulerVersementsPersonne($versements) { $totalPersonnes = array(); $idPersonneCourant = -1; + $dateMin = PHP_INT_MAX; + $dateMax = -1; $totalVersements = 0; foreach ($versements as $ligne) { @@ -172,9 +175,13 @@ function cumulerVersementsPersonne($versements) { $totalPersonnes[$idPersonneCourant]->ajouterVersement( $_SESSION['taux_reduction'], - $totalVersements + $totalVersements, + $dateMin, + $dateMax ); } + $dateMin = strtotime($ligne->date); + $dateMax = strtotime($ligne->date); $idPersonneCourant = $ligne->idUser; $totalVersements = $ligne->versement; // créer les infos de la personne, sauf si elle est déjà présente @@ -183,14 +190,18 @@ function cumulerVersementsPersonne($versements) $totalPersonnes["$idPersonneCourant"] = $_SESSION['membresDonateurs'][$ligne->idUser]->clone(); } } else { - // cumuler versements + // même personne : cumuler versements et mettre à jour les dates $totalVersements += $ligne->versement; + if (strtotime($ligne->date) < $dateMin) { $dateMin = strtotime($ligne->date); } + if (strtotime($ligne->date) > $dateMax) { $dateMax = strtotime($ligne->date); } } } // et le dernier $totalPersonnes[$idPersonneCourant]->ajouterVersement( $_SESSION['taux_reduction'], - $totalVersements + $totalVersements, + $dateMin, + $dateMax ); return $totalPersonnes; } @@ -206,6 +217,8 @@ function cumulerVersementsTarif($versements) $idTarifCourant = -1; $idPersonneCourant = -1; $idCompteCourant = -1; + $dateMin = PHP_INT_MAX; + $dateMax = -1; $totalVersements = 0; foreach ($versements as $ligne) { @@ -217,15 +230,19 @@ function cumulerVersementsTarif($versements) { if ($idTarifCourant != -1) { - // changement de tarif ou de personne + // changement de tarif, de personne ou de compte $tarifCompte = ($idTarifCourant == 0) ? $idCompteCourant : $idTarifCourant . "_" . $idCompteCourant; $totalPersonnes[$idPersonneCourant]->ajouterVersement( $_SESSION['tauxSelectionnes'][$tarifCompte], - $totalVersements + $totalVersements, + $dateMin, + $dateMax ); } + $dateMin = strtotime($ligne->date); + $dateMax = strtotime($ligne->date); $idTarifCourant = $ligne->idTarif; $idPersonneCourant = $ligne->idUser; $idCompteCourant = $ligne->idCompte; @@ -236,8 +253,10 @@ function cumulerVersementsTarif($versements) $totalPersonnes["$idPersonneCourant"] = $_SESSION['membresDonateurs'][$ligne->idUser]->clone(); } } else { - // cumuler versements + // même personne : cumuler versements et mettre à jour les dates $totalVersements += $ligne->versement; + if (strtotime($ligne->date) < $dateMin) { $dateMin = strtotime($ligne->date); } + if (strtotime($ligne->date) > $dateMax) { $dateMax = strtotime($ligne->date); } } } // et le dernier @@ -246,7 +265,9 @@ function cumulerVersementsTarif($versements) $idTarifCourant . "_" . $idCompteCourant; $totalPersonnes[$idPersonneCourant]->ajouterVersement( $_SESSION['tauxSelectionnes'][$tarifCompte], - $totalVersements + $totalVersements, + $dateMin, + $dateMax ); return $totalPersonnes; }