facturation/www/admin/facture_pdf.php

235 lines
4.2 KiB
PHP
Raw Normal View History

2019-11-02 17:53:27 +01:00
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
require_once PLUGIN_ROOT . '/lib/MPDF/vendor/autoload.php';
$session->requireAccess('compta', Membres::DROIT_ACCES);
$membres = new Membres;
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$f = $facture->get($id);
if (!$f)
{
throw new UserException("Ce document n'existe pas.");
}
$cats = new Compta\Categories;
$moyen_paiement = $cats->getMoyenPaiement($f->moyen_paiement);
try
{
if ($f->receveur_membre)
{
$c = $membres->get($f->receveur_id);
foreach(['ville','code_postal','adresse'] as $v)
{
if($c->$v == '')
{
$c->$v = '[A RENSEIGNER DANS LA FICHE MEMBRE]';
}
}
}
else
{
$c = $client->get($f->receveur_id);
}
}
catch(UserException $e)
{
$form->addError("Pas de document correspondant à cet id trouvée.");
}
// Création du PDF
$pdf = new \Mpdf\Mpdf([
'default_font_size' => 10,
2019-11-03 17:51:31 +01:00
'default_font' => 'dejavusans',
// 'tempDir' => PLUGINS_ROOT . '/mpdf-tmp/'
2019-11-02 17:53:27 +01:00
]);
$pdf->SetAuthor($config->get('nom_asso'));
ob_start();
$doc = ($f->type_facture?'Facture':'Devis').' n°'.$f->numero;
$emission = date('d/m/Y' ,$f->date_emission);
$pdf->SetTitle($doc.' - '.$emission);
$asso =
2019-11-03 17:51:31 +01:00
// 'Émis par :<br><br>'.
'<b>'.$config->get('nom_asso')."</b><br>".
str_replace("\n", '<br>', $config->get('adresse_asso'))."<br>".
2020-10-24 01:57:41 +02:00
(($t = $plugin->getConfig('rna_asso'))?"RNA : $t<br>":'').
(($t = $plugin->getConfig('siret_asso'))?"SIRET : $t<br>":'').
2019-11-03 17:51:31 +01:00
(($t = $config->get('email_asso'))?"Email : $t<br>":'').
(($t = $config->get('site_asso'))?"Site web : $t<br>":'');
2019-11-02 17:53:27 +01:00
$receveur =
2019-11-03 17:51:31 +01:00
'Adressé à :<br><br>'.
'<b>'.$c->nom.'</b><br>'.
$c->adresse."<br>".
$c->code_postal.' '.$c->ville."<br>".
(($t = $c->email)?"Email : $t<br>":'').
(($t = $c->telephone)?"Tel : $t<br>":'');
2019-11-02 17:53:27 +01:00
$total = number_format($f->total, 2, ',', ' ');
$echeance = date('d/m/Y' ,$f->date_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.';
$footer = str_replace("\n", '<br>', $plugin->getConfig('footer'));
2019-11-02 17:53:27 +01:00
echo <<<EOF
<!-- STYLE -->
<style>
.titre {
2019-11-03 17:51:31 +01:00
text-align: center;
font-size: 8pt;
position: absolute;
top: 6mm;
width: 180mm;
2019-11-02 17:53:27 +01:00
}
.h2 {
2019-11-03 17:51:31 +01:00
margin: 25 20 0 20;
2019-11-02 17:53:27 +01:00
}
.h2 span {
2019-11-03 17:51:31 +01:00
font-weight: bold;
font-size: 15pt;
2019-11-02 17:53:27 +01:00
}
hr {
2019-11-03 17:51:31 +01:00
margin: 5 0 20 0;
2019-11-02 17:53:27 +01:00
}
.adressage {
2019-11-03 17:51:31 +01:00
font-size: 11pt;
2019-11-02 17:53:27 +01:00
}
.adressage td {
2019-11-03 17:51:31 +01:00
width: 95mm;
vertical-align: top;
2019-11-02 17:53:27 +01:00
}
.contenu td, .contenu th {
2019-11-03 17:51:31 +01:00
vertical-align: top;
padding: 8 10;
margin : 0;
border-collapse: collapse;
2019-11-02 17:53:27 +01:00
}
.contenu tr th, .contenu tr td {
2019-11-03 17:51:31 +01:00
text-align: right;
width: 16%;
2019-11-02 17:53:27 +01:00
}
.contenu tr td:nth-child(1), .contenu tr th:nth-child(1) {
2019-11-03 17:51:31 +01:00
text-align: left;
width: 84%;
2019-11-02 17:53:27 +01:00
}
.contenu thead tr, .contenu tfoot tr {
2019-11-03 17:51:31 +01:00
background-color: #CCE;
border: 10px solid black;
2019-11-02 17:53:27 +01:00
}
.contenu tbody tr:nth-child(even) {
2019-11-03 17:51:31 +01:00
background-color: #DDF;
2019-11-02 17:53:27 +01:00
}
footer {
2019-11-03 17:51:31 +01:00
position: absolute;
bottom: 0;
margin: 14mm 0;
2019-11-02 17:53:27 +01:00
}
</style>
<!-- CONTENU -->
<p class="titre">
$doc - Émis le $emission
</p>
<table class="adressage">
<tr>
2019-11-03 17:51:31 +01:00
<td>$asso</td>
<td>$receveur</td>
2019-11-02 17:53:27 +01:00
</tr>
</table>
<br>
<div class="h2">
<span>Contenu</span> - $doc
</div>
<hr>
<table class="contenu">
<thead>
2019-11-03 17:51:31 +01:00
<tr>
<th>
Désignations
</th>
<th>
Prix
</th>
</tr>
2019-11-02 17:53:27 +01:00
</thead>
<tbody>
EOF;
$i = 1;
foreach($f->contenu as $k=>$v)
{
2019-11-03 17:51:31 +01:00
echo '<tr><td>';
echo str_replace("\n", '<br>', $v['designation']);
echo '</td><td>';
echo number_format($v['prix'], 2, ',', ' ').'€';
echo '</td></tr>';
2019-11-02 17:53:27 +01:00
$i++;
}
echo <<<EOF
</tbody>
<tfoot>
2019-11-03 17:51:31 +01:00
<tr>
<td><h3>Total</h3>Net à payer</td>
<td><b>$total </b> (HT)</td>
</tr>
2019-11-02 17:53:27 +01:00
</tfoot>
</table>
<footer>
<div class="h2"><span>Détails</span></div>
<hr>
$echeance <br>
$reglee
Moyen de paiement : $moyen_paiement
<p>
2019-11-03 17:51:31 +01:00
$footer
2019-11-02 17:53:27 +01:00
</p>
</footer>
EOF;
$html = ob_get_clean();
$pdf->WriteHTML($html);
if(qg('d') !== null)
{
2019-11-03 17:51:31 +01:00
$t = \Mpdf\Output\Destination::DOWNLOAD;
2019-11-02 17:53:27 +01:00
}
else
{
2019-11-03 17:51:31 +01:00
$t = \Mpdf\Output\Destination::INLINE;
2019-11-02 17:53:27 +01:00
}
$pdf->Output(
2019-11-03 17:51:31 +01:00
($f->type_facture?'Facture':'Devis').' '.$f->numero
. ' du '.date('d-m-Y' ,$f->date_emission)
.'.pdf', $t);