Overview
Comment:Modernisation: saisie compta / suppression exercice
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: eb64e665741028decafdfec347920eda42fe6561
User & Date: bohwaz on 2017-08-17 00:30:57
Other Links: branch diff | manifest | tags
Context
2017-08-17
00:49
Modernisation catégories compta check-in: ba738d8d9a user: bohwaz tags: dev
00:30
Modernisation: saisie compta / suppression exercice check-in: eb64e66574 user: bohwaz tags: dev
2017-08-14
01:27
Le mot de passe ne doit pas être obligatoire par défaut, parce que en fait dans 99% des cas on s'en fout qu'un membre ait un mot de passe check-in: 87feaa92c2 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Compta/Comptes.php from [aaa9c6fdc2] to [62194cfbde].

285
286
287
288
289
290
291




292
293
294

295
296
297
298
299
300
301
285
286
287
288
289
290
291
292
293
294
295
296
297

298
299
300
301
302
303
304
305







+
+
+
+


-
+







    {
        $db = DB::getInstance();

        if ($include_children && $parent_id)
        {
            $where = $db->where('parent', 'LIKE', $parent_id . '%');
        }
        elseif ($include_children && !$parent_id)
        {
            $where = '1';
        }
        else
        {
            $where = $db->where('parent', $parent_id);
            $where = $db->where('parent', !$parent_id ? (int) $parent_id : (string) $parent_id);
        }

        $query = 'SELECT * FROM compta_comptes WHERE %s OR %s ORDER BY id;';
        $query = sprintf($query, $db->where('id', (string) $parent_id), $where);

        return $db->get($query);
    }

Modified src/include/lib/Garradin/Compta/Journal.php from [d0690cb385] to [da92b4acf3].

98
99
100
101
102
103
104
105
106


107
108
109
110
111
112
113
98
99
100
101
102
103
104


105
106
107
108
109
110
111
112
113







