diff --git a/lib/RecusHTML.php b/lib/RecusHTML.php deleted file mode 100644 index 13e0ba9..0000000 --- a/lib/RecusHTML.php +++ /dev/null @@ -1,259 +0,0 @@ -nomAsso = $nomAsso; - $this->adresseAsso = $adresseAsso; - $this->objetAsso = $objetAsso; - $this->nomResponsable = $nomResponsable; - $this->fonctionResponsable = $fonctionResponsable; - $this->signature = $signature; - $this->articlesCGI = $articlesCGI; - $this->html = $this->entete(); - } - - function get() - { - return $this->html; - } - - // imprimer le reçu - function imprimer_recu($annee_recu, - $numero, - $nom, - $lesMontants, - $adresse, - $code_postal, - $ville) - { - ob_start(); -echo << -

Reçu numéro {$annee_recu}/{$numero}

- - -
-

Bénéficiaire des versements

-

Association « {$this->nomAsso} »

-

{$this->adresseAsso}

-

Objet : {$this->objetAsso}

-
- -
-

Donateur

-

{$nom}

-

{$adresse}

-

{$code_postal} {$ville}

-
- -
-

Le bénéficiaire reconnaît avoir reçu au titre des dons et versements ouvrant droit à réduction d'impôt :

- \n"; - $this->imprimer_description("Date des versements :", - "année {$annee_recu}"); - $this->imprimer_description("Nature du don : ", - "Numéraire"); - $this->imprimer_description("Mode de versement : ", - "chèque et/ou virement"); - - // articles du CGI - $nbArticles = count($this->articlesCGI); - if ($nbArticles == 1) - { - echo "

Le bénéficiaire certifie sur l’honneur que les dons et versements qu’il reçoit ouvrent droit à la réduction d'impôt prévue à l’article "; - printf("%s du code général des impôts

\n", $this->articlesCGI[0]); - } - else if ($nbArticles > 1) - { - echo "

Le bénéficiaire certifie sur l’honneur que les dons et versements qu’il reçoit ouvrent droit à la réduction d'impôt prévue aux articles "; - for ($i = 0; $i < $nbArticles; ++$i) { - printf("%s", $this->articlesCGI[$i]); - if ($i < $nbArticles - 2) { - echo ", "; - } - else if ($i == $nbArticles - 2) { - echo " et "; - } - } - echo " du code général des impôts

\n"; - } - echo "
\n"; - - // cartouche final - $date = date("j/m/Y"); -echo << -

Rennes le {$date}

- -

$this->nomResponsable

-

$this->fonctionResponsable

- - - -FDD; - $this->html .= ob_get_clean(); - } - - // imprimer un libellé précédé de son titre en gras - function imprimer_description($titre, $libelle) - { - echo <<{$titre} {$libelle}

