Overview
Comment:Add balance sheet
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 58f7cb1c31908881b290b76576bc094c701edefd
User & Date: bohwaz on 2020-10-09 14:36:39
Other Links: branch diff | manifest | tags
Context
2020-10-10
19:18
Don't require an open year to display the list of years, d'oh check-in: b93f899b48 user: bohwaz tags: dev
2020-10-09
14:36
Add balance sheet check-in: 58f7cb1c31 user: bohwaz tags: dev
14:18
Automatic simple view in journal check-in: bfa864d0a1 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Accounting/Reports.php from [ab8624feb2] to [1da0cd20f9].

1
2
3
4
5
6
7
8
9
10
11
12
13












14
15
16
17
18
19
20
<?php

namespace Garradin\Accounting;

use Garradin\Entities\Accounting\Account;
use Garradin\Entities\Accounting\Line;
use Garradin\Entities\Accounting\Transaction;
use Garradin\Utils;
use Garradin\DB;
use KD2\DB\EntityManager;

class Reports
{












	static public function getClosingSumsWithAccounts(array $criterias): array
	{
		$where = self::getWhereClause($criterias);

		// Find sums, link them to accounts
		$sql = sprintf('SELECT a.id, a.code, a.label, SUM(l.credit) AS credit, SUM(l.debit) AS debit,
			SUM(l.credit) - SUM(l.debit) AS sum













>
>
>
>
>
>
>
>
>
>
>
>







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
<?php

namespace Garradin\Accounting;

use Garradin\Entities\Accounting\Account;
use Garradin\Entities\Accounting\Line;
use Garradin\Entities\Accounting\Transaction;
use Garradin\Utils;
use Garradin\DB;
use KD2\DB\EntityManager;

class Reports
{
	static public function getResult(array $criterias): ?int
	{
		$where = self::getWhereClause($criterias);
		$sql = sprintf('SELECT SUM(l.credit) - SUM(l.debit)
			FROM %s l
			INNER JOIN %s t ON t.id = l.id_transaction
			INNER JOIN %s a ON a.id = l.id_account
			WHERE %s AND a.position IN (?, ?);',
			Line::TABLE, Transaction::TABLE, Account::TABLE, $where);
		return DB::getInstance()->firstColumn($sql, Account::EXPENSE, Account::REVENUE);
	}

	static public function getClosingSumsWithAccounts(array $criterias): array
	{
		$where = self::getWhereClause($criterias);

		// Find sums, link them to accounts
		$sql = sprintf('SELECT a.id, a.code, a.label, SUM(l.credit) AS credit, SUM(l.debit) AS debit,
			SUM(l.credit) - SUM(l.debit) AS sum

Modified src/templates/acc/reports/balance_sheet.tpl from [b3279556ab] to [ed92ea6d58].

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
{include file="admin/_head.tpl" title="Bilan" 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>Actif</h3></caption>
                    <tbody>
                    {foreach from=$bilan.actif.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>Passif</h3></caption>
                    <tbody>
                    {foreach from=$bilan.passif.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 actif</th>
                            <td>{$bilan.actif.total|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            </td>
           <td>
                <table>
                    <tfoot>
                        <tr>
                            <th>Total passif</th>
                            <td>{$bilan.passif.total|escape|html_money}</td>
                        </tr>
                    </tfoot>
                </table>
            </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
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
{include file="admin/_head.tpl" title="Compte de résultat" current="acc/years"}

{include file="acc/reports/_header.tpl" current="balance_sheet"}

<table class="statement">
    <colgroup>
        <col width="50%" />
        <col width="50%" />
    </colgroup>
    <tbody>
        <tr>
            <td>

                {include file="acc/reports/_statement_table.tpl" accounts=$asset caption="Actif"}















            </td>
            <td>

                {include file="acc/reports/_statement_table.tpl" accounts=$liability caption="Passif"}















            </td>
        </tr>
    </tbody>
    <tfoot>
        <tr>
            <td>
                <table>
                    <tfoot>
                        <tr>
                            <th>Total actif</th>
                            <td class="money">{$asset_sum|raw|html_money:false}</td>
                        </tr>
                    </tfoot>
                </table>
            </td>
            <td>
                <table>
                    <tfoot>
                        <tr>
                            <th>Total passif</th>
                            <td class="money">{$liability_sum|raw|html_money:false}</td>
                        </tr>
                    </tfoot>
                </table>
            </td>
        </tr>
    </tfoot>
</table>

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

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

Modified src/www/admin/acc/reports/balance_sheet.php from [a817281776] to [5392999ce9].

1
2
3
4



5
6


7

8
























9
<?php

namespace Garradin;




require_once __DIR__ . '/_inc.php';



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


























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




>
>
>


>
>
|
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
<?php

namespace Garradin;

use Garradin\Accounting\Reports;
use Garradin\Entities\Accounting\Account;

require_once __DIR__ . '/_inc.php';

$liability = Reports::getClosingSumsWithAccounts($criterias + ['position' => Account::LIABILITY]);
$asset = Reports::getClosingSumsWithAccounts($criterias + ['position' => Account::ASSET]);

$result = Reports::getResult($criterias);

if ($result > 0) {
	$result = (object) ['id' => null, 'label' => 'Résultat de l\'exercice courant (excédent)', 'sum' => $result];
	$liability = array_merge($liability, [$result]);
}
elseif ($result < 0) {
	$result = (object) ['id' => null, 'label' => 'Résultat de l\'exercice courant (débiteur)', 'sum' => abs($result)];
	$asset = array_merge($asset, [$result]);
}

$get_sum = function (array $in): int {
	$sum = 0;

	foreach ($in as $row) {
		$sum += $row->sum;
	}

	return abs($sum);
};

$liability_sum = $get_sum($liability);
$asset_sum = $get_sum($asset);

$tpl->assign(compact('liability', 'asset', 'liability_sum', 'asset_sum'));

$tpl->display('acc/reports/balance_sheet.tpl');