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') .
|
($credit['balance'] > 0 ? 'Utilized' : 'Exhausted') .
|
||||||
(empty($credit['receipt']) ? ' Credit' : ' Receipt'));
|
(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'])) {
|
if (empty($credit['receipt'])) {
|
||||||
// Explicit Credit
|
// Explicit Credit
|
||||||
$result = $this->Transaction->addTransactionEntries
|
$result = $this->Transaction->addTransactionEntries
|
||||||
@@ -507,7 +513,7 @@ class StatementEntry extends AppModel {
|
|||||||
),
|
),
|
||||||
array
|
array
|
||||||
(array('type' => $disbursement_type,
|
(array('type' => $disbursement_type,
|
||||||
'effective_date' => $credit['StatementEntry']['effective_date'],
|
'effective_date' => $disbursement_edate,
|
||||||
'account_id' => $credit['StatementEntry']['account_id'],
|
'account_id' => $credit['StatementEntry']['account_id'],
|
||||||
'amount' => $disbursement_amount,
|
'amount' => $disbursement_amount,
|
||||||
'charge_entry_id' => $charge['StatementEntry']['id'],
|
'charge_entry_id' => $charge['StatementEntry']['id'],
|
||||||
@@ -520,12 +526,19 @@ class StatementEntry extends AppModel {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Receipt Credit
|
// 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
|
// Add a disbursement that uses the available credit to pay the charge
|
||||||
$disbursement =
|
$disbursement =
|
||||||
array('type' => $disbursement_type,
|
array('type' => $disbursement_type,
|
||||||
|
'effective_date' => $disbursement_edate,
|
||||||
'amount' => $disbursement_amount,
|
'amount' => $disbursement_amount,
|
||||||
'account_id' => $credit['LedgerEntry']['account_id'],
|
'account_id' => $credit['LedgerEntry']['account_id'],
|
||||||
'effective_date' => $credit['Transaction']['stamp'],
|
|
||||||
'transaction_id' => $credit['Transaction']['id'],
|
'transaction_id' => $credit['Transaction']['id'],
|
||||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||||
'lease_id' => $charge['StatementEntry']['lease_id'],
|
'lease_id' => $charge['StatementEntry']['lease_id'],
|
||||||
|
|||||||
@@ -506,34 +506,15 @@ class Transaction extends AppModel {
|
|||||||
'amount' => $result['receipt_balance'],
|
'amount' => $result['receipt_balance'],
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
$ret['credit'] = $result;
|
||||||
|
if ($result['error'])
|
||||||
|
$ret['error'] = true;
|
||||||
|
|
||||||
/* $result = $this->addInvoice */
|
// Verify the explicit credit worked. Use either Debit or Credit
|
||||||
/* (array('control' => array('assign' => false), */
|
// do determine the receipt total (they BETTER be the same value!)
|
||||||
/* 'Transaction' => */
|
$stats = $this->stats($transaction['id']);
|
||||||
/* array_intersect_key($transaction, array('stamp'=>1)) */
|
if ($transaction['amount'] != $stats['StatementEntry']['disbursements'])
|
||||||
/* + array('type' => 'CREDIT_NOTE'), */
|
$this->INTERNAL_ERROR('Explicit credit did not resolve receipt balance');
|
||||||
/* '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'); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -971,10 +952,8 @@ class Transaction extends AppModel {
|
|||||||
'Transaction' =>
|
'Transaction' =>
|
||||||
array('stamp' => $stamp,
|
array('stamp' => $stamp,
|
||||||
'type' => 'CREDIT_NOTE',
|
'type' => 'CREDIT_NOTE',
|
||||||
|
'crdr' => 'CREDIT',
|
||||||
'crdr' => 'CREDIT',
|
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
|
||||||
|
|
||||||
'amount' => $charge['StatementEntry']['amount'],
|
'amount' => $charge['StatementEntry']['amount'],
|
||||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||||
'lease_id' => null,
|
'lease_id' => null,
|
||||||
|
|||||||
Reference in New Issue
Block a user