More work on refund. I'm going to skip the whole voucher/credit_note bit and simply present a page that lets the user enter a date, an account, and the amount to refund, recording 1 payment transaction.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@491 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-06 02:52:45 +00:00
parent cca698d437
commit 4d62d7da73
7 changed files with 111 additions and 73 deletions

View File

@@ -203,8 +203,7 @@ class CustomersController extends AppController {
//pr($customer); //pr($customer);
// Figure out the outstanding balances for this customer // Figure out the outstanding balances for this customer
$stats = $this->Customer->stats($id); $outstanding_balance = $this->Customer->balance($id);
$outstanding_balance = $stats['balance'];
$outstanding_deposit = $this->Customer->securityDepositBalance($id); $outstanding_deposit = $this->Customer->securityDepositBalance($id);
// Figure out if this customer has any non-closed leases // Figure out if this customer has any non-closed leases
@@ -407,7 +406,7 @@ class CustomersController extends AppController {
)); ));
pr(compact('entries')); pr(compact('entries'));
$this->Customer->StatementEntry->reverse($entries); $this->Customer->refund($entries);
} }

View File

@@ -239,12 +239,14 @@ class LeasesController extends AppController {
*/ */
function refund($id) { function refund($id) {
// Obtain the overall lease balance $this->Lease->refund($id);
$stats = $this->Lease->stats($id); $this->render('/fake');
$outstanding_balance = $stats['balance']; /* // Obtain the overall lease balance */
/* $stats = $this->Lease->stats($id); */
/* $outstanding_balance = $stats['balance']; */
$this->set(compact('lease', 'title', /* $this->set(compact('lease', 'title', */
'outstanding_balance')); /* 'outstanding_balance')); */
} }
@@ -381,13 +383,9 @@ class LeasesController extends AppController {
$this->set('charge_gaps', $this->Lease->rentChargeGaps($id)); $this->set('charge_gaps', $this->Lease->rentChargeGaps($id));
$this->set('charge_through', $this->Lease->rentChargeThrough($id)); $this->set('charge_through', $this->Lease->rentChargeThrough($id));
// Obtain the overall lease balance // Figure out the outstanding balances for this lease
$this->Lease->statsMerge($lease['Lease'], $outstanding_balance = $this->Lease->balance($id);
array('stats' => $this->Lease->stats($id))); $outstanding_deposit = $this->Lease->securityDepositBalance($id);
$outstanding_balance = $lease['Lease']['stats']['balance'];
// Determine the lease security deposit
$outstanding_deposit = $this->Lease->securityDepositBalance($lease['Lease']['id']);
// Set up dynamic menu items // Set up dynamic menu items
if (!isset($lease['Lease']['close_date'])) { if (!isset($lease['Lease']['close_date'])) {

View File

@@ -128,6 +128,7 @@ class Account extends AppModel {
function nsfChargeAccountID() { return $this->nameToID('NSF Charge'); } function nsfChargeAccountID() { return $this->nameToID('NSF Charge'); }
function taxAccountID() { return $this->nameToID('Tax'); } function taxAccountID() { return $this->nameToID('Tax'); }
function accountReceivableAccountID() { return $this->nameToID('A/R'); } function accountReceivableAccountID() { return $this->nameToID('A/R'); }
function accountPayableAccountID() { return $this->nameToID('A/P'); }
function cashAccountID() { return $this->nameToID('Cash'); } function cashAccountID() { return $this->nameToID('Cash'); }
function checkAccountID() { return $this->nameToID('Check'); } function checkAccountID() { return $this->nameToID('Check'); }
function moneyOrderAccountID() { return $this->nameToID('Money Order'); } function moneyOrderAccountID() { return $this->nameToID('Money Order'); }

View File

@@ -127,49 +127,6 @@ class Customer extends AppModel {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* function: details
* - Returns detail information for the customer
*/
function details($id = null) {
$this->prEnter(compact('id'));
// Query the DB for need information.
$customer = $this->find
('first', array
('contain' => array
(// Models
'Contact' =>
array('order' => array('Contact.display_name'),
// Models
'ContactPhone',
'ContactEmail',
'ContactAddress',
),
'Lease' =>
array('Unit' =>
array('order' => array('sort_order'),
'fields' => array('id', 'name'),
),
),
),
'conditions' => array('Customer.id' => $id),
));
// Figure out the outstanding balance for this customer
$customer['stats'] = $this->stats($id);
// Figure out the total security deposit for the current lease.
$customer['deposits'] = $this->securityDeposits($id);
return $this->prReturn($customer);
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
@@ -271,6 +228,19 @@ class Customer extends AppModel {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* function: balance
* - Returns the balance of money owed on the lease
*/
function balance($id) {
$stats = $this->stats($id);
return $stats['balance'];
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************

View File

@@ -464,6 +464,51 @@ class Lease extends AppModel {
} }
/**************************************************************************
**************************************************************************
**************************************************************************
* function: refund
* - Marks any lease balance as payable to the customer.
*/
function refund($id, $stamp = null) {
$this->prEnter(compact('id'));
$balance = $this->balance($id);
if ($balance >= 0)
return $this->prReturn(array('error' => true));
$balance *= -1;
// Build a transaction
$refund = array('Transaction' => array(), 'Entry' => array());
$refund['Transaction']['stamp'] = $stamp;
$refund['Transaction']['comment'] = "Lease Refund";
$refund['Entry'][] =
array('amount' => $balance);
$result = $this->StatementEntry->Transaction->addRefund
($refund, null, $id);
return $this->prReturn($result);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: balance
* - Returns the balance of money owed on the lease
*/
function balance($id) {
$this->prEnter(compact('id'));
$stats = $this->stats($id);
return $this->prReturn($stats['balance']);
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************

View File

@@ -24,29 +24,54 @@ class StatementEntry extends AppModel {
//var $default_log_level = array('log' => 30, 'show' => 15); //var $default_log_level = array('log' => 30, 'show' => 15);
/**************************************************************************
**************************************************************************
**************************************************************************
* function: debit/creditTypes
*/
function debitTypes() {
return array('CHARGE', 'VOUCHER');
}
function creditTypes() {
return array('DISBURSEMENT', 'WAIVER', 'SURPLUS');
}
/************************************************************************** /**************************************************************************
************************************************************************** **************************************************************************
************************************************************************** **************************************************************************
* function: chargeDisbursementFields * function: chargeDisbursementFields
*/ */
function chargeDisbursementFields($sum = false, $entry_name = 'StatementEntry') { function chargeDisbursementFields($sum = false, $entry_name = 'StatementEntry') {
$charges = array('CHARGE', 'VOUCHER');
$nulls = array('PAYMENT', 'VOID');
foreach ($charges AS &$enum)
$enum = "'" . $enum . "'";
foreach ($nulls AS &$enum)
$enum = "'" . $enum . "'";
$charge_set = implode(", ", $charges);
$null_set = implode(", ", $nulls);
$fields = array $fields = array
( (
($sum ? 'SUM(' : '') . ($sum ? 'SUM(' : '') .
"IF({$entry_name}.type = 'CHARGE'," . "IF({$entry_name}.type IN ({$charge_set})," .
" {$entry_name}.amount, NULL)" . " {$entry_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS charge' . ($sum ? 's' : ''), ($sum ? ')' : '') . ' AS charge' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') . ($sum ? 'SUM(' : '') .
"IF({$entry_name}.type NOT IN('CHARGE', 'PAYMENT', 'VOID')," . "IF({$entry_name}.type NOT IN({$charge_set}, ${null_set})," .
" {$entry_name}.amount, NULL)" . " {$entry_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS disbursement' . ($sum ? 's' : ''), ($sum ? ')' : '') . ' AS disbursement' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') . ($sum ? 'SUM(' : '') .
"IF({$entry_name}.type IN ('VOID', 'PAYMENT'), 0," . "IF({$entry_name}.type IN ({$null_set}), 0," .
" IF({$entry_name}.type = 'CHARGE', 1, -1))" . " IF({$entry_name}.type IN ({$charge_set}), 1, -1))" .
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" . " * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
($sum ? ')' : '') . ' AS balance', ($sum ? ')' : '') . ' AS balance',
); );
@@ -602,7 +627,7 @@ class StatementEntry extends AppModel {
$charge_query['fields'] = array(); $charge_query['fields'] = array();
$charge_query['fields'][] = "SUM(StatementEntry.amount) AS total"; $charge_query['fields'][] = "SUM(StatementEntry.amount) AS total";
$charge_query['conditions'][] = array('StatementEntry.type' => 'CHARGE'); $charge_query['conditions'][] = array('StatementEntry.type' => array('CHARGE', 'VOUCHER'));
$result = $this->find('first', $charge_query); $result = $this->find('first', $charge_query);
$stats['Charge'] = $result[0]; $stats['Charge'] = $result[0];
@@ -688,4 +713,4 @@ class StatementEntry extends AppModel {
return $this->prReturn($stats); return $this->prReturn($stats);
} }
} }

View File

@@ -332,17 +332,17 @@ class Transaction extends AppModel {
$refund =& $data['Transaction']; $refund =& $data['Transaction'];
$refund += $refund +=
array('type' => 'CREDIT_NOTE', array('type' => 'CREDIT_NOTE',
'crdr' => 'CREDIT', 'crdr' => 'DEBIT',
'account_id' => $this->Account->accountPayableAccountID(), 'account_id' => $this->Account->accountReceivableAccountID(),
'customer_id' => $customer_id, 'customer_id' => $customer_id,
'lease_id' => $lease_id, 'lease_id' => $lease_id,
); );
// Go through the statement entries and flag as vouchers // Go through the statement entries and flag as vouchers
foreach ($data['Entry'] AS &$entry) foreach ($data['Entry'] AS &$entry)
$entry += array('type' => 'VOUCHER', $entry += array('type' => 'VOUCHER',
'crdr' => 'DEBIT', 'crdr' => 'CREDIT',
'account_id' => $this->Account->accountReceivableAccountID(), 'account_id' => $this->Account->accountPayableAccountID(),
); );
$ids = $this->addTransaction($data['Transaction'], $data['Entry']); $ids = $this->addTransaction($data['Transaction'], $data['Entry']);
@@ -575,9 +575,9 @@ class Transaction extends AppModel {
// (DISBURSEMENTS will have statement entries created below, when // (DISBURSEMENTS will have statement entries created below, when
// assigning credits, and DEPOSITS don't have statement entries) // assigning credits, and DEPOSITS don't have statement entries)
if (($transaction['account_id'] != $this->Account->accountReceivableAccountID() && if (empty($transaction['customer_id']) ||
$transaction['account_id'] != $this->Account->nsfAccountID()) || ($transaction['account_id'] == $this->Account->accountReceivableAccountID() &&
$transaction['crdr'] != 'DEBIT') $transaction['crdr'] == 'CREDIT'))
$se = null; $se = null;
// NSF transactions don't use LedgerEntries // NSF transactions don't use LedgerEntries