diff --git a/lib/Facture.php b/lib/Facture.php index 43fc626..21bf50e 100644 --- a/lib/Facture.php +++ b/lib/Facture.php @@ -55,16 +55,20 @@ class Facture switch($k) { case 'type_facture': - if (!array_key_exists($datas[$k], $this->type)) - { + if (!array_key_exists($datas[$k], $this->type)) { throw new UserException("$k est de type non-attendue ($data)."); } + if ($datas[$k] > 1) { + $recu = true; + } + else { + $recu = false; + } break; case 'receveur_membre': case 'reglee': case 'archivee': - if ($datas[$k] != 1 && $datas[$k] != 0) - { + if ($datas[$k] != 1 && $datas[$k] != 0) { throw new UserException("$k est de valeur non-attendue ($data)."); } break; @@ -94,13 +98,7 @@ class Facture unset($cats); break; case 'contenu': - $tmp = false; - if ($datas['type_facture'] > 1) { - // $datas[$k] = null; - // break; - $tmp = true; - } - if (!$tmp && !is_array($datas[$k]) || empty($datas[$k])) { + if (!$recu && (!is_array($datas[$k]) || empty($datas[$k]))) { throw new UserException("Le contenu du document est vide ($data)."); } $total = 0; @@ -117,18 +115,14 @@ class Facture } $total += $r['prix']; } - if($vide) + if(!$recu && $vide) { throw new UserException("Toutes les désignations/prix sont vides."); } $datas[$k] = json_encode($datas[$k]); break; case 'total': - if ($datas['type_facture'] > 1) { - // $datas[$k] = null; - break; - } - if (!isset($datas['contenu'])) { + if (!$recu && !isset($datas['contenu'])) { throw new UserException("Pas de contenu fourni pour vérifier le total."); } if ($total != $datas[$k]) diff --git a/templates/_js.tpl b/templates/_js.tpl new file mode 100644 index 0000000..fa2d0a1 --- /dev/null +++ b/templates/_js.tpl @@ -0,0 +1,43 @@ + \ No newline at end of file diff --git a/templates/facture_ajouter.tpl b/templates/facture_ajouter.tpl index 4123285..a91588b 100644 --- a/templates/facture_ajouter.tpl +++ b/templates/facture_ajouter.tpl @@ -15,6 +15,7 @@
{csrf_field key="ajout_facture"} diff --git a/templates/facture_modifier.tpl b/templates/facture_modifier.tpl index ea4a5a6..eeae1ac 100644 --- a/templates/facture_modifier.tpl +++ b/templates/facture_modifier.tpl @@ -15,9 +15,9 @@