Differences From Artifact [84a95ced43]:

To Artifact [e0ff2d0685]:


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
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
$journal = new Compta\Journal;

$journal->checkExercice();

$cats = new Compta\Categories;
$banques = new Compta\Comptes_Bancaires;

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

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

    if (!$form->hasErrors())
    {
        try
        {
            if (is_null($type))
            {
                $id = $journal->add([
                    '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'       =>  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(f('categorie'));

                if (!$cat)
                {
                    throw new UserException('Il faut choisir une catégorie.');
                }

                if ($type == 'dette')







<
<
<
<
<
<
<
|
<
<













|












|














>
>
>
>
>
>
>
>
>
>
|







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
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
$journal = new Compta\Journal;

$journal->checkExercice();

$cats = new Compta\Categories;
$banques = new Compta\Comptes_Bancaires;








$type = f('type') ?: 'recette';



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

    if (!$form->hasErrors())
    {
        try
        {
            if ($type == 'avance')
            {
                $id = $journal->add([
                    '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'       =>  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
            {
                if ($type == 'recette')
                {
                    $cat = 'categorie_recette';
                }
                else
                {
                    // Dette ou dépense
                    $cat = 'categorie_depense';
                }

                $cat = $cats->get(f($cat));

                if (!$cat)
                {
                    throw new UserException('Il faut choisir une catégorie.');
                }

                if ($type == 'dette')
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
                        }

                        $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 = f('compte');
                }

                $id = $journal->add([
                    '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'  =>  f('numero_piece'),
                    'remarques'     =>  f('remarques'),
                    'id_categorie'  =>  ($type === 'dette') ? null : (int)$cat->id,
                    'id_auteur'     =>  $user->id,
                ]);
            }

            $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)
        {
            $form->addError($e->getMessage());
        }
    }
}

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

if ($type === null)
{
    $tpl->assign('comptes', $comptes->listTree());
}
else
{
    $tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
    $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', f('banque'));
}

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

    if ($exercice->debut > time() || $exercice->fin < time())







|




|




|









|
|











<
<
<
<
<
<
<
|










<
<
|
<
<
<
|
|
|
>
|
|
<







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
                        }

                        $a = f('banque');
                        $b = $cat->compte;
                    }
                }

                if ($type == 'depense')
                {
                    $debit = $b;
                    $credit = $a;
                }
                elseif ($type == 'recette')
                {
                    $debit = $a;
                    $credit = $b;
                }
                elseif ($type == 'dette')
                {
                    $debit = $cat->compte;
                    $credit = f('compte');
                }

                $id = $journal->add([
                    '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'  =>  f('numero_piece'),
                    'remarques'     =>  f('remarques'),
                    'id_categorie'  =>  ($type === 'dette') ? null : (int)$cat->id,
                    'id_auteur'     =>  $user->id,
                ]);
            }

            $session->sessionStore('compta_date', f('date'));








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

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



$tpl->assign('comptes', $comptes->listTree());



$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
$tpl->assign('moyen_paiement', f('moyen_paiement') ?: 'ES');
$tpl->assign('categories_depenses', $cats->getList(Compta\Categories::DEPENSES));
$tpl->assign('categories_recettes', $cats->getList(Compta\Categories::RECETTES));
$tpl->assign('comptes_bancaires', $banques->getList());
$tpl->assign('banque', f('banque'));


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

    if ($exercice->debut > time() || $exercice->fin < time())