From f63f3b6ecd159b5ce735e432cd0adf3084201b3d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Engel Date: Wed, 26 Feb 2025 11:02:45 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20contr=C3=B4les=20saisie=20f?= =?UTF-8?q?acture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/_facture_common.php | 84 ++++++++++++++++++++++----------------- lib/Facture.php | 7 +++- 2 files changed, 52 insertions(+), 39 deletions(-) diff --git a/admin/_facture_common.php b/admin/_facture_common.php index 10b10a4..e0ac6e5 100644 --- a/admin/_facture_common.php +++ b/admin/_facture_common.php @@ -94,10 +94,15 @@ $form->runIf(f('save') && !$form->hasErrors(), $data['type_facture'] = f('type'); if (in_array(f('type'), [DEVIS, FACT])) { - 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 . ' !!'); + } elseif (empty($value) && f('prix')[$k] == null) { + continue; } $data['contenu'][$k]['designation'] = $value; @@ -106,6 +111,9 @@ $form->runIf(f('save') && !$form->hasErrors(), } $data['total'] = $data['toto']; unset($data['toto']); + if (! isset($data['contenu'])) { + throw new UserException("Aucune désignation ni aucun prix saisi !!"); + } } elseif ( f('type') == CERFA ) { @@ -142,45 +150,45 @@ $form->runIf(f('save') && !$form->hasErrors(), $form->runIf(f('select_cotis') && !$form->hasErrors(), function () use ($step) - { - $step = true; - }, 'add_cotis_1'); + { + $step = true; + }, 'add_cotis_1'); $form->runIf(f('add_cotis') && !$form->hasErrors(), function () use ($radio, $fields, $facture, $form) - { - $radio['type'] = f('cotisation'); - try - { - $num = (int) str_replace('cotis_', '', $radio['type']); - foreach($fields as $field) - { - $cotis[$field] = f($field.'_'.$num); - } + { + $radio['type'] = f('cotisation'); + try + { + $num = (int) str_replace('cotis_', '', $radio['type']); + foreach($fields as $field) + { + $cotis[$field] = f($field.'_'.$num); + } - $r = $facture->getCotis(f('membre_cotis'), $cotis['id']); - $r = $r[0]; + $r = $facture->getCotis(f('membre_cotis'), $cotis['id']); + $r = $r[0]; - $data = [ - 'type_facture' => COTIS, - 'numero' => f('numero_facture'), - 'receveur_membre' => 1, - 'receveur_id' => f('membre_cotis'), - 'date_emission' => f('date_emission'), - 'moyen_paiement' => 'AU', - 'total' => $r->paid_amount ?? $r->amount, - 'contenu' => ['id' => $cotis['id'], - 'intitule' => $cotis['label'], - 'souscription' => $cotis['date'], - 'expiration' => $cotis['expiry'] ] - ]; + $data = [ + 'type_facture' => COTIS, + 'numero' => f('numero_facture'), + 'receveur_membre' => 1, + 'receveur_id' => f('membre_cotis'), + 'date_emission' => f('date_emission'), + 'moyen_paiement' => 'AU', + 'total' => $r->paid_amount ?? $r->amount, + 'contenu' => ['id' => $cotis['id'], + 'intitule' => $cotis['label'], + 'souscription' => $cotis['date'], + 'expiration' => $cotis['expiry'] ] + ]; - } - catch (UserException $e) - { - $form->addError($e->getMessage()); - } - }, 'add_cotis_2'); + } + catch (UserException $e) + { + $form->addError($e->getMessage()); + } + }, 'add_cotis_2'); if (! $form->hasErrors()) { @@ -314,8 +322,10 @@ if (in_array($radio['type'], [DEVIS, FACT])) } } else { - $designations = ['Exemple']; - $prix = [250]; + /* + $designations = ['Exemple']; + $prix = [250]; + */ } } diff --git a/lib/Facture.php b/lib/Facture.php index 9baabf8..0abd435 100644 --- a/lib/Facture.php +++ b/lib/Facture.php @@ -144,10 +144,13 @@ class Facture unset($datas[$k]['prix']); continue; } - elseif (empty($r['prix'])) + elseif (! is_numeric($r['prix']) && empty($r['prix'])) { $datas[$k]['prix'] = 0; } + elseif (empty($r['designation'])) { + throw new UserException("Une au moins des désignations est absente."); + } if (!is_int($r['prix'])) { @@ -157,7 +160,7 @@ class Facture $total += $r['prix']; } - if($fac && !$total) + if ($fac && count($datas['contenu']) == 0) { throw new UserException("Toutes les désignations/prix sont vides."); }