Ajout génération cerfa dans facture_pdf

This commit is contained in:
Noizette 2020-10-24 08:35:00 +02:00
parent ba5096bfb2
commit e5ff2e8cd7
5 changed files with 161 additions and 201 deletions

View File

@ -42,9 +42,9 @@
<legend>Objet</legend> <legend>Objet</legend>
<dl> <dl>
<dt><label>L'objet (but) de l'association doit tenir sur 3 lignes, chaque ligne pouvant accueillir un maximum de 100 caractères.</label><b title="(Champ obligatoire)">obligatoire pour reçus fiscaux</b></dt> <dt><label>L'objet (but) de l'association doit tenir sur 3 lignes, chaque ligne pouvant accueillir un maximum de 100 caractères.</label><b title="(Champ obligatoire)">obligatoire pour reçus fiscaux</b></dt>
<dd><input type="text" maxlength=100 name="objet_0" value="{form_field data=$plugin.config name=objet_0}" /></dd> <dd><input type="text" maxlength=95 name="objet_0" value="{form_field data=$plugin.config name=objet_0}" /></dd>
<dd><input type="text" maxlength=100 name="objet_1" value="{form_field data=$plugin.config name=objet_1}" /></dd> <dd><input type="text" maxlength=95 name="objet_1" value="{form_field data=$plugin.config name=objet_1}" /></dd>
<dd><input type="text" maxlength=100 name="objet_2" value="{form_field data=$plugin.config name=objet_2}" /></dd> <dd><input type="text" maxlength=95 name="objet_2" value="{form_field data=$plugin.config name=objet_2}" /></dd>
</dl> </dl>
</fieldset> </fieldset>

View File

@ -12,10 +12,6 @@
<button type="button" class="btn btn-primary">Télécharger ce document</button></a> <button type="button" class="btn btn-primary">Télécharger ce document</button></a>
<div> <div>
{if $type < 2}
<embed src="facture_pdf.php?id={$id}" type="application/pdf" width="100%" height="800px;" style="max-width: 900px;"> <embed src="facture_pdf.php?id={$id}" type="application/pdf" width="100%" height="800px;" style="max-width: 900px;">
{else}
<embed src="generation.php?id={$id}" type="application/pdf" width="100%" height="800px;" style="max-width: 900px;">
{/if}
</div> </div>
{include file="admin/_foot.tpl"} {include file="admin/_foot.tpl"}

View File

@ -21,7 +21,21 @@
<tbody> <tbody>
{foreach from=$factures item=facture} {foreach from=$factures item=facture}
<tr> <tr>
<td>{if $facture.type_facture == 1}Facture{else}Devis{/if}</td> <td><?php switch($facture->type_facture) {
case 0:
echo 'Devis';
break;
case 1:
echo 'Facture';
break;
case 2:
echo 'Reçu fiscal';
break;
case 3:
echo 'Reçu cotisation';
break;
}
?></td>
<td><a href="{plugin_url file="facture.php"}?id={$facture.id}">{$facture.numero}</a></td> <td><a href="{plugin_url file="facture.php"}?id={$facture.id}">{$facture.numero}</a></td>
{if $facture.receveur_membre} {if $facture.receveur_membre}
<td><a href="{$admin_url}membres/fiche.php?id={$facture.receveur.id}">{$facture.receveur.nom}</a></td> <td><a href="{$admin_url}membres/fiche.php?id={$facture.receveur.id}">{$facture.receveur.nom}</a></td>
@ -32,8 +46,8 @@
<td>{$facture.receveur.ville}</td> <td>{$facture.receveur.ville}</td>
<td>{$facture.date_emission|date_fr:'d/m/Y'}</td> <td>{$facture.date_emission|date_fr:'d/m/Y'}</td>
<td>{$facture.date_echeance|date_fr:'d/m/Y'}</td> <td>{$facture.date_echeance|date_fr:'d/m/Y'}</td>
<td>{$facture.reglee}</td> <td><?= $facture->reglee?'Réglée':'Non' ?></td>
<td>{$facture.archivee}</td> <td><?= $facture->archivee?'Archivée':'Non' ?></td>
<td>{$facture.moyen_paiement}</td> <td>{$facture.moyen_paiement}</td>
<td> <td>
{foreach from=$facture.contenu item=contenu} {foreach from=$facture.contenu item=contenu}

