Ajout : ./garradin
[garradin.git] / www / admin / compta / operations / index.php
1 <?php
2 namespace Garradin;
3
4 require_once __DIR__ . '/../_inc.php';
5
6 $cats = new Compta_Categories;
7 $cat = $type = false;
8
9 if (utils::get('cat'))
10 {
11 $cat = $cats->get(utils::get('cat'));
12
13 if (!$cat)
14 {
15 throw new UserException("La catégorie demandée n'existe pas.");
16 }
17
18 $type = $cat['type'];
19 }
20 else
21 {
22 if (isset($_GET['autres']))
23 $type = Compta_Categories::AUTRES;
24 elseif (isset($_GET['depenses']))
25 $type = Compta_Categories::DEPENSES;
26 else
27 $type = Compta_Categories::RECETTES;
28 }
29
30 $journal = new Compta_Journal;
31
32 $list = $journal->getListForCategory($type === Compta_Categories::AUTRES ? null : $type, $cat ? $cat['id'] : null);
33
34 $tpl->assign('categorie', $cat);
35 $tpl->assign('type', $type);
36
37 if ($type !== Compta_Categories::AUTRES)
38 {
39 $tpl->assign('liste_cats', $cats->getList($type));
40 }
41
42 $total = 0.0;
43 foreach ($list as &$row)
44 {
45 $db = DB::getInstance();
46 $row['montant'] =
47 $db->simpleQuerySingle('
48 SELECT sum(CASE WHEN montant > 0 THEN montant ELSE 0 END)
49 FROM compta_flux
50 WHERE compta_flux.id_journal = ?', false, $row['id']);
51 $total += round((float) $row['montant'], 2);
52 }
53 $tpl->assign('journal', $list);
54 $tpl->assign('total', $total);
55
56 $tpl->display('admin/compta/operations/index.tpl');
57
58 ?>