- -FDD; - } - - // imprimer le montant du versement et un libellé - function imprimer_montant($montant, $libelle = "") - { - $valeur = number_format($montant, 2, ',', ''); - echo "
  • la somme de {$valeur} euros"; - if ($libelle != "") { - echo " ({$libelle})"; - } - echo "
  • \n"; - } - - protected function entete() - { -// $styleSheet = \Garradin\PLUGIN_ROOT . "/lib/pdf.css"; -// error_log("pdf.css = " . $styleSheet); - ob_start(); -echo << - - - - - - -
    -
    - Cerfa -
    -
    - N° 11580*4 -
    -

    Reçu au titre des dons à certains organismes d'intérêt général

    -

    Articles 200, 238 bis et 978 du code général des impôts

    - -FDD; - return ob_get_clean(); - } -} diff --git a/lib/RecusPDF.php b/lib/RecusPDF.php deleted file mode 100644 index 9891cc2..0000000 --- a/lib/RecusPDF.php +++ /dev/null @@ -1,196 +0,0 @@ -AddFont($family, - '', - $family.$style.".ttf", - true); - // bold - $this->AddFont($family, - 'B', - $family.$style."-Bold.ttf", - true); - $this->nomAsso = $nomAsso; - $this->adresseAsso = $adresseAsso; - $this->logoCerfa = $logo; - $this->signature = $signature; - } - - // Header - function Header() - { - parent::Header(); - // Logo - $this->Image($this->logoCerfa, 10, 6, 30); - - // document title - $this->SetTextColor(0, 0, 0); - $this->SetFont('DejaVu','B',12); - $titre = "Reçu au titre des dons à certains organismes d'intérêt général"; - $this->SetXY(50, 10); - // Titre - $this->MultiCell(100, - 6, - $titre, - 0, - 'C'); - - // numéro de Cerfa - $cerfa = "N° 11580*3"; - $this->SetFont('DejaVu', 'B', 10); - $this->SetXY(10, 25); - $this->Cell(100, 0, $cerfa); - - // Articles - $this->SetFont('DejaVu', '', 9); - $this->SetXY(50, 25); - $this->Cell(100, 0, 'Article 200, 238 bis et 885-0 V bis A du code général des impôts'); - } - - // imprimer les informations du bénéficiaire - function imprimer_beneficiaire($nom, $adresse) - { - $this->titre_rubrique("Bénéficiaire des versements"); - $this->SetFont('DejaVu', 'B', 11); - $this->Cell(0, 6, 'Association « ' . $nom . ' »', 'LR', 1); - $this->Cell(0, 6, str_replace(array("\r\n", "\n", "\r"), " ", $adresse), 'LR', 1); - $this->imprimer_description("Objet : ", - "célébrer le culte protestant évangélique et pourvoir aux frais et besoins de ce culte."); - $this->Cell(0, 6, "", 'LRB', 1); - } - - // imprimer un libellé précédé de son titre en gras - function imprimer_description($titre, $libelle) - { - $this->SetFont('DejaVu', 'B', 11); - $this->Cell($this->GetStringWidth($titre), 6, $titre, 'L', 0); - $this->SetFont('DejaVu', '', 11); - $this->Cell(0, 6, $libelle, 'R', 1); - } - - // imprimer le montant de la réduction et un libellé - function imprimer_montant($texte, $montant, $libelle = "") - { - $this->SetFont('DejaVu'); - $this->Cell($this->GetStringWidth($texte), - 6, - $texte, - 'L', - 0); - $this->SetFont('DejaVu','B'); - $valeur = number_format($montant, 2, "," , "") . " euros"; - $this->Cell($this->GetStringWidth($valeur), - 6, - $valeur, - '', - 0); - $this->SetFont('DejaVu'); - if ($libelle != "") - { - $this->Cell(0, - 6, - " : " . $libelle, - 'R', - 1); - } - else - { - $this->Cell(0, 6, "", 'R', 1); - } - } - - function titre_rubrique($texte) - { - $this->SetFont('DejaVu','B',12); - $largeur_texte = $this->GetStringWidth($texte); - $this->setX(10); - $this->SetFillColor(0, 255, 255); - $this->Cell(0, 6, $texte, 'LTR', 1, 'C', true); - $this->Cell(0, 6, "", 'LR', 1); - } - - // imprimer le reçu - function imprimer_recu($annee_recu, - $numero, - $nom, - $lesMontants, - $adresse, - $code_postal, - $ville) - { - - $this->AddPage(); - // Numéro de reçu - $this->SetFont('DejaVu', 'B', 11); - $this->MultiCell(0, 20, 'Reçu numéro ' . $annee_recu . '/' . $numero); - - // bénéficiaire - $this->imprimer_beneficiaire($this->nomAsso, $this->adresseAsso); - - // donateur - $this->Ln(10); - $this->titre_rubrique("Donateur"); - $this->SetFont('DejaVu', 'B', 11); - $this->Cell(0, 6, $nom, 'LR', 1); - $this->Cell(0, 6, $adresse, 'LR', 1); - $this->Cell(0, 6, $code_postal . " " . $ville, 'LR', 1); - $this->Cell(0, 6, "", 'LRB', 1); - - // Montant et autres informations - $this->Ln(10); - $this->SetFont('DejaVu', '', 11); - $this->Cell(0, - 6, - "Le bénéficiaire reconnaît avoir reçu au titre des dons et versements ouvrant droit à réduction d'impôt :", - 'LTR', - 1); - foreach ($lesMontants as $taux => $montant) - { - $this->imprimer_montant(" - la somme de ", $montant, Utils::getLigneReduction($taux)); - } - $this->Cell(0, 3, "", 'LR', 1); - $this->imprimer_description('Date des versements : ', - 'année ' . $annee_recu); - $this->Cell(0, 3, "", 'LR', 1); - $this->MultiCell(0, 6, - "Le bénéficiaire certifie sur l’honneur que les dons et versements qu’il reçoit ouvrent droit à la réduction -d'impôt prévue à l’article 200 du CGI", - 'LR'); - $this->Cell(0, 3, "", 'LR', 1); - $this->imprimer_description("Forme du don : ", "Autre"); - $this->Cell(0, 3, "", 'LR', 1); - $this->imprimer_description("Nature du don : ", "Numéraire"); - $this->Cell(0, 3, "", 'LR', 1); - $this->imprimer_description("Mode de versement : ", "chèque et/ou virement"); - $this->Cell(0, 0, "", 'LRB', 1); - - // cartouche final - $this->Ln(10); - $this->Cell(0, 6, "", 'LRT', 1); - $this->Cell(0, 6, "Rennes le " . date("j/m/Y"), 'LR', 1, 'R'); - $this->Cell(0, 36, "", 'LR', 1); - $this->Cell(0, 0, "", 'LBR', 1); - $this->SetXY(100, 220); - $this->Image($this->signature, null, null, 50); - } -} // class RecusPDF diff --git a/templates/recuHTML.tpl b/templates/recuHTML.tpl new file mode 100644 index 0000000..39cc87e --- /dev/null +++ b/templates/recuHTML.tpl @@ -0,0 +1,67 @@ + + + + + +{* + + +*} + + + + +
    +
    + Cerfa +
    +
    + N° 11580*4 +
    +

    Reçu au titre des dons à certains organismes d'intérêt général

    +

    Articles 200, 238 bis et 978 du code général des impôts

    +
    +

    Reçu numéro {$anneeRecu}/{$numero}

    +
    +
    + +
    +

    Bénéficiaire des versements

    +

    Association « {$nomAsso} »

    +

    {$adresseAsso}

    +

    Objet : {$objetAsso}

    +
    + +
    +

    Donateur

    +

    {$nom}

    +

    {$adresse}

    +

    {$codePostal} {$ville}

    +
    + +
    +

    Le bénéficiaire reconnaît avoir reçu au titre des dons et versements ouvrant droit à réduction + d'impôt :

    +
      + {foreach from=$lesMontants key=taux item=montant} + {imprimer_montant montant=$montant taux=$taux} + {/foreach} +
    +

    Date des versements : année {$anneeRecu}

    +

    Nature du don : Numéraire

    +

    Mode de versement : chèque et/ou virement

    + {imprimer_articles articles=$articlesCGI} +
    + +
    + +

    Rennes le {$date}

    + +

    {$nomResponsable}

    +

    {$fonctionResponsable}

    +
    + + + \ No newline at end of file diff --git a/uninstall.php b/uninstall.php index 5f8bdeb..86e35bf 100644 --- a/uninstall.php +++ b/uninstall.php @@ -18,3 +18,4 @@ if (null !== $signature) { $sig_file->delete(); } } +unset($_SESSION['sig_file']); diff --git a/www/admin/generer_activites.php b/www/admin/generer_activites.php index ea42398..6a290b6 100644 --- a/www/admin/generer_activites.php +++ b/www/admin/generer_activites.php @@ -17,13 +17,16 @@ foreach ($lesLignes as $ligne) { // cumuler les versements d'une personne $totalPersonnes = cumulerVersements($versementsSelectionnes); -// 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(); @@ -33,19 +36,168 @@ 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(' +
  • la somme de %s euros', + $valeur); + if ($libelle != "") { + $out .= sprintf(' (%s)', $libelle); + } + $out .= ' +
  • +'; + 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 = "

    Le bénéficiaire certifie sur l’honneur que les dons et versements qu’il reçoit ouvrent droit à la réduction d'impôt prévue"; + if ($nbArticles == 1) + { + $out .= sprintf(' à l’article %s du code général des impôts

    ', 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.

    "; + } + return $out; +}); + $listeFichiers = array(); // fichiers pdf générés foreach ($totalPersonnes as $idPersonne => $personne) { - // 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 - ); // extraire les montants des versements $lesMontants = array(); foreach ($personne->versements as $versement) @@ -57,17 +209,30 @@ foreach ($totalPersonnes as $idPersonne => $personne) $lesMontants[$versement->tauxReduction] = $versement->montant; } } - $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'); + + 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); diff --git a/www/admin/generer_personnes.php b/www/admin/generer_personnes.php index 524d3d1..7f07c23 100644 --- a/www/admin/generer_personnes.php +++ b/www/admin/generer_personnes.php @@ -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,198 @@ 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(' +
  • la somme de %s euros', + $valeur); + if ($libelle != "") { + $out .= sprintf(' (%s)', $libelle); + } + $out .= ' +
  • +'; + 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 = "

    Le bénéficiaire certifie sur l’honneur que les dons et versements qu’il reçoit ouvrent droit à la réduction d'impôt prévue"; + if ($nbArticles == 1) + { + $out .= sprintf(' à l’article %s du code général des impôts

    ', 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.

    "; + } + 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 - ); - // 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);