Updated the balance algorithm for units and customers as was done for leases.
git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@253 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -51,7 +51,7 @@ class CustomersController extends AppController {
|
||||
$params['action'] = 'all';
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
function jqGridDataCountTables(&$params, &$model) {
|
||||
return array
|
||||
('link' =>
|
||||
array(// Models
|
||||
@@ -61,9 +61,35 @@ class CustomersController extends AppController {
|
||||
);
|
||||
}
|
||||
|
||||
function jqGridDataTables(&$params, &$model) {
|
||||
$link = $this->jqGridDataCountTables($params, $model);
|
||||
$link['link']['LedgerEntry'] = array('fields' => array());
|
||||
$link['link']['LedgerEntry']['Ledger'] = array('fields' => array());
|
||||
$link['link']['LedgerEntry']['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']['LedgerEntry']['Ledger']['Account']['type'] = 'INNER';
|
||||
$link['link']['LedgerEntry']['Ledger']['Account']['conditions']
|
||||
= array('Account.id' =>
|
||||
$this->Customer->LedgerEntry->Ledger->Account->accountReceivableAccountID());
|
||||
return $link;
|
||||
}
|
||||
|
||||
function jqGridDataFields(&$params, &$model) {
|
||||
return array('Customer.*',
|
||||
'COUNT(CurrentLease.id) AS lease_count');
|
||||
$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(LedgerEntry.debit_ledger_id = Account.id," .
|
||||
" 1, -1))" .
|
||||
" * IF(LedgerEntry.amount IS NULL, 0, LedgerEntry.amount))" .
|
||||
" AS 'balance'");
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function jqGridDataConditions(&$params, &$model) {
|
||||
@@ -80,13 +106,19 @@ class CustomersController extends AppController {
|
||||
}
|
||||
|
||||
function jqGridDataOrder(&$params, &$model, $index, $direction) {
|
||||
$order = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||
if ($index === 'PrimaryContact.last_name') {
|
||||
$order[] = 'PrimaryContact.first_name ' . $direction;
|
||||
}
|
||||
if ($index === 'PrimaryContact.first_name') {
|
||||
$order[] = 'PrimaryContact.last_name ' . $direction;
|
||||
}
|
||||
$order = array();
|
||||
$order[] = parent::jqGridDataOrder($params, $model, $index, $direction);
|
||||
|
||||
if ($index !== 'PrimaryContact.last_name')
|
||||
$order[] = parent::jqGridDataOrder($params, $model,
|
||||
'PrimaryContact.last_name', $direction);
|
||||
if ($index !== 'PrimaryContact.first_name')
|
||||
$order[] = parent::jqGridDataOrder($params, $model,
|
||||
'PrimaryContact.first_name', $direction);
|
||||
if ($index !== 'Customer.id')
|
||||
$order[] = parent::jqGridDataOrder($params, $model,
|
||||
'Customer.id', $direction);
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
@@ -309,8 +341,8 @@ class CustomersController extends AppController {
|
||||
pr("CUSTOMER SAVE FAILED");
|
||||
}
|
||||
|
||||
// Exisisting Customer, then view it, else if this
|
||||
// is a new customer, go to the move in screen.
|
||||
// If existing customer, then view it. Otherwise, since
|
||||
// this is a new customer, go to the move in screen.
|
||||
if ($this->data['Customer']['id'])
|
||||
$this->redirect(array('action'=>'view', $this->Customer->id));
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user