Amélioration contrôles saisie facture

This commit is contained in:
Jean-Christophe Engel 2025-02-26 11:02:45 +01:00
parent 6e2ee31670
commit f63f3b6ecd
2 changed files with 52 additions and 39 deletions

View File

@ -96,8 +96,13 @@ $form->runIf(f('save') && !$form->hasErrors(),
{ {
foreach(f('designation') as $k=>$value) foreach(f('designation') as $k=>$value)
{ {
if ($value != '' && f('prix')[$k] == null) { if (empty($value) && f('prix')[$k] != null) {
throw new UserException("Il manque la désignation de la ligne " . $k+1 . " !!");
}
elseif ($value != '' && f('prix')[$k] == null) {
throw new UserException('Il manque le prix sur la ligne '. $k+1 . ' !!'); throw new UserException('Il manque le prix sur la ligne '. $k+1 . ' !!');
} elseif (empty($value) && f('prix')[$k] == null) {
continue;
} }
$data['contenu'][$k]['designation'] = $value; $data['contenu'][$k]['designation'] = $value;
@ -106,6 +111,9 @@ $form->runIf(f('save') && !$form->hasErrors(),
} }
$data['total'] = $data['toto']; $data['total'] = $data['toto'];
unset($data['toto']); unset($data['toto']);
if (! isset($data['contenu'])) {
throw new UserException("Aucune désignation ni aucun prix saisi !!");
}
} }
elseif ( f('type') == CERFA ) elseif ( f('type') == CERFA )
{ {
@ -314,8 +322,10 @@ if (in_array($radio['type'], [DEVIS, FACT]))
} }
} }
else { else {
/*
$designations = ['Exemple']; $designations = ['Exemple'];
$prix = [250]; $prix = [250];
*/
} }
} }

View File

@ -144,10 +144,13 @@ class Facture
unset($datas[$k]['prix']); unset($datas[$k]['prix']);
continue; continue;
} }
elseif (empty($r['prix'])) elseif (! is_numeric($r['prix']) && empty($r['prix']))
{ {
$datas[$k]['prix'] = 0; $datas[$k]['prix'] = 0;
} }
elseif (empty($r['designation'])) {
throw new UserException("Une au moins des désignations est absente.");
}
if (!is_int($r['prix'])) if (!is_int($r['prix']))
{ {
@ -157,7 +160,7 @@ class Facture
$total += $r['prix']; $total += $r['prix'];
} }
if($fac && !$total) if ($fac && count($datas['contenu']) == 0)
{ {
throw new UserException("Toutes les désignations/prix sont vides."); throw new UserException("Toutes les désignations/prix sont vides.");
} }