Changed the explicit receipt amount to be driven from stats instead of the assignCredits return value. This is in anticipation of creating an explicit credit directly, without even calling assignCredits. I'll do that for reversal on the next checkin.
git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@577 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -44,6 +44,7 @@ class Transaction extends AppModel {
|
||||
|
||||
|
||||
var $default_log_level = array('log' => 30, 'show' => 15);
|
||||
//var $max_log_level = 10;
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -454,6 +455,11 @@ class Transaction extends AppModel {
|
||||
function addTransaction($control, $transaction, $entries) {
|
||||
$this->prEnter(compact('control', 'transaction', 'entries'));
|
||||
|
||||
// By default, let's create an explicit credit if there
|
||||
// is any balance remaining after assigning credits.
|
||||
if (!empty($control['assign']) && !empty($control['assign_receipt']))
|
||||
$control += array('create_explicit_credit' => true);
|
||||
|
||||
$result = $this->_splitEntries($control, $transaction, $entries);
|
||||
if (!empty($result['error']))
|
||||
return $this->prReturn(array('error' => true));
|
||||
@@ -491,32 +497,36 @@ class Transaction extends AppModel {
|
||||
);
|
||||
|
||||
$ret['assigned'] = $result;
|
||||
if ($result['error'])
|
||||
if (!empty($result['error']))
|
||||
$ret['error'] = true;
|
||||
}
|
||||
|
||||
if (!empty($control['assign_receipt']) &&
|
||||
!empty($result['receipt_balance'])) {
|
||||
if (!empty($control['create_explicit_credit']) &&
|
||||
empty($ret['error'])) {
|
||||
$stats = $this->stats($transaction['id']);
|
||||
if ($stats['undisbursed'] < 0)
|
||||
$this->INTERNAL_ERROR('Receipt has negative undisbursed balance');
|
||||
|
||||
if (!empty($stats['undisbursed'])) {
|
||||
$result = $this->addTransactionEntries
|
||||
(array('include_ledger_entry' => true,
|
||||
'include_statement_entry' => true),
|
||||
array('crdr' => 'DEBIT') + $transaction,
|
||||
array(array('type' => 'SURPLUS',
|
||||
'account_id' => $this->Account->accountPayableAccountID(),
|
||||
'amount' => $result['receipt_balance'],
|
||||
'amount' => $stats['undisbursed'],
|
||||
),
|
||||
));
|
||||
|
||||
$ret['credit'] = $result;
|
||||
if ($result['error'])
|
||||
if (!empty($result['error']))
|
||||
$ret['error'] = true;
|
||||
|
||||
// Verify the explicit credit worked. Use either Debit or Credit
|
||||
// do determine the receipt total (they BETTER be the same value!)
|
||||
// Verify the explicit credit worked.
|
||||
$stats = $this->stats($transaction['id']);
|
||||
if ($transaction['amount'] != $stats['StatementEntry']['disbursements'])
|
||||
if (!empty($stats['undisbursed']))
|
||||
$this->INTERNAL_ERROR('Explicit credit did not resolve receipt balance');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->Customer->update($transaction['customer_id']);
|
||||
@@ -1128,6 +1138,13 @@ class Transaction extends AppModel {
|
||||
unset($stats[$table][0]);
|
||||
}
|
||||
|
||||
if (!empty($id)) {
|
||||
$this->id = $id;
|
||||
$stats['total'] = $this->field('amount');
|
||||
$stats['uncharged'] = $stats['total'] - $stats['StatementEntry']['charges'];
|
||||
$stats['undisbursed'] = $stats['total'] - $stats['StatementEntry']['disbursements'];
|
||||
}
|
||||
|
||||
return $this->prReturn($stats);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user