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;'));