-
-
+
+







            ORDER BY date ASC;';

        $result = $db->get($query);
        $solde = 0.0;

        foreach ($result as &$row)
        {
            $solde += $row['solde'];
            $row['solde'] = $solde;
            $solde += $row->solde;
            $row->solde = $solde;
        }

        return $result;
    }

    public function add($data)
    {

Modified src/include/lib/Garradin/Template.php from [6ee6d1d6a7] to [a5df5d901f].

399
400
401
402
403
404
405
406

407
408
409

410
411

412
413

414
415

416
417
418

419
420
421
422

423
424

425
426
427
428
429

430
431
432
433
434
435
436
399
400
401
402
403
404
405

406
407
408

409
410

411
412

413
414

415
416
417

418
419
420
421

422
423

424
425
426
427
428

429
430
431
432
433
434
435
436







-
+


-
+

-
+

-
+

-
+


-
+



-
+

-
+




-
+







    $selected = isset($params['data'][$params['name']]) ? $params['data'][$params['name']] : Utils::post($name);

    $out = '<select name="'.$name.'" id="f_'.$name.'" class="large">';

    foreach ($comptes as $compte)
    {
        // Ne pas montrer les comptes désactivés
        if (!empty($compte['desactive']))
        if (!empty($compte->desactive))
            continue;

        if (!isset($compte['id'][1]) && empty($params['create']))
        if (!isset($compte->id[1]) && empty($params['create']))
        {
            $out.= '<optgroup label="'.htmlspecialchars($compte['libelle'], ENT_QUOTES, 'UTF-8', false).'" class="niveau_1"></optgroup>';
            $out.= '<optgroup label="'.htmlspecialchars($compte->libelle, ENT_QUOTES, 'UTF-8', false).'" class="niveau_1"></optgroup>';
        }
        elseif (!isset($compte['id'][2]) && empty($params['create']))
        elseif (!isset($compte->id[2]) && empty($params['create']))
        {
            if ($compte['id'] > 10)
            if ($compte->id > 10)
                $out.= '</optgroup>';

            $out.= '<optgroup label="'.htmlspecialchars($compte['id'] . ' - ' . $compte['libelle'], ENT_QUOTES, 'UTF-8', false).'" class="niveau_2">';
            $out.= '<optgroup label="'.htmlspecialchars($compte->id . ' - ' . $compte->libelle, ENT_QUOTES, 'UTF-8', false).'" class="niveau_2">';
        }
        else
        {
            $out .= '<option value="'.htmlspecialchars($compte['id'], ENT_QUOTES, 'UTF-8', false).'" class="niveau_'.strlen($compte['id']).'"';
            $out .= '<option value="'.htmlspecialchars($compte->id, ENT_QUOTES, 'UTF-8', false).'" class="niveau_'.strlen($compte->id).'"';

            if ($selected == $compte['id'])
            if ($selected == $compte->id)
            {
                $out .= ' selected="selected"';
            }

            $out .= '>' . htmlspecialchars($compte['id'] . ' - ' . $compte['libelle'], ENT_QUOTES, 'UTF-8', false);
            $out .= '>' . htmlspecialchars($compte->id . ' - ' . $compte->libelle, ENT_QUOTES, 'UTF-8', false);
            $out .= '</option>';
        }
    }

    $out .= '</optgroup>';
    $out .= '</select>';

Modified src/templates/admin/compta/comptes/journal.tpl from [8a4a9b424e] to [4fe6662efe].

1

2
3
4
5
6
7
8

1
2
3
4
5
6
7
8
-
+







{if isset($tpl.get.suivi)}
{if $suivi}
    {include file="admin/_head.tpl" title="Journal : %s - %s"|args:$compte.id:$compte.libelle current="compta/banques" body_id="rapport"}

    <ul class="actions">
        <li><a href="{$www_url}admin/compta/banques/">Comptes bancaires</a></li>
        <li><a href="{$www_url}admin/compta/comptes/journal.php?id={$id_caisse}">Journal de caisse</a></li>
    </ul>
{else}

Modified src/templates/admin/compta/exercices/supprimer.tpl from [74847df662] to [604797e2eb].

1
2
3
4
5

6
7
8
9
10
11
12
13
14
1
2



3


4
5
6
7
8
9
10


-
-
-
+
-
-







{include file="admin/_head.tpl" title="Supprimer un exercice" current="compta/exercices"}

{if $error}
    <p class="error">
        {$error}
{form_errors}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Supprimer un exercice</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer l'exercice «&nbsp;{$exercice.libelle}&nbsp;»

Modified src/templates/admin/compta/operations/saisir.tpl from [f694808ea6] to [e4a817f3eb].

1
2
3
4
5

6
7
8
9
10
11
12
13
14
1
2



3


4
5
6
7
8
9
10


-
-
-
+
-
-







{include file="admin/_head.tpl" title="Saisie d'une opération" current="compta/saisie" js=1}

{if $error}
    <p class="error">
        {$error}
{form_errors}
    </p>
{/if}

{if $ok}
    <p class="confirm">
        L'opération numéro <a href="{$www_url}admin/compta/operations/voir.php?id={$ok}">{$ok}</a> a été ajoutée.
        (<a href="{$www_url}admin/compta/operations/voir.php?id={$ok}">Voir l'opération</a>)
    </p>
{/if}

Modified src/www/admin/compta/comptes/journal.php from [d5dfdbe319] to [82a2dbba77].

8
9
10
11
12
13
14
15

16
17

18
19
20
21
22
23
24
25
26
27
28
29
30


31
32
8
9
10
11
12
13
14

15
16

17
18
19
20
21
22
23
24
25
26
27
28
29

30
31
32
33







-
+

-
+












-
+
+


if (!$compte)
{
    throw new UserException("Le compte demandé n'existe pas.");
}

$journal = new Compta\Journal;

$solde = $journal->getSolde($compte['id']);
$solde = $journal->getSolde($compte->id);

if (($compte['position'] & Compta\Comptes::ACTIF) || ($compte['position'] & Compta\Comptes::CHARGE))
if (($compte->position & Compta\Comptes::ACTIF) || ($compte->position & Compta\Comptes::CHARGE))
{
    $tpl->assign('credit', '-');
    $tpl->assign('debit', '+');
}
else
{
    $tpl->assign('credit', '+');
    $tpl->assign('debit', '-');
}

$tpl->assign('compte', $compte);
$tpl->assign('solde', $solde);
$tpl->assign('journal', $journal->getJournalCompte($compte['id']));
$tpl->assign('journal', $journal->getJournalCompte($compte->id));
$tpl->assign('suivi', qg('suivi'));

$tpl->display('admin/compta/comptes/journal.tpl');

Modified src/www/admin/compta/exercices/supprimer.php from [90312d8c29] to [5b9eced062].

10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
48
10
11
12
13
14
15
16

17
18
19
20
21


22
23

24




25
26
27
28
29
30
31
32
33

34
35
36
37
38

39
40
41







-
+




-
-


-
+
-
-
-
-









-
+




-



$exercice = $e->get((int)qg('id'));

if (!$exercice)
{
	throw new UserException('Exercice inconnu.');
}

if ($exercice['cloture'])
if ($exercice->cloture)
{
    throw new UserException('Impossible de supprimer un exercice clôturé.');
}

$error = false;

if (f('delete'))
{
    if (!Utils::CSRF_check('compta_supprimer_exercice_'.$exercice['id']))
    if ($form->check('compta_supprimer_exercice_'.$exercice->id))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try
        {
            $id = $e->delete($exercice->id);

            Utils::redirect('/admin/compta/exercices/');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('error', $error);
$tpl->assign('exercice', $exercice);

$tpl->display('admin/compta/exercices/supprimer.tpl');

Modified src/www/admin/compta/operations/saisir.php from [f05e543934] to [0528898813].

19
20
21
22
23
24
25
26
27

28
29
30
31






32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48








49
50
51
52
53
54
55
56
57
58
59
60
61








62
63
64
65
66

67
68
69
70
71
72
73
74
75
76


77
78
79
80
81
82
83

84
85
86

87
88
89
90

91
92
93
94
95

96
97
98
99
100
101


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

119
120
121
122
123
124
125
126





127
128
129
130
131
132




133
134
135
136

137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168

169
170
171

172
173
174
175
176

177
178

179
180
181
182

183
184
185
186

187
188
189
19
20
21
22
23
24
25


26

27


28
29
30
31
32
33



34
35
36
37
38
39
40








41
42
43
44
45
46
47
48
49
50
51
52
53








54
55
56
57
58
59
60
61
62
63
64
65

66
67
68
69
70
71
72
73
74


75
76
77
78
79
80
81
82

83
84
85

86
87
88
89

90
91
92
93
94

95
96
97
98
99


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

118
119
120
121





122
123
124
125
126
127
128




129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148

149
150
151
152
153


154
155
156
157
158
159
160
161
162

163
164
165

166
167
168

169
170
171
172
173

174
175

176
177
178
179

180
181
182
183

184
185
186
187







-
-
+
-

-
-
+
+
+
+
+
+
-
-
-
+






-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+





-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+




-
+








-
-
+
+






-
+


-
+



-
+




-
+




-
-
+
+
















-
+



-
-
-
-
-
+
+
+
+
+


-
-
-
-
+
+
+
+



-
+












-
+




-
-









-
+


-
+


-
+




-
+

-
+



-
+



-
+



elseif (null !== qg('dette'))
    $type = 'dette';
elseif (null !== qg('avance'))
    $type = null;
else
    $type = Compta\Categories::RECETTES;

$error = false;

if (f('save'))
if (!empty($_POST['save']))
{
    if (!Utils::CSRF_check('compta_saisie'))
    {
    $form->check('compta_saisie', [
        'libelle' => 'required',
        'date'    => 'date_format:Y-m-d|required',
        'montant' => 'money|required',
    ]);

        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    if (!$form->hasErrors())
    {
        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'],
                    'libelle'       =>  f('libelle'),
                    'montant'       =>  f('montant'),
                    'date'          =>  f('date'),
                    'compte_credit' =>  f('compte_credit'),
                    'compte_debit'  =>  f('compte_debit'),
                    'numero_piece'  =>  f('numero_piece'),
                    'remarques'     =>  f('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'],
                    'libelle'       =>  f('libelle'),
                    'montant'       =>  f('montant'),
                    'date'          =>  f('date'),
                    'compte_debit'  =>  f('compte1'),
                    'compte_credit' =>  f('compte2'),
                    'numero_piece'  =>  f('numero_piece'),
                    'remarques'     =>  f('remarques'),
                    'id_auteur'     =>  $user->id,
                ]);
            }
            else
            {
                $cat = $cats->get(Utils::post('categorie'));
                $cat = $cats->get(f('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))
                    if (!trim(f('compte')) ||
                        (f('compte') != 4010 && f('compte') != 4110))
                    {
                        throw new UserException('Type de dette invalide.');
                    }
                }
                else
                {
                    if (Utils::post('moyen_paiement') == 'ES')
                    if (f('moyen_paiement') == 'ES')
                    {
                        $a = Compta\Comptes::CAISSE;
                        $b = $cat['compte'];
                        $b = $cat->compte;
                    }
                    else
                    {
                        if (!trim(Utils::post('banque')))
                        if (!trim(f('banque')))
                        {
                            throw new UserException('Le compte bancaire choisi est invalide.');
                        }

                        if (!array_key_exists(Utils::post('banque'), $banques->getList()))
                        if (!array_key_exists(f('banque'), $banques->getList()))
                        {
                            throw new UserException('Le compte bancaire choisi n\'existe pas.');
                        }

                        $a = Utils::post('banque');
                        $b = $cat['compte'];
                        $a = f('banque');
                        $b = $cat->compte;
                    }
                }

                if ($type === Compta\Categories::DEPENSES)
                {
                    $debit = $b;
                    $credit = $a;
                }
                elseif ($type === Compta\Categories::RECETTES)
                {
                    $debit = $a;
                    $credit = $b;
                }
                elseif ($type === 'dette')
                {
                    $debit = $cat['compte'];
                    $credit = Utils::post('compte');
                    $credit = f('compte');
                }

                $id = $journal->add([
                    'libelle'       =>  Utils::post('libelle'),
                    'montant'       =>  Utils::post('montant'),
                    'date'          =>  Utils::post('date'),
                    'moyen_paiement'=>  ($type === 'dette') ? null : Utils::post('moyen_paiement'),
                    'numero_cheque' =>  ($type === 'dette') ? null : Utils::post('numero_cheque'),
                    'libelle'       =>  f('libelle'),
                    'montant'       =>  f('montant'),
                    'date'          =>  f('date'),
                    'moyen_paiement'=>  ($type === 'dette') ? null : f('moyen_paiement'),
                    'numero_cheque' =>  ($type === 'dette') ? null : f('numero_cheque'),
                    'compte_credit' =>  $credit,
                    'compte_debit'  =>  $debit,
                    'numero_piece'  =>  Utils::post('numero_piece'),
                    'remarques'     =>  Utils::post('remarques'),
                    'id_categorie'  =>  ($type === 'dette') ? null : (int)$cat['id'],
                    'id_auteur'     =>  $user['id'],
                    'numero_piece'  =>  f('numero_piece'),
                    'remarques'     =>  f('remarques'),
                    'id_categorie'  =>  ($type === 'dette') ? null : (int)$cat->id,
                    'id_auteur'     =>  $user->id,
                ]);
            }

            $membres->sessionStore('compta_date', Utils::post('date'));
            $session->sessionStore('compta_date', f('date'));

            if ($type == Compta\Categories::DEPENSES)
                $type = 'depense';
            elseif (is_null($type))
                $type = 'avance';
            elseif ($type == Compta\Categories::RECETTES)
                $type = 'recette';

            Utils::redirect('/admin/compta/operations/saisir.php?'.$type.'&ok='.(int)$id);
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
            $form->addError($e->getMessage());
        }
    }
}

$tpl->assign('error', $error);

$tpl->assign('type', $type);

if ($type === null)
{
    $tpl->assign('comptes', $comptes->listTree());
}
else
{
    $tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
    $tpl->assign('moyen_paiement', Utils::post('moyen_paiement') ?: 'ES');
    $tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
    $tpl->assign('categories', $cats->getList($type === 'dette' ? Compta\Categories::DEPENSES : $type));
    $tpl->assign('comptes_bancaires', $banques->getList());
    $tpl->assign('banque', Utils::post('banque'));
    $tpl->assign('banque', f('banque'));
}

if (!$membres->sessionGet('compta_date'))
if (!$session->sessionGet('compta_date'))
{
    $exercices = new Compta\Exercices;
    $exercice = $exercices->getCurrent();

    if ($exercice['debut'] > time() || $exercice['fin'] < time())
    if ($exercice->debut > time() || $exercice->fin < time())
    {
        $membres->sessionStore('compta_date', date('Y-m-d', $exercice['debut']));
        $session->sessionStore('compta_date', date('Y-m-d', $exercice->debut));
    }
    else
    {
        $membres->sessionStore('compta_date', date('Y-m-d'));
        $session->sessionStore('compta_date', date('Y-m-d'));
    }
}

$tpl->assign('date', $membres->sessionGet('compta_date') ?: false);
$tpl->assign('date', $session->sessionGet('compta_date') ?: false);
$tpl->assign('ok', (int) qg('ok'));

$tpl->display('admin/compta/operations/saisir.tpl');