2019-11-02 17:53:27 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
2023-07-21 23:28:54 +02:00
|
|
|
|
namespace Paheko;
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/_inc.php';
|
2021-04-11 14:25:59 +02:00
|
|
|
|
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
|
2023-08-01 22:56:38 +02:00
|
|
|
|
$users = new Users\Users;
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2023-08-01 22:56:38 +02:00
|
|
|
|
f(['id' => 'required|numeric']);
|
2019-11-02 17:53:27 +01:00
|
|
|
|
$id = (int) qg('id');
|
2023-08-04 17:41:29 +02:00
|
|
|
|
$sign_tag = UserTemplate\Functions::signature();
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
// Vérification que le document existe
|
2020-10-24 08:35:00 +02:00
|
|
|
|
if (!$f = $facture->get($id))
|
2019-11-02 17:53:27 +01:00
|
|
|
|
{
|
|
|
|
|
throw new UserException("Ce document n'existe pas.");
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-29 18:07:26 +01:00
|
|
|
|
$moyen_paiement = $facture->getMoyenPaiement($f->moyen_paiement);
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
// Récupération infos membre
|
2019-11-02 17:53:27 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if ($f->receveur_membre)
|
|
|
|
|
{
|
2023-08-01 22:56:38 +02:00
|
|
|
|
$c = $users->get($f->receveur_id);
|
2024-08-30 21:32:13 +02:00
|
|
|
|
// l'identité du membre peut être redéfinie dans la configuration des membres
|
|
|
|
|
$name_fields = \Paheko\Users\DynamicFields::getNameFields();
|
|
|
|
|
array_walk($name_fields, function(&$elem) use ($c) {
|
2024-09-18 18:44:06 +02:00
|
|
|
|
$elem = $c->$elem;
|
2024-08-30 21:32:13 +02:00
|
|
|
|
});
|
2024-09-18 18:44:06 +02:00
|
|
|
|
$nom_client = implode(" ", $name_fields);
|
|
|
|
|
if (preg_match('/^ +$/', $nom_client)) {
|
|
|
|
|
$nom_client = "** ABSENT **";
|
|
|
|
|
}
|
2024-08-30 21:32:13 +02:00
|
|
|
|
|
|
|
|
|
// adresse, code postal et ville peuvent être redéfini(e)s dans la configuration du plugin
|
|
|
|
|
$adresse_client = $plugin->getConfig('adresse_client');
|
|
|
|
|
if ($adresse_client != null && $c->$adresse_client != null) { $c->adresse = $c->$adresse_client; }
|
|
|
|
|
$code_postal_client = $plugin->getConfig('code_postal_client');
|
|
|
|
|
if ($code_postal_client != null && $c->$code_postal_client != null) { $c->code_postal = $c->$code_postal_client; }
|
|
|
|
|
$ville_client = $plugin->getConfig('ville_client');
|
|
|
|
|
if ($ville_client != null && $c->$ville_client != null) { $c->ville = $c->$ville_client; }
|
|
|
|
|
|
2019-11-02 17:53:27 +01:00
|
|
|
|
foreach(['ville','code_postal','adresse'] as $v)
|
|
|
|
|
{
|
|
|
|
|
if($c->$v == '')
|
|
|
|
|
{
|
2024-08-30 21:32:13 +02:00
|
|
|
|
$c->$v = '[À RENSEIGNER DANS LA FICHE MEMBRE]';
|
2019-11-02 17:53:27 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
$c = $client->get($f->receveur_id);
|
2024-09-18 18:44:06 +02:00
|
|
|
|
$nom_client = $c->nom;
|
2019-11-02 17:53:27 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(UserException $e)
|
|
|
|
|
{
|
2020-10-24 09:19:21 +02:00
|
|
|
|
$form->addError($e);
|
2019-11-02 17:53:27 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
// Formatage dates
|
2020-12-29 18:07:26 +01:00
|
|
|
|
$emission = $f->date_emission->format('d/m/Y');
|
|
|
|
|
if (isset($f->date_echeance))
|
|
|
|
|
{
|
|
|
|
|
$echeance = $f->date_echeance->format('d/m/Y');
|
|
|
|
|
}
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
|
|
|
|
|
// -- Création du PDF
|
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
// Génération factures, devis
|
|
|
|
|
switch ($f->type_facture)
|
2020-10-24 08:35:00 +02:00
|
|
|
|
{
|
2024-09-06 21:40:27 +02:00
|
|
|
|
case FACT:
|
|
|
|
|
$doc = 'Facture n° '. $f->numero;
|
|
|
|
|
$txtemis = $doc . " - Émise le " . $emission;
|
|
|
|
|
$txtdest = "Adressée à :";
|
|
|
|
|
break;
|
|
|
|
|
case DEVIS:
|
|
|
|
|
$doc = 'Devis n° '. $f->numero;
|
|
|
|
|
$txtemis = $doc . " - Émis le " . $emission;
|
|
|
|
|
$txtdest = "Adressé à :";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-10-24 08:35:00 +02:00
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
// utiliser l'adresse configurée dans le plugin sinon celle de l'asso sinon rien !
|
|
|
|
|
if ($plugin->getConfig('rue_asso') != null &&
|
|
|
|
|
$plugin->getConfig('cp_asso') != null &&
|
|
|
|
|
$plugin->getConfig('ville_asso') != null)
|
|
|
|
|
{
|
|
|
|
|
$adresse =
|
|
|
|
|
(($plugin->getConfig('numero_rue_asso') != null) ? $plugin->getConfig('numero_rue_asso') . " " : "") .
|
|
|
|
|
$plugin->getConfig('rue_asso') . "<br>" .
|
|
|
|
|
$plugin->getConfig('cp_asso') . " " .
|
|
|
|
|
$plugin->getConfig('ville_asso');
|
|
|
|
|
}
|
|
|
|
|
else if ($config->get('org_address') != null)
|
|
|
|
|
{
|
|
|
|
|
$adresse = str_replace("\n", '<br>', $config->get('org_address'));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$adresse = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$logo='';
|
|
|
|
|
if ($plugin->getConfig('logo')) {
|
|
|
|
|
$logo = '<img id="logo" src="' . $config->fileURL('logo') . '" />';
|
|
|
|
|
}
|
|
|
|
|
$asso =
|
|
|
|
|
// 'Émis par :<br><br>'.
|
|
|
|
|
'<b>'.$config->get('org_name')."</b><br>".
|
|
|
|
|
$adresse ."<br>".
|
|
|
|
|
(($t = $plugin->getConfig('rna_asso'))?"RNA : $t<br>":'').
|
|
|
|
|
(($t = $plugin->getConfig('siret_asso'))?"SIRET : " . implode(' ', str_split($t, 3)) . "<br>":'').
|
|
|
|
|
(($t = $config->get('email_asso'))?"Email : $t<br>":'').
|
|
|
|
|
(($t = $config->get('site_asso'))?"Site web : $t<br>":'');
|
2020-10-24 08:35:00 +02:00
|
|
|
|
|
|
|
|
|
$receveur =
|
2024-01-12 16:37:04 +01:00
|
|
|
|
$txtdest.'<br>'.
|
2024-09-18 18:44:06 +02:00
|
|
|
|
'<b>'.$nom_client.'</b><br>'.
|
2020-10-24 08:35:00 +02:00
|
|
|
|
$c->adresse."<br>".
|
|
|
|
|
$c->code_postal.' '.$c->ville."<br>".
|
2024-01-11 20:41:19 +01:00
|
|
|
|
(($t = $c->siret)?"SIREN/SIRET : " . implode(' ', str_split($t, 3)) . "<br>":'').
|
2020-10-24 08:35:00 +02:00
|
|
|
|
(($t = $c->email)?"Email : $t<br>":'').
|
|
|
|
|
(($t = $c->telephone)?"Tel : $t<br>":'');
|
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
$total = Utils::money_format($f->total, ',', ' ');
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
// Devis et facture
|
|
|
|
|
{
|
|
|
|
|
$echeance = ($f->type_facture?'Échéance de paiement':'Échéance du devis')." : ".$echeance;
|
2024-10-18 21:30:45 +02:00
|
|
|
|
if ($f->type_facture == FACT) {
|
|
|
|
|
$reglee = !$f->reglee?'Cette facture est en attente de règlement.':'Cette facture a été réglée.';
|
|
|
|
|
} else {
|
|
|
|
|
$reglee = "";
|
|
|
|
|
}
|
2024-09-06 21:40:27 +02:00
|
|
|
|
$footer = str_replace("\n", '<br>', $plugin->getConfig('footer') ?? '[Pied de page à configurer]');
|
|
|
|
|
$ttc = $plugin->getConfig('ttc') ? 'TTC':'HT';
|
|
|
|
|
|
|
|
|
|
// Génération du contenu de la facture
|
|
|
|
|
ob_start();
|
|
|
|
|
echo <<<EOF
|
2021-11-10 23:27:07 +01:00
|
|
|
|
<div class="h2">
|
|
|
|
|
<span>Contenu</span> - $doc
|
|
|
|
|
</div>
|
|
|
|
|
<hr>
|
|
|
|
|
|
|
|
|
|
<table class="contenu">
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>
|
|
|
|
|
Désignations
|
|
|
|
|
</th>
|
|
|
|
|
<th>
|
|
|
|
|
Prix
|
|
|
|
|
</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
EOF;
|
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
$i = 1;
|
|
|
|
|
foreach($f->contenu as $k=>$v)
|
|
|
|
|
{
|
|
|
|
|
echo '<tr><td>';
|
|
|
|
|
echo str_replace("\n", '<br>', $v['designation']);
|
|
|
|
|
echo '</td><td>';
|
|
|
|
|
echo Utils::money_format($v['prix'], ',', ' ') .' €';
|
|
|
|
|
echo '</td></tr>';
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
2021-11-10 23:27:07 +01:00
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
echo <<<EOF
|
2021-11-10 23:27:07 +01:00
|
|
|
|
</tbody>
|
|
|
|
|
<tfoot>
|
|
|
|
|
<tr>
|
2022-01-10 18:16:32 +01:00
|
|
|
|
<td><b>Total</b><br>Net à payer</td>
|
2023-04-14 18:52:48 +02:00
|
|
|
|
<td><b>$total €</b><br>({$ttc})</td>
|
2021-11-10 23:27:07 +01:00
|
|
|
|
</tr>
|
|
|
|
|
</tfoot>
|
|
|
|
|
</table>
|
|
|
|
|
<footer>
|
|
|
|
|
<div class="h2"><span>Détails</span></div>
|
|
|
|
|
<hr>
|
|
|
|
|
|
|
|
|
|
$echeance <br>
|
|
|
|
|
$reglee
|
|
|
|
|
Moyen de paiement : $moyen_paiement
|
|
|
|
|
|
|
|
|
|
<p>
|
|
|
|
|
$footer
|
|
|
|
|
</p>
|
|
|
|
|
</footer>
|
|
|
|
|
EOF;
|
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
$content = ob_get_clean();
|
2021-11-10 23:27:07 +01:00
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
}
|
2021-11-10 23:27:07 +01:00
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
//-- Layout du document
|
2024-08-30 21:32:13 +02:00
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
ob_start();
|
|
|
|
|
echo <<<EOF
|
2021-11-10 23:27:07 +01:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
2021-11-10 23:33:00 +01:00
|
|
|
|
<head>
|
2023-07-22 21:31:15 +02:00
|
|
|
|
<meta charset="UTF-8">
|
2023-10-20 12:21:57 +02:00
|
|
|
|
<title>{$doc}_{$emission}</title>
|
2021-11-10 23:33:00 +01:00
|
|
|
|
<style>
|
|
|
|
|
@page {
|
|
|
|
|
size: A4 portrait;
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
2024-08-30 21:32:13 +02:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
body {
|
|
|
|
|
padding: 4mm;
|
|
|
|
|
font-family: Helvetica, Arial, sans;
|
|
|
|
|
font-size: 10pt;
|
|
|
|
|
background: white;
|
|
|
|
|
}
|
2021-11-10 23:27:07 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
.titre {
|
|
|
|
|
text-align: center;
|
|
|
|
|
font-size: 8pt;
|
|
|
|
|
margin-bottom: 6mm;
|
|
|
|
|
margin-top: 0mm;
|
|
|
|
|
}
|
|
|
|
|
.h2 {
|
|
|
|
|
margin: 20px 20px 0px 20px;
|
|
|
|
|
}
|
|
|
|
|
.h2 span {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
font-size: 14pt;
|
|
|
|
|
}
|
|
|
|
|
hr {
|
|
|
|
|
margin: 5px 0px 15px 0px;
|
|
|
|
|
border: none;
|
|
|
|
|
border-top: 1px solid;
|
|
|
|
|
}
|
|
|
|
|
.adressage {
|
|
|
|
|
font-size: 11pt;
|
|
|
|
|
margin: auto;
|
|
|
|
|
}
|
|
|
|
|
.adressage td {
|
|
|
|
|
width: 40%;
|
|
|
|
|
vertical-align: top;
|
|
|
|
|
}
|
2024-06-20 15:55:33 +02:00
|
|
|
|
.adressage td#logo {
|
|
|
|
|
width: 20%;
|
|
|
|
|
vertical-align: top;
|
|
|
|
|
}
|
|
|
|
|
.adressage img#logo {
|
|
|
|
|
height : 3cm;
|
|
|
|
|
}
|
2021-11-10 23:27:07 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
.contenuTexte {
|
|
|
|
|
padding: 0 6mm;
|
|
|
|
|
}
|
2021-11-06 21:23:49 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
.contenu {
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
.contenu td, .contenu th {
|
|
|
|
|
vertical-align: top;
|
|
|
|
|
padding: 8px 10px;
|
|
|
|
|
margin : 0px;
|
|
|
|
|
border-collapse: collapse;
|
|
|
|
|
}
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
.contenu tr th, .contenu tr td {
|
|
|
|
|
text-align: right;
|
|
|
|
|
width: 16%;
|
|
|
|
|
}
|
|
|
|
|
.contenu tr td:nth-child(1), .contenu tr th:nth-child(1) {
|
|
|
|
|
text-align: left;
|
|
|
|
|
width: 84%;
|
|
|
|
|
}
|
2019-11-02 17:53:27 +01:00
|
|
|
|
|
2021-11-10 23:33:00 +01:00
|
|
|
|
.contenu thead tr, .contenu tfoot tr {
|
|
|
|
|
background-color: #CCE;
|
|
|
|
|
border: 10px solid black;
|
|
|
|
|
}
|
|
|
|
|
.contenu tbody tr:nth-child(even) {
|
|
|
|
|
background-color: #DDF !important;
|
|
|
|
|
}
|
|
|
|
|
.contenu tfoot {
|
|
|
|
|
display: table-row-group;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
footer {
|
|
|
|
|
bottom: 0;
|
|
|
|
|
margin: 14mm 0;
|
|
|
|
|
width: inherit;
|
|
|
|
|
font-size: 9pt;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<p class="titre">
|
2024-01-12 16:37:04 +01:00
|
|
|
|
$txtemis
|
2021-11-10 23:33:00 +01:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<table class="adressage">
|
|
|
|
|
<tr>
|
2024-06-20 15:55:33 +02:00
|
|
|
|
<td id="logo">$logo</td>
|
2021-11-10 23:33:00 +01:00
|
|
|
|
<td>$asso</td>
|
|
|
|
|
<td>$receveur</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</table>
|
|
|
|
|
<br>
|
|
|
|
|
$content
|
|
|
|
|
</body>
|
2021-11-10 23:27:07 +01:00
|
|
|
|
</html>
|
2019-11-02 17:53:27 +01:00
|
|
|
|
EOF;
|
|
|
|
|
|
2024-09-06 21:40:27 +02:00
|
|
|
|
$html = ob_get_clean();
|
2020-10-24 10:08:44 +02:00
|
|
|
|
|
2019-11-02 17:53:27 +01:00
|
|
|
|
if(qg('d') !== null)
|
|
|
|
|
{
|
2021-11-10 23:27:07 +01:00
|
|
|
|
$filename = 'Print';
|
|
|
|
|
if (preg_match('!<title>(.*)</title>!U', $html, $match)) {
|
2024-09-18 18:44:06 +02:00
|
|
|
|
$filename = str_replace(" ", "_", trim($match[1]));
|
2021-11-10 23:27:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
header('Content-type: application/pdf');
|
|
|
|
|
header(sprintf('Content-Disposition: attachment; filename="%s.pdf"', Utils::safeFileName($filename)));
|
|
|
|
|
Utils::streamPDF($html);
|
2019-11-02 17:53:27 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-11-10 23:27:07 +01:00
|
|
|
|
echo $html;
|
2019-11-02 17:53:27 +01:00
|
|
|
|
}
|