Integration contrib @DDgallo sur CERFA

This commit is contained in:
Noizette 2022-01-07 01:24:32 +01:00
parent 637c493671
commit 61f40e100d
8 changed files with 218 additions and 42 deletions

View File

@ -42,6 +42,25 @@ INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('ES', 'Esp
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('PR', 'Prélèvement'); INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('PR', 'Prélèvement');
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('TI', 'TIP'); INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('TI', 'TIP');
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('VI', 'Virement'); INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('VI', 'Virement');
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('HA', 'HelloAsso');
INSERT OR IGNORE INTO plugin_facturation_paiement (code, nom) VALUES ('AU', 'Autre');
-- Modif DD -- ajout de la table des textes associés aux CERFA
CREATE TABLE IF NOT EXISTS plugin_facturation_txt_cerfa
-- Textes explicatifs associés aux CERFA
(
id PRIMARY KEY,
menu TEXT NOT NULL UNIQUE,
texte TEXT NOT NULL
);
----
-- Data dump for plugin_facturation_txt_cerfa, a total of 4 rows
----
INSERT OR IGNORE INTO "plugin_facturation_txt_cerfa" ("id","menu","texte") VALUES ('0','Aucun','');
INSERT OR IGNORE INTO "plugin_facturation_txt_cerfa" ("id","menu","texte") VALUES ('1','HelloAsso','Don via HelloAsso');
INSERT OR IGNORE INTO "plugin_facturation_txt_cerfa" ("id","menu","texte") VALUES ('2','Frais de déplacement','Renonciation aux remboursements de frais de déplacement');
INSERT OR IGNORE INTO "plugin_facturation_txt_cerfa" ("id","menu","texte") VALUES ('3','Don en nature','Don en nature');
-- CREATE TABLE IF NOT EXISTS plugin_facturation_produits ( -- CREATE TABLE IF NOT EXISTS plugin_facturation_produits (
-- id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, -- id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,

View File

@ -1,4 +1,5 @@
DROP TABLE `plugin_facturation_factures`; DROP TABLE `plugin_facturation_factures`;
DROP TABLE `plugin_facturation_clients`; DROP TABLE `plugin_facturation_clients`;
DROP TABLE `plugin_facturation_paiement`; DROP TABLE `plugin_facturation_paiement`;
DROP TABLE `plugin_facturation_txt_cerfa`;
-- DROP TABLE `plugin_facturation_produits`; -- DROP TABLE `plugin_facturation_produits`;

View File

@ -79,7 +79,7 @@ class Facture
{ {
throw new UserException("La valeur de $k est vide"); throw new UserException("La valeur de $k est vide");
} }
switch($k) switch($k)
{ {
case 'type_facture': case 'type_facture':
@ -205,7 +205,7 @@ class Facture
{ {
throw new UserException('Un document avec ce numéro existe déjà, hors le numéro doit être unique.'); throw new UserException('Un document avec ce numéro existe déjà, hors le numéro doit être unique.');
} }
$db->insert('plugin_facturation_factures', $data); $db->insert('plugin_facturation_factures', $data);
$id = $db->lastInsertRowId(); $id = $db->lastInsertRowId();
@ -384,11 +384,15 @@ class Facture
Utils::date_fr($content->souscription, 'd/m/Y') Utils::date_fr($content->souscription, 'd/m/Y')
); );
} }
else { elseif ($row->type_facture != CERFA) {
$row->contenu = implode("\n", array_map(function ($row) use ($currency) { $row->contenu = implode("\n", array_map(function ($row) use ($currency) {
return sprintf('%s : %s %s', $row->designation, Utils::money_format($row->prix), $currency); return sprintf('%s : %s %s', $row->designation, Utils::money_format($row->prix), $currency);
}, (array)$content)); }, (array)$content));
} }
else
{
$row->contenu = '';
}
}); });
$list->setPageSize(1000); $list->setPageSize(1000);
@ -498,6 +502,17 @@ class Facture
} }
} }
/* modif DD -- lecture et retour des textes de CERFA -- */
public function listTextesCerfa($menu = true)
{
$db = DB::getInstance();
$sel = ($menu) ? 'id, menu' : 'id, texte';
$query = 'SELECT '.$sel.' FROM "plugin_facturation_txt_cerfa" WHERE 1 ORDER BY id ;';
return $db->getAssoc($query);
}
public function getMoyenPaiement($code) public function getMoyenPaiement($code)
{ {
$db = DB::getInstance(); $db = DB::getInstance();

View File

@ -84,7 +84,7 @@
{/if} {/if}
</fieldset> </fieldset>
<fieldset data-types="t0 t1 t2"> <fieldset data-types="t0 t1">
<legend>Contenu</legend> <legend>Contenu</legend>
<dl> <dl>
@ -139,6 +139,19 @@
</dd> </dd>
</dl> </dl>
</fieldset> </fieldset>
<fieldset data-types="t2">
<legend>Contenu</legend>
<p><b>Montant du don</b>
{input type="money" name="total" label="Montant" required=1 source=$doc}
<dl>
{input type="select" name="forme_don" required=1 label="Forme du don" source=$doc options=$formes_don default=$doc.forme_don}
{input type="select" name="nature_don" required=1 label="Nature du don" source=$doc options=$natures_don default=$doc.nature_don}
{input type="select" name="texte_don" required=1 label="Texte explicatif" source=$doc options=$textes_don default=$doc.texte_don}
{input type="select" name="moyen_paiement" required=1 label="Moyen de paiement" source=$doc options=$moyens_paiement default=$doc.moyen_paiement}
</dl>
</fieldset>
<p class="submit" data-types="t0 t1 t2"> <p class="submit" data-types="t0 t1 t2">
{csrf_field key=$csrf_key} {csrf_field key=$csrf_key}

View File

@ -39,7 +39,7 @@ if (version_compare($infos->version, '0.3.0', '<'))
$db->exec('DROP TABLE `plugin_facturation_config`;'); $db->exec('DROP TABLE `plugin_facturation_config`;');
} }
// 0.4.0 - Migration Facturation\Config vers la table plugins // 0.4.0 -
if (version_compare($infos->version, '0.4.0', '<')) if (version_compare($infos->version, '0.4.0', '<'))
{ {
$db->exec(<<<EOT $db->exec(<<<EOT
@ -84,7 +84,7 @@ EOT
} }
// 0.6.0 - Migration Facturation\Config vers la table plugins // 0.6.0 -
if (version_compare($infos->version, '0.6.0', '<')) if (version_compare($infos->version, '0.6.0', '<'))
{ {
$r = $db->first('SELECT id, total FROM plugin_facturation_factures;'); $r = $db->first('SELECT id, total FROM plugin_facturation_factures;');
@ -113,8 +113,9 @@ if (version_compare($infos->version, '0.6.0', '<'))
ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures; ALTER TABLE plugin_facturation_factures_tmp RENAME TO plugin_facturation_factures;
EOT EOT
); );
foreach($factures = $facture->listAll() as $k=>$f) $factures = $facture->listAll();
foreach($factures as $k=>$f)
{ {
foreach($f->contenu as $line => $content) foreach($f->contenu as $line => $content)
{ {
@ -141,4 +142,54 @@ EOT
$path = __DIR__.'/data/default_sign.png'; $path = __DIR__.'/data/default_sign.png';
$png = (new File)->createAndStore('skel/plugin/facturation','sign.png', $path, null); $png = (new File)->createAndStore('skel/plugin/facturation','sign.png', $path, null);
} }
}
// 0.6.2 -
if (version_compare($infos->version, '0.6.2', '<'))
{
$db->exec(<<<EOT
INSERT OR IGNORE INTO plugin_facturation_paiement
(code, nom) VALUES ('HA', 'HelloAsso');
INSERT OR IGNORE INTO plugin_facturation_paiement
(code, nom) VALUES ('AU', 'Autre');
CREATE TABLE IF NOT EXISTS
plugin_facturation_txt_cerfa
(
id PRIMARY KEY,
menu TEXT NOT NULL UNIQUE,
texte TEXT NOT NULL
);
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
("id","menu","texte") VALUES ('0','Aucun','');
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
("id","menu","texte")
VALUES ('1','HelloAsso','Don via HelloAsso');
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
("id","menu","texte")
VALUES ('2','Frais de déplacement',
'Renonciation aux remboursements de frais de déplacement');
INSERT OR IGNORE INTO plugin_facturation_txt_cerfa
("id","menu","texte")
VALUES ('3','Don en nature','Don en nature');
EOT
);
// Migration CERFA
$factures = $facture->listAll();
foreach($factures as $k=>$f)
{
if ($f->type_facture != CERFA)
{
continue;
}
$f->contenu = ['forme' => 1, 'nature' => 1, 'texte' => 0];
$data = (array) $f;
unset($data['id']);
unset($data['date_emission']);
unset($data['date_echeance']);
$facture->edit($f->id, $data);
}
} }

View File

@ -35,6 +35,12 @@ if (qg('copy') !== null && $f = $facture->get((int)qg('copy'))) {
$doc['base_receveur'] = $f->receveur_membre ? 'membre' : 'client'; $doc['base_receveur'] = $f->receveur_membre ? 'membre' : 'client';
$doc['client'] = $f->receveur_id; $doc['client'] = $f->receveur_id;
$doc['membre'] = $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'];
}
} }
$tpl->assign('require_number', $require_number); $tpl->assign('require_number', $require_number);
@ -43,6 +49,15 @@ $tpl->assign('number_pattern', PATTERNS_LIST[$plugin->getConfig('pattern')]);
$tpl->assign('moyens_paiement', $moyens_paiement); $tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES'); $tpl->assign('moyen_paiement', f('moyen_paiement') ?: '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 (f('save')) if (f('save'))
{ {
$form->check($csrf_key, [ $form->check($csrf_key, [
@ -78,21 +93,29 @@ if (f('save'))
'moyen_paiement' => f('moyen_paiement'), 'moyen_paiement' => f('moyen_paiement'),
'toto' => 0 'toto' => 0
]; ];
$truc['type_facture'] = f('type');
if (in_array(f('type'), [DEVIS, FACT, CERFA])) if (in_array(f('type'), [DEVIS, FACT]))
{ {
$truc['type_facture'] = f('type');
}
foreach(f('designation') as $k=>$value)
{
$truc['contenu'][$k]['designation'] = $value;
$truc['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
$truc['toto'] += Utils::moneyToInteger(f('prix')[$k]);
}
$truc['total'] = $truc['toto'];
unset($truc['toto']);
foreach(f('designation') as $k=>$value)
{
$truc['contenu'][$k]['designation'] = $value;
$truc['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
$truc['toto'] += Utils::moneyToInteger(f('prix')[$k]);
}
$truc['total'] = $truc['toto'];
unset($truc['toto']);
}
elseif (f('type') == CERFA)
{
$truc['contenu'] = [
'forme' => f('forme_don'),
'nature' => f('nature_don'),
'texte' => f('texte_don')];
unset($truc['toto']);
$truc['total'] = Utils::moneyToInteger(f('total'));
}
if (f('base_receveur') == 'client') if (f('base_receveur') == 'client')
{ {
$truc['receveur_membre'] = 0; $truc['receveur_membre'] = 0;

View File

@ -18,6 +18,15 @@ $moyens_paiement = $facture->listMoyensPaiement(true);
$tpl->assign('moyens_paiement', $moyens_paiement); $tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES'); $tpl->assign('moyen_paiement', f('moyen_paiement') ?: '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());
qv(['id' => 'required|numeric']); qv(['id' => 'required|numeric']);
$id = (int) qg('id'); $id = (int) qg('id');
@ -66,21 +75,30 @@ if(f('save'))
'moyen_paiement' => f('moyen_paiement'), 'moyen_paiement' => f('moyen_paiement'),
'toto' => 0 'toto' => 0
]; ];
$truc['type_facture'] = f('type');
if (in_array(f('type'), [DEVIS, FACT, CERFA])) if (in_array(f('type'), [DEVIS, FACT]))
{ {
$truc['type_facture'] = f('type'); foreach(f('designation') as $k=>$value)
{
$truc['contenu'][$k]['designation'] = $value;
$truc['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
$truc['toto'] += Utils::moneyToInteger(f('prix')[$k]);
}
$truc['total'] = $truc['toto'];
unset($truc['toto']);
}
elseif ( f('type') == CERFA )
{
$truc['contenu'] = [
'forme' => f('forme_don'),
'nature' => f('nature_don'),
'texte' => f('texte_don')];
$truc['total'] = Utils::moneyToInteger(f('total'));
unset($truc['toto']);
} }
foreach(f('designation') as $k=>$value)
{
$truc['contenu'][$k]['designation'] = $value;
$truc['contenu'][$k]['prix'] = Utils::moneyToInteger(f('prix')[$k]);
$truc['toto'] += Utils::moneyToInteger(f('prix')[$k]);
}
$truc['total'] = $truc['toto'];
unset($truc['toto']);
if (f('base_receveur') == 'client') if (f('base_receveur') == 'client')
{ {
@ -206,7 +224,13 @@ $doc['membre'] = $f->receveur_id;
$doc['date_emission'] = strtotime(f('date_emission')) ?: $f->date_emission; $doc['date_emission'] = strtotime(f('date_emission')) ?: $f->date_emission;
$doc['date_echeance'] = strtotime(f('date_echeance')) ?: $f->date_echeance; // Smarty m'a saoulé pour utiliser form_field|date_fr:--- $doc['date_echeance'] = strtotime(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'];
}
$tpl->assign('doc', $doc); $tpl->assign('doc', $doc);
$radio['type'] = f('type')??$doc['type']; $radio['type'] = f('type')??$doc['type'];
@ -223,7 +247,7 @@ $prix = [];
// C'est un peu l'équivalent de form_field, mais j'avais écrit ça avant // 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 // et oulala, c'est un peu complexe, faudrait réfléchir keskivomieux
$from_user = false; $from_user = false;
if ($f->type_facture != COTIS) if (in_array($f->type_facture, [DEVIS, FACT]))
{ {
if (($d = f('designation')) && ($p = f('prix'))) if (($d = f('designation')) && ($p = f('prix')))
{ {

View File

@ -309,6 +309,7 @@ elseif ($f->type_facture == CERFA)
$doc = 'Reçu de don n°'. $f->numero; $doc = 'Reçu de don n°'. $f->numero;
$url = WWW_URL; $url = WWW_URL;
$libelles = $facture->listTextesCerfa(false);
$t['numero'] = $f->numero; $t['numero'] = $f->numero;
$t['nom_asso'] = $config->get('nom_asso'); $t['nom_asso'] = $config->get('nom_asso');
@ -332,6 +333,10 @@ elseif ($f->type_facture == CERFA)
$t['m'] = utf8_decode($f->date_emission->format('m')); $t['m'] = utf8_decode($f->date_emission->format('m'));
$t['Y'] = utf8_decode($f->date_emission->format('Y')); $t['Y'] = utf8_decode($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'] = ''; $t['art200'] = $t['art238'] = $t['art885'] = '';
if($plugin->getConfig('droit_art200')){ if($plugin->getConfig('droit_art200')){
$t['art200'] = 'X'; $t['art200'] = 'X';
@ -343,15 +348,41 @@ elseif ($f->type_facture == CERFA)
$t['art885'] = 'X'; $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){ switch ($f->moyen_paiement){
case 'ES': case 'ES':
$t['pos'] = ' top: 158.2mm; left: 15mm;'; $t['pos'] = 'left: 15mm;';
break; break;
case 'CH': case 'CH':
$t['pos'] = ' top: 158.2mm; left: 57.3mm;'; $t['pos'] = 'left: 57.3mm;';
break; break;
default: default:
$t['pos'] = ' top: 158.2mm; left: 115.2mm;'; $t['pos'] = 'left: 115.2mm;';
} }
$t['d2'] = utf8_decode($f->date_echeance->format('d')); $t['d2'] = utf8_decode($f->date_echeance->format('d'));
@ -436,11 +467,10 @@ elseif ($f->type_facture == CERFA)
<div style="top: 96mm; left: 53mm;">${t['art200']}</div> <div style="top: 96mm; left: 53mm;">${t['art200']}</div>
<div style="top: 96mm; left: 103mm;">${t['art238']}</div> <div style="top: 96mm; left: 103mm;">${t['art238']}</div>
<div style="top: 96mm; left: 153.0mm;">${t['art885']}</div> <div style="top: 96mm; left: 153.0mm;">${t['art885']}</div>
<div style="top: 113mm; ${t['frm']}">X</div>
<div style="top: 113mm; left: 115mm;">X</div> <div style="top: 136mm; ${t['nat']}">X</div>
<div style="top: 136mm; left: 15mm;">X</div> <div style="top: 142mm; left: 25mm;">${t['texte']}</div>
<div style="top: 158.2mm; ${t['pos']}">X</div>
<div style="${t['pos']}">X</div>
<div style="top: 239mm; left: 139mm;">${t['d2']}</div> <div style="top: 239mm; left: 139mm;">${t['d2']}</div>
<div style="top: 239mm; left: 148mm;">${t['m2']}</div> <div style="top: 239mm; left: 148mm;">${t['m2']}</div>