More good progress on reversals. There is still an issue where after reversing, a disbursement can be applied to a new charge from the old charge account, instead of the surplus account. I'll work on that next.
git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@576 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -493,6 +493,12 @@ class StatementEntry extends AppModel {
|
||||
($credit['balance'] > 0 ? 'Utilized' : 'Exhausted') .
|
||||
(empty($credit['receipt']) ? ' Credit' : ' Receipt'));
|
||||
|
||||
if (strtotime($charge['StatementEntry']['effective_date']) >
|
||||
strtotime($credit['StatementEntry']['effective_date']))
|
||||
$disbursement_edate = $charge['StatementEntry']['effective_date'];
|
||||
else
|
||||
$disbursement_edate = $credit['StatementEntry']['effective_date'];
|
||||
|
||||
if (empty($credit['receipt'])) {
|
||||
// Explicit Credit
|
||||
$result = $this->Transaction->addTransactionEntries
|
||||
@@ -507,7 +513,7 @@ class StatementEntry extends AppModel {
|
||||
),
|
||||
array
|
||||
(array('type' => $disbursement_type,
|
||||
'effective_date' => $credit['StatementEntry']['effective_date'],
|
||||
'effective_date' => $disbursement_edate,
|
||||
'account_id' => $credit['StatementEntry']['account_id'],
|
||||
'amount' => $disbursement_amount,
|
||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||
@@ -520,12 +526,19 @@ class StatementEntry extends AppModel {
|
||||
}
|
||||
else {
|
||||
// Receipt Credit
|
||||
|
||||
if (strtotime($charge['StatementEntry']['effective_date']) >
|
||||
strtotime($credit['Transaction']['stamp']))
|
||||
$disbursement_edate = $charge['StatementEntry']['effective_date'];
|
||||
else
|
||||
$disbursement_edate = $credit['Transaction']['stamp'];
|
||||
|
||||
// Add a disbursement that uses the available credit to pay the charge
|
||||
$disbursement =
|
||||
array('type' => $disbursement_type,
|
||||
'effective_date' => $disbursement_edate,
|
||||
'amount' => $disbursement_amount,
|
||||
'account_id' => $credit['LedgerEntry']['account_id'],
|
||||
'effective_date' => $credit['Transaction']['stamp'],
|
||||
'transaction_id' => $credit['Transaction']['id'],
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => $charge['StatementEntry']['lease_id'],
|
||||
|
||||
@@ -506,34 +506,15 @@ class Transaction extends AppModel {
|
||||
'amount' => $result['receipt_balance'],
|
||||
),
|
||||
));
|
||||
$ret['credit'] = $result;
|
||||
if ($result['error'])
|
||||
$ret['error'] = true;
|
||||
|
||||
/* $result = $this->addInvoice */
|
||||
/* (array('control' => array('assign' => false), */
|
||||
/* 'Transaction' => */
|
||||
/* array_intersect_key($transaction, array('stamp'=>1)) */
|
||||
/* + array('type' => 'CREDIT_NOTE'), */
|
||||
/* 'Entry' => array */
|
||||
/* (array('type' => 'SURPLUS', */
|
||||
/* 'account_id' => $this->Account->accountPayableAccountID(), */
|
||||
/* 'amount' => $result['receipt_balance'], */
|
||||
/* ), */
|
||||
/* ), */
|
||||
/* ), */
|
||||
/* $transaction['customer_id'], */
|
||||
/* $transaction['lease_id'] */
|
||||
/* ); */
|
||||
|
||||
/* $result2 = $this->StatementEntry->assignCredits */
|
||||
/* (null, */
|
||||
/* $ret['transaction_id'], */
|
||||
/* null, */
|
||||
/* null, */
|
||||
/* $transaction['customer_id'], */
|
||||
/* $transaction['lease_id'] */
|
||||
/* ); */
|
||||
|
||||
/* if (!empty($result2['receipt_balance'])) */
|
||||
/* $this->INTERNAL_ERROR('Surplus invoice did not resolve receipt balance'); */
|
||||
// Verify the explicit credit worked. Use either Debit or Credit
|
||||
// do determine the receipt total (they BETTER be the same value!)
|
||||
$stats = $this->stats($transaction['id']);
|
||||
if ($transaction['amount'] != $stats['StatementEntry']['disbursements'])
|
||||
$this->INTERNAL_ERROR('Explicit credit did not resolve receipt balance');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -971,10 +952,8 @@ class Transaction extends AppModel {
|
||||
'Transaction' =>
|
||||
array('stamp' => $stamp,
|
||||
'type' => 'CREDIT_NOTE',
|
||||
|
||||
'crdr' => 'CREDIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
|
||||
'crdr' => 'CREDIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'amount' => $charge['StatementEntry']['amount'],
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => null,
|
||||
|
||||
Reference in New Issue
Block a user