Playing with different means for determining stats. Nothing decided yet.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@391 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-26 23:23:19 +00:00
parent 36f439ff38
commit 2cc58255c3
2 changed files with 47 additions and 12 deletions

View File

@@ -345,28 +345,58 @@ class Customer extends AppModel {
* - Returns summary data from the requested customer. * - Returns summary data from the requested customer.
*/ */
function stats($id = null) { function stats($id = null, $query = null) {
if (!$id) if (!$id)
return null; return null;
$stats = $this->StatementEntry->find $this->queryInit($query);
// REVISIT <AP>: 20090725
// We'll need to go directly to the statement entries if
// transactions are not always associated with the customer.
// This could happen if either we remove the customer_id
// field from Transaction, or we allow multiple customers
// to be part of the same transaction (essentially making
// the Transaction.customer_id meaningless).
/* $stats = $this->StatementEntry->find */
/* ('first', array */
/* ('contain' => false, */
/* 'fields' => $this->StatementEntry->chargePaymentFields(true), */
/* 'conditions' => array('StatementEntry.customer_id' => $id), */
/* )); */
$find_stats = $this->StatementEntry->find
('first', array ('first', array
('contain' => false, ('contain' => false,
'fields' => $this->StatementEntry->chargePaymentFields(true), 'fields' => $this->StatementEntry->chargePaymentFields(true),
'conditions' => array('StatementEntry.customer_id' => $id), 'conditions' => array('StatementEntry.customer_id' => $id),
)); ));
pr(compact('find_stats'));
pr(compact('stats')); $tquery = $query;
$tquery['conditions'][] = array('StatementEntry.customer_id' => $id);
$statement_stats = $this->StatementEntry->stats(null, $tquery);
$statement_stats['balance'] = $statement_stats['Charge']['balance'];
pr(compact('statement_stats'));
$stat2 = $tquery = $query;
$this->Transaction->stats(null, //$tquery['conditions'][] = array('StatementEntry.customer_id' => $id);
array('conditions' => $tquery['conditions'][] = array('Transaction.customer_id' => $id);
array('Transaction.customer_id' => $id), $transaction_stats = $this->Transaction->stats(null, $tquery);
)); $transaction_stats += $transaction_stats['StatementEntry'];
pr(compact('transaction_stats'));
pr(compact('stat2')); $tquery = $query;
//$tquery['conditions'][] = array('StatementEntry.customer_id' => $id);
$tquery['conditions'][] = array('Transaction.customer_id' => $id);
$ar_transaction_stats = $this->Transaction->stats(null, $tquery,
$this->Transaction->Account->accountReceivableAccountID());
$ar_transaction_stats += $ar_transaction_stats['LedgerEntry'];
pr(compact('ar_transaction_stats'));
return $stats[0]; $stats = $statement_stats;
return $stats;
} }
} }

View File

@@ -367,7 +367,7 @@ class Transaction extends AppModel {
* function: stats * function: stats
* - Returns summary data from the requested transaction * - Returns summary data from the requested transaction
*/ */
function stats($id = null, $query = null) { function stats($id = null, $query = null, $balance_account_id = null) {
//pr(array('Transaction::stats' => compact('id', 'query'))); //pr(array('Transaction::stats' => compact('id', 'query')));
$this->queryInit($query); $this->queryInit($query);
@@ -392,8 +392,13 @@ class Transaction extends AppModel {
$squery['link'][$table] = array('fields' => array()); $squery['link'][$table] = array('fields' => array());
if ($table == 'LedgerEntry') { if ($table == 'LedgerEntry') {
if (isset($balance_account_id)) {
$squery['link']['LedgerEntry']['Account'] = array('fields' => array());
$squery['conditions'][] = array("Account.id" => $balance_account_id);
}
$squery['fields'] = array_merge($squery['fields'], $squery['fields'] = array_merge($squery['fields'],
$this->LedgerEntry->debitCreditFields(true, false)); $this->LedgerEntry->debitCreditFields(true, $balance_account_id != null));
} }
elseif ($table == 'StatementEntry') { elseif ($table == 'StatementEntry') {
$squery['fields'] = array_merge($squery['fields'], $squery['fields'] = array_merge($squery['fields'],