diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 290fc4a..42c5459 100644 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -249,12 +249,17 @@ class CustomersController extends AppController { /* $id)); */ /* } */ - if ($show_payment) { + if ($show_payment || $outstanding_balance > 0) $this->sidemenu_links[] = array('name' => 'Payment', 'url' => array('action' => 'receipt', $id)); - } + + if (!$show_moveout && $outstanding_balance > 0) + $this->sidemenu_links[] = + array('name' => 'Write-Off', + 'url' => array('action' => 'bad_debt', + $id)); if ($outstanding_balance < 0) $this->sidemenu_links[] = @@ -439,6 +444,35 @@ class CustomersController extends AppController { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: bad_debt + * - Sets up the write-off entry page, so that the + * user can write off remaining charges of a customer. + */ + + function bad_debt($id) { + $this->Customer->id = $id; + $customer = $this->Customer->find + ('first', array + ('contain' => false, + )); + + // Make sure we have a valid customer to write off + if (empty($customer)) + $this->redirect(array('action' => 'index')); + + // Get the customer balance + $balance = $this->Customer->balance($id); + + // Prepare to render + $title = ($customer['Customer']['name'] . ': Write Off Bad Debt'); + $this->set(compact('title', 'customer', 'balance')); + $this->render('/transactions/bad_debt'); + } + + /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/controllers/leases_controller.php b/controllers/leases_controller.php index a9bdf4a..4362967 100644 --- a/controllers/leases_controller.php +++ b/controllers/leases_controller.php @@ -291,6 +291,7 @@ class LeasesController extends AppController { */ function bad_debt($id) { + $this->Lease->id = $id; $lease = $this->Lease->find ('first', array ('contain' => array @@ -298,20 +299,14 @@ class LeasesController extends AppController { 'Unit' => array('fields' => array('id', 'name')), 'Customer' => array('fields' => array('id', 'name')), ), - - 'conditions' => array(array('Lease.id' => $id), - // Make sure lease is not closed... - array('Lease.close_date' => null), - ), )); // Make sure we have a valid lease to write off if (empty($lease)) $this->redirect(array('action' => 'view', $id)); - // Get the lease balance, part of lease stats - $stats = $this->Lease->stats($id); - $balance = $stats['balance']; + // Get the lease balance + $balance = $this->Lease->balance($id); // Prepare to render $title = ('Lease #' . $lease['Lease']['number'] . ': ' . @@ -465,8 +460,11 @@ class LeasesController extends AppController { $outstanding_balance = $this->Lease->balance($id); $outstanding_deposit = $this->Lease->securityDepositBalance($id); - // Set up dynamic menu items - if (!isset($lease['Lease']['close_date'])) { + // Set up dynamic menu items. Normally, these will only be present + // on an open lease, but it's possible for a lease to be closed, and + // yet still have an outstanding balance. This can happen if someone + // were to reverse charges, or if a payment should come back NSF. + if (!isset($lease['Lease']['close_date']) || $outstanding_balance > 0) { $this->sidemenu_links[] = array('name' => 'Operations', 'header' => true); @@ -475,9 +473,10 @@ class LeasesController extends AppController { array('name' => 'Move-Out', 'url' => array('action' => 'move_out', $id)); - $this->sidemenu_links[] = - array('name' => 'Charges', 'url' => array('action' => 'invoice', - $id)); + if (!isset($lease['Lease']['close_date'])) + $this->sidemenu_links[] = + array('name' => 'Charges', 'url' => array('action' => 'invoice', + $id)); $this->sidemenu_links[] = array('name' => 'Payments', 'url' => array('controller' => 'customers',