2022-01-29 15:03:41 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Garradin;
|
|
|
|
|
|
2022-03-24 19:00:39 +01:00
|
|
|
|
use Garradin\Files\Files;
|
|
|
|
|
use Garradin\Entities\Files\File;
|
2022-03-31 21:55:30 +02:00
|
|
|
|
use Garradin\UserTemplate\UserTemplate;
|
2022-03-24 19:00:39 +01:00
|
|
|
|
|
2022-01-29 15:03:41 +01:00
|
|
|
|
use Garradin\Plugin\RecusFiscaux\Utils;
|
|
|
|
|
use Garradin\Plugin\RecusFiscaux\Personne;
|
|
|
|
|
|
2022-03-31 21:55:30 +02:00
|
|
|
|
// signature
|
2022-02-25 13:23:30 +01:00
|
|
|
|
$signature =
|
2022-03-25 10:08:46 +01:00
|
|
|
|
(null !== $plugin->getConfig('signature')) ?
|
|
|
|
|
Files::get($plugin->getConfig('signature'))->fullpath() :
|
2022-03-04 11:11:00 +01:00
|
|
|
|
"";
|
2022-02-25 13:23:30 +01:00
|
|
|
|
|
2022-03-23 11:00:37 +01:00
|
|
|
|
// logo
|
2022-03-24 19:00:39 +01:00
|
|
|
|
$logo_file = Files::get(File::CONTEXT_CONFIG . '/logo.png');
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$logo_asso =
|
2022-03-25 10:08:46 +01:00
|
|
|
|
(null !== $logo_file) ?
|
|
|
|
|
Files::get($logo_file->path)->fullpath() :
|
2022-03-24 19:00:39 +01:00
|
|
|
|
"";
|
2022-03-23 11:00:37 +01:00
|
|
|
|
|
2022-02-25 15:51:48 +01:00
|
|
|
|
// articles du CGI
|
|
|
|
|
$articlesCGI = array();
|
|
|
|
|
foreach ($plugin->getConfig('articlesCGI') as $article)
|
|
|
|
|
{
|
|
|
|
|
if ($article->valeur == 1) {
|
|
|
|
|
$articlesCGI[] = $article->titre;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$nbArticles = count($articlesCGI);
|
|
|
|
|
if ($nbArticles == 1)
|
|
|
|
|
{
|
|
|
|
|
$texteArticles = 'à l’article ' . $articlesCGI[0];
|
|
|
|
|
}
|
|
|
|
|
elseif ($nbArticles > 1)
|
|
|
|
|
{
|
|
|
|
|
$texteArticles = 'aux articles ';
|
|
|
|
|
for ($i = 0; $i < $nbArticles; ++$i) {
|
|
|
|
|
$texteArticles .= $articlesCGI[$i];
|
|
|
|
|
if ($i < $nbArticles - 2) {
|
|
|
|
|
$texteArticles .= ", ";
|
|
|
|
|
}
|
|
|
|
|
else if ($i == $nbArticles - 2) {
|
|
|
|
|
$texteArticles .= " et ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 12:29:48 +02:00
|
|
|
|
// libellés pour les taux de réduction
|
|
|
|
|
$libelles_taux = Utils::getLignesReduction($plugin->getConfig('reduction'));
|
|
|
|
|
|
2022-03-31 21:55:30 +02:00
|
|
|
|
// filtrer les versements sélectionnés
|
|
|
|
|
$lesLignes = f('selected');
|
|
|
|
|
$versementsSelectionnes = array();
|
|
|
|
|
foreach ($lesLignes as $ligne) {
|
|
|
|
|
$versementsSelectionnes[] = $_SESSION['lesVersements'][$ligne];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// cumuler les versements
|
|
|
|
|
if ($_GET['type'] == 'personne')
|
|
|
|
|
{
|
|
|
|
|
$totalPersonnes = cumulerVersementsPersonne($versementsSelectionnes);
|
|
|
|
|
}
|
|
|
|
|
elseif ($_GET['type'] == 'activite')
|
|
|
|
|
{
|
|
|
|
|
$totalPersonnes = cumulerVersementsTarif($versementsSelectionnes);
|
|
|
|
|
}
|
2022-03-24 19:00:39 +01:00
|
|
|
|
|
2022-03-31 11:10:24 +02:00
|
|
|
|
// générer les reçus
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$listeFichiersPDF = array();
|
2022-07-13 10:13:19 +02:00
|
|
|
|
$fmt = new \NumberFormatter('fr_FR', \NumberFormatter::SPELLOUT);
|
2022-02-22 10:47:54 +01:00
|
|
|
|
foreach ($totalPersonnes as $idPersonne => $personne)
|
|
|
|
|
{
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$tpl = new UserTemplate();
|
|
|
|
|
$tpl->setSource(PLUGIN_ROOT . '/templates/recu.skel');
|
2022-03-25 16:09:55 +01:00
|
|
|
|
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$tpl->assignArray(compact('signature', 'logo_asso', 'texteArticles'));
|
|
|
|
|
$tpl->assign('objet_asso', $plugin->getConfig('objet_asso'));
|
|
|
|
|
$tpl->assign('nom_responsable', $plugin->getConfig('nom_responsable'));
|
|
|
|
|
$tpl->assign('fonction_responsable', $plugin->getConfig('fonction_responsable'));
|
|
|
|
|
$tpl->assign('ville_asso', $plugin->getConfig('ville_asso'));
|
|
|
|
|
$tpl->assign('annee_recu', $_SESSION['annee_recu']);
|
|
|
|
|
$tpl->assign('numero', $personne->id);
|
|
|
|
|
$tpl->assign('nom', $personne->nomPrenom);
|
|
|
|
|
$tpl->assign('adresse', $personne->adresse);
|
|
|
|
|
$tpl->assign('code_postal', $personne->codePostal);
|
|
|
|
|
$tpl->assign('ville', $personne->ville);
|
|
|
|
|
$tpl->assign('date', date("j/m/Y"));
|
|
|
|
|
|
|
|
|
|
// les versements
|
|
|
|
|
$tpl->registerSection('versements',
|
2022-07-13 10:13:19 +02:00
|
|
|
|
function () use($personne, $libelles_taux, $fmt)
|
2022-03-31 21:55:30 +02:00
|
|
|
|
{
|
2022-05-20 21:43:38 +02:00
|
|
|
|
foreach ($personne->versements as $taux => $versement)
|
2022-03-31 21:55:30 +02:00
|
|
|
|
{
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$ligne['montant'] = $versement->montant;
|
2022-07-13 10:13:19 +02:00
|
|
|
|
$ligne['euros'] = $fmt->format((int)($versement->montant/100));
|
|
|
|
|
if ($versement->montant % 100 != 0) {
|
|
|
|
|
$ligne['cents'] = $fmt->format($versement->montant % 100);
|
|
|
|
|
} else {
|
|
|
|
|
$ligne['cents'] = "";
|
|
|
|
|
}
|
2022-05-18 12:29:48 +02:00
|
|
|
|
$ligne['libelle'] = $libelles_taux[$taux];
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$ligne['dateMin'] = date("d/m/Y", $versement->dateMin);
|
|
|
|
|
$ligne['dateMax'] = date("d/m/Y", $versement->dateMax);
|
2022-03-31 21:55:30 +02:00
|
|
|
|
yield $ligne;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// mentions complémentaires
|
|
|
|
|
$donnees = array(
|
|
|
|
|
'Nature du don : ' => "Numéraire",
|
|
|
|
|
'Mode de versement : ' => "chèque et/ou virement"
|
2022-01-29 15:03:41 +01:00
|
|
|
|
);
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$infos = array();
|
|
|
|
|
foreach ($donnees as $titre => $libelle)
|
|
|
|
|
{
|
|
|
|
|
$elem = new \stdClass();
|
|
|
|
|
$elem->titre = $titre;
|
|
|
|
|
$elem->libelle = $libelle;
|
|
|
|
|
$infos[] = $elem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tpl->registerSection('informations',
|
|
|
|
|
function () use ($infos)
|
|
|
|
|
{
|
|
|
|
|
foreach ($infos as $elem)
|
|
|
|
|
{
|
|
|
|
|
yield (array) $elem;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2022-02-19 20:06:22 +01:00
|
|
|
|
// fabriquer le fichier PDF
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$result = $tpl->fetch();
|
|
|
|
|
$nomPDF = \Garradin\Utils::filePDF($result);
|
2022-02-22 10:47:54 +01:00
|
|
|
|
// changer le nom du fichier
|
|
|
|
|
$nom = str_replace(' ', '_', $personne->nomPrenom);
|
|
|
|
|
$nom = str_replace("'", "", $nom);
|
2022-05-17 10:41:55 +02:00
|
|
|
|
$nomFichier = sprintf('%s/recu_%s_%s.pdf',
|
|
|
|
|
dirname($nomPDF),
|
|
|
|
|
$_SESSION['annee_recu'],
|
|
|
|
|
$nom);
|
2022-02-22 10:47:54 +01:00
|
|
|
|
rename($nomPDF, $nomFichier);
|
2022-01-29 15:03:41 +01:00
|
|
|
|
// ajouter le nom du fichier à la liste pour mettre dans une archive
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$listeFichiersPDF[] = $nomFichier;
|
2022-01-29 15:03:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// faire une archive zip
|
|
|
|
|
$fichierZip = Utils::makeArchive(
|
2022-03-31 21:55:30 +02:00
|
|
|
|
$listeFichiersPDF,
|
2022-01-29 15:03:41 +01:00
|
|
|
|
$_SESSION['annee_recu'],
|
|
|
|
|
PLUGIN_ROOT . "/zip"
|
|
|
|
|
);
|
|
|
|
|
|
2022-05-17 10:41:55 +02:00
|
|
|
|
//supprimer les fichiers pdf (utile ?)
|
|
|
|
|
// foreach ($listeFichiersPDF as $f)
|
|
|
|
|
// {
|
|
|
|
|
// unlink($f);
|
|
|
|
|
// }
|
|
|
|
|
|
2022-03-31 11:10:24 +02:00
|
|
|
|
/**
|
|
|
|
|
* Cumuler les versements de chaque personne
|
|
|
|
|
* @param tableau des versements triés par idUser, date
|
|
|
|
|
* @return tableau des versements cumulés : id => Personne
|
|
|
|
|
*/
|
|
|
|
|
function cumulerVersementsPersonne($versements)
|
|
|
|
|
{
|
|
|
|
|
$totalPersonnes = array();
|
|
|
|
|
$idPersonneCourant = -1;
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$dateMin = PHP_INT_MAX;
|
|
|
|
|
$dateMax = -1;
|
2022-03-31 11:10:24 +02:00
|
|
|
|
$totalVersements = 0;
|
|
|
|
|
foreach ($versements as $ligne)
|
|
|
|
|
{
|
|
|
|
|
if ($ligne->idUser != $idPersonneCourant)
|
|
|
|
|
{
|
|
|
|
|
// changement de personne
|
|
|
|
|
if ($idPersonneCourant != -1)
|
|
|
|
|
{
|
|
|
|
|
$totalPersonnes[$idPersonneCourant]->ajouterVersement(
|
|
|
|
|
$_SESSION['taux_reduction'],
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$totalVersements,
|
|
|
|
|
$dateMin,
|
|
|
|
|
$dateMax
|
2022-03-31 11:10:24 +02:00
|
|
|
|
);
|
|
|
|
|
}
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$dateMin = strtotime($ligne->date);
|
|
|
|
|
$dateMax = strtotime($ligne->date);
|
2022-03-31 11:10:24 +02:00
|
|
|
|
$idPersonneCourant = $ligne->idUser;
|
|
|
|
|
$totalVersements = $ligne->versement;
|
|
|
|
|
// créer les infos de la personne, sauf si elle est déjà présente
|
|
|
|
|
if (!array_key_exists($idPersonneCourant, $totalPersonnes))
|
|
|
|
|
{
|
|
|
|
|
$totalPersonnes["$idPersonneCourant"] = $_SESSION['membresDonateurs'][$ligne->idUser]->clone();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-05-20 21:43:38 +02:00
|
|
|
|
// même personne : cumuler versements et mettre à jour les dates
|
2022-03-31 11:10:24 +02:00
|
|
|
|
$totalVersements += $ligne->versement;
|
2022-05-20 21:43:38 +02:00
|
|
|
|
if (strtotime($ligne->date) < $dateMin) { $dateMin = strtotime($ligne->date); }
|
|
|
|
|
if (strtotime($ligne->date) > $dateMax) { $dateMax = strtotime($ligne->date); }
|
2022-03-31 11:10:24 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// et le dernier
|
|
|
|
|
$totalPersonnes[$idPersonneCourant]->ajouterVersement(
|
|
|
|
|
$_SESSION['taux_reduction'],
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$totalVersements,
|
|
|
|
|
$dateMin,
|
|
|
|
|
$dateMax
|
2022-03-31 11:10:24 +02:00
|
|
|
|
);
|
|
|
|
|
return $totalPersonnes;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 15:03:41 +01:00
|
|
|
|
/**
|
2022-02-10 17:05:24 +01:00
|
|
|
|
* Cumuler les versements de chaque personne par tarif
|
2022-02-17 10:21:33 +01:00
|
|
|
|
* @param tableau des versements triés par idTarif, idUser, date
|
|
|
|
|
* @return tableau des versements cumulés : id => Personne
|
2022-01-29 15:03:41 +01:00
|
|
|
|
*/
|
2022-03-31 11:10:24 +02:00
|
|
|
|
function cumulerVersementsTarif($versements)
|
2022-01-29 15:03:41 +01:00
|
|
|
|
{
|
|
|
|
|
$totalPersonnes = array();
|
2022-03-24 19:00:39 +01:00
|
|
|
|
$idTarifCourant = -1;
|
|
|
|
|
$idPersonneCourant = -1;
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$idCompteCourant = -1;
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$dateMin = PHP_INT_MAX;
|
|
|
|
|
$dateMax = -1;
|
2022-01-29 15:03:41 +01:00
|
|
|
|
$totalVersements = 0;
|
2022-02-18 12:51:13 +01:00
|
|
|
|
foreach ($versements as $ligne)
|
|
|
|
|
{
|
2022-01-29 15:03:41 +01:00
|
|
|
|
if (
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$ligne->idTarif != $idTarifCourant ||
|
|
|
|
|
$ligne->idUser != $idPersonneCourant ||
|
|
|
|
|
$ligne->idCompte != $idCompteCourant
|
2022-02-18 12:51:13 +01:00
|
|
|
|
)
|
|
|
|
|
{
|
2022-03-25 16:09:55 +01:00
|
|
|
|
if ($idTarifCourant != -1)
|
|
|
|
|
{
|
2022-05-20 21:43:38 +02:00
|
|
|
|
// changement de tarif, de personne ou de compte
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$tarifCompte = ($idTarifCourant == 0) ?
|
|
|
|
|
$idCompteCourant :
|
|
|
|
|
$idTarifCourant . "_" . $idCompteCourant;
|
2022-03-24 19:00:39 +01:00
|
|
|
|
$totalPersonnes[$idPersonneCourant]->ajouterVersement(
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$_SESSION['tauxSelectionnes'][$tarifCompte],
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$totalVersements,
|
|
|
|
|
$dateMin,
|
|
|
|
|
$dateMax
|
2022-01-29 15:03:41 +01:00
|
|
|
|
);
|
|
|
|
|
}
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$dateMin = strtotime($ligne->date);
|
|
|
|
|
$dateMax = strtotime($ligne->date);
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$idTarifCourant = $ligne->idTarif;
|
2022-03-24 19:00:39 +01:00
|
|
|
|
$idPersonneCourant = $ligne->idUser;
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$idCompteCourant = $ligne->idCompte;
|
|
|
|
|
$totalVersements = $ligne->versement;
|
2022-01-29 15:03:41 +01:00
|
|
|
|
// créer les infos de la personne, sauf si elle est déjà présente
|
2022-03-24 19:00:39 +01:00
|
|
|
|
if (!array_key_exists($idPersonneCourant, $totalPersonnes))
|
2022-02-10 17:05:24 +01:00
|
|
|
|
{
|
2022-03-25 11:27:03 +01:00
|
|
|
|
$totalPersonnes["$idPersonneCourant"] = $_SESSION['membresDonateurs'][$ligne->idUser]->clone();
|
2022-01-29 15:03:41 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-05-20 21:43:38 +02:00
|
|
|
|
// même personne : cumuler versements et mettre à jour les dates
|
2022-01-29 15:03:41 +01:00
|
|
|
|
$totalVersements += $ligne->versement;
|
2022-05-20 21:43:38 +02:00
|
|
|
|
if (strtotime($ligne->date) < $dateMin) { $dateMin = strtotime($ligne->date); }
|
|
|
|
|
if (strtotime($ligne->date) > $dateMax) { $dateMax = strtotime($ligne->date); }
|
2022-01-29 15:03:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// et le dernier
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$tarifCompte = ($idTarifCourant == 0) ?
|
|
|
|
|
$idCompteCourant :
|
|
|
|
|
$idTarifCourant . "_" . $idCompteCourant;
|
2022-03-24 19:00:39 +01:00
|
|
|
|
$totalPersonnes[$idPersonneCourant]->ajouterVersement(
|
2022-05-18 21:38:59 +02:00
|
|
|
|
$_SESSION['tauxSelectionnes'][$tarifCompte],
|
2022-05-20 21:43:38 +02:00
|
|
|
|
$totalVersements,
|
|
|
|
|
$dateMin,
|
|
|
|
|
$dateMax
|
2022-02-18 12:51:13 +01:00
|
|
|
|
);
|
2022-01-29 15:03:41 +01:00
|
|
|
|
return $totalPersonnes;
|
|
|
|
|
}
|