660b879875fbd4a4f032c73115d8eb7493c1aaa0
4 require_once __DIR__
. '/../_inc.php';
6 if ($user['droits']['compta'] < Membres
::DROIT_ADMIN
)
8 throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
11 $journal = new Compta_Journal
;
12 $cats = new Compta_Categories
;
13 $banques = new Compta_Comptes_Bancaires
;
15 $operation = $journal->get(utils
::get('id'));
19 throw new UserException("L'opération demandée n'existe pas.");
22 if ($operation['id_categorie'])
24 $categorie = $cats->get($operation['id_categorie']);
31 if ($categorie && $categorie['type'] != Compta_Categories
::AUTRES
)
33 $type = $categorie['type'];
42 if (!empty($_POST['save']))
44 if (!utils
::CSRF_check('compta_modifier_'.$operation['id']))
46 $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
54 $journal->edit($operation['id'], [
55 'libelle' => utils
::post('libelle'),
56 'montant' => utils
::post('montant'),
57 'date' => utils
::post('date'),
58 'compte_credit' => utils
::post('compte_credit'),
59 'compte_debit' => utils
::post('compte_debit'),
60 'numero_piece' => utils
::post('numero_piece'),
61 'remarques' => utils
::post('remarques'),
66 $cat = $cats->get(utils
::post('id_categorie'));
70 throw new UserException('Il faut choisir une catégorie.');
73 if (!array_key_exists(utils
::post('moyen_paiement'), $cats->listMoyensPaiement()))
75 throw new UserException('Moyen de paiement invalide.');
78 if (utils
::post('moyen_paiement') == 'ES')
80 $a = Compta_Comptes
::CAISSE
;
85 if (!trim(utils
::post('banque')))
87 throw new UserException('Le compte bancaire choisi est invalide.');
90 if (!array_key_exists(utils
::post('banque'), $banques->getList()))
92 throw new UserException('Le compte bancaire choisi n\'existe pas.');
95 $a = utils
::post('banque');
99 if ($type == Compta_Categories
::DEPENSES
)
104 elseif ($type == Compta_Categories
::RECETTES
)
110 $journal->edit($operation['id'], [
111 'libelle' => utils
::post('libelle'),
112 'montant' => utils
::post('montant'),
113 'date' => utils
::post('date'),
114 'moyen_paiement'=> utils
::post('moyen_paiement'),
115 'numero_cheque' => utils
::post('numero_cheque'),
116 'compte_credit' => $credit,
117 'compte_debit' => $debit,
118 'numero_piece' => utils
::post('numero_piece'),
119 'remarques' => utils
::post('remarques'),
120 'id_categorie' => (int)$cat['id'],
124 utils
::redirect('/admin/compta/operations/voir.php?id='.(int)$operation['id']);
126 catch (UserException
$e)
128 $error = $e->getMessage();
133 $tpl->assign('error', $error);
135 $tpl->assign('type', $type);
139 $tpl->assign('comptes', $comptes->listTree());
143 $tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
144 $tpl->assign('categories', $cats->getList($type));
145 $tpl->assign('comptes_bancaires', $banques->getList());
148 $tpl->assign('operation', $operation);
150 $tpl->display('admin/compta/operations/modifier.tpl');