diff --git a/controllers/leases_controller.php b/controllers/leases_controller.php index 9189556..2830569 100644 --- a/controllers/leases_controller.php +++ b/controllers/leases_controller.php @@ -252,57 +252,39 @@ class LeasesController extends AppController { ************************************************************************** ************************************************************************** * action: bad_debt - * - Writes off remaining charges on a lease. - * REVISIT : 20090710 - * Should this be a customer function? What customer - * would have only one lease that results in bad debt. + * - Sets up the write-off entry page, so that the + * user can write off remaining charges on a lease. */ function bad_debt($id) { - $A = new Account(); - $lease = $this->Lease->find ('first', array ('contain' => array (// Models - 'Unit' => - array('order' => array('sort_order'), - 'fields' => array('id', 'name'), - ), - - 'Customer' => - array('fields' => array('id', 'name'), - ), + '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 - $this->Lease->statsMerge($lease['Lease'], - array('stats' => $this->Lease->stats($id))); - - // Determine the lease security deposit - $deposit_balance = $this->Lease->securityDepositBalance($lease['Lease']['id']); - if ($deposit_balance > 0) - die("Still have un-utilized security deposit"); - - $this->set('customer', $lease['Customer']); - $this->set('unit', $lease['Unit']); - $this->set('lease', $lease['Lease']); - $this->set('account', array('id' => $A->badDebtAccountID())); - -/* $redirect = array('controller' => 'leases', */ -/* 'action' => 'view', */ -/* $id); */ + $stats = $this->Lease->stats($id); + $balance = $stats['balance']; + // Prepare to render $title = ('Lease #' . $lease['Lease']['number'] . ': ' . $lease['Unit']['name'] . ': ' . $lease['Customer']['name'] . ': Write Off Bad Debt'); - $this->set(compact('title', 'redirect')); + $this->set(compact('title', 'lease', 'balance')); + $this->render('/transactions/bad_debt'); } diff --git a/controllers/transactions_controller.php b/controllers/transactions_controller.php index 1261fda..5fe0b5a 100644 --- a/controllers/transactions_controller.php +++ b/controllers/transactions_controller.php @@ -261,6 +261,53 @@ class TransactionsController extends AppController { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: postWriteOff + * - handles the write off of bad debt + */ + + function postWriteOff() { + if (!$this->RequestHandler->isPost()) { + echo('

THIS IS NOT A POST FOR SOME REASON

'); + return; + } + + $data = $this->data; + $data['Entry'][0]['account_id'] = + $this->Transaction->Account->badDebtAccountID(); + + if (empty($data['Customer']['id'])) + $data['Customer']['id'] = null; + if (empty($data['Lease']['id'])) + $data['Lease']['id'] = null; + + if (!$this->Transaction->addReceipt($data, + $data['Customer']['id'], + $this->data['Lease']['id'])) { + $this->Session->setFlash("WRITE OFF FAILED", true); + // REVISIT 20090706: + // Until we can work out the session problems, + // just die. + die("

RECEIPT FAILED

"); + } + + pr(compact('data')); + $this->render('/fake'); + + // Return to viewing the lease/customer + if (empty($data['Lease']['id'])) + $this->redirect(array('controller' => 'customers', + 'action' => 'view', + $data['Customer']['id'])); + else + $this->redirect(array('controller' => 'leases', + 'action' => 'view', + $data['Lease']['id'])); + } + + /************************************************************************** ************************************************************************** ************************************************************************** diff --git a/views/leases/apply_deposit.ctp b/views/leases/apply_deposit.ctp deleted file mode 100644 index e5d1496..0000000 --- a/views/leases/apply_deposit.ctp +++ /dev/null @@ -1,88 +0,0 @@ -' . "\n"; - -echo ('
' . - - 'Lease #' . $lease['number'] . - ' / Customer #' . $customer['id'] . - ': ' . $customer['name'] . - ' / Unit ' . $unit['name'] . - - '
' . - '' . - -/* '' . */ - - '' . - - '
Balance:' . */ -/* FormatHelper::currency($lease['stats']['balance']) . */ -/* '
Deposit:' . - FormatHelper::currency($depositBalance) . - '
' . - '
' . - - '
' . "\n"); - - -echo $form->create(null, array('id' => 'apply-deposit-form', - 'url' => array('controller' => 'leases', - 'action' => 'apply_deposit') - ) - ); - -echo $form->input("Customer.id", - array('id' => 'customer-id', - 'type' => 'hidden', - 'value' => $customer['id'])); - -echo $form->input("Lease.id", - array('id' => 'lease-id', - 'type' => 'hidden', - 'value' => $lease['id'])); - -echo $form->input("LedgerEntry.Account.id", - array('id' => 'account-id', - 'type' => 'hidden', - 'value' => $account['id'])); - - -echo $this->element('form_table', - array('class' => "item receipt transaction entry", - //'with_name_after' => ':', - 'field_prefix' => 'Transaction', - 'fields' => array - ("stamp" => array('opts' => array('type' => 'text'), - 'between' => 'Now', - ), - "amount" => array('prefix' => 'LedgerEntry', - 'opts' => array('value' => $depositBalance), - ), - "comment" => array('opts' => array('size' => 50), - ), - ))); - -echo $form->end('Utilize Deposit'); -?> - - - - diff --git a/views/leases/bad_debt.ctp b/views/leases/bad_debt.ctp deleted file mode 100644 index fec8b58..0000000 --- a/views/leases/bad_debt.ctp +++ /dev/null @@ -1,80 +0,0 @@ -' . "\n"; - -echo ('
' . - - 'Lease #' . $lease['number'] . - ' / Customer #' . $customer['id'] . - ': ' . $customer['name'] . - ' / Unit ' . $unit['name'] . - - '
' . - '' . - '' . - '
Balance:'.$lease['stats']['balance'].'
' . - '
' . - - '
' . "\n"); - - -echo $form->create(null, array('id' => 'receipt-form', - 'url' => array('controller' => 'transactions', - 'action' => 'postReceipt'))); - -echo $form->input("Customer.id", - array('id' => 'customer-id', - 'type' => 'hidden', - 'value' => $customer['id'])); - -echo $form->input("Lease.id", - array('id' => 'lease-id', - 'type' => 'hidden', - 'value' => $lease['id'])); - -echo $form->input("LedgerEntry.0.account_id", - array('id' => 'account-id', - 'type' => 'hidden', - 'value' => $account['id'])); - -echo $form->input("LedgerEntry.0.amount", - array('id' => 'amount', - 'type' => 'hidden', - 'value' => $lease['stats']['balance'])); - - -echo $this->element('form_table', - array('class' => "item receipt transaction entry", - //'with_name_after' => ':', - 'field_prefix' => 'Transaction', - 'fields' => array - ("stamp" => array('opts' => array('type' => 'text'), - 'between' => 'Now', - ), - "comment" => array('opts' => array('size' => 50), - ), - ))); - -echo $form->end('Write Off Remaining Balance'); -?> - - - - diff --git a/views/transactions/bad_debt.ctp b/views/transactions/bad_debt.ctp new file mode 100644 index 0000000..668f260 --- /dev/null +++ b/views/transactions/bad_debt.ctp @@ -0,0 +1,89 @@ +' . "\n"; + +if (isset($lease)) { + $customer = $lease['Customer']; + $unit = $lease['Unit']; +} + +if (isset($customer['Customer'])) + $customer = $customer['Customer']; + +if (isset($lease['Lease'])) + $lease = $lease['Lease']; + +// We're not actually using a grid to select the customer / lease +// but we could/should be, and the result would be selection-text +echo ('
' . + '' . "\n"); + +echo ('' . + ' ' . + '' . "\n"); + +if (isset($lease)) + echo ('' . + ' ' . + '' . "\n"); + +echo ('' . + ' ' . + '' . "\n"); + +echo ('
' . $customer['name'] . '' . '(Customer #' . $customer['id'] . ')' . '
' . 'Unit ' . $unit['name'] . '' . '(Lease #' . $lease['number'] . ')' . '
Remaining Balance:' . FormatHelper::currency($balance) . '
' . + '
' . "\n"); + + +echo $form->create(null, array('id' => 'receipt-form', + 'url' => array('controller' => 'transactions', + 'action' => 'postWriteOff'))) . "\n"; + +echo $form->input("Customer.id", + array('type' => 'hidden', + 'value' => $customer['id'])) . "\n"; + +if (isset($lease['id'])) + echo $form->input("Lease.id", + array('type' => 'hidden', + 'value' => $lease['id'])) . "\n"; + +echo $form->input("Entry.0.amount", + array('type' => 'hidden', + 'value' => $balance)) . "\n"; + +echo $this->element('form_table', + array('class' => "item receipt transaction entry", + //'with_name_after' => ':', + 'field_prefix' => 'Transaction', + 'fields' => array + ("stamp" => array('opts' => array('type' => 'text'), + 'between' => 'Now', + ), + "comment" => array('opts' => array('size' => 50), + ), + ))) . "\n"; + +echo $form->end('Write Off Remaining Balance'); +?> + + + +