Customers is working somewhat. I want to see if the grid query logic can be simplified, so I'm checking in first

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@359 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-21 09:40:51 +00:00
parent 59e6379977
commit fd856323a5
3 changed files with 41 additions and 73 deletions

View File

@@ -47,8 +47,6 @@ class CustomersController extends AppController {
function jqGridDataSetup(&$params) {
parent::jqGridDataSetup($params);
if (!isset($params['action']))
$params['action'] = 'all';
}
function jqGridDataCountTables(&$params, &$model) {
@@ -63,20 +61,7 @@ class CustomersController extends AppController {
function jqGridDataTables(&$params, &$model) {
$link = $this->jqGridDataCountTables($params, $model);
$link['link']['DoubleEntry'] = array('fields' => array());
$link['link']['DoubleEntry']['Ledger'] = array('fields' => array());
$link['link']['DoubleEntry']['Ledger']['Account'] = array('fields' => array());
// INNER JOIN would be great, as it would ensure we're only looking
// at the ledger entries that we truly want. However, this also
// removes from the query any units that do not yet have a ledger
// entry in A/R. A solution would be to INNER JOIN these tables,
// and LEFT JOIN it to the rest. Grouping of JOINs, however, is
// implemented with the 'joins' tag, and is not available through
// the Linkable behavior interface.
//$link['link']['DoubleEntry']['Ledger']['Account']['type'] = 'INNER';
$link['link']['DoubleEntry']['Ledger']['Account']['conditions']
= array('Account.id' =>
$this->Customer->DoubleEntry->Ledger->Account->accountReceivableAccountID());
$link['link']['StatementEntry'] = array('fields' => array());
return $link;
}
@@ -84,11 +69,8 @@ class CustomersController extends AppController {
$db = &$model->getDataSource();
$fields = $db->fields($model, $model->alias);
$fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count');
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
" IF(DoubleEntry.debit_ledger_id = Account.id," .
" 1, -1))" .
" * IF(DoubleEntry.amount IS NULL, 0, DoubleEntry.amount))" .
" AS 'balance'");
$fields = array_merge($fields,
$this->Customer->StatementEntry->chargePaymentFields(true));
return $fields;
}
@@ -137,7 +119,7 @@ class CustomersController extends AppController {
array('CurrentLease'=>1))),
array_diff_key($query, array('link'=>1))));
if ($params['action'] === 'all')
if ($params['action'] == 'all')
return $count;
$query['conditions'][] = 'CurrentLease.id IS NULL';
@@ -155,18 +137,6 @@ class CustomersController extends AppController {
return $count;
}
function jqGridDataRecords(&$params, &$model, $query) {
$customers = parent::jqGridDataRecords($params, $model, $query);
// Get the balance on each customer.
foreach ($customers AS &$customer) {
$stats = $this->Customer->stats($customer['Customer']['id']);
$customer['Customer']['balance'] = $stats['balance'];
}
return $customers;
}
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
$links['Customer'] = array('name');
return parent::jqGridRecordLinks($params, $model, $records, $links);
@@ -437,17 +407,17 @@ class CustomersController extends AppController {
*/
function refund() {
$entries = $this->Customer->DoubleEntry->find
$entries = $this->Customer->StatementEntry->find
('all', array
('contain' => false,
'conditions' => array('DoubleEntry.id' =>
'conditions' => array('StatementEntry.id' =>
//array(199,200,201)
61
),
));
pr(compact('entries'));
$this->Customer->DoubleEntry->reverse($entries);
$this->Customer->StatementEntry->reverse($entries);
}
@@ -482,7 +452,7 @@ class CustomersController extends AppController {
unset($unreconciled['entries']['entry']);
//pr($unreconciled);
//$reconciled = $cust->reconcileNewDoubleEntry($cust_id, 'credit', $amount);
//$reconciled = $cust->reconcileNewStatementEntry($cust_id, 'credit', $amount);
$opts = array();
//$opts['format'] = 'tags';

View File

@@ -19,7 +19,7 @@ class Customer extends AppModel {
'conditions' => 'CurrentLease.close_date IS NULL',
),
'Lease',
'DoubleEntry',
'StatementEntry',
'ContactsCustomer',
'Transaction',
@@ -81,17 +81,15 @@ class Customer extends AppModel {
$A = new Account();
if (!isset($query['link']['DoubleEntry']))
$query['link']['DoubleEntry'] = array();
if (!isset($query['link']['DoubleEntry']['Customer']))
$query['link']['DoubleEntry']['Customer'] = array();
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
$query['link']['DoubleEntry']['Customer']['fields'] = array();
if (!isset($query['link']['Customer']))
$query['link']['Customer'] = array();
if (!isset($query['link']['Customer']['fields']))
$query['link']['Customer']['fields'] = array();
$query['conditions'][] = array('Customer.id' => $id);
$query['conditions'][] = array('Entry.account_id' => $A->securityDepositAccountID());
$query['conditions'][] = array('StatementEntry.account_id' => $A->securityDepositAccountID());
$set = $this->DoubleEntry->Entry->reconciledSet('CHARGE', $query);
$set = $this->StatementEntry->reconciledSet('CHARGE', $query);
//pr(compact('set'));
return $set;
}
@@ -107,16 +105,16 @@ class Customer extends AppModel {
function unreconciledCharges($id, $query = null) {
$this->queryInit($query);
if (!isset($query['link']['DoubleEntry']))
$query['link']['DoubleEntry'] = array();
if (!isset($query['link']['DoubleEntry']['Customer']))
$query['link']['DoubleEntry']['Customer'] = array();
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
$query['link']['DoubleEntry']['Customer']['fields'] = array();
if (!isset($query['link']['StatementEntry']))
$query['link']['StatementEntry'] = array();
/* if (!isset($query['link']['StatementEntry']['Customer'])) */
/* $query['link']['StatementEntry']['Customer'] = array(); */
/* if (!isset($query['link']['StatementEntry']['Customer']['fields'])) */
/* $query['link']['StatementEntry']['Customer']['fields'] = array(); */
$query['conditions'][] = array('Customer.id' => $id);
$set = $this->DoubleEntry->Entry->reconciledSet('CHARGE', $query, true);
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, true);
//pr(compact('set'));
return $set;
}
@@ -132,16 +130,16 @@ class Customer extends AppModel {
function excessPayments($id, $query = null) {
$this->queryInit($query);
if (!isset($query['link']['DoubleEntry']))
$query['link']['DoubleEntry'] = array();
if (!isset($query['link']['DoubleEntry']['Customer']))
$query['link']['DoubleEntry']['Customer'] = array();
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
$query['link']['DoubleEntry']['Customer']['fields'] = array();
if (!isset($query['link']['StatementEntry']))
$query['link']['StatementEntry'] = array();
/* if (!isset($query['link']['StatementEntry']['Customer'])) */
/* $query['link']['StatementEntry']['Customer'] = array(); */
/* if (!isset($query['link']['StatementEntry']['Customer']['fields'])) */
/* $query['link']['StatementEntry']['Customer']['fields'] = array(); */
$query['conditions'][] = array('Customer.id' => $id);
$set = $this->DoubleEntry->Entry->reconciledSet('PAYMENT', $query, true);
$set = $this->StatementEntry->reconciledSet('PAYMENT', $query, true);
//pr(compact('set'));
return $set;
}
@@ -171,7 +169,7 @@ class Customer extends AppModel {
$unreconciled['entries'] = $this->unreconciledCharges($id, $query);
foreach ($unreconciled['entries'] AS $i => &$item) {
$entry =& $item['DoubleEntry'];
$entry =& $item['StatementEntry'];
// Determine if amount is sufficient to cover the entry
if ($amount > $entry['balance'])
$apply = $entry['balance'];
@@ -214,7 +212,7 @@ class Customer extends AppModel {
$A = new Account();
$reconciled = $A->reconcileLedgerEntries
($A->accountReceivableAccountID(),
array('DoubleEntry.customer_id' => $id));
array('StatementEntry.customer_id' => $id));
return $reconciled;
}
@@ -347,13 +345,15 @@ class Customer extends AppModel {
if (!$id)
return null;
$A = new Account();
$stats = $A->stats($A->accountReceivableAccountID(), true,
array('DoubleEntry.customer_id' => $id));
$stats = $this->StatementEntry->find
('first', array
('contain' => false,
'fields' => $this->StatementEntry->chargePaymentFields(true),
'conditions' => array('StatementEntry.customer_id' => $id),
));
// Pull to the top level and return
$stats = $stats['Ledger'];
return $stats;
//pr(compact('stats'));
return $stats[0];
}
}

View File

@@ -62,11 +62,10 @@ echo $this->element('contacts', array
*/
echo $this->element('leases', array
('no_customer' => true,
('customer_id' => $customer['id'],
'config' => array
('caption' => 'Lease History',
'rows' => $customer['Lease'],
)));
@@ -74,10 +73,9 @@ echo $this->element('leases', array
* Customer Account History
*/
echo $this->element('entries', array
echo $this->element('ledger_entries', array
(// Element configuration
'customer_id' => $customer['Customer']['id'],
'entry_type' => array('CHARGE', 'PAYMENT'),
// Grid configuration
'config' => array