diff --git a/data/schema.sql b/data/schema.sql index cf3fa58..b108bb3 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -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 ('TI', 'TIP'); 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 ( -- id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, diff --git a/data/schema_remove.sql b/data/schema_remove.sql index 2a3e2dc..e346aa2 100644 --- a/data/schema_remove.sql +++ b/data/schema_remove.sql @@ -1,4 +1,5 @@ DROP TABLE `plugin_facturation_factures`; DROP TABLE `plugin_facturation_clients`; DROP TABLE `plugin_facturation_paiement`; +DROP TABLE `plugin_facturation_txt_cerfa`; -- DROP TABLE `plugin_facturation_produits`; \ No newline at end of file diff --git a/lib/Facture.php b/lib/Facture.php index ece72c0..e1ecae7 100644 --- a/lib/Facture.php +++ b/lib/Facture.php @@ -79,7 +79,7 @@ class Facture { throw new UserException("La valeur de $k est vide"); } - + switch($k) { 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.'); } - + $db->insert('plugin_facturation_factures', $data); $id = $db->lastInsertRowId(); @@ -384,11 +384,15 @@ class Facture Utils::date_fr($content->souscription, 'd/m/Y') ); } - else { + elseif ($row->type_facture != CERFA) { $row->contenu = implode("\n", array_map(function ($row) use ($currency) { return sprintf('%s : %s %s', $row->designation, Utils::money_format($row->prix), $currency); }, (array)$content)); } + else + { + $row->contenu = ''; + } }); $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) { $db = DB::getInstance(); diff --git a/templates/_form.tpl b/templates/_form.tpl index 8a55b0c..666e85e 100644 --- a/templates/_form.tpl +++ b/templates/_form.tpl @@ -84,7 +84,7 @@ {/if} -
+
Contenu
@@ -139,6 +139,19 @@
+ +
+ Contenu +

Montant du don + {input type="money" name="total" label="Montant" required=1 source=$doc} +

+ {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} +
+ +

{csrf_field key=$csrf_key} diff --git a/upgrade.php b/upgrade.php index 512acb8..47b6cc6 100644 --- a/upgrade.php +++ b/upgrade.php @@ -39,7 +39,7 @@ if (version_compare($infos->version, '0.3.0', '<')) $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', '<')) { $db->exec(<<version, '0.6.0', '<')) { $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; EOT ); - - foreach($factures = $facture->listAll() as $k=>$f) + + $factures = $facture->listAll(); + foreach($factures as $k=>$f) { foreach($f->contenu as $line => $content) { @@ -141,4 +142,54 @@ EOT $path = __DIR__.'/data/default_sign.png'; $png = (new File)->createAndStore('skel/plugin/facturation','sign.png', $path, null); } +} + +// 0.6.2 - +if (version_compare($infos->version, '0.6.2', '<')) +{ + $db->exec(<<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); + } } \ No newline at end of file diff --git a/www/admin/facture_ajouter.php b/www/admin/facture_ajouter.php index 7d56042..3f458e9 100644 --- a/www/admin/facture_ajouter.php +++ b/www/admin/facture_ajouter.php @@ -35,6 +35,12 @@ if (qg('copy') !== null && $f = $facture->get((int)qg('copy'))) { $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']; + } } $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('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')) { $form->check($csrf_key, [ @@ -78,21 +93,29 @@ if (f('save')) 'moyen_paiement' => f('moyen_paiement'), 'toto' => 0 ]; - - if (in_array(f('type'), [DEVIS, FACT, CERFA])) + $truc['type_facture'] = f('type'); + 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') { $truc['receveur_membre'] = 0; diff --git a/www/admin/facture_modifier.php b/www/admin/facture_modifier.php index 6b950fc..d261712 100644 --- a/www/admin/facture_modifier.php +++ b/www/admin/facture_modifier.php @@ -18,6 +18,15 @@ $moyens_paiement = $facture->listMoyensPaiement(true); $tpl->assign('moyens_paiement', $moyens_paiement); $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']); $id = (int) qg('id'); @@ -66,21 +75,30 @@ if(f('save')) 'moyen_paiement' => f('moyen_paiement'), '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') { @@ -206,7 +224,13 @@ $doc['membre'] = $f->receveur_id; $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:--- - +/* 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); $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 // et oulala, c'est un peu complexe, faudrait réfléchir keskivomieux $from_user = false; -if ($f->type_facture != COTIS) +if (in_array($f->type_facture, [DEVIS, FACT])) { if (($d = f('designation')) && ($p = f('prix'))) { diff --git a/www/admin/pdf.php b/www/admin/pdf.php index 6d697f6..33eaff2 100644 --- a/www/admin/pdf.php +++ b/www/admin/pdf.php @@ -309,6 +309,7 @@ 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'); @@ -332,6 +333,10 @@ elseif ($f->type_facture == CERFA) $t['m'] = utf8_decode($f->date_emission->format('m')); $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'] = ''; if($plugin->getConfig('droit_art200')){ $t['art200'] = 'X'; @@ -343,15 +348,41 @@ elseif ($f->type_facture == CERFA) $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'] = ' top: 158.2mm; left: 15mm;'; + $t['pos'] = 'left: 15mm;'; break; case 'CH': - $t['pos'] = ' top: 158.2mm; left: 57.3mm;'; + $t['pos'] = 'left: 57.3mm;'; break; default: - $t['pos'] = ' top: 158.2mm; left: 115.2mm;'; + $t['pos'] = 'left: 115.2mm;'; } $t['d2'] = utf8_decode($f->date_echeance->format('d')); @@ -436,11 +467,10 @@ elseif ($f->type_facture == CERFA)

${t['art200']}
${t['art238']}
${t['art885']}
- -
X
-
X
- -
X
+
X
+
X
+
${t['texte']}
+
X
${t['d2']}
${t['m2']}