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/site@491 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -203,8 +203,7 @@ class CustomersController extends AppController {
|
||||
//pr($customer);
|
||||
|
||||
// Figure out the outstanding balances for this customer
|
||||
$stats = $this->Customer->stats($id);
|
||||
$outstanding_balance = $stats['balance'];
|
||||
$outstanding_balance = $this->Customer->balance($id);
|
||||
$outstanding_deposit = $this->Customer->securityDepositBalance($id);
|
||||
|
||||
// Figure out if this customer has any non-closed leases
|
||||
@@ -407,7 +406,7 @@ class CustomersController extends AppController {
|
||||
));
|
||||
pr(compact('entries'));
|
||||
|
||||
$this->Customer->StatementEntry->reverse($entries);
|
||||
$this->Customer->refund($entries);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -239,12 +239,14 @@ class LeasesController extends AppController {
|
||||
*/
|
||||
|
||||
function refund($id) {
|
||||
// Obtain the overall lease balance
|
||||
$stats = $this->Lease->stats($id);
|
||||
$outstanding_balance = $stats['balance'];
|
||||
$this->Lease->refund($id);
|
||||
$this->render('/fake');
|
||||
/* // Obtain the overall lease balance */
|
||||
/* $stats = $this->Lease->stats($id); */
|
||||
/* $outstanding_balance = $stats['balance']; */
|
||||
|
||||
$this->set(compact('lease', 'title',
|
||||
'outstanding_balance'));
|
||||
/* $this->set(compact('lease', 'title', */
|
||||
/* 'outstanding_balance')); */
|
||||
}
|
||||
|
||||
|
||||
@@ -381,13 +383,9 @@ class LeasesController extends AppController {
|
||||
$this->set('charge_gaps', $this->Lease->rentChargeGaps($id));
|
||||
$this->set('charge_through', $this->Lease->rentChargeThrough($id));
|
||||
|
||||
// Obtain the overall lease balance
|
||||
$this->Lease->statsMerge($lease['Lease'],
|
||||
array('stats' => $this->Lease->stats($id)));
|
||||
$outstanding_balance = $lease['Lease']['stats']['balance'];
|
||||
|
||||
// Determine the lease security deposit
|
||||
$outstanding_deposit = $this->Lease->securityDepositBalance($lease['Lease']['id']);
|
||||
// Figure out the outstanding balances for this lease
|
||||
$outstanding_balance = $this->Lease->balance($id);
|
||||
$outstanding_deposit = $this->Lease->securityDepositBalance($id);
|
||||
|
||||
// Set up dynamic menu items
|
||||
if (!isset($lease['Lease']['close_date'])) {
|
||||
|
||||
@@ -128,6 +128,7 @@ class Account extends AppModel {
|
||||
function nsfChargeAccountID() { return $this->nameToID('NSF Charge'); }
|
||||
function taxAccountID() { return $this->nameToID('Tax'); }
|
||||
function accountReceivableAccountID() { return $this->nameToID('A/R'); }
|
||||
function accountPayableAccountID() { return $this->nameToID('A/P'); }
|
||||
function cashAccountID() { return $this->nameToID('Cash'); }
|
||||
function checkAccountID() { return $this->nameToID('Check'); }
|
||||
function moneyOrderAccountID() { return $this->nameToID('Money Order'); }
|
||||
|
||||
@@ -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'];
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
@@ -24,29 +24,54 @@ class StatementEntry extends AppModel {
|
||||
|
||||
//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($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
|
||||
(
|
||||
($sum ? 'SUM(' : '') .
|
||||
"IF({$entry_name}.type = 'CHARGE'," .
|
||||
"IF({$entry_name}.type IN ({$charge_set})," .
|
||||
" {$entry_name}.amount, NULL)" .
|
||||
($sum ? ')' : '') . ' AS charge' . ($sum ? 's' : ''),
|
||||
|
||||
($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)" .
|
||||
($sum ? ')' : '') . ' AS disbursement' . ($sum ? 's' : ''),
|
||||
|
||||
($sum ? 'SUM(' : '') .
|
||||
"IF({$entry_name}.type IN ('VOID', 'PAYMENT'), 0," .
|
||||
" IF({$entry_name}.type = 'CHARGE', 1, -1))" .
|
||||
"IF({$entry_name}.type IN ({$null_set}), 0," .
|
||||
" IF({$entry_name}.type IN ({$charge_set}), 1, -1))" .
|
||||
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
|
||||
($sum ? ')' : '') . ' AS balance',
|
||||
);
|
||||
@@ -602,7 +627,7 @@ class StatementEntry extends AppModel {
|
||||
|
||||
$charge_query['fields'] = array();
|
||||
$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);
|
||||
$stats['Charge'] = $result[0];
|
||||
|
||||
|
||||
@@ -332,8 +332,8 @@ class Transaction extends AppModel {
|
||||
$refund =& $data['Transaction'];
|
||||
$refund +=
|
||||
array('type' => 'CREDIT_NOTE',
|
||||
'crdr' => 'CREDIT',
|
||||
'account_id' => $this->Account->accountPayableAccountID(),
|
||||
'crdr' => 'DEBIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'customer_id' => $customer_id,
|
||||
'lease_id' => $lease_id,
|
||||
);
|
||||
@@ -341,8 +341,8 @@ class Transaction extends AppModel {
|
||||
// Go through the statement entries and flag as vouchers
|
||||
foreach ($data['Entry'] AS &$entry)
|
||||
$entry += array('type' => 'VOUCHER',
|
||||
'crdr' => 'DEBIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'crdr' => 'CREDIT',
|
||||
'account_id' => $this->Account->accountPayableAccountID(),
|
||||
);
|
||||
|
||||
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
|
||||
@@ -575,9 +575,9 @@ class Transaction extends AppModel {
|
||||
|
||||
// (DISBURSEMENTS will have statement entries created below, when
|
||||
// assigning credits, and DEPOSITS don't have statement entries)
|
||||
if (($transaction['account_id'] != $this->Account->accountReceivableAccountID() &&
|
||||
$transaction['account_id'] != $this->Account->nsfAccountID()) ||
|
||||
$transaction['crdr'] != 'DEBIT')
|
||||
if (empty($transaction['customer_id']) ||
|
||||
($transaction['account_id'] == $this->Account->accountReceivableAccountID() &&
|
||||
$transaction['crdr'] == 'CREDIT'))
|
||||
$se = null;
|
||||
|
||||
// NSF transactions don't use LedgerEntries
|
||||
|
||||
Reference in New Issue
Block a user