First steps in update to 1.3.0

This commit is contained in:
Noizette 2023-07-21 23:28:54 +02:00
parent 4aaed6f3c2
commit 3537314762
18 changed files with 33 additions and 34 deletions

336
admin/_facture_common.php Normal file
View file

@ -0,0 +1,336 @@
<?php
namespace Paheko;
require_once __DIR__ . '/_inc.php';
if (!isset($target) || !in_array( $target, ['new', 'edit'])) {
throw new Exception('blabla illegal call'); // Fix: exception type?
} else {
$target = ($target === 'new' ? true:false);
}
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE);
use Paheko\DB;
use stdClass;
use const \Garradin\Plugin\Facturation\PATTERNS_LIST;
$db = DB::getInstance();
$step = false;
$radio = $liste = $designations = $prix = [];
$fields = $facture->recu_fields;
$moyens_paiement = $facture->listMoyensPaiement(true);
$tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
$tpl->assign('moyen_paiement_cerfa', f('moyen_paiement_cerfa') ?: 'ES');
$tpl->assign('formes_don', array('1' => 'Acte authentique',
'2' => 'Acte sous seing privé',
'3' => 'Don manuel',
'4' => 'Autres'));
$tpl->assign('natures_don', array('1' => 'Numéraire',
'2' => 'Chèque',
'3' => 'Virement, CB; ...'));
$tpl->assign('textes_don', $facture->listTextesCerfa());
if ( !$target ) {
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
if (!$f = $facture->get($id))
{
throw new UserException("Ce document n'existe pas.");
}
}
// Traitement
if (f('save'))
{
$str_moyen = 'moyen_paiement'. (f('type') == CERFA ? '_cerfa':'');
$form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
'numero_facture' => $require_number ? 'required|string' : 'string',
'date_emission' => 'required|date_format:d/m/Y',
'date_echeance' => 'required|date_format:d/m/Y',
// 'reglee' => '',
// 'archivee' => '',
'base_receveur' => 'required|in:membre,client',
// 'client' => '',
// 'membre' => '',
$str_moyen => 'required|in:' . implode(',', array_keys($moyens_paiement)),
'designation' => 'array|required',
'prix' => 'array|required'
]);
if (!$form->hasErrors())
{
try
{
if ( count(f('designation')) !== count(f('prix')) )
{
throw new UserException('Nombre de désignations et de prix reçus différent.');
}
$data = [
'numero' => f('numero_facture'),
'date_emission' => f('date_emission'),
'date_echeance' => f('date_echeance'),
'reglee' => f('reglee') == 1?1:0,
'archivee' => f('archivee') == 1?1:0,
'moyen_paiement' => f('moyen_paiement'),
'toto' => 0
];
$data['type_facture'] = f('type');
if (in_array(f('type'), [DEVIS, FACT]))
{
foreach(f('designation') as $k=>$value)
{
$data['contenu'][$k]['designation'] = $value;
$data['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
$data['toto'] += Utils::moneyToInteger(f('prix')[$k]);
}
$data['total'] = $data['toto'];
unset($data['toto']);
}
elseif ( f('type') == CERFA )
{
$data['moyen_paiement'] = f('moyen_paiement_cerfa');
$data['contenu'] = [
'forme' => f('forme_don'),
'nature' => f('nature_don'),
'texte' => f('texte_don')];
$data['total'] = Utils::moneyToInteger(f('total'));
unset($data['toto']);
}
if (f('base_receveur') == 'client')
{
$data['receveur_membre'] = 0;
$data['receveur_id'] = f('client');
}
elseif (f('base_receveur') == 'membre')
{
$data['receveur_membre'] = 1;
$data['receveur_id'] = f('membre');
}
}
catch(UserException $e)
{
$form->addError($e->getMessage());
}
}
}
elseif (f('select_cotis'))
{
$form->check('add_cotis_1',[
'numero_facture' => $require_number ? 'required|string' : 'string',
'date_emission' => 'required|date_format:d/m/Y',
'membre_cotis' => 'required|numeric',
]);
$step = true;
}
elseif (f('add_cotis'))
{
$form->check('add_cotis_2',[
'numero_facture' => $require_number ? 'required|string' : 'string',
'date_emission' => 'required|date_format:d/m/Y',
'membre_cotis' => 'required|numeric',
'cotisation' => 'required',
]);
$radio['type'] = f('cotisation');
if (!$form->hasErrors())
{
try
{
$num = (int) str_replace('cotis_', '', $radio['type']);
foreach($fields as $field)
{
$cotis[$field] = f($field.'_'.$num);
}
$r = $facture->getCotis(f('membre_cotis'), $cotis['id']);
$r = $r[0];
$data = [
'type_facture' => COTIS,
'numero' => f('numero_facture'),
'receveur_membre' => 1,
'receveur_id' => f('membre_cotis'),
'date_emission' => f('date_emission'),
'moyen_paiement' => 'AU',
'total' => $r->paid_amount ?? $r->amount,
'contenu' => ['id' => $cotis['id'],
'intitule' => $cotis['label'],
'souscription' => $cotis['date'],
'expiration' => $cotis['expiry'] ]
];
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
if ($step)
{
try
{
$liste = $facture->getCotis((int)f('membre_cotis'));
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
elseif (isset($data))
{
if ($target)
{
$id = $facture->add($data, $plugin->getConfig('pattern'));
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
}
else
{
if ($facture->edit($id, $data))
{
Utils::redirect(PLUGIN_URL . 'facture.php?id='.(int)$id);
}
throw new UserException('Erreur d\'édition du reçu');
}
}
// Affichage
if ($target)
{
$doc = null;
if (qg('copy') !== null && $f = $facture->get((int)qg('copy'))) {
$doc = (array) $f;
// Copié depuis facture_modifier.php
$doc['type'] = $f->type_facture;
$doc['numero_facture'] = '';
$doc['base_receveur'] = $f->receveur_membre ? 'membre' : 'client';
$doc['client'] = $f->receveur_id;
$doc['membre'] = $f->receveur_id;
if ( $f->type_facture == CERFA ) {
$doc['forme_don'] = $f->contenu['forme'];
$doc['nature_don'] = $f->contenu['nature'];
$doc['texte_don'] = $f->contenu['texte'];
}
}
// Type du document:
$type = qg('t') ? (int) qg('t') : null;
// Si le type est défini dans l'URL
if (in_array($type, [DEVIS, FACT, CERFA, COTIS], true))
{
$radio['type'] = $type;
} // ... s'il a été rempli dans le formulaire envoyé
elseif (null !== f('type'))
{
$radio['type'] = f('type');
} // ... s'il est défini dans le document copié
elseif (isset($doc['type'])) {
$radio['type'] = $doc['type'];
} // ... ou par défaut
else
{
$radio['type'] = FACT;
}
}
else
{
$doc['moyen_paiement'] = $f->moyen_paiement;
$doc['type'] = $f->type_facture;
$doc['numero_facture'] = $f->numero;
$doc['reglee'] = $f->reglee;
$doc['base_receveur'] = $f->receveur_membre?'membre':'client';
$doc['client'] = $f->receveur_id;
$doc['membre'] = $f->receveur_id;
$doc['contenu'] = $f->contenu;
$doc['date_emission'] = f('date_emission') ?: $f->date_emission;
$doc['date_echeance'] = f('date_echeance')?: $f->date_echeance; // Smarty m'a saoulé pour utiliser form_field|date_fr:---
/* modif DD -- CERFA -------------------------------------- */
if ( $f->type_facture == CERFA ) {
$doc['total'] = $f->total;
$doc['forme_don'] = $f->contenu['forme'];
$doc['nature_don'] = $f->contenu['nature'];
$doc['texte_don'] = $f->contenu['texte'];
}
$radio['type'] = f('type')??$doc['type'];
}
$tpl->assign('types_details', $facture->types);
$tpl->assign('client_id', f('client') ?: -1);
$tpl->assign('membre_id', f('membre') ?: -1);
// C'est un peu l'équivalent de form_field, mais j'avais écrit ça avant
// et oulala, c'est un peu complexe, faudrait réfléchir keskivomieux
$from_user = false;
if (in_array($radio['type'], [DEVIS, FACT]))
{
if (($d = f('designation')) && ($p = f('prix')) && implode($d))
{
foreach($d as $k=>$v)
{
if (empty($v) && empty($p[$k]))
{
continue;
}
$designations[] = $v;
$prix[] = $p[$k];
}
$from_user = true;
}
else if (!empty($doc['contenu'])) {
foreach($doc['contenu'] as $k=>$v)
{
if (empty($v['designation']) && empty($v['prix']))
{
continue;
}
$designations[] = $v['designation'];
$prix[] = $v['prix'];
}
}
else {
$designations = ['Exemple'];
$prix = [250];
}
}
$date = new \DateTime;
$date->setTimestamp(time());
$tpl->assign('date', $date->format('d/m/Y'));
$tpl->assign(compact('liste', 'radio', 'step', 'designations', 'prix', 'from_user', 'identite', 'csrf_key', 'doc'));
$tpl->assign('membres', $db->getAssoc('SELECT id, '.$identite.' FROM membres WHERE id_category != -2 NOT IN (SELECT id FROM users_categories WHERE hidden = 1);'));
$tpl->assign('clients', $db->getAssoc('SELECT id, nom FROM plugin_facturation_clients;'));
$tpl->assign('require_number', $require_number);
$tpl->assign('number_pattern', PATTERNS_LIST[$plugin->getConfig('pattern')]);
if ($target) {
$tpl->display(PLUGIN_ROOT . '/templates/facture_ajouter.tpl');
} else {
$tpl->display(PLUGIN_ROOT . '/templates/facture_modifier.tpl');
}

69
admin/_inc.php Normal file
View file

@ -0,0 +1,69 @@
<?php
namespace Paheko\Plugin\Facturation;
use Paheko\Config;
use Paheko\Utils;
define('DEVIS', 0);
define('FACT', 1);
define('CERFA', 2);
define('COTIS', 3);
const PATTERNS_LIST = [
null => 'Aucun, le numéro sera à spécifier manuellement pour chaque document',
'%{type}-%{year}-%{ynumber}' => 'Type-Année-Numéro du document par année ("FACT-2021-42")',
'%{year}-%{type}-%04{ynumber}' => 'Année-Type-Numéro du document par année ("2021-DEVIS-0042")',
'%{t}-%{year}-%{ynumber}' => 'Type court-Année-Numéro du document par année ("F-2021-42")',
'%{y}%{t}%{ynumber}' => 'Année courte-Type court-Numéro du document par année ("21D42")',
'%{type}-%{id}' => 'Type - Numéro unique du document ("FACT-42")',
'%{t}%{id}' => 'Type court et numéro unique du document ("F42")',
'%{id}' => 'Numéro unique du document ("42"))',
'%06{id}' => 'Numéro unique du document sur 6 chiffres ("000042")',
];
$client = new Client;
$facture = new Facture;
$tpl->assign('www_url', \Garradin\WWW_URL);
$tpl->assign('f_obj', $facture);
$tpl->assign('plugin_url', Utils::plugin_url());
$identite = (string) Config::getInstance()->get('champ_identite');
$tpl->register_function('money_fac', function (array $params)
{
static $params_list = ['value', 'name', 'user'];
// Extract params and keep attributes separated
$attributes = array_diff_key($params, array_flip($params_list));
$params = array_intersect_key($params, array_flip($params_list));
extract($params, \EXTR_SKIP);
$current_value = null;
if (isset($value)) {
$current_value = $value;
}
if (!isset($user)) {
$user = false;
}
if (!isset($name))
{
$name = 'prix[]';
}
if (null !== $current_value && !$user) {
$current_value = Utils::money_format($current_value, ',', '');
}
if (null !== $current_value) {
$current_value = htmlspecialchars($current_value, ENT_QUOTES, 'UTF-8');
}
$currency = Config::getInstance()->get('monnaie');
return sprintf('<td><nobr><input type="text" pattern="[0-9]*([.,][0-9]{1,2})?" inputmode="decimal" size="8" class="money" style="width: 60%%" onchange="updateSum();" name="%s" value="%s" /><b>%s</b></nobr></td>', $name, $current_value, $currency);
}
);

9
admin/aide.php Normal file
View file

@ -0,0 +1,9 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
$tpl->display(PLUGIN_ROOT . '/templates/aide.tpl');

22
admin/client.php Normal file
View file

@ -0,0 +1,22 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$client = $client->get($id);
if (!$client)
{
throw new UserException("Ce client n'existe pas.");
}
$tpl->assign('docs', $facture->listUserDoc(0, $id));
$tpl->assign('client', $client);
$tpl->display(PLUGIN_ROOT . '/templates/client.tpl');

54
admin/client_modifier.php Normal file
View file

@ -0,0 +1,54 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE);
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$c = $client->get($id);
if (!$c)
{
throw new UserException("Ce client n'existe pas.");
}
if(f('save'))
{
$form->check('edit_client', [
'nom' => 'required|string',
'adresse' => 'required|string',
'code_postal' => 'required|string',
'ville' => 'required|string',
'telephone' => 'string',
'email' => 'email'
]);
if (!$form->hasErrors())
{
try
{
$r = $client->edit($id,[
'nom' => f('nom'),
'adresse' => f('adresse'),
'code_postal' => f('code_postal'),
'ville' => f('ville'),
'telephone' => f('telephone'),
'email' => f('email')
]);
$r ? Utils::redirect(PLUGIN_URL . 'client.php?id='.(int)$id):'';
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('client', $c);
$tpl->display(PLUGIN_ROOT . '/templates/client_modifier.tpl');

View file

@ -0,0 +1,29 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE);
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$c = $client->get($id);
if (!$client)
{
throw new UserException("Ce client n'existe pas.");
}
$csrf_key = 'delete_client_'.$c->id;
$form->runIf('delete', function () use ($client, $c) {
$client->delete($c->id);
}, $csrf_key, PLUGIN_URL . 'clients.php');
$tpl->assign('deletable', $client->isDeletable($id));
$tpl->assign('client', $c);
$tpl->assign(compact('csrf_key'));
$tpl->display(PLUGIN_ROOT . '/templates/client_supprimer.tpl');

48
admin/clients.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
if(f('add'))
{
$form->check('add_client', [
'nom' => 'required|string',
'adresse' => 'required|string',
'code_postal' => 'required|string',
'ville' => 'required|string',
'telephone' => 'string',
'email' => 'email'
]);
if (!$form->hasErrors())
{
try
{
$id = $client->add([
'nom' => f('nom'),
'adresse' => f('adresse'),
'code_postal' => f('code_postal'),
'ville' => f('ville'),
'telephone' => f('telephone'),
'email' => f('email')
]);
$id ? Utils::redirect(PLUGIN_URL . 'client.php?id='.(int)$id):'';
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$list = $client->list();
$list->loadFromQueryString();
$tpl->assign(compact('list'));
$tpl->display(PLUGIN_ROOT . '/templates/clients.tpl');

48
admin/config.php Normal file
View file

@ -0,0 +1,48 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_ADMIN);
if (f('save') && $form->check('facturation_config'))
{
try {
$plugin->setConfig('rna_asso', trim(f('rna_asso')));
$plugin->setConfig('siret_asso', trim(f('siret_asso')));
$plugin->setConfig('ttc', (bool)trim(f('ttc')));
$plugin->setConfig('numero_rue_asso', trim(f('numero_rue_asso')));
$plugin->setConfig('rue_asso', trim(f('rue_asso')));
$plugin->setConfig('cp_asso', trim(f('cp_asso')));
$plugin->setConfig('ville_asso', trim(f('ville_asso')));
$plugin->setConfig('droit_art200', (bool)f('droit_art200'));
$plugin->setConfig('droit_art238bis', (bool)f('droit_art238bis'));
$plugin->setConfig('droit_art885-0VbisA', (bool)f('droit_art885-0VbisA'));
$plugin->setConfig('objet_0', trim(f('objet_0')));
$plugin->setConfig('objet_1', trim(f('objet_1')));
$plugin->setConfig('objet_2', trim(f('objet_2')));;
$plugin->setConfig('footer', f('footer'));
$plugin->setConfig('validate_cp', (bool)f('validate_cp'));
$plugin->setConfig('unique_client_name', (bool)f('unique_client_name'));
$plugin->setConfig('pattern', f('pattern'));
Utils::redirect(PLUGIN_URL . 'config.php?ok');
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
$tpl->assign('ok', qg('ok') !== null);
$tpl->assign('patterns', \Garradin\Plugin\Facturation\PATTERNS_LIST);
$tpl->display(PLUGIN_ROOT . '/templates/config.tpl');

29
admin/facture.php Normal file
View file

@ -0,0 +1,29 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
use Garradin\Membres;
$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.");
}
$tpl->assign('type', $f->type_facture);
$tpl->assign('facture', $f);
$tpl->assign('id', $id);
$tpl->assign('footer', $plugin->getConfig('footer')?:'');
$tpl->assign('siret_asso', $plugin->getConfig('siret_asso')?:'');
$tpl->display(PLUGIN_ROOT . '/templates/facture.tpl');

View file

@ -0,0 +1,9 @@
<?php
namespace Paheko;
$target = 'new';
$csrf_key = 'ajout_facture';
$require_number = $plugin->getConfig('pattern') ? false : true;
require __DIR__ .'/_facture_common.php';

View file

@ -0,0 +1,9 @@
<?php
namespace Paheko;
$target = 'edit';
$csrf_key = 'modifier_facture';
$require_number = true;
require __DIR__ .'/_facture_common.php';

View file

@ -0,0 +1,38 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_WRITE);
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
$f = $facture->get($id);
if (!$client)
{
throw new UserException("Ce document n'existe pas.");
}
if (f('delete'))
{
$form->check('delete_doc_'.$f->id);
if (!$form->hasErrors())
{
try {
$facture->delete($f->id);
Utils::redirect(PLUGIN_URL . 'index.php');
}
catch (UserException $e)
{
$form->addError($e->getMessage());
}
}
}
$tpl->assign('doc', $f);
$tpl->display(PLUGIN_ROOT . '/templates/facture_supprimer.tpl');

15
admin/index.php Normal file
View file

@ -0,0 +1,15 @@
<?php
namespace Garradin;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
$list = $facture->list();
$list->loadFromQueryString();
$tpl->assign(compact('list'));
$tpl->display(PLUGIN_ROOT . '/templates/index.tpl');

505
admin/pdf.php Normal file
View file

@ -0,0 +1,505 @@
<?php
namespace Paheko;
require_once __DIR__ . '/_inc.php';
$session->requireAccess($session::SECTION_ACCOUNTING, $session::ACCESS_READ);
$membres = new Membres;
qv(['id' => 'required|numeric']);
$id = (int) qg('id');
// Vérification que le document existe
if (!$f = $facture->get($id))
{
throw new UserException("Ce document n'existe pas.");
}
$moyen_paiement = $facture->getMoyenPaiement($f->moyen_paiement);
// Récupération infos membre
try
{
if ($f->receveur_membre)
{
$c = $membres->get($f->receveur_id);
$c->identite = $c->$identite;
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);
$c->identite = $c->nom;
}
}
catch(UserException $e)
{
$form->addError($e);
}
// Formatage dates
$emission = $f->date_emission->format('d/m/Y');
if (isset($f->date_echeance))
{
$echeance = $f->date_echeance->format('d/m/Y');
}
// -- Création du PDF
// Génération factures, devis et cotisation
if ($f->type_facture != CERFA)
{
switch ($f->type_facture)
{
case FACT:
$doc = 'Facture n°'. $f->numero;
break;
case DEVIS:
$doc = 'Devis n°'. $f->numero;
break;
case COTIS:
$doc = 'Reçu de cotisation n°'. $f->numero;
break;
}
$asso =
// 'Émis par :<br><br>'.
'<b>'.$config->get('nom_asso')."</b><br>".
str_replace("\n", '<br>', $config->get('adresse_asso'))."<br>".
(($t = $plugin->getConfig('rna_asso'))?"RNA : $t<br>":'').
(($t = $plugin->getConfig('siret_asso'))?"SIRET : $t<br>":'').
(($t = $config->get('email_asso'))?"Email : $t<br>":'').
(($t = $config->get('site_asso'))?"Site web : $t<br>":'');
$receveur =
'Adressé à :<br><br>'.
'<b>'.$c->identite.'</b><br>'.
$c->adresse."<br>".
$c->code_postal.' '.$c->ville."<br>".
(($t = $c->email)?"Email : $t<br>":'').
(($t = $c->telephone)?"Tel : $t<br>":'');
$total = Utils::money_format($f->total, ',', ' ');
// Devis et facture
if ($f->type_facture != COTIS)
{
$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'));
$ttc = $plugin->getConfig('ttc') ? 'TTC':'HT';
// Génération du contenu de la facture
ob_start();
echo <<<EOF
<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;
$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++;
}
echo <<<EOF
</tbody>
<tfoot>
<tr>
<td><b>Total</b><br>Net à payer</td>
<td><b>$total </b><br>({$ttc})</td>
</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;
$content = ob_get_clean();
}
else // Reçu de cotisation
{
$lieu = $plugin->getConfig('ville_asso');
$intitule = $f->contenu['intitule'];
$souscription = date('d/m/Y', strtotime($f->contenu['souscription']));
if($f->contenu['expiration'] == '1970-01-01')
{
$expiration = "jour même, s'agissant d'une cotisation ponctuelle.";
}
else {
$expiration = date('d/m/Y', strtotime($f->contenu['expiration']));
}
// Génération du contenu du reçu de cotisation
$content = <<<EOF
<div class="h2">
<span>Reçu de votre cotisation</span> - $doc
</div>
<hr>
<div class="contenuTexte">
<p>À $lieu, le $emission,</p>
<p>Bonjour,</p>
<p>Nous accusons réception de votre cotisation « $intitule » reçue le $emission et nous vous en remercions.</p>
<p>Nous reconnaissons que vous avez acquitté la somme de {$total} .<br>111
Votre adhésion sera donc effective à compter du $souscription jusquau $expiration.</p>
<br>
<p>Nous vous prions de recevoir, chère adhérente, cher adhérent, nos meilleures salutations,</p>
<br>
<p>-représentant·e de l'asso-</p>
<br>
<p><i>Nous vous rappelons que la cotisation nest pas soumise à la TVA et quelle ne donne pas lieu à la délivrance dune facture. Elle nouvre pas droit au bénéfice des dispositions des articles 200, 238 bis et 885-0 V bis A du code général des impôts.</i></p>
</div>
EOF;
}
//-- Layout du document
ob_start();
echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>{$doc}_{$emission}</title>
<style>
@page {
size: A4 portrait;
margin: 0;
}
body {
padding: 4mm;
font-family: Helvetica, Arial, sans;
font-size: 10pt;
background: white;
}
.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;
}
.contenuTexte {
padding: 0 6mm;
}
.contenu {
width: 100%;
}
.contenu td, .contenu th {
vertical-align: top;
padding: 8px 10px;
margin : 0px;
border-collapse: collapse;
}
.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%;
}
.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">
$doc - Émis le $emission
</p>
<table class="adressage">
<tr>
<td>$asso</td>
<td>$receveur</td>
</tr>
</table>
<br>
$content
</body>
</html>
EOF;
$html = ob_get_clean();
} // Génération du CERFA
elseif ($f->type_facture == CERFA)
{
$doc = 'Reçu de don n°'. $f->numero;
$url = WWW_URL;
$libelles = $facture->listTextesCerfa(false);
$t['numero'] = $f->numero;
$t['nom_asso'] = $config->get('nom_asso');
$t['n_rue_asso'] = $plugin->getConfig('numero_rue_asso');
$t['rue_asso'] = $plugin->getConfig('rue_asso');
$t['cp_asso'] = $plugin->getConfig('cp_asso');
$t['ville_asso'] = $plugin->getConfig('ville_asso');
$t['objet0'] = $plugin->getConfig('objet_0');
$t['objet1'] = $plugin->getConfig('objet_1');
$t['objet2'] = $plugin->getConfig('objet_2');
$t['nom'] = $c->identite;
$t['adresse'] = $c->adresse;
$t['cp'] = $c->code_postal;
$t['ville'] = $c->ville;
$t['total'] = '***'.Utils::money_format($f->total).'***';
$t['total_lettre'] = numfmt_create('fr_FR', \NumberFormatter::SPELLOUT)->format($f->total/100). ' euros';
$t['d'] = ($f->date_emission->format('d'));
$t['m'] = ($f->date_emission->format('m'));
$t['Y'] = ($f->date_emission->format('Y'));
$t['forme'] = $f->contenu['forme'];
$t['nature'] = $f->contenu['nature'];
$t['texte'] = $libelles[$f->contenu['texte']];
$t['art200'] = $t['art238'] = $t['art885'] = '';
if($plugin->getConfig('droit_art200')){
$t['art200'] = 'X';
}
if($plugin->getConfig('droit_art238bis')){
$t['art238'] = 'X';
}
if($plugin->getConfig('droit_art885-0VbisA')){
$t['art885'] = 'X';
}
// forme du don
switch ($t['forme']){
case '1':
$t['frm'] = 'left: 15mm;';
break;
case '2':
$t['frm'] = 'left: 57.3mm;';
break;
case '3':
$t['frm'] = 'left: 115.2mm;';
break;
case '4':
$t['frm'] = 'left: 175.2mm;';
}
// nature du don
switch ($t['nature']){
case '1':
$t['nat'] = 'left: 15mm;';
break;
case '2':
$t['nat'] = 'left: 57.3mm;';
break;
case '3':
$t['nat'] = 'left: 115.2mm;';
}
// moyen de paiement
switch ($f->moyen_paiement){
case 'ES':
$t['pos'] = 'left: 15mm;';
break;
case 'CH':
$t['pos'] = 'left: 57.3mm;';
break;
default:
$t['pos'] = 'left: 115.2mm;';
}
$t['d2'] = ($f->date_echeance->format('d'));
$t['m2'] = ($f->date_echeance->format('m'));
$t['Y2'] = ($f->date_echeance->format('Y'));
ob_start();
echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>{$doc}_{$emission}</title>
<style>
@page {
size: A4 portrait;
margin: 0;
padding: 0;
}
body {
font-family: Helvetica, Arial, sans;
font-size: 10pt;
background: white;
padding: 0;
margin: 0;
}
.page div {
position: absolute;
}
.page {
padding: 0;
margin: 0;
break-after: always;
width: 210mm;
height: 297mm;
background-size: cover;
background-position: -5mm -4.8mm;
}
#p1 {
background-image: url('{$url}p/facturation/cerfa-1.png');
}
#p2 {
background-image: url('{$url}p/facturation/cerfa-2.png');
position: relative;
}
</style>
</head>
<body>
<div class="page" id="p1">
<div style="top: 10mm; left: 170mm;">{$t['numero']}</div>
<div style="top: 35mm; left: 20mm;">{$t['nom_asso']}</div>
<div style="top: 46mm; left: 20mm;">{$t['n_rue_asso']}</div>
<div style="top: 46mm; left: 40mm;">{$t['rue_asso']}</div>
<div style="top: 51.5mm; left: 37mm;">{$t['cp_asso']}</div>
<div style="top: 51.5mm; left: 75mm;">{$t['ville_asso']}</div>
<div style="top: 62mm; left: 18mm;">{$t['objet0']}</div>
<div style="top: 66.5mm; left: 18mm;">{$t['objet1']}</div>
<div style="top: 70.8mm; left: 18mm;">{$t['objet2']}</div>
<div style="top: 128.5mm; left: 15mm;">X</div>
</div>
<div class="page" id="p2">
<div style="top: 18mm; left: 18mm;">{$t['nom']}</div>
<div style="top: 32mm; left: 18mm;">{$t['adresse']}</div>
<div style="top: 37mm; left: 40mm;">{$t['cp']}</div>
<div style="top: 37mm; left: 80mm;">{$t['ville']}</div>
<div style="top: 63mm; left: 87mm;">{$t['total']}</div>
<div style="top: 73mm; left: 58mm;">{$t['total_lettre']}</div>
<div style="top: 82mm; left: 69mm;">{$t['d']}</div>
<div style="top: 82mm; left: 82mm;">{$t['m']}</div>
<div style="top: 82mm; left: 99mm;">{$t['Y']}</div>
<div style="top: 96mm; left: 53mm;">{$t['art200']}</div>
<div style="top: 96mm; left: 103mm;">{$t['art238']}</div>
<div style="top: 96mm; left: 153.0mm;">{$t['art885']}</div>
<div style="top: 113mm; {$t['frm']}">X</div>
<div style="top: 136mm; {$t['nat']}">X</div>
<div style="top: 142mm; left: 25mm;">{$t['texte']}</div>
<div style="top: 158.2mm; {$t['pos']}">X</div>
<div style="top: 239mm; left: 139mm;">{$t['d2']}</div>
<div style="top: 239mm; left: 148mm;">{$t['m2']}</div>
<div style="top: 239mm; left: 156mm;">{$t['Y2']}</div>
<div style="top: 243mm; left: 137mm;"><img src="{$url}plugin/facturation/sign.png" style="width: 50mm;"/></div>
</div>
</body>
</html>
EOF;
$html = ob_get_clean();
} // End if cerfa
if(qg('d') !== null)
{
$filename = 'Print';
if (preg_match('!<title>(.*)</title>!U', $html, $match)) {
$filename = trim($match[1]);
}
header('Content-type: application/pdf');
header(sprintf('Content-Disposition: attachment; filename="%s.pdf"', Utils::safeFileName($filename)));
Utils::streamPDF($html);
}
else
{
echo $html;
}