From 8663c258067359805d332e32b2b30424aef8e946 Mon Sep 17 00:00:00 2001 From: abijah Date: Mon, 24 Aug 2009 21:49:40 +0000 Subject: [PATCH] Added some lease operations to the customer menu. If there is only one current lease, this works great, and if there are multiple, it works as if it were performed from the top level, ignoring the fact that the user clicked the operation from the customer page. git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@769 97e9348a-65ac-dc4b-aefc-98561f571b83 --- site/controllers/customers_controller.php | 62 ++++++++++++++++------- site/models/customer.php | 8 +-- site/views/leases/invoice.ctp | 1 + 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/site/controllers/customers_controller.php b/site/controllers/customers_controller.php index 1954db4..4a93f44 100644 --- a/site/controllers/customers_controller.php +++ b/site/controllers/customers_controller.php @@ -244,36 +244,58 @@ class CustomersController extends AppController { $outstanding_deposit = $this->Customer->securityDepositBalance($id); // Figure out if this customer has any non-closed leases - $show_moveout = false; - $show_payment = false; + $show_moveout = false; $moveout_lease_id = null; + $show_payment = false; $payment_lease_id = null; foreach ($customer['Lease'] AS $lease) { - if (!isset($lease['close_date'])) + if (!isset($lease['close_date'])) { + if ($show_payment) + $payment_lease_id = null; + else + $payment_lease_id = $lease['id']; $show_payment = true; - if (!isset($lease['moveout_date'])) + } + if (!isset($lease['moveout_date'])) { + if ($show_moveout) + $moveout_lease_id = null; + else + $moveout_lease_id = $lease['id']; $show_moveout = true; + } } // Set up dynamic menu items - $this->addSideMenuLink('Edit', - array('action' => 'edit', $id), null, - 'ACTION'); - - $this->addSideMenuLink('Move-In', - array('action' => 'move_in', $id), null, - 'ACTION'); - -/* if ($show_moveout) { */ -/* $this->addSideMenuLink('Move-Out', */ -/* array('action' => 'move_out', $id), null, */ -/* 'ACTION'); */ -/* } */ - if ($show_payment || $outstanding_balance > 0) $this->addSideMenuLink('New Receipt', array('action' => 'receipt', $id), null, 'ACTION'); + if ($show_payment) { +/* $ids = $this->Customer->leaseIds($id, true); */ +/* if (count($ids) == 1) */ +/* $lease_id = $ids[0]; */ +/* else */ +/* $lease_id = null; */ + + $this->addSideMenuLink('New Invoice', + array('controller' => 'leases', + 'action' => 'invoice', + $payment_lease_id), null, + 'ACTION'); + } + + $this->addSideMenuLink('Move-In', + array('action' => 'move_in', $id), null, + 'ACTION'); + + if ($show_moveout) { + $this->addSideMenuLink('Move-Out', + array('controller' => 'leases', + 'action' => 'move_out', + $moveout_lease_id), null, + 'ACTION'); + } + if (!$show_moveout && $outstanding_balance > 0) $this->addSideMenuLink('Write-Off', array('action' => 'bad_debt', $id), null, @@ -284,6 +306,10 @@ class CustomersController extends AppController { array('action' => 'refund', $id), null, 'ACTION'); + $this->addSideMenuLink('Edit', + array('action' => 'edit', $id), null, + 'ACTION'); + // Prepare to render. $title = 'Customer: ' . $customer['Customer']['name']; $this->set(compact('customer', 'title', diff --git a/site/models/customer.php b/site/models/customer.php index 3df1ebb..22a1055 100644 --- a/site/models/customer.php +++ b/site/models/customer.php @@ -54,17 +54,19 @@ class Customer extends AppModel { * function: leaseIds * - Returns the lease IDs for the given customer */ - function leaseIds($id) { + function leaseIds($id, $current = false) { + $Lease = $current ? 'CurrentLease' : 'Lease'; + $this->cacheQueries = true; $customer = $this->find('first', array('contain' => - array('Lease' => array('fields' => array('id'))), + array($Lease => array('fields' => array('id'))), 'fields' => array(), 'conditions' => array(array('Customer.id' => $id)))); $this->cacheQueries = false; $ids = array(); - foreach ($customer['Lease'] AS $lease) + foreach ($customer[$Lease] AS $lease) $ids[] = $lease['id']; return $ids; diff --git a/site/views/leases/invoice.ctp b/site/views/leases/invoice.ctp index bc48cc8..da0e3af 100644 --- a/site/views/leases/invoice.ctp +++ b/site/views/leases/invoice.ctp @@ -209,6 +209,7 @@ if (empty($movein)) array('gridstate' => 'onGridState("#"+$(this).attr("id"), gridstate)'), ), + 'exclude' => array('Closed'), 'action' => 'active', 'nolinks' => true, 'limit' => 10,