I need to check again in the morning, but it seem like this is finally what we need for reversals. Of course, we're still using A/P as a temporary solution. If we do indeed move forward with this sort of solution (dedicated customer credit account), then we'll have to create a new account fairly soon.

git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@580 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-16 09:31:19 +00:00
parent 3decfff33b
commit 892618db36
2 changed files with 47 additions and 15 deletions

View File

@@ -24,7 +24,7 @@ class StatementEntry extends AppModel {
);
var $default_log_level = array('log' => 30, 'show' => 15);
var $max_log_level = 10;
var $max_log_level = 19;
/**************************************************************************
**************************************************************************

View File

@@ -737,6 +737,15 @@ class Transaction extends AppModel {
array_intersect_key($transaction,
array_flip(array('ledger_id', 'account_id', 'crdr')));
}
if ($entry['amount'] < 0 && !empty($entry['force_positive'])) {
$le1['amount'] *= -1;
$le2['amount'] *= -1;
$entry += array('swap_crdr' => true);
}
if (!empty($entry['swap_crdr']))
list($le1['crdr'], $le2['crdr']) = array($le2['crdr'], $le1['crdr']);
}
else
$le1 = $le1_tender = $le2 = null;
@@ -975,7 +984,7 @@ class Transaction extends AppModel {
'type' => 'CREDIT_NOTE',
'crdr' => 'CREDIT',
'account_id' => $this->Account->accountReceivableAccountID(),
'amount' => $charge['StatementEntry']['amount'],
//'amount' => $charge['StatementEntry']['amount'],
'customer_id' => $charge['StatementEntry']['customer_id'],
'lease_id' => null,
'comment' => $comment,
@@ -983,9 +992,26 @@ class Transaction extends AppModel {
'Entry' => array());
// Reverse the charge
$rollback['Entry'][] =
array('include_ledger_entry' => true,
'include_statement_entry' => true,
'type' => 'REVERSAL',
'account_id' => $charge['StatementEntry']['account_id'],
'amount' => $charge['StatementEntry']['amount'],
'customer_id' => $charge['StatementEntry']['customer_id'],
'lease_id' => $charge['StatementEntry']['lease_id'],
'charge_entry_id' => $charge['StatementEntry']['id'],
);
$credit = 0;
foreach ($disb_entries['DisbursementEntry'] AS $disbursement) {
$rollback['Entry'][] =
array(
'include_ledger_entry' =>
($disbursement['type'] !== 'DISBURSEMENT'),
'force_positive' => true,
'type' => $disbursement['type'],
//'type' => 'REVERSAL',
'amount' => -1 * $disbursement['amount'],
@@ -994,21 +1020,27 @@ class Transaction extends AppModel {
'lease_id' => $disbursement['lease_id'],
'charge_entry_id' => $disbursement['charge_entry_id'],
);
if ($disbursement['type'] === 'DISBURSEMENT')
$credit += $disbursement['amount'];
}
// Add the sole ledger entry for this transaction
$rollback['Entry'][] =
array('include_ledger_entry' => true,
'include_statement_entry' => true,
'type' => 'REVERSAL',
'account_id' => $charge['StatementEntry']['account_id'],
'amount' => $rollback['Transaction']['amount'],
'customer_id' => $charge['StatementEntry']['customer_id'],
'lease_id' => $charge['StatementEntry']['lease_id'],
'charge_entry_id' => $charge['StatementEntry']['id'],
);
// Add the customer surplus entry for this transaction
$rollback['Transaction']['amount'] = $credit;
if (0 && $credit > 0) {
$rollback['Entry'][] =
array('include_ledger_entry' => true,
'include_statement_entry' => true,
//'force_positive' => true,
'swap_crdr' => true,
'type' => 'SURPLUS',
'account_id' => $this->Account->accountPayableAccountID(),
'amount' => $credit,
'customer_id' => $charge['StatementEntry']['customer_id'],
//'lease_id' => $charge['StatementEntry']['lease_id'],
//'charge_entry_id' => $charge['StatementEntry']['id'],
);
}
// Record the transaction, which will un-disburse previously
// disbursed payments, and other similar work.