Added transaction stats. Added (possibly unwanted) columns.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@389 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-25 08:06:50 +00:00
parent 0170dbc310
commit 7a42bee8ef
9 changed files with 192 additions and 20 deletions

View File

@@ -44,7 +44,8 @@ class LedgerEntry extends AppModel {
* on the overall balance of the account/ledger.
*/
function debitCreditFields($sum = false, $entry_name = 'LedgerEntry', $account_name = 'Account') {
function debitCreditFields($sum = false, $balance = true,
$entry_name = 'LedgerEntry', $account_name = 'Account') {
$fields = array
(
($sum ? 'SUM(' : '') .
@@ -56,15 +57,17 @@ class LedgerEntry extends AppModel {
"IF({$entry_name}.crdr = 'CREDIT'," .
" {$entry_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS credit' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF(${account_name}.type IN ('ASSET', 'EXPENSE')," .
" IF({$entry_name}.crdr = 'DEBIT', 1, -1)," .
" IF({$entry_name}.crdr = 'CREDIT', 1, -1))" .
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
($sum ? ')' : '') . ' AS balance',
);
if ($balance)
$fields[] =
($sum ? 'SUM(' : '') .
"IF(${account_name}.type IN ('ASSET', 'EXPENSE')," .
" IF({$entry_name}.crdr = 'DEBIT', 1, -1)," .
" IF({$entry_name}.crdr = 'CREDIT', 1, -1))" .
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
($sum ? ')' : '') . ' AS balance';
if ($sum)
$fields[] = "COUNT({$entry_name}.id) AS entries";