Added back in the logic to simply update an existing explicit credit instead of creating an additional one. At the moment, I can't think of a scenario for this other than when reversing charges, which is still broken. So, until I make progress on that, it's not even clear this changes is needed, let alone whether it works.
git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@575 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -507,31 +507,12 @@ class StatementEntry extends AppModel {
|
|||||||
),
|
),
|
||||||
array
|
array
|
||||||
(array('type' => $disbursement_type,
|
(array('type' => $disbursement_type,
|
||||||
//$credit['StatementEntry']['effective_date'];
|
|
||||||
'effective_date' => $credit['StatementEntry']['effective_date'],
|
'effective_date' => $credit['StatementEntry']['effective_date'],
|
||||||
'account_id' => $credit['StatementEntry']['account_id'],
|
'account_id' => $credit['StatementEntry']['account_id'],
|
||||||
'amount' => $disbursement_amount,
|
'amount' => $disbursement_amount,
|
||||||
/* 'customer_id' => $charge['StatementEntry']['customer_id'], */
|
|
||||||
/* 'lease_id' => $charge['StatementEntry']['lease_id'], */
|
|
||||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
/* $result = $this->Transaction->addReceipt */
|
|
||||||
/* (array('control' => */
|
|
||||||
/* array('include_ledger_entry' => true, */
|
|
||||||
/* 'include_statement_entry' => false), */
|
|
||||||
|
|
||||||
/* 'Transaction' => */
|
|
||||||
/* array('id' => $credit['StatementEntry']['transaction_id'], */
|
|
||||||
/* 'account_id' => $credit['StatementEntry']['account_id'], */
|
|
||||||
/* 'crdr' => 'DEBIT'), */
|
|
||||||
/* array(array('type' => $disbursement_type, */
|
|
||||||
/* //$credit['StatementEntry']['effective_date']; */
|
|
||||||
/* 'effective_date' => $charge['StatementEntry']['effective_date'], */
|
|
||||||
/* 'account_id' => $charge['StatementEntry']['account_id'], */
|
|
||||||
/* 'amount' => $disbursement_amount, */
|
|
||||||
/* ), */
|
|
||||||
/* )); */
|
|
||||||
|
|
||||||
$ret['Disbursement'][] = $result;
|
$ret['Disbursement'][] = $result;
|
||||||
if ($result['error'])
|
if ($result['error'])
|
||||||
@@ -576,8 +557,9 @@ class StatementEntry extends AppModel {
|
|||||||
|
|
||||||
// Clean up any explicit credits that have been used
|
// Clean up any explicit credits that have been used
|
||||||
foreach ($credits AS $credit) {
|
foreach ($credits AS $credit) {
|
||||||
if (empty($credit['receipt'])) {
|
if (!empty($credit['receipt']))
|
||||||
// Explicit Credit
|
continue;
|
||||||
|
|
||||||
if (empty($credit['applied']))
|
if (empty($credit['applied']))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -595,30 +577,46 @@ class StatementEntry extends AppModel {
|
|||||||
$this->delete($credit['StatementEntry']['id'], false);
|
$this->delete($credit['StatementEntry']['id'], false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// Receipt Credit
|
// Check for any implicit receipt credits, converting
|
||||||
|
// into explicit credits if there is a remaining balance.
|
||||||
|
foreach ($credits AS $credit) {
|
||||||
|
if (empty($credit['receipt']))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (empty($credit['balance']))
|
if (empty($credit['balance']))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$ret['receipt_balance'] = $credit['balance'];
|
// See if there is an existing explicit credit
|
||||||
// Convert non-exhausted receipt credit to an explicit one
|
// for this transaction.
|
||||||
$this->pr(18, compact('credit'),
|
$explicit_credit = $this->find
|
||||||
'Create Explicit Credit');
|
('first', array('contain' => false,
|
||||||
|
'conditions' =>
|
||||||
|
array(array('transaction_id' => $credit['Transaction']['id']),
|
||||||
|
array('type' => 'SURPLUS')),
|
||||||
|
));
|
||||||
|
|
||||||
/* //$result = $this->Transaction->LedgerEntry->DoubleEntry->addDoubleEntry */
|
if (!empty($explicit_credit)) {
|
||||||
/* $result = $this->addStatementEntry */
|
// Since there IS an existing explicit credit, we must update
|
||||||
/* (array('type' => 'SURPLUS', */
|
// its balance instead of creating a new one, since it has
|
||||||
/* 'account_id' => $credit['LedgerEntry']['account_id'], */
|
// already been incorporated in the overall credit balance.
|
||||||
/* 'amount' => $credit['balance'], */
|
// If we were to create a new one, we would erroneously create
|
||||||
/* 'effective_date' => $credit['Transaction']['stamp'], */
|
// an excess of credit available.
|
||||||
/* 'transaction_id' => $credit['Transaction']['id'], */
|
$this->pr(18, compact('explicit_credit', 'credit'),
|
||||||
/* 'customer_id' => $customer_id, */
|
'Update existing explicit credit');
|
||||||
/* 'lease_id' => $lease_id, */
|
$EC = new StatementEntry();
|
||||||
/* )); */
|
$EC->id = $explicit_credit['StatementEntry']['id'];
|
||||||
/* $ret['Credit'] = $result; */
|
$EC->saveField('amount', $credit['balance']);
|
||||||
/* if ($result['error']) */
|
continue;
|
||||||
/* $ret['error'] = true; */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($ret['receipt_balance']))
|
||||||
|
$this->INTERNAL_ERROR('Only one receipt expected in assignCredits');
|
||||||
|
|
||||||
|
// Give caller the information necessary to create an explicit
|
||||||
|
// credit from the passed receipt, which we've not exhausted.
|
||||||
|
$this->pr(18, compact('credit'), 'Convert to explicit credit');
|
||||||
|
$ret['receipt_balance'] = $credit['balance'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->prReturn($ret + array('error' => false));
|
return $this->prReturn($ret + array('error' => false));
|
||||||
|
|||||||
Reference in New Issue
Block a user