Mise en commun du code entre modifier et ajouter, moins de duplication à gérer

This commit is contained in:
bohwaz 2021-12-17 14:35:12 +01:00
parent a28b644795
commit 92408f663c
5 changed files with 239 additions and 457 deletions

View file

@ -14,14 +14,19 @@ $db = DB::getInstance();
$step = $radio = false;
$liste = [];
$csrf_key = 'ajout_facture';
$fields = $facture->recu_fields;
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
$moyens_paiement = $facture->listMoyensPaiement(true);
$doc = null;
$tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
if (f('add'))
{
$form->check('ajout_facture', [
$form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y',
@ -31,7 +36,7 @@ if (f('add'))
'base_receveur' => 'required|in:membre,client',
// 'client' => '',
// 'membre' => '',
'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
'designation' => 'array|required',
'prix' => 'array|required'
]);
@ -214,7 +219,7 @@ $date = new \DateTime;
$date->setTimestamp(time());
$tpl->assign('date', $date->format('d/m/Y'));
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite'));
$tpl->assign(compact('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;'));

View file

@ -13,9 +13,9 @@ $db = DB::getInstance();
$step = false;
$liste = [];
$fields = $facture->recu_fields;
$moyens_paiement = $facture->listMoyensPaiement(true);
$tpl->assign('moyens_paiement', $facture->listMoyensPaiement());
$tpl->assign('moyens_paiement', $moyens_paiement);
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
qv(['id' => 'required|numeric']);
@ -26,11 +26,13 @@ if (!$f = $facture->get($id))
throw new UserException("Ce document n'existe pas.");
}
$csrf_key = 'modifier_facture';
// Traitement
if(f('save'))
{
$form->check('modifier_facture', [
$form->check($csrf_key, [
'type' => 'required|in:'.implode(',', [DEVIS, FACT, CERFA]),
'numero_facture' => 'required|string',
'date_emission' => 'required|date_format:d/m/Y',
@ -40,7 +42,7 @@ if(f('save'))
'base_receveur' => 'required|in:membre,client',
// 'client' => '',
// 'membre' => '',
'moyen_paiement' => 'required|in:' . implode(',', array_keys($facture->listMoyensPaiement())),
'moyen_paiement' => 'required|in:' . implode(',', array_keys($moyens_paiement)),
'designation' => 'array|required',
'prix' => 'array|required'
]);
@ -193,7 +195,6 @@ if ($step)
// Affichage
$doc['moyens_paiement'] = $facture->listMoyensPaiement(true);
// $doc['moyen_paiement'] = $doc['moyens_paiement'][$f->moyen_paiement];
$doc['moyen_paiement'] = $f->moyen_paiement;
$doc['type'] = $f->type_facture;
@ -253,7 +254,7 @@ if ($f->type_facture != COTIS)
}
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite'));
$tpl->assign(compact('designations', 'prix', 'from_user', 'identite', 'csrf_key'));
$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;'));