$type = 'virement'; } elseif (isset($_GET['dette'])) { $type = 'dette'; } elseif (isset($_GET['avance'])) { $type = null; } else { $type = Compta\Categories::RECETTES; } $error = false; if (!empty($_POST['save'])) { if (!Utils::CSRF_check('compta_saisie')) { $error = 'Une erreur est survenue, merci de renvoyer le formulaire.'; } else { try { if (is_null($type)) { $id = $journal->add(['libelle' => Utils::post('libelle'), 'montant' => Utils::post('montant'), 'date' => Utils::post('date'), 'compte_credit' => Utils::post('compte_credit'), 'compte_debit' => Utils::post('compte_debit'), 'numero_piece' => Utils::post('numero_piece'), 'remarques' => Utils::post('remarques'), 'id_auteur' => $user['id']]); } elseif ($type === 'virement') { $id = $journal->add(['libelle' => Utils::post('libelle'), 'montant' => Utils::post('montant'), 'date' => Utils::post('date'), 'compte_debit' => Utils::post('compte1'), 'compte_credit' => Utils::post('compte2'), 'numero_piece' => Utils::post('numero_piece'), 'remarques' => Utils::post('remarques'), 'id_auteur' => $user['id']]); } else { $cat = $cats->get(Utils::post('categorie')); if (!$cat) { throw new UserException('Il faut choisir une catégorie.'); } if ($type == 'dette') { if (!trim(Utils::post('compte')) || Utils::post('compte') != 4010 && Utils::post('compte') != 4110) { throw new UserException('Type de dette invalide.'); } } else { if (Utils::post('moyen_paiement') == 'ES') { $a = Compta\Comptes::CAISSE; $b = $cat['compte'];