Even with all the effort put into getting the counts right on the customers grid, it still didn't work right. The root of the problem is the join to CurrentLease, which can result in multiple rows for the same customer. I can revisit this in the future to put some clever solution back in, but in the meantime, it was easiest just to add fields to the customers table, and simply update it whenever the customer lease situation changes. I don't like it... but it just made life much simpler.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@481 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -50,7 +50,6 @@ class CustomersController extends AppController {
|
||||
('link' =>
|
||||
array(// Models
|
||||
'PrimaryContact',
|
||||
'CurrentLease' => array('fields' => array()),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -64,7 +63,6 @@ class CustomersController extends AppController {
|
||||
|
||||
function gridDataFields(&$params, &$model) {
|
||||
$fields = parent::gridDataFields($params, $model);
|
||||
$fields[] = ('COUNT(DISTINCT CurrentLease.id) AS lease_count');
|
||||
return array_merge($fields,
|
||||
$this->Customer->StatementEntry->chargePaymentFields(true));
|
||||
}
|
||||
@@ -73,10 +71,11 @@ class CustomersController extends AppController {
|
||||
$conditions = parent::gridDataConditions($params, $model);
|
||||
|
||||
if ($params['action'] === 'current') {
|
||||
$conditions[] = 'CurrentLease.id IS NOT NULL';
|
||||
$conditions[] = array('Customer.current_lease_count >' => 0);
|
||||
}
|
||||
elseif ($params['action'] === 'past') {
|
||||
$conditions[] = 'CurrentLease.id IS NULL';
|
||||
$conditions[] = array('Customer.current_lease_count' => 0);
|
||||
$conditions[] = array('Customer.past_lease_count >' => 0);
|
||||
}
|
||||
|
||||
return $conditions;
|
||||
@@ -99,30 +98,6 @@ class CustomersController extends AppController {
|
||||
return $order;
|
||||
}
|
||||
|
||||
function gridDataCount(&$params, &$model) {
|
||||
|
||||
if ($params['action'] != 'current')
|
||||
return parent::gridDataCount($params, $model);
|
||||
|
||||
// OK, for current customers, we have an issue.
|
||||
// We don't have a good way to use the query to obtain
|
||||
// our count. The problem is that we're relying on the
|
||||
// group by for the query, but that simply won't work
|
||||
// for the count. However, it's not difficult to simply
|
||||
// derive it since 'current' customers are mutually
|
||||
// exclusive to 'past' customers.
|
||||
|
||||
$tmp_params = $params;
|
||||
$tmp_params['action'] = 'all';
|
||||
$all_count = parent::gridDataCount($tmp_params, $model);
|
||||
$tmp_params['action'] = 'past';
|
||||
$past_count = parent::gridDataCount($tmp_params, $model);
|
||||
|
||||
// The current customer count is simply calculated
|
||||
// as all customers that are not past customers.
|
||||
return $all_count - $past_count;
|
||||
}
|
||||
|
||||
function gridDataPostProcessLinks(&$params, &$model, &$records, $links) {
|
||||
$links['Customer'] = array('name');
|
||||
return parent::gridDataPostProcessLinks($params, $model, $records, $links);
|
||||
|
||||
Reference in New Issue
Block a user