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

@@ -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];
@@ -688,4 +713,4 @@ class StatementEntry extends AppModel {
return $this->prReturn($stats);
}
}
}