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/site@359 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -47,8 +47,6 @@ class CustomersController extends AppController {
|
|||||||
|
|
||||||
function jqGridDataSetup(&$params) {
|
function jqGridDataSetup(&$params) {
|
||||||
parent::jqGridDataSetup($params);
|
parent::jqGridDataSetup($params);
|
||||||
if (!isset($params['action']))
|
|
||||||
$params['action'] = 'all';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function jqGridDataCountTables(&$params, &$model) {
|
function jqGridDataCountTables(&$params, &$model) {
|
||||||
@@ -63,20 +61,7 @@ class CustomersController extends AppController {
|
|||||||
|
|
||||||
function jqGridDataTables(&$params, &$model) {
|
function jqGridDataTables(&$params, &$model) {
|
||||||
$link = $this->jqGridDataCountTables($params, $model);
|
$link = $this->jqGridDataCountTables($params, $model);
|
||||||
$link['link']['DoubleEntry'] = array('fields' => array());
|
$link['link']['StatementEntry'] = 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());
|
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,11 +69,8 @@ class CustomersController extends AppController {
|
|||||||
$db = &$model->getDataSource();
|
$db = &$model->getDataSource();
|
||||||
$fields = $db->fields($model, $model->alias);
|
$fields = $db->fields($model, $model->alias);
|
||||||
$fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count');
|
$fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count');
|
||||||
$fields[] = ("SUM(IF(Account.id IS NULL, 0," .
|
$fields = array_merge($fields,
|
||||||
" IF(DoubleEntry.debit_ledger_id = Account.id," .
|
$this->Customer->StatementEntry->chargePaymentFields(true));
|
||||||
" 1, -1))" .
|
|
||||||
" * IF(DoubleEntry.amount IS NULL, 0, DoubleEntry.amount))" .
|
|
||||||
" AS 'balance'");
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +119,7 @@ class CustomersController extends AppController {
|
|||||||
array('CurrentLease'=>1))),
|
array('CurrentLease'=>1))),
|
||||||
array_diff_key($query, array('link'=>1))));
|
array_diff_key($query, array('link'=>1))));
|
||||||
|
|
||||||
if ($params['action'] === 'all')
|
if ($params['action'] == 'all')
|
||||||
return $count;
|
return $count;
|
||||||
|
|
||||||
$query['conditions'][] = 'CurrentLease.id IS NULL';
|
$query['conditions'][] = 'CurrentLease.id IS NULL';
|
||||||
@@ -155,18 +137,6 @@ class CustomersController extends AppController {
|
|||||||
return $count;
|
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) {
|
function jqGridRecordLinks(&$params, &$model, &$records, $links) {
|
||||||
$links['Customer'] = array('name');
|
$links['Customer'] = array('name');
|
||||||
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
return parent::jqGridRecordLinks($params, $model, $records, $links);
|
||||||
@@ -437,17 +407,17 @@ class CustomersController extends AppController {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function refund() {
|
function refund() {
|
||||||
$entries = $this->Customer->DoubleEntry->find
|
$entries = $this->Customer->StatementEntry->find
|
||||||
('all', array
|
('all', array
|
||||||
('contain' => false,
|
('contain' => false,
|
||||||
'conditions' => array('DoubleEntry.id' =>
|
'conditions' => array('StatementEntry.id' =>
|
||||||
//array(199,200,201)
|
//array(199,200,201)
|
||||||
61
|
61
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
pr(compact('entries'));
|
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']);
|
unset($unreconciled['entries']['entry']);
|
||||||
|
|
||||||
//pr($unreconciled);
|
//pr($unreconciled);
|
||||||
//$reconciled = $cust->reconcileNewDoubleEntry($cust_id, 'credit', $amount);
|
//$reconciled = $cust->reconcileNewStatementEntry($cust_id, 'credit', $amount);
|
||||||
|
|
||||||
$opts = array();
|
$opts = array();
|
||||||
//$opts['format'] = 'tags';
|
//$opts['format'] = 'tags';
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class Customer extends AppModel {
|
|||||||
'conditions' => 'CurrentLease.close_date IS NULL',
|
'conditions' => 'CurrentLease.close_date IS NULL',
|
||||||
),
|
),
|
||||||
'Lease',
|
'Lease',
|
||||||
'DoubleEntry',
|
'StatementEntry',
|
||||||
'ContactsCustomer',
|
'ContactsCustomer',
|
||||||
|
|
||||||
'Transaction',
|
'Transaction',
|
||||||
@@ -81,17 +81,15 @@ class Customer extends AppModel {
|
|||||||
|
|
||||||
$A = new Account();
|
$A = new Account();
|
||||||
|
|
||||||
if (!isset($query['link']['DoubleEntry']))
|
if (!isset($query['link']['Customer']))
|
||||||
$query['link']['DoubleEntry'] = array();
|
$query['link']['Customer'] = array();
|
||||||
if (!isset($query['link']['DoubleEntry']['Customer']))
|
if (!isset($query['link']['Customer']['fields']))
|
||||||
$query['link']['DoubleEntry']['Customer'] = array();
|
$query['link']['Customer']['fields'] = array();
|
||||||
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
|
|
||||||
$query['link']['DoubleEntry']['Customer']['fields'] = array();
|
|
||||||
|
|
||||||
$query['conditions'][] = array('Customer.id' => $id);
|
$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'));
|
//pr(compact('set'));
|
||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
@@ -107,16 +105,16 @@ class Customer extends AppModel {
|
|||||||
function unreconciledCharges($id, $query = null) {
|
function unreconciledCharges($id, $query = null) {
|
||||||
$this->queryInit($query);
|
$this->queryInit($query);
|
||||||
|
|
||||||
if (!isset($query['link']['DoubleEntry']))
|
if (!isset($query['link']['StatementEntry']))
|
||||||
$query['link']['DoubleEntry'] = array();
|
$query['link']['StatementEntry'] = array();
|
||||||
if (!isset($query['link']['DoubleEntry']['Customer']))
|
/* if (!isset($query['link']['StatementEntry']['Customer'])) */
|
||||||
$query['link']['DoubleEntry']['Customer'] = array();
|
/* $query['link']['StatementEntry']['Customer'] = array(); */
|
||||||
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
|
/* if (!isset($query['link']['StatementEntry']['Customer']['fields'])) */
|
||||||
$query['link']['DoubleEntry']['Customer']['fields'] = array();
|
/* $query['link']['StatementEntry']['Customer']['fields'] = array(); */
|
||||||
|
|
||||||
$query['conditions'][] = array('Customer.id' => $id);
|
$query['conditions'][] = array('Customer.id' => $id);
|
||||||
|
|
||||||
$set = $this->DoubleEntry->Entry->reconciledSet('CHARGE', $query, true);
|
$set = $this->StatementEntry->reconciledSet('CHARGE', $query, true);
|
||||||
//pr(compact('set'));
|
//pr(compact('set'));
|
||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
@@ -132,16 +130,16 @@ class Customer extends AppModel {
|
|||||||
function excessPayments($id, $query = null) {
|
function excessPayments($id, $query = null) {
|
||||||
$this->queryInit($query);
|
$this->queryInit($query);
|
||||||
|
|
||||||
if (!isset($query['link']['DoubleEntry']))
|
if (!isset($query['link']['StatementEntry']))
|
||||||
$query['link']['DoubleEntry'] = array();
|
$query['link']['StatementEntry'] = array();
|
||||||
if (!isset($query['link']['DoubleEntry']['Customer']))
|
/* if (!isset($query['link']['StatementEntry']['Customer'])) */
|
||||||
$query['link']['DoubleEntry']['Customer'] = array();
|
/* $query['link']['StatementEntry']['Customer'] = array(); */
|
||||||
if (!isset($query['link']['DoubleEntry']['Customer']['fields']))
|
/* if (!isset($query['link']['StatementEntry']['Customer']['fields'])) */
|
||||||
$query['link']['DoubleEntry']['Customer']['fields'] = array();
|
/* $query['link']['StatementEntry']['Customer']['fields'] = array(); */
|
||||||
|
|
||||||
$query['conditions'][] = array('Customer.id' => $id);
|
$query['conditions'][] = array('Customer.id' => $id);
|
||||||
|
|
||||||
$set = $this->DoubleEntry->Entry->reconciledSet('PAYMENT', $query, true);
|
$set = $this->StatementEntry->reconciledSet('PAYMENT', $query, true);
|
||||||
//pr(compact('set'));
|
//pr(compact('set'));
|
||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
@@ -171,7 +169,7 @@ class Customer extends AppModel {
|
|||||||
$unreconciled['entries'] = $this->unreconciledCharges($id, $query);
|
$unreconciled['entries'] = $this->unreconciledCharges($id, $query);
|
||||||
|
|
||||||
foreach ($unreconciled['entries'] AS $i => &$item) {
|
foreach ($unreconciled['entries'] AS $i => &$item) {
|
||||||
$entry =& $item['DoubleEntry'];
|
$entry =& $item['StatementEntry'];
|
||||||
// Determine if amount is sufficient to cover the entry
|
// Determine if amount is sufficient to cover the entry
|
||||||
if ($amount > $entry['balance'])
|
if ($amount > $entry['balance'])
|
||||||
$apply = $entry['balance'];
|
$apply = $entry['balance'];
|
||||||
@@ -214,7 +212,7 @@ class Customer extends AppModel {
|
|||||||
$A = new Account();
|
$A = new Account();
|
||||||
$reconciled = $A->reconcileLedgerEntries
|
$reconciled = $A->reconcileLedgerEntries
|
||||||
($A->accountReceivableAccountID(),
|
($A->accountReceivableAccountID(),
|
||||||
array('DoubleEntry.customer_id' => $id));
|
array('StatementEntry.customer_id' => $id));
|
||||||
|
|
||||||
return $reconciled;
|
return $reconciled;
|
||||||
}
|
}
|
||||||
@@ -347,13 +345,15 @@ class Customer extends AppModel {
|
|||||||
if (!$id)
|
if (!$id)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
$A = new Account();
|
$stats = $this->StatementEntry->find
|
||||||
$stats = $A->stats($A->accountReceivableAccountID(), true,
|
('first', array
|
||||||
array('DoubleEntry.customer_id' => $id));
|
('contain' => false,
|
||||||
|
'fields' => $this->StatementEntry->chargePaymentFields(true),
|
||||||
|
'conditions' => array('StatementEntry.customer_id' => $id),
|
||||||
|
));
|
||||||
|
|
||||||
// Pull to the top level and return
|
//pr(compact('stats'));
|
||||||
$stats = $stats['Ledger'];
|
return $stats[0];
|
||||||
return $stats;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,11 +62,10 @@ echo $this->element('contacts', array
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
echo $this->element('leases', array
|
echo $this->element('leases', array
|
||||||
('no_customer' => true,
|
('customer_id' => $customer['id'],
|
||||||
|
|
||||||
'config' => array
|
'config' => array
|
||||||
('caption' => 'Lease History',
|
('caption' => 'Lease History',
|
||||||
'rows' => $customer['Lease'],
|
|
||||||
)));
|
)));
|
||||||
|
|
||||||
|
|
||||||
@@ -74,10 +73,9 @@ echo $this->element('leases', array
|
|||||||
* Customer Account History
|
* Customer Account History
|
||||||
*/
|
*/
|
||||||
|
|
||||||
echo $this->element('entries', array
|
echo $this->element('ledger_entries', array
|
||||||
(// Element configuration
|
(// Element configuration
|
||||||
'customer_id' => $customer['Customer']['id'],
|
'customer_id' => $customer['Customer']['id'],
|
||||||
'entry_type' => array('CHARGE', 'PAYMENT'),
|
|
||||||
|
|
||||||
// Grid configuration
|
// Grid configuration
|
||||||
'config' => array
|
'config' => array
|
||||||
|
|||||||
Reference in New Issue
Block a user