test génération reçu html avec template

FossilOrigin-Name: 1070052b9c2d7df2121a02c7ad2b9653459d96e66bf58ad02ef88712e45e16e0
This commit is contained in:
engel 2022-03-10 17:12:42 +00:00
parent 5074876f0a
commit 7c197abbc8
2 changed files with 258 additions and 22 deletions

67
templates/recuHTML.tpl Normal file
View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
{*
<link rel="stylesheet" type="text/css" href="{$styleSheet}" media="print" />
<link rel="stylesheet" type="text/css" href="{plugin_url file=$styleSheet}?{$version_hash}" media="print" />
*}
<style type="text/css">
{ajouter_style}
</style>
</head>
<body>
<div class="cartouche" id="entete">
<div id="logoCerfa">
<span class="centre">Cerfa</span>
</div>
<div id="numCerfa">
<span>N° 11580*4</span>
</div>
<p id="titre">Reçu au titre des dons à certains organismes d'intérêt général</p>
<p id="articles">Articles 200, 238 bis et 978 du code général des impôts</p>
<div id="numRecu">
<p class="important">Reçu numéro {$anneeRecu}/{$numero}</p>
</div>
</div>
<div class="cartouche" id="beneficiaire">
<h3 class="rubrique">Bénéficiaire des versements</h3>
<p class="important">Association « {$nomAsso} »</p>
<p class="important">{$adresseAsso}</p>
<p><span class="titre">Objet : </span><span class="libelle">{$objetAsso}</span></p>
</div>
<div class="cartouche" id="donateur">
<h3 class="rubrique">Donateur</h3>
<p>{$nom}</p>
<p>{$adresse}</p>
<p>{$codePostal} {$ville}</p>
</div>
<div class="cartouche" id="versements">
<p>Le bénéficiaire reconnaît avoir reçu au titre des dons et versements ouvrant droit à réduction
d'impôt :</p>
<ul>
{foreach from=$lesMontants key=taux item=montant}
{imprimer_montant montant=$montant taux=$taux}
{/foreach}
</ul>
<p><span class="titre">Date des versements : </span><span class="libelle">année {$anneeRecu}</span></p>
<p><span class="titre">Nature du don : </span><span class="libelle">Numéraire</span></p>
<p><span class="titre">Mode de versement : </span><span class="libelle">chèque et/ou virement</span></p>
{imprimer_articles articles=$articlesCGI}
</div>
<div class="cartouche" id="final">
<?php $date = date("j/m/Y"); ?>
<p>Rennes le {$date}</p>
<img id="signature" src="{$signature}" />
<p id="nom">{$nomResponsable}</p>
<p id="fonction">{$fonctionResponsable}</p>
</div>
</body>
</html>

View File

