Continued waiver progress. At the moment, it works ok, but I don't like the way that security deposit balances work. It's probably a general issue, not just security deposits, but it's not clear whether stats from StatementEntry should be subtracting waiver totals from the overall charge reconciliation total. It should in some cases, and not in others. I'll tweak on it in later checkins.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@479 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-03 21:50:21 +00:00
parent 09e650d841
commit aa846de284
3 changed files with 77 additions and 28 deletions

View File

@@ -22,7 +22,7 @@ class StatementEntry extends AppModel {
);
var $default_log_level = 30;
var $default_log_level = array('log' => 30, 'show' => 15);
/**************************************************************************
**************************************************************************
@@ -40,13 +40,16 @@ class StatementEntry extends AppModel {
($sum ? ')' : '') . ' AS charge' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF({$entry_name}.type = 'PAYMENT' OR {$entry_name}.type = 'SURPLUS'," .
//"IF({$entry_name}.type IN('PAYMENT', 'SURPLUS', 'WAIVE')," .
"IF({$entry_name}.type NOT IN('CHARGE', 'VOID')," .
" {$entry_name}.amount, NULL)" .
($sum ? ')' : '') . ' AS payment' . ($sum ? 's' : ''),
($sum ? 'SUM(' : '') .
"IF({$entry_name}.type = 'CHARGE', 1," .
" IF({$entry_name}.type = 'PAYMENT' OR {$entry_name}.type = 'SURPLUS', -1, 0))" .
//"IF({$entry_name}.type = 'CHARGE', 1," .
//" IF({$entry_name}.type IN('PAYMENT', 'SURPLUS', 'WAIVE'), -1, 0))" .
"IF({$entry_name}.type = 'VOID', 0," .
" IF({$entry_name}.type = 'CHARGE', 1, -1))" .
" * IF({$entry_name}.amount, {$entry_name}.amount, 0)" .
($sum ? ')' : '') . ' AS balance',
);
@@ -373,11 +376,16 @@ OPTION 2
* the user to specify how payments should be applied.
*
*/
function assignCredits($query = null, $receipt_id = null, $charge_ids = null) {
function assignCredits($query = null, $receipt_id = null,
$charge_ids = null, $payment_type = null)
{
//$this->prFunctionLevel(25);
$this->prEnter( compact('query', 'receipt_id', 'charge_ids'));
$this->prEnter( compact('query', 'receipt_id', 'charge_ids', 'payment_type'));
$this->queryInit($query);
if (empty($payment_type))
$payment_type = 'PAYMENT';
$ret = array();
// First, find all known credits
@@ -439,7 +447,7 @@ OPTION 2
// just saves extra processing if/when there is no
// means to resolve a charge anyway.
if (count($credits) == 0 && empty($receipt_credit['balance'])) {
$this->pr(15, 'No more available credits');
$this->pr(17, 'No more available credits');
break;
}
@@ -495,7 +503,7 @@ OPTION 2
$used_credits[] = array_shift($credits);
// Add a payment that uses the available credit to pay the charge
$payment = array('type' => 'PAYMENT',
$payment = array('type' => $payment_type,
'account_id' => $payment_account_id,
'amount' => $payment_amount,
'effective_date' => $payment_date,
@@ -612,6 +620,33 @@ OPTION 2
$this->pr(17, compact('rquery', 'result'),
'Charges');
$rquery = $query;
unset($rquery['link']['ChargeEntry']);
$rquery['link']['PaymentEntry'] = array('fields' => array(),
/* 'conditions' => */
/* array('PaymentEntry.type' => 'WAIVE'), */
);
$rquery['fields'] = array();
$rquery['fields'][] = "SUM(PaymentEntry.amount) AS reconciled";
$rquery['conditions'][] = array('StatementEntry.type' => 'CHARGE');
$rquery['conditions'][] = array('PaymentEntry.type' => 'WAIVE');
$rquery['group'] = 'StatementEntry.id';
$result = $this->find('first', $rquery);
$stats['Charge']['waived'] = $result[0]['reconciled'];
/* $stats['Waiver'] = array('total' => 0, 'reconciled' => 0); */
/* foreach($result AS $charge) { */
/* $stats['Waiver']['total'] += $charge['StatementEntry']['amount']; */
/* $stats['Waiver']['reconciled'] += $charge[0]['reconciled']; */
/* } */
/* $stats['Waiver']['balance'] = */
/* $stats['Waiver']['total'] - $stats['Waiver']['reconciled']; */
$this->pr(17, compact('rquery', 'result'),
'Waived');
$rquery = $query;
unset($rquery['link']['PaymentEntry']);
$rquery['link']['ChargeEntry'] = array('fields' => array());
@@ -630,6 +665,25 @@ OPTION 2
$this->pr(17, compact('rquery', 'result'),
'Payments');
$rquery = $query;
unset($rquery['link']['PaymentEntry']);
unset($rquery['link']['ChargeEntry']);
$rquery['fields'] = array();
$rquery['fields'][] = "SUM(StatementEntry.amount) AS total";
$rquery['fields'][] = "SUM(0) AS reconciled";
$rquery['conditions'][] = array('StatementEntry.type' => 'SURPLUS');
$result = $this->find('first', $rquery);
$result[0]['balance'] = $result[0]['total'] - $result[0]['reconciled'];
if (!isset($result[0]['balance']))
$result[0]['balance'] = 0;
$stats['Surplus'] = $result[0];
$this->pr(17, compact('rquery', 'result'),
'Surplus');
return $this->prReturn($stats);
}