requireAccess('compta', Membres::DROIT_ADMIN); require_once __DIR__ . '/_inc.php'; require_once PLUGIN_ROOT . '/lib/MPDF/vendor/autoload.php'; qv(['id' => 'required|numeric']); $id = (int) qg('id'); if (!$recu = $facture->get($id)) { throw new UserException("Ce document n'existe pas."); } $membres = new Membres; try { if ($recu->receveur_membre) { $c = $membres->get($recu->receveur_id); foreach(['ville','code_postal','adresse'] as $v) { if($c->$v == '') { $c->$v = '[A RENSEIGNER DANS LA FICHE MEMBRE]'; } } } else { $c = $client->get($recu->receveur_id); } } catch(UserException $e) { $form->addError("Pas de document correspondant à cet id trouvée."); } // Oui bon faut juste harmoniser les choses, quoi $recu->nom = $c->nom; $recu->prenom = $c->nom; $recu->adresse = $c->adresse; $recu->codepostal = $c->code_postal; $recu->ville = $c->ville; $recu->montant = $recu->total; $recu->date = $recu->date_emission; $recu->mode_paiement = $recu->moyen_paiement; $recu->gen_ordre = $recu->numero; // var_dump($recu->adresse); // die(); // Génération du PDF à partir du cerfa $pdf = new \Mpdf\Mpdf([ 'default_font_size' => 10, 'default_font' => 'Helvetica', ]); $pdf->AddPage(); $pdf->setSourceFile(PLUGIN_ROOT . '/data/11580-03.pdf'); $pdf->useTemplate( $pdf->importPage(1) ); $pdf->SetTextColor(0); $pdf->WriteText(180, 18, $recu->numero); $pdf->WriteText(20, 43, $config->get('nom_asso')); $pdf->WriteText(25, 54, utf8_decode($plugin->getConfig('numero_rue_asso'))); $pdf->WriteText(43, 54, utf8_decode($plugin->getConfig('rue_asso'))); $pdf->WriteText(39, 59, utf8_decode($plugin->getConfig('cp_asso'))); $pdf->WriteText(74, 59, utf8_decode($plugin->getConfig('ville_asso'))); $pdf->WriteText(20, 70, utf8_decode($plugin->getConfig('objet_0'))); $pdf->WriteText(20, 74, utf8_decode($plugin->getConfig('objet_1'))); $pdf->WriteText(20, 78, utf8_decode($plugin->getConfig('objet_2'))); $pdf->WriteText(19.9, 136, "X"); $pdf->AddPage(); $pdf->useTemplate( $pdf->importPage(2) ); $pdf->WriteText(22, 26, $recu->nom); $pdf->WriteText(110, 26, $recu->prenom); $pdf->WriteText(22, 39, utf8_decode($recu->adresse)); $pdf->WriteText(41, 45, $recu->codepostal); $pdf->WriteText(81, 45, utf8_decode($recu->ville)); $pdf->WriteText(90, 70, utf8_decode("***".$recu->montant."***")); // numfmt a l'air de patauger avec des valeurs < 1 $pdf->WriteText(62, 80, utf8_decode(numfmt_create('fr_FR', \NumberFormatter::SPELLOUT)->format($recu->montant)) . ' euros'); $date = date_parse($recu->date); $pdf->WriteText(73, 89.5, utf8_decode($date['day'])); $pdf->WriteText(84, 89.5, utf8_decode($date['month'])); $pdf->WriteText(100, 89.5, utf8_decode($date['year'])); if($plugin->getConfig('droit_art200')){ $pdf->WriteText(57.5, 103.5, "X"); } if($plugin->getConfig('droit_art238bis')){ $pdf->WriteText(107.6, 103.5, "X"); } if($plugin->getConfig('droit_art885-0VbisA')){ $pdf->WriteText(157.7, 103.5, "X"); } // Forme du don $pdf->WriteText(119.9, 121.2, "X"); // Nature du don $pdf->WriteText(20, 143.6, "X"); switch ($recu->mode_paiement){ case 0: $pdf->WriteText(19.9, 165.9, "X"); break; case 1: $pdf->WriteText(62, 165, "X"); break; case 2: $pdf->WriteText(119.7, 165, "X"); break; } // Date d'édition du document $pdf->WriteText(144.4, 246.2, date('d')); $pdf->WriteText(152.2, 246.2, date('m')); $pdf->WriteText(160, 246.2, date('Y')); // Signature $img = new Fichiers($plugin->getConfig('signaturetxt')); $cache_id = 'fichiers.' . $img->id_contenu; if (!Static_Cache::exists($cache_id)) { $blob = DB::getInstance()->openBlob('fichiers_contenu', 'contenu', (int)$img->id_contenu); Static_Cache::storeFromPointer($cache_id, $blob); fclose($blob); } $uri = Static_Cache::getPath($cache_id); $pdf->Image($uri, 150, 245, 32, 0, 'PNG' ); // Emplacement de la signature avec restriction de largeur pour tenir dans sur la case. $pdf->Output($recu->gen_ordre.".pdf", "I");