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

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@391 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-26 23:23:19 +00:00
parent d4292a85a0
commit 68fe787209
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.
*/
function stats($id = null) {
function stats($id = null, $query = null) {
if (!$id)
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
('contain' => false,
'fields' => $this->StatementEntry->chargePaymentFields(true),
'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 =
$this->Transaction->stats(null,
array('conditions' =>
array('Transaction.customer_id' => $id),
));
$tquery = $query;
//$tquery['conditions'][] = array('StatementEntry.customer_id' => $id);
$tquery['conditions'][] = 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;
}
}