Overview
Comment:Affichage des contributions en nature dans le compte de résultat
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | stable
Files: files | file ages | folders
SHA1: 8666b175a39417b9641b9784881561d40bc438dd
User & Date: bohwaz on 2019-01-09 21:56:01
Other Links: manifest | tags
Context
2019-01-10
11:13
Fix bouton visibilité mot de passe sur mobile check-in: a2544d6b57 user: bohwaz tags: trunk, stable
2019-01-09
21:56
Affichage des contributions en nature dans le compte de résultat check-in: 8666b175a3 user: bohwaz tags: trunk, stable
2018-12-24
16:36
Changement dénomination champ privé check-in: ebc410d846 user: bohwaz tags: trunk, stable
Changes

Modified src/include/lib/Garradin/Compta/Exercices.php from [40f25a7060] to [a2ca824f36].

229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
        {
            throw new UserException('Impossible de solder l\'exercice : le compte de résultat débiteur ' . $resultat_debiteur . ' n\'existe pas ou est désactivé.');
        }

        unset($comptes);

        $rapports = new Rapports;
        $resultat = $rapports->compteResultat(['id_exercice' => $exercice]);
        $resultat = $resultat['resultat'];

        if ($resultat != 0)
        {
            $journal = new Journal;
            $journal->add([
                'libelle'   =>  'Résultat de l\'exercice précédent',







|







229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
        {
            throw new UserException('Impossible de solder l\'exercice : le compte de résultat débiteur ' . $resultat_debiteur . ' n\'existe pas ou est désactivé.');
        }

        unset($comptes);

        $rapports = new Rapports;
        $resultat = $rapports->compteResultat(['id_exercice' => $exercice], [6, 7]);
        $resultat = $resultat['resultat'];

        if ($resultat != 0)
        {
            $journal = new Journal;
            $journal->add([
                'libelle'   =>  'Résultat de l\'exercice précédent',

Modified src/include/lib/Garradin/Compta/Rapports.php from [4e82cf4b4a] to [9726d24a12].

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
        }

        $res->finalize();

        return $livre;
    }

    public function compteResultat(array $criterias)
    {
        $db = DB::getInstance();
        $where = $this->getWhereClause($criterias);

        $charges    = ['comptes' => [], 'total' => 0.0];
        $produits   = ['comptes' => [], 'total' => 0.0];
        $resultat   = 0.0;










        $res = $db->preparedQuery('SELECT compte, SUM(debit), SUM(credit)
            FROM
                (SELECT compte_debit AS compte, SUM(montant) AS debit, 0 AS credit
                    FROM compta_journal WHERE ' . $where . ' GROUP BY compte_debit
                UNION
                SELECT compte_credit AS compte, 0 AS debit, SUM(montant) AS credit
                    FROM compta_journal WHERE ' . $where . ' GROUP BY compte_credit)
            WHERE compte LIKE \'6%\' OR compte LIKE \'7%\'
            GROUP BY compte
            ORDER BY compte ASC;');

        while ($row = $res->fetchArray(SQLITE3_NUM))
        {
            list($compte, $debit, $credit) = $row;
            $classe = substr($compte, 0, 1);

            $parent = substr($compte, 0, 2);

            if ($classe == 6)
            {
                if (!isset($charges['comptes'][$parent]))
                {
                    $charges['comptes'][$parent] = ['comptes' => [], 'solde' => 0.0];
                }

                $solde = round($debit - $credit, 2);

                if (empty($solde))
                    continue;

                $charges['comptes'][$parent]['comptes'][$compte] = $solde;
                $charges['total'] += $solde;
                $charges['comptes'][$parent]['solde'] += $solde;
            }
            elseif ($classe == 7)
            {
                if (!isset($produits['comptes'][$parent]))
                {
                    $produits['comptes'][$parent] = ['comptes' => [], 'solde' => 0.0];
                }

                $solde = round($credit - $debit, 2);







|








>
>
>
>
>
>
>
>
>







|







>


|















|







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
        }

        $res->finalize();

        return $livre;
    }

    public function compteResultat(array $criterias, array $comptes)
    {
        $db = DB::getInstance();
        $where = $this->getWhereClause($criterias);

        $charges    = ['comptes' => [], 'total' => 0.0];
        $produits   = ['comptes' => [], 'total' => 0.0];
        $resultat   = 0.0;

        $where_comptes = [];

        foreach ($comptes as $compte)
        {
            $where_comptes[] = sprintf('compte LIKE \'%s%%\'', $compte);
        }

        $where_comptes = implode(' OR ', $where_comptes);

        $res = $db->preparedQuery('SELECT compte, SUM(debit), SUM(credit)
            FROM
                (SELECT compte_debit AS compte, SUM(montant) AS debit, 0 AS credit
                    FROM compta_journal WHERE ' . $where . ' GROUP BY compte_debit
                UNION
                SELECT compte_credit AS compte, 0 AS debit, SUM(montant) AS credit
                    FROM compta_journal WHERE ' . $where . ' GROUP BY compte_credit)
            WHERE ' . $where_comptes . '
            GROUP BY compte
            ORDER BY compte ASC;');

        while ($row = $res->fetchArray(SQLITE3_NUM))
        {
            list($compte, $debit, $credit) = $row;
            $classe = substr($compte, 0, 1);
            $sousclasse = substr($compte, 0, 2);
            $parent = substr($compte, 0, 2);

            if ($classe == 6 || $sousclasse == 86)
            {
                if (!isset($charges['comptes'][$parent]))
                {
                    $charges['comptes'][$parent] = ['comptes' => [], 'solde' => 0.0];
                }

                $solde = round($debit - $credit, 2);

                if (empty($solde))
                    continue;

                $charges['comptes'][$parent]['comptes'][$compte] = $solde;
                $charges['total'] += $solde;
                $charges['comptes'][$parent]['solde'] += $solde;
            }
            elseif ($classe == 7 || $sousclasse == 87)
            {
                if (!isset($produits['comptes'][$parent]))
                {
                    $produits['comptes'][$parent] = ['comptes' => [], 'solde' => 0.0];
                }

                $solde = round($credit - $debit, 2);
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
        $include = [Comptes::ACTIF, Comptes::PASSIF,
            Comptes::PASSIF | Comptes::ACTIF];

        $actif           = ['comptes' => [], 'total' => 0.0];
        $passif          = ['comptes' => [], 'total' => 0.0];
        $actif_ou_passif = ['comptes' => [], 'total' => 0.0];

        $resultat = $this->compteResultat($criterias);

        if ($resultat['resultat'] >= 0)
        {
            $passif['comptes']['12'] = [
                'comptes'   =>  ['120' => $resultat['resultat']],
                'solde'     =>  $resultat['resultat']
            ];







|







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
        $include = [Comptes::ACTIF, Comptes::PASSIF,
            Comptes::PASSIF | Comptes::ACTIF];

        $actif           = ['comptes' => [], 'total' => 0.0];
        $passif          = ['comptes' => [], 'total' => 0.0];
        $actif_ou_passif = ['comptes' => [], 'total' => 0.0];

        $resultat = $this->compteResultat($criterias, [6, 7]);

        if ($resultat['resultat'] >= 0)
        {
            $passif['comptes']['12'] = [
                'comptes'   =>  ['120' => $resultat['resultat']],
                'solde'     =>  $resultat['resultat']
            ];

Added src/templates/admin/compta/rapports/_table_resultat.tpl version [183cfa0c6a].

















































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
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
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
<table>
    <colgroup>
        <col width="50%" />
        <col width="50%" />
    </colgroup>
    <tbody>
        <tr>
            <td>
                <table>
                    {if $header}
                    <caption><h3>Charges</h3></caption>
                    {/if}
                    <tbody>
                    {foreach from=$comptes.charges.comptes key="parent_code" item="parent"}
                        <tr class="parent">
                            <th>{$parent_code|get_nom_compte}</th>
                            <td>{$parent.solde|escape|html_money}</td>
                        </tr>
                        {foreach from=$parent.comptes item="solde" key="compte"}
                        <tr class="compte">
                            <th>{$compte|get_nom_compte}</th>
                            <td>{$solde|escape|html_money}</td>
                        </tr>
                        {/foreach}
                    {/foreach}
                    </tbody>
                </table>
            </td>
            <td>
                <table>
                    {if $header}
                    <caption><h3>Produits</h3></caption>
                    {/if}
                    <tbody>
                    {foreach from=$comptes.produits.comptes key="parent_code" item="parent"}
                        <tr class="parent">
                            <th>{$parent_code|get_nom_compte}</th>
                            <td>{$parent.solde|escape|html_money}</td>
                        </tr>
                        {foreach from=$parent.comptes item="solde" key="compte"}
                        <tr class="compte">
                            <th>{$compte|get_nom_compte}</th>
                            <td>{$solde|escape|html_money}</td>
                        </tr>
                        {/foreach}
                    {/foreach}
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>
                <table>
                    <tfoot>
                        <tr>
                            <th>Total charges</th>
                            <td>{$comptes.charges.total|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            </td>
           <td>
                <table>
                    <tfoot>
                        <tr>
                            <th>Total produits</th>
                            <td>{$comptes.produits.total|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            </td>
        </tr>
        {if $result}
        <tr>
            <td>
            {if ($comptes.resultat >= 0)}
                <table>
                    <tfoot>
                        <tr>
                            <th>Résultat (excédent)</th>
                            <td>{$comptes.resultat|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            {/if}
            </td>
            <td>
            {if ($comptes.resultat < 0)}
                <table>
                    <tfoot>
                        <tr>
                            <th>Résultat (déficit)</th>
                            <td>{$comptes.resultat|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            {/if}
            </td>
        </tr>
        {/if}
    </tfoot>
</table>

Modified src/templates/admin/compta/rapports/compte_resultat.tpl from [510a2bfff7] to [4206fc3206].

1
2
3
4
5
6
7
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
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
{include file="admin/_head.tpl" title="Compte de résultat" current="compta/exercices" body_id="rapport"}

{include file="admin/compta/rapports/_header.tpl"}

<table>
    <colgroup>
        <col width="50%" />
        <col width="50%" />
    </colgroup>
    <tbody>
        <tr>
            <td>
                <table>
                    <caption><h3>Charges</h3></caption>
                    <tbody>
                    {foreach from=$compte_resultat.charges.comptes key="parent_code" item="parent"}
                        <tr class="parent">
                            <th>{$parent_code|get_nom_compte}</th>
                            <td>{$parent.solde|escape|html_money}</td>
                        </tr>
                        {foreach from=$parent.comptes item="solde" key="compte"}
                        <tr class="compte">
                            <th>{$compte|get_nom_compte}</th>
                            <td>{$solde|escape|html_money}</td>
                        </tr>
                        {/foreach}
                    {/foreach}
                    </tbody>
                </table>
            </td>
            <td>
                <table>
                    <caption><h3>Produits</h3></caption>
                    <tbody>
                    {foreach from=$compte_resultat.produits.comptes key="parent_code" item="parent"}
                        <tr class="parent">
                            <th>{$parent_code|get_nom_compte}</th>
                            <td>{$parent.solde|escape|html_money}</td>
                        </tr>
                        {foreach from=$parent.comptes item="solde" key="compte"}
                        <tr class="compte">
                            <th>{$compte|get_nom_compte}</th>
                            <td>{$solde|escape|html_money}</td>
                        </tr>
                        {/foreach}
                    {/foreach}
                    </tbody>
                </table>
            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>
                <table>
                    <tfoot>
                        <tr>
                            <th>Total charges</th>
                            <td>{$compte_resultat.charges.total|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            </td>
           <td>
                <table>
                    <tfoot>
                        <tr>
                            <th>Total produits</th>
                            <td>{$compte_resultat.produits.total|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            </td>
        </tr>
        <tr>
            <td>
            {if ($compte_resultat.resultat >= 0)}
                <table>
                    <tfoot>
                        <tr>
                            <th>Résultat (excédent)</th>
                            <td>{$compte_resultat.resultat|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            {/if}
            </td>
            <td>
            {if ($compte_resultat.resultat < 0)}
                <table>
                    <tfoot>
                        <tr>
                            <th>Résultat (déficit)</th>
                            <td>{$compte_resultat.resultat|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            {/if}
            </td>
        </tr>
    </tfoot>
</table>

<p class="help">Toutes les opérations sont libellées en {$config.monnaie}.</p>

{include file="admin/_foot.tpl"}




<
<
<
<
<
<
<
<
<
<
<
|
|
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




1
2
3
4











5
6




7













8








































9








10
















11
12
13
14
{include file="admin/_head.tpl" title="Compte de résultat" current="compta/exercices" body_id="rapport"}

{include file="admin/compta/rapports/_header.tpl"}












{include file="admin/compta/rapports/_table_resultat.tpl" comptes=$compte_resultat header=true result=true}





{if !empty($compte_nature.charges.comptes)}













    <h2 class="ruler">Contributions en nature</h2>








































    {include file="admin/compta/rapports/_table_resultat.tpl" comptes=$compte_nature header=false result=false}








{/if}

















<p class="help">Toutes les opérations sont libellées en {$config.monnaie}.</p>

{include file="admin/_foot.tpl"}

Modified src/www/admin/compta/rapports/compte_resultat.php from [7128f79903] to [4bb5da1833].

1
2
3
4
5
6
7

8
9
<?php

namespace Garradin;

require_once __DIR__ . '/_inc.php';

$tpl->assign('compte_resultat', $rapports->compteResultat($criterias));


$tpl->display('admin/compta/rapports/compte_resultat.tpl');






|
>


1
2
3
4
5
6
7
8
9
10
<?php

namespace Garradin;

require_once __DIR__ . '/_inc.php';

$tpl->assign('compte_resultat', $rapports->compteResultat($criterias, [6, 7]));
$tpl->assign('compte_nature', $rapports->compteResultat($criterias, [86, 87]));

$tpl->display('admin/compta/rapports/compte_resultat.tpl');