@ -15,13 +15,16 @@ foreach ($lesLignes as $ligne) {
$versementsSelectionnes[] = $_SESSION['lesVersementsTotaux'][$ligne];
}
// générer les reçus
// informations de l'association
$nomAsso = Utils::getNomAsso();
$adresseAsso = Utils::getAdresseAsso();
$signature =
(null !== $plugin->getConfig('signature')) ?
\Garradin\Files\Files::get($plugin->getConfig('signature'))->fullpath() :
"";
$objetAsso = $plugin->getConfig('objet_asso');
$nomResponsable = $plugin->getConfig('nom_responsable');
$fonctionResponsable = $plugin->getConfig('fonction_responsable');
// articles du CGI
$articlesCGI = array();
@ -31,34 +34,199 @@ foreach ($plugin->getConfig('articlesCGI') as $article)
$articlesCGI[] = $article->titre;
}
}
/**
* insérer une feuille de style
*/
$tpl->register_function('ajouter_style', function()
{
$out = '
@page
{
size: A4 portrait;
margin: 1cm;
}
body
{
font-family: Serif;
font-size: 11pt;
background-color: white;
}
#logoCerfa
{
line-height: 40px;
width: 100px;
background-color: rgb(0, 0, 128);
border-radius : 50%;
text-align : center;
margin : 2mm;
}
.centre
{
display : inline-block;
vertical-align : middle;
line-height: 20px; /* moitié de la hauteur du logo */
color : white;
font-weight: bold;
font-size : 14pt;
}
#numCerfa
{
width: 100px; /* largeur du logo */
text-align: center;
}
#titre
{
margin : 0 4cm 0 4cm;
text-align : center;
font-size : 14pt;
font-weight: bold;
}
#articles
{
margin : 0 4cm 0 4cm; /* idem titre */
text-align : center;
}
#numRecu
{
text-align : right;
}
#final
{
height : 5cm;
}
.rubrique
{
background-color : rgb(200, 200, 250);
padding : 2mm;
}
.cartouche
{
margin : 2mm auto;
padding : 0 2mm;
border : 1px solid rgb(0, 0, 128);
border-radius : 8px;
}
.titre, .important
{
font-weight:bold;
}
#signature
{
display: block;
max-width : 7cm;
max-height : 2cm;
margin: 0 auto;
padding-bottom : 2mm;
}
#fonction, #nom
{
text-align : center;
}
';
return $out;
});
/**
* imprimer un montant et le taux de réduction associé
* @param montant
* @param taux
*/
$tpl->register_function('imprimer_montant', function ($params)
{
$montant = $params['montant'];
$taux = $params['taux'];
$valeur = number_format($montant, 2, ',', '');
$libelle = Utils::getLigneReduction($taux);
$out = sprintf('
<li>la somme de <b>%s euros</b>',
$valeur);
if ($libelle != "") {
$out .= sprintf(' (%s)', $libelle);
}
$out .= '
</li>
';
return $out;
});
/**
* imprimer les articles du code général des impôts concernés
* @param articles
*/
$tpl->register_function('imprimer_articles', function ($params)
{
$articlesCGI = $params['articles'];
$nbArticles = count($articlesCGI);
$out = "<p>Le bénéficiaire certifie sur lhonneur que les dons et versements quil reçoit ouvrent droit à la réduction d'impôt prévue";
if ($nbArticles == 1)
{
$out .= sprintf(' à larticle %s du code général des impôts</p>', articlesCGI[0]);
}
else if ($nbArticles > 1)
{
$out .= " aux articles ";
for ($i = 0; $i < $nbArticles; ++$i) {
$out .= sprintf("%s", $articlesCGI[$i]);
if ($i < $nbArticles - 2) {
$out .= ", ";
}
else if ($i == $nbArticles - 2) {
$out .= " et ";
}
}
$out .= " du code général des impôts.</p>";
}
return $out;
});
$listeFichiers = array(); // fichiers pdf générés
foreach ($versementsSelectionnes as $ligne)
{
// générer un fichier par reçu
$html = new RecusHTML(
$nomAsso,
$adresseAsso,
$plugin->getConfig('objet_asso'),
$plugin->getConfig('nom_responsable'),
$plugin->getConfig('fonction_responsable'),
$articlesCGI,
$signature
);
//$ligne = $versementsSelectionnes[0];
// extraire les montants des versements
$lesMontants[$_SESSION['taux_reduction']] = $ligne->versement/100;
$personne = $_SESSION['membresDonateurs'][$ligne->idUser];
$html->imprimer_recu(
$_SESSION['annee_recu'],
$personne->id,
$personne->nomPrenom,
$lesMontants,
$personne->adresse,
$personne->codePostal,
$personne->ville
);
$tpl->assign(compact('nomAsso',
'adresseAsso',
'objetAsso',
'nomResponsable',
'fonctionResponsable',
'articlesCGI',
'signature'
));
$tpl->assign('anneeRecu', $_SESSION['annee_recu']);
$tpl->assign('numero', $personne->id);
$tpl->assign('nom', $personne->nomPrenom);
$tpl->assign('lesMontants', $lesMontants);
$tpl->assign('adresse', $personne->adresse);
$tpl->assign('codePostal', $personne->codePostal);
$tpl->assign('ville', $personne->ville);
$tpl->assign('styleSheet', 'pdf.css');
// $tpl->assign('styleSheet', \Garradin\PLUGIN_URL . 'pdf.css');
//$tpl->assign('plugin_css', ['pdf.css']);
ob_start();
$tpl->display(PLUGIN_ROOT . '/templates/recuHTML.tpl');
$html = ob_get_clean();
// fabriquer le fichier PDF
$nomPDF = \Garradin\Utils::filePDF($html->get());
$nomPDF = \Garradin\Utils::filePDF($html);
// changer le nom du fichier
$nom = str_replace(' ', '_', $personne->nomPrenom);
$nom = str_replace("'", "", $nom);
@ -66,6 +234,7 @@ foreach ($versementsSelectionnes as $ligne)
rename($nomPDF, $nomFichier);
// ajouter le nom du fichier à la liste pour mettre dans une archive
$listeFichiers[] = $nomFichier;
}
// faire une archive zip