A couple bugfixes and some more tweaks to how reversals are handled.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@566 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -414,7 +414,7 @@ class StatementEntry extends AppModel {
|
||||
|
||||
$stats = $this->Transaction->stats($receipt_id);
|
||||
$receipt_credit['balance'] =
|
||||
$receipt_credit['Transaction']['amount'] - $stats['Disbursement']['total'];
|
||||
$receipt_credit['Transaction']['amount'] - $stats['StatementEntry']['disbursements'];
|
||||
|
||||
$receipt_credit['receipt'] = true;
|
||||
$credits = array($receipt_credit);
|
||||
@@ -529,6 +529,8 @@ class StatementEntry extends AppModel {
|
||||
if ($charge['balance'] <= 0)
|
||||
$this->pr(20, 'Fully Paid Charge');
|
||||
}
|
||||
// Break the $credit reference to avoid future problems
|
||||
unset($credit);
|
||||
}
|
||||
|
||||
$this->pr(18, compact('credits'),
|
||||
|
||||
@@ -171,69 +171,6 @@ class Transaction extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: addReversal
|
||||
* - Adds a new charge reversal
|
||||
*/
|
||||
|
||||
function addReversal1($data, $charge) {
|
||||
$this->prEnter(compact('data', 'charge'));
|
||||
|
||||
if (count($data['Entry']) != 1)
|
||||
$this->INTERNAL_ERROR("Should be one Entry for addReversal");
|
||||
|
||||
$data += array('control' => array());
|
||||
|
||||
/* 'amount' => $stats['Charge']['total'], */
|
||||
/* 'account_id' => $charge['account_id'], */
|
||||
|
||||
// First, reverse the charge
|
||||
$reversal = $data;
|
||||
$reversal['control'] +=
|
||||
array('assign' => false,
|
||||
'include_ledger_entry' => true,
|
||||
'include_statement_entry' => true,
|
||||
);
|
||||
|
||||
//$reversal['Transaction']['type'] = 'CREDIT_NOTE';
|
||||
$reversal['Entry'][0]['charge_entry_id'] = $charge_id;
|
||||
//$reversal['Entry'][0]['type'] = 'REVERSAL';
|
||||
$reversal['Entry'][0]['amount'] *= -1;
|
||||
|
||||
//$reversal['Transaction']['crdr'] = 'CREDIT';
|
||||
//$reversal['Entry'][0]['crdr'] = 'DEBIT';
|
||||
|
||||
$ids['reversal'] = $this->addInvoice($reversal, $customer_id, $lease_id);
|
||||
|
||||
|
||||
// Then issue a credit for the amount already paid, if any
|
||||
if ($credit_amount > 0) {
|
||||
$ids['credit'] = $this->addReceipt
|
||||
(array('control' =>
|
||||
array('include_ledger_entry' => false,
|
||||
'include_statement_entry' => true,
|
||||
),
|
||||
|
||||
'Transaction' =>
|
||||
array('stamp' => $data['Transaction']['stamp'],
|
||||
),
|
||||
|
||||
'Entry' =>
|
||||
array(array('amount' => $credit_amount,
|
||||
'charge_entry_id' => $charge_id,
|
||||
// REVISIT <AP>: 20090814
|
||||
// TEMPORARY. JUST NEED AN ACCOUNT AT THE MOMENT
|
||||
'account_id' => $this->StatementEntry->Account->accountPayableAccountID(),
|
||||
))),
|
||||
$customer_id, $lease_id);
|
||||
}
|
||||
|
||||
return $this->prReturn($ids);
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
@@ -693,33 +630,6 @@ class Transaction extends AppModel {
|
||||
// sum of the entry amounts.
|
||||
$transaction += array('amount' => $transaction_amount);
|
||||
|
||||
/* // Add a summary ledger entry if requested */
|
||||
/* if (!empty($control['summary_double_entry'])) { */
|
||||
/* $entry = $control['summary_double_entry']; */
|
||||
|
||||
/* $le1 = */
|
||||
/* array_intersect_key($entry, */
|
||||
/* array_flip(array('ledger_id', 'account_id', 'crdr', 'comment'))) + */
|
||||
/* array_intersect_key($transaction, */
|
||||
/* array_flip(array('amount'))); */
|
||||
/* $le1_tender = isset($entry['Tender']) ? $entry['Tender'] : null; */
|
||||
|
||||
/* $le2 = */
|
||||
/* array_intersect_key($transaction, */
|
||||
/* array_flip(array('ledger_id', 'account_id', 'crdr'))); */
|
||||
|
||||
/* array_unshift($entries, */
|
||||
/* array('le1' => array('account_id' => $de['le1']['account_id'], */
|
||||
/* 'crdr' => strtoupper($this->Account->fundamentalOpposite */
|
||||
/* ($control['ar_ledger_entry'])), */
|
||||
/* 'amount' => -1 * $transaction['amount']), */
|
||||
|
||||
/* 'le2' => array('account_id' => $this->Account->accountReceivableAccountID(), */
|
||||
/* 'crdr' => $control['ar_ledger_entry'], */
|
||||
/* 'amount' => -1 * $transaction['amount']) */
|
||||
/* )); */
|
||||
/* } */
|
||||
|
||||
$this->pr(20, compact('transaction', 'entries'));
|
||||
|
||||
// Move forward, verifying and saving everything.
|
||||
@@ -983,12 +893,10 @@ class Transaction extends AppModel {
|
||||
|
||||
'Transaction' =>
|
||||
array('stamp' => $stamp,
|
||||
//'type' => 'RECEIPT',
|
||||
'type' => 'CREDIT_NOTE',
|
||||
// The transaction amount will equal that of the charge
|
||||
'crdr' => 'DEBIT',
|
||||
'amount' => $charge['StatementEntry']['amount'],
|
||||
'account_id' => $charge['StatementEntry']['account_id'],
|
||||
'crdr' => 'DEBIT',
|
||||
'account_id' => $charge['StatementEntry']['account_id'],
|
||||
'customer_id' => $charge['StatementEntry']['customer_id'],
|
||||
'lease_id' => null,
|
||||
'comment' => $comment,
|
||||
@@ -998,7 +906,9 @@ class Transaction extends AppModel {
|
||||
|
||||
foreach ($disb_entries['DisbursementEntry'] AS $disbursement) {
|
||||
$rollback['Entry'][] =
|
||||
array('type' => $disbursement['type'],
|
||||
array(
|
||||
'type' => $disbursement['type'],
|
||||
//'type' => 'REVERSAL',
|
||||
'amount' => -1 * $disbursement['amount'],
|
||||
'account_id' => $disbursement['account_id'],
|
||||
'customer_id' => $disbursement['customer_id'],
|
||||
@@ -1010,12 +920,14 @@ class Transaction extends AppModel {
|
||||
// Add the sole ledger entry for this transaction
|
||||
$rollback['Entry'][] =
|
||||
array('include_ledger_entry' => true,
|
||||
'include_statement_entry' => false,
|
||||
'include_statement_entry' => true,
|
||||
'type' => 'REVERSAL',
|
||||
'crdr' => 'CREDIT',
|
||||
'amount' => $rollback['Transaction']['amount'],
|
||||
//'account_id' => $this->Account->accountPayableAccountID(),
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'crdr' => 'CREDIT',
|
||||
'account_id' => $this->Account->accountReceivableAccountID(),
|
||||
'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
|
||||
@@ -1025,15 +937,11 @@ class Transaction extends AppModel {
|
||||
$rollback['Transaction'],
|
||||
$rollback['Entry']);
|
||||
$this->pr(20, compact('rollback', 'rollback_result'));
|
||||
$ret['rollback'] = $rollback_result;
|
||||
$ret = $rollback_result;
|
||||
if ($rollback_result['error'])
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
}
|
||||
|
||||
/* $ret['nsf_transaction_id'] = $ret['bounce']['transaction_id']; */
|
||||
/* if (!empty($ret['rollback'])) */
|
||||
/* $ret['nsf_ledger_entry_id'] = $ret['rollback']['entries'][0]['DoubleEntry']['Entry1']['ledger_entry_id']; */
|
||||
$ret = $ret['rollback'];
|
||||
return $this->prReturn($ret + array('error' => false));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user