View File

@ -12,9 +12,7 @@ $membres = new Membres;
qv(['id' => 'required|numeric']); qv(['id' => 'required|numeric']);
$id = (int) qg('id'); $id = (int) qg('id');
$f = $facture->get($id); if (!$f = $facture->get($id))
if (!$f)
{ {
throw new UserException("Ce document n'existe pas."); throw new UserException("Ce document n'existe pas.");
} }
@ -42,25 +40,30 @@ try
} }
catch(UserException $e) catch(UserException $e)
{ {
$form->addError("Pas de document correspondant à cet id trouvée."); $form->addError($e);
} }
// Création du PDF // Création du PDF
$pdf = new \Mpdf\Mpdf([ $pdf = new \Mpdf\Mpdf([
'default_font_size' => 10, 'default_font_size' => 10,
'default_font' => 'dejavusans', 'default_font' => 'dejavusans',
// 'tempDir' => PLUGINS_ROOT . '/mpdf-tmp/'
]); ]);
$pdf->SetAuthor($config->get('nom_asso')); $pdf->SetAuthor($config->get('nom_asso'));
ob_start();
$doc = ($f->type_facture?'Facture':'Devis').' n°'.$f->numero; // Génération factures et devis
$emission = date('d/m/Y' ,$f->date_emission);
$pdf->SetTitle($doc.' - '.$emission);
$asso = if ($f->type_facture < 2)
{
ob_start();
$doc = ($f->type_facture?'Facture':'Devis').' n°'.$f->numero;
$emission = date('d/m/Y' ,$f->date_emission);
$pdf->SetTitle($doc.' - '.$emission);
$asso =
// 'Émis par :<br><br>'. // 'Émis par :<br><br>'.
'<b>'.$config->get('nom_asso')."</b><br>". '<b>'.$config->get('nom_asso')."</b><br>".
str_replace("\n", '<br>', $config->get('adresse_asso'))."<br>". str_replace("\n", '<br>', $config->get('adresse_asso'))."<br>".
@ -69,7 +72,7 @@ $asso =
(($t = $config->get('email_asso'))?"Email : $t<br>":''). (($t = $config->get('email_asso'))?"Email : $t<br>":'').
(($t = $config->get('site_asso'))?"Site web : $t<br>":''); (($t = $config->get('site_asso'))?"Site web : $t<br>":'');
$receveur = $receveur =
'Adressé à :<br><br>'. 'Adressé à :<br><br>'.
'<b>'.$c->nom.'</b><br>'. '<b>'.$c->nom.'</b><br>'.
$c->adresse."<br>". $c->adresse."<br>".
@ -77,11 +80,11 @@ $receveur =
(($t = $c->email)?"Email : $t<br>":''). (($t = $c->email)?"Email : $t<br>":'').
(($t = $c->telephone)?"Tel : $t<br>":''); (($t = $c->telephone)?"Tel : $t<br>":'');
$total = number_format($f->total, 2, ',', ' '); $total = number_format($f->total, 2, ',', ' ');
$echeance = date('d/m/Y' ,$f->date_echeance); $echeance = date('d/m/Y' ,$f->date_echeance);
$echeance = ($f->type_facture?'Échéance de paiement':'Échéance du devis')." : ".$echeance; $echeance = ($f->type_facture?'Échéance de paiement':'Échéance du devis')." : ".$echeance;
$reglee = !$f->reglee?'Cette facture est en attente de règlement.':'Cette facture a été reglée.'; $reglee = !$f->reglee?'Cette facture est en attente de règlement.':'Cette facture a été reglée.';
$footer = str_replace("\n", '<br>', $plugin->getConfig('footer')); $footer = str_replace("\n", '<br>', $plugin->getConfig('footer'));
echo <<<EOF echo <<<EOF
@ -179,16 +182,16 @@ $doc - Émis le $emission
<tbody> <tbody>
EOF; EOF;
$i = 1; $i = 1;
foreach($f->contenu as $k=>$v) foreach($f->contenu as $k=>$v)
{ {
echo '<tr><td>'; echo '<tr><td>';
echo str_replace("\n", '<br>', $v['designation']); echo str_replace("\n", '<br>', $v['designation']);
echo '</td><td>'; echo '</td><td>';
echo number_format($v['prix'], 2, ',', ' ').'€'; echo number_format($v['prix'], 2, ',', ' ').'€';
echo '</td></tr>'; echo '</td></tr>';
$i++; $i++;
} }
echo <<<EOF echo <<<EOF
</tbody> </tbody>
@ -217,8 +220,104 @@ echo <<<EOF
EOF; EOF;
$html = ob_get_clean(); $html = ob_get_clean();
$pdf->WriteHTML($html); $pdf->WriteHTML($html);
} // End if facture+devis
elseif ($f->type_facture == 2)
{
// nom prénom ? pas de champs prénoms
// date d'émission = date du don
// date d'échéance = date d'édition du reçu
$pdf->AddPage();
$pdf->setSourceFile(PLUGIN_ROOT . '/data/11580-03.pdf');
$pdf->useTemplate(
$pdf->importPage(1)
);
$pdf->SetTextColor(0);
$pdf->WriteText(180, 18, $f->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(80, 26, $c->nom); // Nom + prénoms centrés ?
// $pdf->WriteText(22, 26, $c->nom); // Nom
// $pdf->WriteText(110, 26, $c->nom); // Prénoms
$pdf->WriteText(22, 39, $c->adresse);
$pdf->WriteText(41, 45, $c->code_postal);
$pdf->WriteText(81, 45, $c->ville);
$pdf->WriteText(90, 70, utf8_decode("***".$f->total."***"));
// numfmt a l'air de patauger avec des valeurs < 1
$pdf->WriteText(62, 80, utf8_decode(numfmt_create('fr_FR', \NumberFormatter::SPELLOUT)->format($f->total)) . ' euros');
$pdf->WriteText(73, 89.5, utf8_decode(strftime('%d', $f->date_emission)));
$pdf->WriteText(84, 89.5, utf8_decode(strftime('%m', $f->date_emission)));
$pdf->WriteText(100, 89.5, utf8_decode(strftime('%Y', $f->date_emission)));
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 ($f->moyen_paiement){
case 'ES':
$pdf->WriteText(19.9, 165.9, "X");
break;
case 'CH':
$pdf->WriteText(62.6, 165.9, "X");
break;
default:
$pdf->WriteText(119.9, 165.9, "X");
break;
}
// Date d'édition du document
$pdf->WriteText(144.4, 246.2, utf8_decode(strftime('%d', $f->date_echeance)));
$pdf->WriteText(152.2, 246.2, utf8_decode(strftime('%m', $f->date_echeance)));
$pdf->WriteText(160, 246.2, utf8_decode(strftime('%Y', $f->date_echeance)));
// 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.
} // End if cerfa
elseif ($f->type_facture == 3)
{
} // End if reçu cotis
if(qg('d') !== null) if(qg('d') !== null)
{ {
@ -228,6 +327,7 @@ else
{ {
$t = \Mpdf\Output\Destination::INLINE; $t = \Mpdf\Output\Destination::INLINE;
} }
$pdf->Output( $pdf->Output(
($f->type_facture?'Facture':'Devis').' '.$f->numero ($f->type_facture?'Facture':'Devis').' '.$f->numero
. ' du '.date('d-m-Y' ,$f->date_emission) . ' du '.date('d-m-Y' ,$f->date_emission)

View File

@ -1,150 +0,0 @@
<?php
namespace Garradin;
use Garradin\Plugin\Facturation\GenDon;
$session->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");