Élimination de form->check() pour version 1.3

This commit is contained in:
Jean-Christophe Engel 2023-10-19 10:24:49 +02:00
parent 0ed03eb362
commit 2454883ffc
4 changed files with 150 additions and 209 deletions

View File

@ -49,27 +49,9 @@ if ( !$target ) {
}
// 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())
$data=[];
$form->runIf(f('save') && !$form->hasErrors(),
function () use ($client, &$data)
{
try
{
@ -120,37 +102,24 @@ if (f('save'))
$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',
]);
}, $csrf_key);
$radio['type'] = f('cotisation');
if (!$form->hasErrors())
$form->runIf(f('select_cotis') && !$form->hasErrors(),
function () use ($step)
{
$step = true;
}, 'add_cotis_1');
$form->runIf(f('add_cotis') && !$form->hasErrors(),
function () use ($radio, $fields, $facture)
{
$radio['type'] = f('cotisation');
try
{
$num = (int) str_replace('cotis_', '', $radio['type']);
@ -181,8 +150,7 @@ elseif (f('add_cotis'))
{
$form->addError($e->getMessage());
}
}
}
}, 'add_cotis_2');
if ($step)
{
@ -195,7 +163,7 @@ if ($step)
$form->addError($e->getMessage());
}
}
elseif (isset($data))
elseif (count($data) > 0)
{
if ($target)
{

View File

@ -16,18 +16,8 @@ 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())
$form->runIf(f('save') && !$form->hasErrors(),
function () use ($client, $id)
{
try
{
@ -46,8 +36,7 @@ if(f('save'))
{
$form->addError($e->getMessage());
}
}
}
}, 'edit_client');
$tpl->assign('client', $c);

View File

@ -6,18 +6,8 @@ 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())
$form->runIf(f('add') && !$form->hasErrors(),
function () use ($client)
{
try
{
@ -36,9 +26,7 @@ if(f('add'))
{
$form->addError($e->getMessage());
}
}
}
}, 'add_client');
$list = $client->list();
$list->loadFromQueryString();

View File

@ -17,11 +17,8 @@ if (!$client)
throw new UserException("Ce document n'existe pas.");
}
if (f('delete'))
{
$form->check('delete_doc_'.$f->id);
if (!$form->hasErrors())
$form->runIf(f('delete') && !$form->hasErrors(),
function () use ($facture, $f)
{
try {
$facture->delete($f->id);
@ -31,8 +28,7 @@ if (f('delete'))
{
$form->addError($e->getMessage());
}
}
}
});
$tpl->assign('doc', $f);
$tpl->display(PLUGIN_ROOT . '/templates/facture_supprimer.tpl');