Comment: | General ledger |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | dev |
Files: | files | file ages | folders |
SHA1: |
65893d90e5dd44a35f233a5b6e3aaadf |
User & Date: | bohwaz on 2020-10-09 10:15:39 |
Other Links: | branch diff | manifest | tags |
2020-10-09
| ||
11:05 | Add year journal check-in: 58411fe14f user: bohwaz tags: dev | |
10:15 | General ledger check-in: 65893d90e5 user: bohwaz tags: dev | |
2020-10-08
| ||
13:47 | Simplified view for favorite accounts check-in: 5d47c23bff user: bohwaz tags: dev | |
Added src/include/lib/Garradin/Accounting/Reports.php version [085a5801bf].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 107 108 109 110 111 112 113 114 115 116 117 118 | <?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(int $year_id): array { // Find sums, link them to accounts $sql = sprintf('SELECT l.id_account, a.code AS account_code, a.label AS account_name, SUM(l.credit) AS credit, SUM(l.debit) AS 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 t.id_year = %d GROUP BY l.id_account;', Line::TABLE, Transaction::TABLE, Account::TABLE, $year_id); return DB::getInstance()->getGrouped($sql); } static public function getClosingSums(int $year_id): array { $year = Years::get($year_id); if (true || $year->closed) { return self::computeClosingSums($year->id()); } else { // Get the ID of the account used to store closing sums $closing_account_id = $db->firstColumn(sprintf('SELECT id FROM %s WHERE id_chart = ? AND type = ?;', Account::TABLE, $year->id_chart, Account::TYPE_CLOSING)); // Find sums, link them to accounts $sql = sprintf('SELECT b.id_account, SUM(a.credit) - SUM(a.debit) FROM %s a INNER JOIN %s b ON b.id_transaction = a.id_transaction WHERE a.id_account = %d AND a.id_year = %d;', Line::TABLE, Line::TABLE, $closing_account_id, $year_id); return DB::getInstance()->getAssoc($sql); } } static protected function computeClosingSums(int $year_id): array { // Find sums, link them to accounts $sql = sprintf('SELECT l.id_account, SUM(l.credit) - SUM(l.debit) FROM %s l INNER JOIN %s t ON t.id = l.id_transaction WHERE t.id_year = %d GROUP BY l.id_account;', Line::TABLE, Transaction::TABLE, $year_id); return DB::getInstance()->getAssoc($sql); } /** * Grand livre */ static public function getGeneralLedger(array $criterias): \Generator { if (!empty($criterias['year'])) { $year_id = (int)$criterias['year']; $where = sprintf('t.id_year = %d', $year_id); } else { throw new \LogicException('Unknown criteria'); } $db = DB::getInstance(); $sql = sprintf('SELECT t.id_year, l.id_account, l.debit, l.credit, t.id, t.date, t.reference, l.reference AS line_reference, t.label, l.label AS line_label FROM acc_transactions t INNER JOIN acc_transactions_lines l ON l.id_transaction = t.id INNER JOIN acc_accounts a ON a.id = l.id_account WHERE %s ORDER BY a.code COLLATE NOCASE, t.date;', $where); $account = null; $debit = $credit = 0; $accounts = $db->getGrouped('SELECT id, code, label FROM acc_accounts WHERE id_chart = (SELECT id_chart FROM acc_years WHERE id = ?);', $year_id); foreach ($db->iterate($sql) as $row) { if (null !== $account && $account->id != $row->id_account) { yield $account; $account = null; } if (null === $account) { $account = (object) [ 'code' => $accounts[$row->id_account]->code, 'label' => $accounts[$row->id_account]->label, 'id' => $row->id_account, 'sum' => 0, 'debit' => 0, 'credit'=> 0, 'lines' => [], ]; } $row->date = \DateTime::createFromFormat('Y-m-d', $row->date); $account->sum += ($row->credit - $row->debit); $account->debit += $row->debit; $account->credit += $row->credit; $debit += $row->debit; $credit += $row->credit; $row->running_sum = $account->sum; $account->lines[] = $row; } $account->all_debit = $debit; $account->all_credit = $credit; yield $account; } } |
Modified src/templates/acc/accounts/journal.tpl from [4795a14551] to [799d98c204].
1 2 3 4 5 6 7 | {include file="admin/_head.tpl" title="Journal : %s - %s"|args:$account.code:$account.label current="acc/accounts" body_id="rapport"} {include file="acc/_year_select.tpl"} {if $account.type} <nav class="tabs"> <ul> | > > > > > > > > | | | | | 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 | {include file="admin/_head.tpl" title="Journal : %s - %s"|args:$account.code:$account.label current="acc/accounts" body_id="rapport"} {if empty($year)} {include file="acc/_year_select.tpl"} {else} <nav class="acc-year"> <h4>Exercice sélectionné :</h4> <h3>{$current_year.label} — {$current_year.start_date|date_fr:'d/m/Y'} au {$current_year.end_date|date_fr:'d/m/Y'}</h3> </nav> {/if} {if $account.type} <nav class="tabs"> <ul> <li{if $simple_view} class="current"{/if}><a href="{$admin_url}acc/accounts/journal.php?id={$account.id}&simple=1&year={$year_id}">Vue simplifiée</a></li> <li{if !$simple_view} class="current"{/if}><a href="{$admin_url}acc/accounts/journal.php?id={$account.id}&simple=0&year={$year_id}">Vue normale</a></li> </ul> </nav> {/if} <table class="list"> <colgroup> <col width="3%" /> <col width="12%" /> <col width="10%" /> {if !$simple_view}<col width="10%" />{/if} <col width="12%" /> <col /> <col width="6%" /> </colgroup> <thead> <tr> <td>Réf.</td> <td>Date</td> {if $simple_view} <td>Mouvement</td> {else} <td class="money">Débit</td> <td class="money">Crédit</td> {/if} <td>Solde cumulé</td> <th>Libellé</th> <td></td> </tr> </thead> <tbody> {foreach from=$journal item="line"} <tr> <td class="num"><a href="{$admin_url}acc/transactions/details.php?id={$line.id}">{if $line.line_reference}{$line.line_reference}{elseif $line.reference}{$line.reference}{else}#{$line.id}{/if}</a></td> <td>{$line.date|date_fr:'d/m/Y'}</td> {if $simple_view} <td class="money">{if $line.debit}-{$line.debit|escape|html_money}{else}+{$line.credit|escape|html_money}{/if}</td> {else} <td class="money">{if $line.debit}{$line.debit|escape|html_money}{/if}</td> <td class="money">{if $line.credit}{$line.credit|escape|html_money}{/if}</td> {/if} |
︙ | ︙ |
Modified src/templates/acc/reports/_header.tpl from [1061b17f5a] to [0cb7c8e906].
1 2 3 4 5 | <div class="exercice"> <h2>{$config.nom_asso}</h2> {if isset($projet)} <h3>Projet : {$projet.libelle}</h3> {else} | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <div class="exercice"> <h2>{$config.nom_asso}</h2> {if isset($projet)} <h3>Projet : {$projet.libelle}</h3> {else} <p>Exercice comptable {if $year.closed}clôturé{else}en cours{/if} du {$year.start_date|date_fr:'d/m/Y'} au {$year.end_date|date_fr:'d/m/Y'}, généré le {$close_date|date_fr:'d/m/Y'}</p> {/if} <p class="noprint"> <button onclick="window.print(); return false;"> <b href="#need_js" class="action icn print">⎙</b> Imprimer </button> </p> </div> |
Name change from src/templates/admin/compta/rapports/_table_resultat.tpl to src/templates/acc/reports/_table_resultat.tpl.
whitespace changes only
Name change from src/templates/admin/compta/rapports/bilan.tpl to src/templates/acc/reports/bilan.tpl.
whitespace changes only
Name change from src/templates/admin/compta/rapports/compte_resultat.tpl to src/templates/acc/reports/compte_resultat.tpl.
whitespace changes only
Name change from src/templates/admin/compta/rapports/journal.tpl to src/templates/acc/reports/journal.tpl.
whitespace changes only
Modified src/templates/acc/reports/ledger.tpl from [9f320d7052] to [a65f313dac].
1 2 | {include file="admin/_head.tpl" title="Grand livre" current="compta/exercices" body_id="rapport"} | | | < < < | | | > > | > | | | | | > | | | < < < < < < < < < < < < < < < < < < < | | | > > > | 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 | {include file="admin/_head.tpl" title="Grand livre" current="compta/exercices" body_id="rapport"} {include file="acc/reports/_header.tpl"} {foreach from=$ledger item="account"} <table class="list"> <caption><h4><a href="{$admin_url}acc/accounts/journal.php?id={$account.id}&year={$year.id}">{$account.code} — {$account.label}</h4></caption> <colgroup> <col width="10%" /> <col width="10%" /> <col width="50%" /> <col width="10%" /> <col width="10%" /> <col width="10%" /> </colgroup> <thead> <tr> <td>Réf.</td> <td>Date</td> <th>Intitulé</th> <td class="money">Débit</td> <td class="money">Crédit</td> <td class="money">Solde</td> </tr> </thead> <tbody> {foreach from=$account.lines item="line"} <tr> <td class="num"><a href="{$admin_url}acc/transactions/details.php?id={$line.id}">{if $line.line_reference}{$line.line_reference}{elseif $line.reference}{$line.reference}{else}#{$line.id}{/if}</a></td> <td>{$line.date|date_fr:'d/m/Y'}</td> <th>{$line.label}{if $line.line_label} <em>({$line.line_label})</em>{/if}</th> <td class="money">{if $line.debit}{$line.debit|escape|html_money}{/if}</td> <td class="money">{if $line.credit}{$line.credit|escape|html_money}{/if}</td> <td class="money">{$line.running_sum|escape|html_money}</td> </tr> {/foreach} </tbody> <tfoot> <tr> <td></td> <td></td> <th>Solde final</th> <td class="money">{if $account.debit}{$account.debit|escape|html_money}{/if}</td> <td class="money">{if $account.credit}{$account.credit|escape|html_money}{/if}</td> <td class="money">{$account.sum|escape|html_money}</td> </tr> </tfoot> </table> {if isset($account->all_debit)} <table class="list"> <colgroup> <col width="15%" /> <col width="65%" /> <col width="10%" /> <col width="10%" /> </colgroup> <tfoot> <tr> <td><strong>Total</strong></td> <th></th> <td>{$account.all_debit|escape|html_money}</td> <td>{$account.all_credit|escape|html_money}</td> </tr> </tfoot> </table> {/if} {/foreach} <p class="help">Toutes les opérations sont libellées en {$config.monnaie}.</p> {include file="admin/_foot.tpl"} |
Modified src/templates/acc/transactions/details.tpl from [83448201cc] to [22f535a92a].
︙ | ︙ | |||
15 16 17 18 19 20 21 | <dt>Date</dt> <dd>{$transaction.date|date_fr:'l j F Y (d/m/Y)'}</dd> <dt>Numéro pièce comptable</dt> <dd>{if trim($transaction.reference)}{$transaction.reference}{else}-{/if}</dd> <dt>Exercice</dt> <dd> | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <dt>Date</dt> <dd>{$transaction.date|date_fr:'l j F Y (d/m/Y)'}</dd> <dt>Numéro pièce comptable</dt> <dd>{if trim($transaction.reference)}{$transaction.reference}{else}-{/if}</dd> <dt>Exercice</dt> <dd> <a href="{$admin_url}acc/reports/ledger.php?year={$transaction.id_year}">{$tr_year.label}</a> | Du {$tr_year.start_date|date_fr:'d/m/Y'} au {$tr_year.end_date|date_fr:'d/m/Y'} | <strong>{if $tr_year.closed}Clôturé{else}En cours{/if}</strong> </dd> {if $transaction.id_projet} <dt>Projet</dt> <dd> |
︙ | ︙ | |||
79 80 81 82 83 84 85 | <td>Libellé</td> <td>Référence</td> </tr> </thead> <tbody> {foreach from=$transaction->getLinesWithAccounts() item="line"} <tr> | | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | <td>Libellé</td> <td>Référence</td> </tr> </thead> <tbody> {foreach from=$transaction->getLinesWithAccounts() item="line"} <tr> <td class="num"><a href="{$admin_url}acc/accounts/journal.php?id={$line.id_account}&year={$transaction.id_year}">{$line.account_code}</a></td> <td>{$line.account_name}</td> <td class="money">{if $line.debit}{$line.debit|escape|html_money}{/if}</td> <td class="money">{if $line.credit}{$line.credit|escape|html_money}{/if}</td> <td>{$line.label}</td> <td>{$line.reference}</td> </tr> {/foreach} </tbody> </table> {include file="admin/_foot.tpl"} |
Modified src/templates/acc/years/index.tpl from [5080bc206e] to [3df707c5c9].
︙ | ︙ | |||
12 13 14 15 16 17 18 | {foreach from=$list item="year"} <dt>{$year.label}</dt> <dd class="desc"> {if $year.closed}Clôturé{else}En cours{/if} | Du {$year.start_date|date_fr:'d/m/Y'} au {$year.end_date|date_fr:'d/m/Y'} </dd> <dd class="desc"> | | | | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | {foreach from=$list item="year"} <dt>{$year.label}</dt> <dd class="desc"> {if $year.closed}Clôturé{else}En cours{/if} | Du {$year.start_date|date_fr:'d/m/Y'} au {$year.end_date|date_fr:'d/m/Y'} </dd> <dd class="desc"> <a href="{$admin_url}acc/reports/journal.php?year={$year.id}">Journal général</a> | <a href="{$admin_url}acc/reports/ledger.php?year={$year.id}">Grand livre</a> | <a href="{$admin_url}acc/reports/statement.php?year={$year.id}">Compte de résultat</a> | <a href="{$admin_url}acc/reports/balance_sheet.php?year={$year.id}">Bilan</a> </dd> {if $session->canAccess('compta', Membres::DROIT_ADMIN) && !$year.closed} <dd class="actions"> {linkbutton label="Balance d'ouverture" shape="reset" href="acc/years/balance.php?id=%d"|args:$year.id} {linkbutton label="Modifier" shape="edit" href="acc/years/edit.php?id=%d"|args:$year.id} {linkbutton label="Clôturer" shape="lock" href="acc/years/close.php?id=%d"|args:$year.id} {linkbutton label="Supprimer" shape="delete" href="acc/years/delete.php?id=%d"|args:$year.id} |
︙ | ︙ |
Modified src/www/admin/acc/accounts/journal.php from [f736bfd940] to [722ee1c065].
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?php namespace Garradin; use Garradin\Accounting\Accounts; require_once __DIR__ . '/../_inc.php'; $account = Accounts::get((int) qg('id')); if (!$account) { throw new UserException("Le compte demandé n'existe pas."); } | > > > > > > > > > > > > > | > | 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 | <?php namespace Garradin; use Garradin\Accounting\Accounts; use Garradin\Accounting\Years; require_once __DIR__ . '/../_inc.php'; $account = Accounts::get((int) qg('id')); if (!$account) { throw new UserException("Le compte demandé n'existe pas."); } $year_id = (int) qg('year') ?: CURRENT_YEAR_ID; if ($year_id !== CURRENT_YEAR_ID) { $year = Years::get($year_id); if (!$year) { throw new UserException("L'exercice demandé n'existe pas."); } $tpl->assign('year', $year); } $journal = $account->getJournal($year_id); $sum = 0; if (count($journal)) { $sum = end($journal)->running_sum; } /* 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('simple_view', qg('simple')); $tpl->assign('year_id', $year_id); $tpl->assign('account', $account); $tpl->assign('journal', $journal); $tpl->assign('sum', $sum); $tpl->display('acc/accounts/journal.tpl'); |
Modified src/www/admin/acc/reports/_inc.php from [73c58d8a9d] to [5f03524436].
1 2 3 4 5 6 | <?php namespace Garradin; require_once __DIR__ . '/../_inc.php'; | > > > < | < | | < | | | | < | < | < | | | | 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 | <?php namespace Garradin; use Garradin\Accounting\Years; use Garradin\Accounting\Accounts; require_once __DIR__ . '/../_inc.php'; $criterias = []; if (qg('analytical')) { $account = Accounts::get((int) qg('analytical')); if (!$account) { throw new UserException('Numéro de compte analytique inconnu.'); } $criterias['analytical'] = $account->id(); $tpl->assign('analytical', $account); } elseif (qg('year')) { $year = Years::get((int) qg('year')); if (!$year) { throw new UserException('Exercice inconnu.'); } $criterias['year'] = $year->id(); $tpl->assign('year', $year); $tpl->assign('close_date', $year->closed ? $year->end_date : time()); } else { throw new UserException('Critère de rapport inconnu.'); } |
Name change from src/www/admin/compta/rapports/bilan.php to src/www/admin/acc/reports/bilan.php.
whitespace changes only
Name change from src/www/admin/compta/rapports/compte_resultat.php to src/www/admin/acc/reports/compte_resultat.php.
whitespace changes only
Name change from src/www/admin/compta/rapports/journal.php to src/www/admin/acc/reports/journal.php.
whitespace changes only
Modified src/www/admin/acc/reports/ledger.php from [f6b332c56d] to [ea925577f6].
1 2 3 4 5 6 | <?php namespace Garradin; require_once __DIR__ . '/_inc.php'; | > > | | | 1 2 3 4 5 6 7 8 9 10 11 | <?php namespace Garradin; use Garradin\Accounting\Reports; require_once __DIR__ . '/_inc.php'; $tpl->assign('ledger', Reports::getGeneralLedger($criterias)); $tpl->display('acc/reports/ledger.tpl'); |
Modified src/www/admin/static/admin.css from [cc93433f65] to [094b399cf6].
︙ | ︙ | |||
846 847 848 849 850 851 852 | padding: .2rem .5rem; } nav.acc-year h4 { font-weight: normal; } | < < < < < | 846 847 848 849 850 851 852 853 854 855 856 857 858 859 | padding: .2rem .5rem; } nav.acc-year h4 { font-weight: normal; } #rapport table { width: 100%; } #rapport tr { vertical-align: top; } |
︙ | ︙ | |||
1033 1034 1035 1036 1037 1038 1039 | a.icn[title]:hover:after { display: inline-block; } .num a { text-decoration: none; | | | < < | > > | 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 | a.icn[title]:hover:after { display: inline-block; } .num a { text-decoration: none; border-radius: .5rem; display: inline-block; text-align: center; padding: 0 .3rem; background: rgba(var(--gMainColor), 0.7); color: #fff; white-space: pre; } .actions .icn:hover, .num a:hover, .icn.action:hover, .icn-btn:hover { color: darkred; background: #ff9; z-index: 300; } |
︙ | ︙ |