Add refund capability to the customer, and in fact only the customer, as we've revoked refund capability from the lease. This is to help work through various issues surrounding use of security deposits and general refund functionality. For example, a customer who has overpayed (customer surplus, with zero balance on lease), and then moves out. Where that security deposit surplus goes has been a bit of a thorn. Hopefully, this resolves the issue, although there may still be some bugs to flush out.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@504 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-08 04:27:02 +00:00
parent bba3af8163
commit b02a504abb
4 changed files with 58 additions and 27 deletions

View File

@@ -395,18 +395,35 @@ class CustomersController extends AppController {
* - Refunds customer charges
*/
function refund() {
$entries = $this->Customer->StatementEntry->find
('all', array
function refund($id) {
$customer = $this->Customer->find
('first', array
('contain' => false,
'conditions' => array('StatementEntry.id' =>
//array(199,200,201)
61
'conditions' => array(array('Customer.id' => $id),
),
));
pr(compact('entries'));
if (empty($customer)) {
$this->redirect(array('action'=>'view', $id));
}
$this->Customer->refund($entries);
// Determine the customer balance, bailing if the customer owes money
$balance = $this->Customer->balance($id);
if ($balance >= 0) {
$this->redirect(array('action'=>'view', $id));
}
// The refund will be for a positive amount
$balance *= -1;
// Get the accounts capable of paying the refund
$refundAccounts = $this->Customer->StatementEntry->Account->refundAccounts();
$defaultAccount = current($refundAccounts);
$this->set(compact('refundAccounts', 'defaultAccount'));
// Prepare to render
$title = ($customer['Customer']['name'] . ': Refund');
$this->set(compact('title', 'customer', 'balance'));
$this->render('/transactions/refund');
}

View File

@@ -278,6 +278,7 @@ class LeasesController extends AppController {
$lease['Unit']['name'] . ': ' .
$lease['Customer']['name'] . ': Refund');
$this->set(compact('title', 'lease', 'balance'));
$this->render('/transactions/refund');
}
@@ -459,10 +460,19 @@ class LeasesController extends AppController {
/* array('name' => 'Transfer Credit to Customer', */
/* 'url' => array('action' => 'promote_surplus', $id)); */
// REVISIT <AP>:
// Not allowing refund to be issued from the lease, as
// in fact, we should never have a positive lease balance.
// I'll flag this at the moment, since we might get one
// when a charge is reimbursed; a bug that we'll either
// need to fix, or we'll have to revisit this assumption.
if ($outstanding_balance < 0)
$this->sidemenu_links[] =
array('name' => 'Issue Refund',
'url' => array('action' => 'refund', $id));
INTERNAL_ERROR("Should not have a customer lease credit.");
/* if ($outstanding_balance < 0) */
/* $this->sidemenu_links[] = */
/* array('name' => 'Issue Refund', */
/* 'url' => array('action' => 'refund', $id)); */
if (isset($lease['Lease']['moveout_date']) && $outstanding_balance > 0)
$this->sidemenu_links[] =

View File

@@ -44,26 +44,26 @@ class Lease extends AppModel {
$this->prEnter(compact('id', 'query'));
$this->queryInit($query);
// REVISIT <AP>: 20090807
// Let's try simplifying the security deposit issue.
// Presume that security deposits are NOT used at all,
// until the customer moves out of the unit. At that
// time, the ENTIRE deposit is converted to customer
// credit. Piece of cake.
// For more information, see file revision history,
// including the revision just before this, r503.
$this->id = $id;
$moveout_date = $this->field('moveout_date');
if (!empty($moveout_date))
return $this->prReturn(0);
$query['conditions'][] = array('StatementEntry.lease_id' => $id);
$query['conditions'][] = array('StatementEntry.account_id' =>
$this->StatementEntry->Account->securityDepositAccountID());
// REVISIT <AP>: 20090804
// Dilemma... how to handle security deposits used to pay
// charges on the lease, yet are not part of the lease
// security deposit(s)? For example, Lease A & Lease B,
// each with $25 Sec. Dep. Move out of Lease A, and
// promote the lease surplus to the customer. A new
// charge on Lease B for $15, which is assigned $15/$25
// from the promoted Lease A surplus. They way this
// function works at present, it will presume the $15 is
// part of the security deposit balance, and will end up
// calculating it as only $10, which is wrong. Perhaps
// the fix is to release security deposits into some sort
// of income account.
$stats = $this->StatementEntry->stats(null, $query);
return $this->prReturn($stats['account_balance']);
return $this->prReturn($stats['Charge']['disbursement']);
}
@@ -113,8 +113,12 @@ class Lease extends AppModel {
$customer_id = $secdeps[0]['StatementEntry']['customer_id'];
$lease_id = $secdeps[0]['StatementEntry']['lease_id'];
// Add receipt of the security deposit funds. Do NOT
// flag them as part of the lease, as all received funds
// are only associated with the customer, for future
// (or present) disbursement on any lease.
$result = $this->StatementEntry->Transaction->addReceipt
($release, $customer_id, $lease_id);
($release, $customer_id, null);
return $this->prReturn($result);
}