Ajout génération cerfa dans facture_pdf
This commit is contained in:
parent
ba5096bfb2
commit
e5ff2e8cd7
|
@ -42,9 +42,9 @@
|
|||
<legend>Objet</legend>
|
||||
<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>
|
||||
<dd><input type="text" maxlength=100 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=100 name="objet_2" value="{form_field data=$plugin.config name=objet_2}" /></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=95 name="objet_1" value="{form_field data=$plugin.config name=objet_1}" /></dd>
|
||||
<dd><input type="text" maxlength=95 name="objet_2" value="{form_field data=$plugin.config name=objet_2}" /></dd>
|
||||
</dl>
|
||||
</fieldset>
|
||||
|
||||
|
|
|
@ -12,10 +12,6 @@
|
|||
<button type="button" class="btn btn-primary">Télécharger ce document</button></a>
|
||||
|
||||
<div>
|
||||
{if $type < 2}
|
||||
<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>
|
||||
{include file="admin/_foot.tpl"}
|
||||
|
|
|
@ -21,7 +21,21 @@
|
|||
<tbody>
|
||||
{foreach from=$factures item=facture}
|
||||
<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>
|
||||
{if $facture.receveur_membre}
|
||||
<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.date_emission|date_fr:'d/m/Y'}</td>
|
||||
<td>{$facture.date_echeance|date_fr:'d/m/Y'}</td>
|
||||
<td>{$facture.reglee}</td>
|
||||
<td>{$facture.archivee}</td>
|
||||
<td><?= $facture->reglee?'Réglée':'Non' ?></td>
|
||||
<td><?= $facture->archivee?'Archivée':'Non' ?></td>
|
||||
<td>{$facture.moyen_paiement}</td>
|
||||
<td>
|
||||
{foreach from=$facture.contenu item=contenu}
|
||||
|
|
|
@ -12,9 +12,7 @@ $membres = new Membres;
|
|||
qv(['id' => 'required|numeric']);
|
||||
$id = (int) qg('id');
|
||||
|
||||
$f = $facture->get($id);
|
||||
|
||||
if (!$f)
|
||||
if (!$f = $facture->get($id))
|
||||
{
|
||||
throw new UserException("Ce document n'existe pas.");
|
||||
}
|
||||
|
@ -42,18 +40,23 @@ try
|
|||
}
|
||||
catch(UserException $e)
|
||||
{
|
||||
$form->addError("Pas de document correspondant à cet id trouvée.");
|
||||
$form->addError($e);
|
||||
}
|
||||
|
||||
|
||||
// Création du PDF
|
||||
|
||||
$pdf = new \Mpdf\Mpdf([
|
||||
'default_font_size' => 10,
|
||||
'default_font' => 'dejavusans',
|
||||
// 'tempDir' => PLUGINS_ROOT . '/mpdf-tmp/'
|
||||
]);
|
||||
$pdf->SetAuthor($config->get('nom_asso'));
|
||||
|
||||
|
||||
// Génération factures et devis
|
||||
|
||||
if ($f->type_facture < 2)
|
||||
{
|
||||
ob_start();
|
||||
|
||||
$doc = ($f->type_facture?'Facture':'Devis').' n°'.$f->numero;
|
||||
|
@ -220,6 +223,102 @@ EOF;
|
|||
$html = ob_get_clean();
|
||||
$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)
|
||||
{
|
||||
$t = \Mpdf\Output\Destination::DOWNLOAD;
|
||||
|
@ -228,6 +327,7 @@ else
|
|||
{
|
||||
$t = \Mpdf\Output\Destination::INLINE;
|
||||
}
|
||||
|
||||
$pdf->Output(
|
||||
($f->type_facture?'Facture':'Devis').' '.$f->numero
|
||||
. ' du '.date('d-m-Y' ,$f->date_emission)
|
||||
|
|
|
@ -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");
|
Loading…
Reference in New Issue