From 057357a58d59834b5d580249c38f1e9646f2c6cb Mon Sep 17 00:00:00 2001 From: engel <> Date: Sat, 19 Feb 2022 19:06:22 +0000 Subject: [PATCH] =?UTF-8?q?g=C3=A9n=C3=A9ration=20pdf=20depuis=20html?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FossilOrigin-Name: ae0bb1a96a743b32009fb9198051568278f05a15148ca6141c9576b6956929ec --- lib/HtmlPDF.php | 217 ++++++++++++++++++++++++++++++++ www/admin/generer_activites.php | 16 +-- www/admin/generer_personnes.php | 22 ++-- 3 files changed, 232 insertions(+), 23 deletions(-) create mode 100644 lib/HtmlPDF.php diff --git a/lib/HtmlPDF.php b/lib/HtmlPDF.php new file mode 100644 index 0000000..ffdf87c --- /dev/null +++ b/lib/HtmlPDF.php @@ -0,0 +1,217 @@ +nomAsso = $nomAsso; + $this->adresseAsso = $adresseAsso; + $this->objetAsso = $objetAsso; + $this->logoCerfa = $logo; + $this->signature = $signature; + $this->html = $this->debut(); + } + + function get() + { + return $this->html; + } + + // Header + function 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 le reçu + function imprimer_recu($annee_recu, + $numero, + $nom, + $lesMontants, + $adresse, + $code_postal, + $ville) + { + // Numéro de reçu + $this->html .= " +
Reçu numéro {$annee_recu}/{$numero}

+
+"; + // Donateur + $this->html .= " +
+

Donateur

+

{$nom}

+

{$adresse}

+

{$code_postal} {$ville}

+
+"; + + $this->html .= " +
+

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

+
+ +"; + + $this->html .= " +
+

Date des versements : année {$annee_recu}

+

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

+

Forme du don : Autre

+

Nature du don : Numéraire

+

Mode de versement : chèque et/ou virement

+
+"; + + // cartouche final + $date = date("j/m/Y"); +$this->html .= " +
+

Rennes le {$date}

+
+signature\" /> +"; +/* + $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); + */ + $this->fin(); + } + + // 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 = "") + { + $valeur = number_format($montant, 2, ',', ''); + $this->html .= " +
  • {$texte} {$valeur} euros +"; + if ($libelle != "") { + $this->html .= " + : {$libelle} +"; + } +$this->html .= " +
  • +"; + } + + 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); + } + + protected function debut() + { + ob_start(); + echo << + + + + {$this->nomAsso} + + + +

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

    +

    Bénéficiaire des versements

    +

    Association « {$this->nomAsso} »

    +

    {$this->adresseAsso}

    +

    Objet : {$this->objetAsso}

    +FDD; + return ob_get_clean(); + } + + protected function fin() + { + $this->html .= +' + + +'; + } +} // class RecusPDF diff --git a/www/admin/generer_activites.php b/www/admin/generer_activites.php index 5249958..72c5b03 100644 --- a/www/admin/generer_activites.php +++ b/www/admin/generer_activites.php @@ -2,7 +2,7 @@ namespace Garradin; -use Garradin\Plugin\RecusFiscaux\RecusPDF; +use Garradin\Plugin\RecusFiscaux\HtmlPDF; use Garradin\Plugin\RecusFiscaux\Utils; use Garradin\Plugin\RecusFiscaux\Personne; @@ -31,11 +31,10 @@ $listeFichiers = []; foreach ($totalPersonnes as $idPersonne => $personne) { // générer un fichier par reçu - $pdf = new RecusPDF( - 'DejaVu', - 'SerifCondensed', + $pdf = new HtmlPDF( $nomAsso, $adresseAsso, + $plugin->getConfig('objet_asso'), $logoCERFA, $signature ); @@ -59,13 +58,8 @@ foreach ($totalPersonnes as $idPersonne => $personne) { $personne->codePostal, $personne->ville ); - // fabriquer le nom du fichier PDF - $nom = str_replace(' ', '_', $personne->nomPrenom); - $nom = str_replace("'", "", $nom); - // $nomFichier = Utils::getPDFDirectory() . "/" . 'recu_' . $annee_recu . '_' . $nom . '.pdf'; - $nomFichier = PLUGIN_ROOT . '/pdf/recu_' . $_SESSION['annee_recu'] . '_' . $nom . '.pdf'; - - $pdf->Output('F', $nomFichier); + // fabriquer le fichier PDF + $nomFichier = \Garradin\Utils::filePDF($pdf->get()); // ajouter le nom du fichier à la liste pour mettre dans une archive $listeFichiers[] = $nomFichier; } diff --git a/www/admin/generer_personnes.php b/www/admin/generer_personnes.php index 696410d..424ab08 100644 --- a/www/admin/generer_personnes.php +++ b/www/admin/generer_personnes.php @@ -2,7 +2,7 @@ namespace Garradin; -use Garradin\Plugin\RecusFiscaux\RecusPDF; +use Garradin\Plugin\RecusFiscaux\HtmlPDF; use Garradin\Plugin\RecusFiscaux\Utils; use Garradin\Plugin\RecusFiscaux\Personne; @@ -23,16 +23,17 @@ $logoCERFA = PLUGIN_ROOT . "/data/logoCerfa.png"; $signature = PLUGIN_ROOT . "/data/default_signature.png"; $listeFichiers = []; -foreach ($versementsSelectionnes as $ligne) { +foreach ($versementsSelectionnes as $ligne) +{ // générer un fichier par reçu - $pdf = new RecusPDF( - 'DejaVu', - 'SerifCondensed', + $pdf = new HtmlPDF( $nomAsso, $adresseAsso, + $plugin->getConfig('objet_asso'), $logoCERFA, $signature ); + // extraire les montants des versements $lesMontants[$_SESSION['taux_reduction']] = $ligne->versement/100; $pdf->imprimer_recu( @@ -44,19 +45,16 @@ foreach ($versementsSelectionnes as $ligne) { $_SESSION['membresDonateurs'][$ligne->idUser]->codePostal, $_SESSION['membresDonateurs'][$ligne->idUser]->ville ); - // fabriquer le nom du fichier PDF - $nom = str_replace(' ', '_', $_SESSION['membresDonateurs'][$ligne->idUser]->nomPrenom); - $nom = str_replace("'", "", $nom); - // $nomFichier = Utils::getPDFDirectory() . "/" . 'recu_' . $annee_recu . '_' . $nom . '.pdf'; - $nomFichier = PLUGIN_ROOT . '/pdf/recu_' . $_SESSION['annee_recu'] . '_' . $nom . '.pdf'; - - $pdf->Output('F', $nomFichier); + // fabriquer le fichier PDF + $nomFichier = \Garradin\Utils::filePDF($pdf->get()); // ajouter le nom du fichier à la liste pour mettre dans une archive $listeFichiers[] = $nomFichier; } + // faire une archive zip $fichierZip = Utils::makeArchive( $listeFichiers, $_SESSION['annee_recu'], PLUGIN_ROOT . "/zip" ); +