facturation/www/admin/generation.php

105 lines
3.1 KiB
PHP

<?php
namespace Garradin;
$session->requireAccess('compta', Membres::DROIT_ADMIN);
require_once PLUGIN_ROOT . '/lib/MPDF/vendor/autoload.php';
if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
throw new UserException("Le numéro du reçu fiscal est manquant.");
}
$id = (int) $_GET['id'];
$gendon = new Plugin\RecuDon\GenDon;
$recu = $gendon->get($id);
$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->gen_ordre);
$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."***"));
$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");