From b8d0e180149f0c8d829852eed91ccbe1bd56d70d Mon Sep 17 00:00:00 2001 From: abijah Date: Mon, 17 Aug 2009 05:43:01 +0000 Subject: [PATCH] Fixed bug when fetching data for editing a customer (the details function was deleted sometime back and might be worth putting back in). Also, added a tiny helper feature to update cached items while things are still somewhat unstable. Any time customer edit is clicked, the customer (and associated leases) will all be updated. This should allow an easy customer workaround in case there is a bug in the field. git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@599 97e9348a-65ac-dc4b-aefc-98561f571b83 --- controllers/customers_controller.php | 32 +++++++++++++++++++++++++++- models/customer.php | 17 ++++++++++++--- models/lease.php | 2 ++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 7258294..5244feb 100644 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -326,7 +326,37 @@ class CustomersController extends AppController { } if ($id) { - $this->data = $this->Customer->details($id); + // REVISIT : 20090816 + // This should never need to be done by a controller. + // However, until things stabilize, this gives the + // user a way to update any cached items on the + // customer, by just clicking Edit then Cancel. + $this->Customer->update($id); + + // Get details on this customer, its contacts and leases + $customer = $this->Customer->find + ('first', array + ('contain' => array + (// Models + 'Contact' => + array('order' => array('Contact.display_name'), + // Models + 'ContactPhone', + 'ContactEmail', + 'ContactAddress', + ), + 'Lease' => + array('Unit' => + array('order' => array('sort_order'), + 'fields' => array('id', 'name'), + ), + ), + ), + + 'conditions' => array('Customer.id' => $id), + )); + + $this->data = $customer; $title = 'Customer: ' . $this->data['Customer']['name'] . " : Edit"; } else { diff --git a/models/customer.php b/models/customer.php index b3c6fa1..dd9bd91 100644 --- a/models/customer.php +++ b/models/customer.php @@ -208,6 +208,7 @@ class Customer extends AppModel { * - Update any cached or calculated fields */ function update($id) { + $this->prEnter(compact('id')); // REVISIT : 20090812 // updateLeaseCount is handled directly when needed. @@ -216,11 +217,21 @@ class Customer extends AppModel { $current_leases = $this->find('all', - array('link' => array('CurrentLease' => array('type' => 'INNER')), + // REVISIT : 20090816 + // Do we need to update leases other than the current ones? + // It may be necessary. For example, a non-current lease + // can still be hit with an NSF item. In that case, it + // could have stale data if we look only to current leases. + //array('link' => array('CurrentLease' => array('type' => 'INNER')), + array('link' => array('Lease' => array('type' => 'INNER')), 'conditions' => array('Customer.id' => $id))); - foreach ($current_leases AS $lease) - $this->Lease->update($lease['CurrentLease']['id']); + foreach ($current_leases AS $lease) { + if (!empty($lease['CurrentLease']['id'])) + $this->Lease->update($lease['CurrentLease']['id']); + if (!empty($lease['Lease']['id'])) + $this->Lease->update($lease['Lease']['id']); + } } diff --git a/models/lease.php b/models/lease.php index 525d3a0..437b607 100644 --- a/models/lease.php +++ b/models/lease.php @@ -792,6 +792,8 @@ class Lease extends AppModel { * - Update any cached or calculated fields */ function update($id) { + $this->prEnter(compact('id')); + $this->id = $id; $this->saveField('charge_through_date', $this->rentChargeThrough($id)); $this->saveField('paid_through_date', $this->rentPaidThrough($id));