From 99904f22bb10a0cc281b2f05e2a0fedd570145b3 Mon Sep 17 00:00:00 2001 From: abijah Date: Fri, 10 Jul 2009 09:28:29 +0000 Subject: [PATCH] Stripped security deposits out of the Receipt page (and bad debt too). Added a dedicated security deposit utilization page. Works, I think, but my eyes are closing and it really needs fresh eyes again in the morning. git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629/site@293 97e9348a-65ac-dc4b-aefc-98561f571b83 --- controllers/customers_controller.php | 28 +----------- controllers/leases_controller.php | 60 +++++++++++++++++++++++++ controllers/transactions_controller.php | 3 +- models/transaction.php | 5 ++- views/customers/receipt.ctp | 17 +------ 5 files changed, 68 insertions(+), 45 deletions(-) diff --git a/controllers/customers_controller.php b/controllers/customers_controller.php index 59ceb4d..4994824 100644 --- a/controllers/customers_controller.php +++ b/controllers/customers_controller.php @@ -399,27 +399,12 @@ class CustomersController extends AppController { */ function receipt($id = null) { -/* $deposits = $this->Customer->findSecurityDeposits($id); */ -/* pr($deposits); */ -/* $this->autoRender = false; */ -/* return; */ - if (isset($id)) { $this->Customer->recursive = -1; $customer = $this->Customer->read(null, $id); $customer = $customer['Customer']; $unreconciled = $this->Customer->findUnreconciledLedgerEntries($id); $charges = $unreconciled['debit']; - $leases = $this->Customer->find('first', array('contain' => array('CurrentLease'), - 'conditions' => array('Customer.id' => $id))); - $deposits = array(); - foreach ($leases['CurrentLease'] AS $lease) { - $lease_deposits = $this->Customer->Lease->findSecurityDeposits($lease['id']); - $deposits[] = array('lease_id' => $lease['id'], - 'balance' => $lease_deposits['summary']['balance']); - } - pr($deposits); - $this->set(compact('deposits')); } else { $customer = null; @@ -460,23 +445,12 @@ class CustomersController extends AppController { $unreconciled = $this->Customer->findUnreconciledLedgerEntries($id); $unreconciled = array('entries' => array_intersect_key($unreconciled['debit'], - array('entry'=>1, 'balance'=>1)), - 'deposit' => array(), - ); + array('entry'=>1, 'balance'=>1))); // XML Helper will dump an empty tag if the array is empty if (!count($unreconciled['entries']['entry'])) unset($unreconciled['entries']['entry']); - $leases = $this->Customer->find('first', array('contain' => array('CurrentLease'), - 'conditions' => array('Customer.id' => $id))); - foreach ($leases['CurrentLease'] AS $lease) { - $lease_deposits = $this->Customer->Lease->findSecurityDeposits($lease['id']); - $unreconciled['deposit'][] - = array('lease_id' => $lease['id'], - 'balance' => $lease_deposits['summary']['balance']); - } - pr($unreconciled); //$reconciled = $cust->reconcileNewLedgerEntry($cust_id, 'credit', $amount); diff --git a/controllers/leases_controller.php b/controllers/leases_controller.php index d121a89..ae19402 100644 --- a/controllers/leases_controller.php +++ b/controllers/leases_controller.php @@ -228,6 +228,61 @@ class LeasesController extends AppController { } + /************************************************************************** + ************************************************************************** + ************************************************************************** + * action: apply_deposit + * - Applies the security deposit to charges. This is much + * like a receipt, but it's separated to keep it simple and + * to prevent feature overload on the receipt page. + */ + + function apply_deposit($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'), + ), + ), + + 'conditions' => array(array('Lease.id' => $id), + array('Lease.close_date' => null), + ), + )); + + + // 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 = $this->Lease->findSecurityDeposits($lease['Lease']['id']); + $this->set(compact('deposit')); + $this->set('customer', $lease['Customer']); + $this->set('unit', $lease['Unit']); + $this->set('lease', $lease['Lease']); + $this->set('account', array('id' => $A->securityDepositAccountID())); + +/* $redirect = array('controller' => 'leases', */ +/* 'action' => 'view', */ +/* $id); */ + + $title = ('Lease #' . $lease['Lease']['number'] . ': ' . + $lease['Unit']['name'] . ': ' . + $lease['Customer']['name'] . ': Utilize Security Deposit'); + $this->set(compact('title', 'redirect')); + } + + /************************************************************************** ************************************************************************** ************************************************************************** @@ -346,6 +401,11 @@ class LeasesController extends AppController { 'action' => 'receipt', $lease['Customer']['id'])); + if (isset($lease['Lease']['moveout_date']) && $outstanding_deposit > 0) + $this->sidemenu_links[] = + array('name' => 'Apply Deposit', 'url' => array('action' => 'apply_deposit', + $id)); + if ($this->Lease->closeable($id)) $this->sidemenu_links[] = array('name' => 'Close', 'url' => array('action' => 'close', diff --git a/controllers/transactions_controller.php b/controllers/transactions_controller.php index 5d1a68b..9e1fd0e 100644 --- a/controllers/transactions_controller.php +++ b/controllers/transactions_controller.php @@ -146,7 +146,8 @@ class TransactionsController extends AppController { pr($this->data); if (!$this->Transaction->addReceipt($this->data, - $this->data['Customer']['id'])) { + $this->data['Customer']['id'], + $this->data['Lease']['id'])) { $this->Session->setFlash("RECEIPT FAILED", true); // REVISIT 20090706: // Until we can work out the session problems, diff --git a/models/transaction.php b/models/transaction.php index 7dfb7a8..52699a6 100644 --- a/models/transaction.php +++ b/models/transaction.php @@ -135,7 +135,7 @@ class Transaction extends AppModel { * - Adds a new receipt transaction */ - function addReceipt($data, $customer_id) { + function addReceipt($data, $customer_id, $lease_id = null) { // Sanitize the data if (!$data['Transaction']['comment']) $data['Transaction']['comment'] = null; @@ -173,7 +173,7 @@ class Transaction extends AppModel { $this->LedgerEntry->MonetarySource->nameToID('Cash'); unset($entry['MonetarySource']); } - else { + elseif (isset($entry['MonetarySource'])) { $entry['MonetarySource']['name'] = $A->name($entry['account_id']); // Give it a fancy name based on the check number @@ -197,6 +197,7 @@ class Transaction extends AppModel { = $A->currentLedgerID($A->receiptAccountID()); $entry['customer_id'] = $customer_id; + $entry['lease_id'] = $lease_id; // Create it $receipt_entry = new LedgerEntry(); diff --git a/views/customers/receipt.ctp b/views/customers/receipt.ctp index 65dba59..ac198d1 100644 --- a/views/customers/receipt.ctp +++ b/views/customers/receipt.ctp @@ -248,8 +248,8 @@ function addPaymentSource(flash) { $div .= ' ID="payment-creditcard-cvv2-%{id}" />'; $div .= ''; } - elseif ($name == 'Security Deposit') { - $div .= '
'; + else { + continue; } $div .= ''; @@ -291,19 +291,6 @@ function updateCharges(id) { $('entry',xml).each(function(i){ ids.push($(this).attr('id')); }); - var html = ''; - $('deposit',xml).each(function(i){ - html += 'Lease #' + $(this).attr('lease_id') + ' Deposit:' + - fmtCurrency($(this).attr('balance')) + ''; - }); - - var html = ''; - $('.security-deposit-info').html(html); $('#receipt-balance').html(fmtCurrency($('entries',xml).attr('balance'))); $("#receipt-charges-caption").html("Outstanding Charges"); updateChargesGrid(ids);