Change to how reversals are handled. In the process, I've tried to solidify _exactly_ what addTransaction will do, since it was becoming a house of cards of sorts. It was using special logic to decide things like whether to add ledger entries, statement entries, or both, whether to assignCredits afterwards, whether the generated receipt was to be considered a credit, and so on. Consequently, modifications to any calling function (addInvoice, addWaiver, etc) would often require addTransaction modifications, which would turn around and break all of the other calling functions. So, that embedded logic has been removed from addTransaction, and the rules of what addTransaction should do are now defined by the callers. This change is DEFINTELY not complete, as it probably has several bugs, and it DOES NOT YET WORK for reversals. I need a clean baseline to move forward from though, and this checkin approximates where we need to go.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716@562 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -23,7 +23,7 @@ class StatementEntry extends AppModel {
|
||||
|
||||
);
|
||||
|
||||
//var $default_log_level = array('log' => 30, 'show' => 15);
|
||||
var $default_log_level = array('log' => 30, 'show' => 15);
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -169,7 +169,6 @@ class StatementEntry extends AppModel {
|
||||
// Add the charge waiver
|
||||
$waiver['Entry'][] =
|
||||
array('amount' => $stats['Charge']['balance'],
|
||||
'account_id' => $this->Account->waiverAccountID(),
|
||||
'comment' => null,
|
||||
);
|
||||
|
||||
@@ -184,45 +183,47 @@ class StatementEntry extends AppModel {
|
||||
**************************************************************************
|
||||
* function: reverse
|
||||
* - Reverses the charges
|
||||
*
|
||||
*/
|
||||
function reverse($id, $balance = false, $stamp = null) {
|
||||
$this->prEnter(compact('id', 'balance', 'stamp'));
|
||||
function reversable($id) {
|
||||
$this->prEnter(compact('id'));
|
||||
|
||||
$ret = array();
|
||||
// Verify the item is an actual charge
|
||||
$this->id = $id;
|
||||
$charge_type = $this->field('type');
|
||||
if ($charge_type !== 'CHARGE')
|
||||
return $this->prReturn(false);
|
||||
|
||||
// Get the basic information about the entry to be reversed.
|
||||
$this->recursive = -1;
|
||||
$charge = $this->read(null, $id);
|
||||
$charge = $charge['StatementEntry'];
|
||||
|
||||
if ($charge['type'] !== 'CHARGE')
|
||||
$this->INTERNAL_ERROR("Reversal item is not CHARGE.");
|
||||
|
||||
$voided_entry_transactions = array();
|
||||
// Determine anything reconciled against the charge
|
||||
$reconciled = $this->reconciledEntries($id);
|
||||
$this->pr(21, compact('reconciled'));
|
||||
|
||||
if ($reconciled && !$balance) {
|
||||
foreach ($reconciled['entries'] AS $entry) {
|
||||
if (!empty($reconciled)) {
|
||||
// Double check that this charge has not already been reversed
|
||||
foreach ($reconciled['entries'] AS $entry)
|
||||
if ($entry['DisbursementEntry']['type'] === 'REVERSAL')
|
||||
$this->INTERNAL_ERROR("Charge has already been reversed");
|
||||
|
||||
$voided_entry_transactions[$entry['DisbursementEntry']['transaction_id']]
|
||||
= array_intersect_key($entry['DisbursementEntry'],
|
||||
array('customer_id'=>1, 'lease_id'=>1));
|
||||
|
||||
$this->delete($entry['DisbursementEntry']['id']);
|
||||
continue;
|
||||
|
||||
$DE = new StatementEntry();
|
||||
$DE->id = $entry['DisbursementEntry']['id'];
|
||||
$DE->saveField('type', 'VOID');
|
||||
$DE->saveField('charge_entry_id', null);
|
||||
}
|
||||
$this->pr(17, compact('voided_entry_transactions'));
|
||||
return $this->prReturn(false);
|
||||
}
|
||||
|
||||
return $this->prReturn(true);
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: reverse
|
||||
* - Reverses the charges
|
||||
*/
|
||||
function reverse($id, $stamp = null) {
|
||||
$this->prEnter(compact('id', 'stamp'));
|
||||
|
||||
// Verify the item can be reversed
|
||||
if (!$this->reversable($id))
|
||||
$this->INTERNAL_ERROR("Item is not reversable.");
|
||||
|
||||
// Get the basic information about this charge
|
||||
$charge = $this->find('first', array('contain' => true));
|
||||
$charge = $charge['StatementEntry'];
|
||||
|
||||
// Query the stats to get the remaining balance
|
||||
$stats = $this->stats($id);
|
||||
|
||||
@@ -233,35 +234,18 @@ class StatementEntry extends AppModel {
|
||||
|
||||
// Add the charge reversal
|
||||
$reversal['Entry'][] =
|
||||
array('amount' => $stats['Charge']['balance'],
|
||||
array('amount' => $stats['Charge']['total'],
|
||||
'account_id' => $charge['account_id'],
|
||||
'comment' => 'Charge Reversal',
|
||||
);
|
||||
|
||||
// Record the reversal transaction
|
||||
$result = $this->Transaction->addReversal
|
||||
($reversal, $id, $charge['customer_id'], $charge['lease_id']);
|
||||
$this->pr(21, compact('result'));
|
||||
$ret['reversal'] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
($reversal,
|
||||
$id, $stats['Charge']['disbursement'],
|
||||
$charge['customer_id'], $charge['lease_id']);
|
||||
|
||||
foreach ($voided_entry_transactions AS $transaction_id => $tx) {
|
||||
$result = $this->assignCredits
|
||||
(null,
|
||||
$transaction_id,
|
||||
null,
|
||||
null,
|
||||
$tx['customer_id'],
|
||||
null
|
||||
);
|
||||
$this->pr(21, compact('result'));
|
||||
$ret['assigned'][] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
}
|
||||
|
||||
return $this->prReturn($ret + array('error' => false));
|
||||
return $this->prReturn($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user