Another snapshot

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@356 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-20 23:35:11 +00:00
parent bfbf119aca
commit d5bcd9a496
20 changed files with 696 additions and 759 deletions

View File

@@ -97,6 +97,41 @@ class Account extends AppModel {
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: debitCreditFields
* - Returns the fields necessary to determine whether the queried
* entries are a debit, or a credit, and also the effect each have
* on the overall balance of the account.
*/
function debitCreditFields($id, $sum = false,
$entry_name = 'Entry', $double_name = 'DoubleEntry') {
$ftype = strtoupper($this->fundamentalType($id));
$fields = array
(
($sum ? 'SUM(' : '') .
"IF({$entry_name}.crdr = 'DEBIT', {$double_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS debit' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF({$entry_name}.crdr = 'CREDIT', {$double_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS credit' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF({$entry_name}.crdr = '$ftype', 1, -1) * {$double_name}.amount" .
// IF({$double_name}.amount, {$double_name}.amount, 0)" .
($sum ? ')' : '') . ' AS balance',
);
if ($sum)
$fields[] = "COUNT({$entry_name}.id) AS entries";
return $fields;
}
/**************************************************************************
**************************************************************************
**************************************************************************
@@ -346,7 +381,7 @@ class Account extends AppModel {
$link['Account'] = array('fields' => array());
$cond[] = array('Account.id' => $id);
$set = $this->Ledger->Entry->reconciledSet($set, $cond, $link, true);
pr(compact('set'));
//pr(compact('set'));
return $set;
}
@@ -416,7 +451,7 @@ class Account extends AppModel {
function reconcileLedgerEntries($id, $cond = null) {
$unreconciled = $this->findUnreconciledLedgerEntries($id, null, $cond);
pr(compact('unreconciled'));
//pr(compact('unreconciled'));
$entry = array();
foreach (array('debit', 'credit') AS $dc)
@@ -465,7 +500,7 @@ class Account extends AppModel {
$unreconciled['debit'] ['unapplied'] = $unreconciled['credit']['balance'];
$unreconciled['credit']['unapplied'] = $unreconciled['debit'] ['balance'];
pr(compact('unreconciled'));
//pr(compact('unreconciled'));
return $unreconciled;
}
@@ -787,37 +822,47 @@ class Account extends AppModel {
* - Returns summary data from the requested account.
*/
function stats($id = null, $all = false, $cond = null) {
function stats($id = null, $all = false, $query = null) {
if (!$id)
return null;
// All old, closed ledgers MUST balance to 0.
// However, the user may want the ENTIRE running totals,
// (not just the balance), so we may have to query all
// ledgers, as dictated by the $all parameter.
$this->queryInit($query);
$account = $this->find('first',
array('contain' =>
($all
? array('Ledger' => array
('fields' => array('id')))
: array('CurrentLedger' => array
('fields' => array('id')))
),
'conditions' => array
(array('Account.id' => $id))
));
/* if ($all) { */
/* if (!isset($query['link']['Ledger'])) */
/* $query['link']['Ledger'] = array(); */
/* if (!isset($query['link']['Ledger']['fields'])) */
/* $query['link']['Ledger']['fields'] = array(); */
/* $query['link']['Ledger']['fields'][] = 'id'; */
/* } */
/* else { */
/* if (!isset($query['link']['CurrentLedger'])) */
/* $query['link']['CurrentLedger'] = array(); */
/* if (!isset($query['link']['CurrentLedger']['fields'])) */
/* $query['link']['CurrentLedger']['fields'] = array(); */
/* $query['link']['CurrentLedger']['fields'][] = 'id'; */
/* } */
$stats = array();
if ($all) {
foreach ($account['Ledger'] AS $ledger)
$this->statsMerge($stats['Ledger'],
$this->Ledger->stats($ledger['id'], $cond));
}
else {
$stats['Ledger'] =
$this->Ledger->stats($account['CurrentLedger']['id'], $cond);
}
/* $query['conditions'][] = array('Account.id' => $id); */
/* $account = $this->find('first', $query); */
$query['link'] = array('Account' => $query['link']);
foreach ($this->ledgers($id, $all) AS $ledger)
$this->statsMerge($stats['Ledger'],
$this->Ledger->stats($ledger, $query));
/* $stats = array(); */
/* if ($all) { */
/* foreach ($account['Ledger'] AS $ledger) */
/* $this->statsMerge($stats['Ledger'], */
/* $this->Ledger->stats($ledger['id'], $query)); */
/* } */
/* else { */
/* $stats['Ledger'] = */
/* $this->Ledger->stats($account['CurrentLedger']['id'], $query); */
/* } */
return $stats;
}