Change to how reversals are handled. In the process, I've tried to solidify _exactly_ what addTransaction will do, since it was becoming a house of cards of sorts. It was using special logic to decide things like whether to add ledger entries, statement entries, or both, whether to assignCredits afterwards, whether the generated receipt was to be considered a credit, and so on. Consequently, modifications to any calling function (addInvoice, addWaiver, etc) would often require addTransaction modifications, which would turn around and break all of the other calling functions. So, that embedded logic has been removed from addTransaction, and the rules of what addTransaction should do are now defined by the callers. This change is DEFINTELY not complete, as it probably has several bugs, and it DOES NOT YET WORK for reversals. I need a clean baseline to move forward from though, and this checkin approximates where we need to go.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@562 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-14 21:31:56 +00:00
parent 83e552211f
commit ac6a830d27
2 changed files with 286 additions and 167 deletions

View File

@@ -23,7 +23,7 @@ class StatementEntry extends AppModel {
);
//var $default_log_level = array('log' => 30, 'show' => 15);
var $default_log_level = array('log' => 30, 'show' => 15);
/**************************************************************************
**************************************************************************
@@ -169,7 +169,6 @@ class StatementEntry extends AppModel {
// Add the charge waiver
$waiver['Entry'][] =
array('amount' => $stats['Charge']['balance'],
'account_id' => $this->Account->waiverAccountID(),
'comment' => null,
);
@@ -184,45 +183,47 @@ class StatementEntry extends AppModel {
**************************************************************************
* function: reverse
* - Reverses the charges
*
*/
function reverse($id, $balance = false, $stamp = null) {
$this->prEnter(compact('id', 'balance', 'stamp'));
function reversable($id) {
$this->prEnter(compact('id'));
$ret = array();
// Verify the item is an actual charge
$this->id = $id;
$charge_type = $this->field('type');
if ($charge_type !== 'CHARGE')
return $this->prReturn(false);
// Get the basic information about the entry to be reversed.
$this->recursive = -1;
$charge = $this->read(null, $id);
$charge = $charge['StatementEntry'];
if ($charge['type'] !== 'CHARGE')
$this->INTERNAL_ERROR("Reversal item is not CHARGE.");
$voided_entry_transactions = array();
// Determine anything reconciled against the charge
$reconciled = $this->reconciledEntries($id);
$this->pr(21, compact('reconciled'));
if ($reconciled && !$balance) {
foreach ($reconciled['entries'] AS $entry) {
if (!empty($reconciled)) {
// Double check that this charge has not already been reversed
foreach ($reconciled['entries'] AS $entry)
if ($entry['DisbursementEntry']['type'] === 'REVERSAL')
$this->INTERNAL_ERROR("Charge has already been reversed");
$voided_entry_transactions[$entry['DisbursementEntry']['transaction_id']]
= array_intersect_key($entry['DisbursementEntry'],
array('customer_id'=>1, 'lease_id'=>1));
$this->delete($entry['DisbursementEntry']['id']);
continue;
$DE = new StatementEntry();
$DE->id = $entry['DisbursementEntry']['id'];
$DE->saveField('type', 'VOID');
$DE->saveField('charge_entry_id', null);
}
$this->pr(17, compact('voided_entry_transactions'));
return $this->prReturn(false);
}
return $this->prReturn(true);
}
/**************************************************************************
**************************************************************************
**************************************************************************
* function: reverse
* - Reverses the charges
*/
function reverse($id, $stamp = null) {
$this->prEnter(compact('id', 'stamp'));
// Verify the item can be reversed
if (!$this->reversable($id))
$this->INTERNAL_ERROR("Item is not reversable.");
// Get the basic information about this charge
$charge = $this->find('first', array('contain' => true));
$charge = $charge['StatementEntry'];
// Query the stats to get the remaining balance
$stats = $this->stats($id);
@@ -233,35 +234,18 @@ class StatementEntry extends AppModel {
// Add the charge reversal
$reversal['Entry'][] =
array('amount' => $stats['Charge']['balance'],
array('amount' => $stats['Charge']['total'],
'account_id' => $charge['account_id'],
'comment' => 'Charge Reversal',
);
// Record the reversal transaction
$result = $this->Transaction->addReversal
($reversal, $id, $charge['customer_id'], $charge['lease_id']);
$this->pr(21, compact('result'));
$ret['reversal'] = $result;
if ($result['error'])
$ret['error'] = true;
($reversal,
$id, $stats['Charge']['disbursement'],
$charge['customer_id'], $charge['lease_id']);
foreach ($voided_entry_transactions AS $transaction_id => $tx) {
$result = $this->assignCredits
(null,
$transaction_id,
null,
null,
$tx['customer_id'],
null
);
$this->pr(21, compact('result'));
$ret['assigned'][] = $result;
if ($result['error'])
$ret['error'] = true;
}
return $this->prReturn($ret + array('error' => false));
return $this->prReturn($result);
}

View File

@@ -43,7 +43,7 @@ class Transaction extends AppModel {
);
//var $default_log_level = array('log' => 30, 'show' => 15);
var $default_log_level = array('log' => 30, 'show' => 15);
/**************************************************************************
**************************************************************************
@@ -55,9 +55,16 @@ class Transaction extends AppModel {
function addInvoice($data, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
// Set up control parameters
$data += array('control' => array());
$data['control'] +=
array('assign' => true,
'include_ledger_entry' => true,
'include_statement_entry' => true,
);
// Establish the transaction as an invoice
$invoice =& $data['Transaction'];
$invoice +=
$data['Transaction'] +=
array('type' => 'INVOICE',
'crdr' => 'DEBIT',
'account_id' => $this->Account->accountReceivableAccountID(),
@@ -71,7 +78,7 @@ class Transaction extends AppModel {
'crdr' => 'CREDIT',
);
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
$ids = $this->addTransaction($data['control'], $data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['invoice_id'] = $ids['transaction_id'];
@@ -89,9 +96,17 @@ class Transaction extends AppModel {
function addReceipt($data, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
// Set up control parameters
$data += array('control' => array());
$data['control'] +=
array('assign' => true,
'assign_receipt' => true,
'include_ledger_entry' => true,
'include_statement_entry' => false,
);
// Establish the transaction as a receipt
$receipt =& $data['Transaction'];
$receipt +=
$data['Transaction'] +=
array('type' => 'RECEIPT',
'crdr' => 'CREDIT',
'account_id' => $this->Account->accountReceivableAccountID(),
@@ -110,7 +125,7 @@ class Transaction extends AppModel {
: null),
);
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
$ids = $this->addTransaction($data['control'], $data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['receipt_id'] = $ids['transaction_id'];
@@ -131,10 +146,21 @@ class Transaction extends AppModel {
if (count($data['Entry']) != 1)
$this->INTERNAL_ERROR("Should be one Entry for addWaiver");
// No assignment of credits, as we'll manually assign
// using charge_entry_id as part of the entry (below).
$data += array('control' => array());
$data['control'] +=
array('assign' => false,
'include_ledger_entry' => true,
'include_statement_entry' => true,
);
// Just make sure the disbursement(s) are marked as waivers
// and that they go to cover the specific charge.
$data['Transaction']['disbursement_type'] = 'WAIVER';
$data['Transaction']['assign_charge_entry_id'] = $charge_id;
$data['Entry'][0] +=
array('type' => 'WAIVER',
'account_id' => $this->Account->waiverAccountID(),
'charge_entry_id' => $charge_id);
// In all other respects this is just a receipt.
$ids = $this->addReceipt($data, $customer_id, $lease_id);
@@ -152,22 +178,50 @@ class Transaction extends AppModel {
* - Adds a new charge reversal
*/
function addReversal($data, $charge_id, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'charge_id', 'customer_id', 'lease_id'));
function addReversal($data, $charge_id, $credit_amount, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'charge_id', 'credit_amount', 'customer_id', 'lease_id'));
if (count($data['Entry']) != 1)
$this->INTERNAL_ERROR("Should be one Entry for addReversal");
// Just make sure the disbursement(s) are marked as reversals
// and that they go to cover the specific charge.
$data['Transaction']['type'] = 'CREDIT_NOTE';
$data['Transaction']['disbursement_type'] = 'REVERSAL';
$data['Transaction']['assign_charge_entry_id'] = $charge_id;
$data += array('control' => array());
// In all other respects this is just a receipt.
$ids = $this->addReceipt($data, $customer_id, $lease_id);
if (isset($ids['transaction_id']))
$ids['reversal_id'] = $ids['transaction_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['Transaction']['crdr'] = 'CREDIT';
$reversal['Entry'][0]['charge_entry_id'] = $charge_id;
$reversal['Entry'][0]['type'] = 'REVERSAL';
//$reversal['Entry'][0]['crdr'] = 'DEBIT';
$ids['reversal'] = $this->addReceipt($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('assign' => true,
'assign_receipt' => true,
'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,
'account_id' => $this->StatementEntry->Account->accountPayableAccountID(),
))),
$customer_id, $lease_id);
}
return $this->prReturn($ids);
}
@@ -181,15 +235,16 @@ class Transaction extends AppModel {
*/
function addWriteOff($data, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'charge_id', 'customer_id', 'lease_id'));
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
if (count($data['Entry']) != 1)
$this->INTERNAL_ERROR("Should be one Entry for addWriteOff");
// Just make sure the disbursement(s) are marked as write offs,
// and that the write-off account is used.
$data['Transaction']['disbursement_type'] = 'WRITEOFF';
$data['Entry'][0]['account_id'] = $this->Account->badDebtAccountID();
// Just make sure the disbursement(s) are marked as write offs
// and that the write-off account is used for the charge.
$data['Entry'][0] +=
array('type' => 'WRITEOFF',
'account_id' => $this->Account->badDebtAccountID());
// In all other respects this is just a receipt.
$ids = $this->addReceipt($data, $customer_id, $lease_id);
@@ -210,9 +265,16 @@ class Transaction extends AppModel {
function addDeposit($data, $account_id) {
$this->prEnter(compact('data', 'account_id'));
// Set up control parameters
$data += array('control' => array());
$data['control'] +=
array('assign' => false,
'include_ledger_entry' => true,
'include_statement_entry' => false,
);
// Establish the transaction as a deposit
$deposit =& $data['Transaction'];
$deposit +=
$data['Transaction'] +=
array('type' => 'DEPOSIT',
'crdr' => 'DEBIT',
'account_id' => $account_id,
@@ -231,13 +293,13 @@ class Transaction extends AppModel {
if (!isset($group[$entry['account_id']]))
$group[$entry['account_id']] =
array('account_id' => $entry['account_id'],
'crdr' => strtoupper($this->Account->fundamentalOpposite($deposit['crdr'])),
'crdr' => strtoupper($this->Account->fundamentalOpposite($data['Transaction']['crdr'])),
'amount' => 0);
$group[$entry['account_id']]['amount'] += $entry['amount'];
}
$data['Entry'] = $group;
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
$ids = $this->addTransaction($data['control'], $data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['deposit_id'] = $ids['transaction_id'];
@@ -262,9 +324,16 @@ class Transaction extends AppModel {
function addClose($data) {
$this->prEnter(compact('data'));
// Set up control parameters
$data += array('control' => array());
$data['control'] +=
array('assign' => false,
'include_ledger_entry' => true,
'include_statement_entry' => false,
);
// Establish the transaction as a close
$close =& $data['Transaction'];
$close +=
$data['Transaction'] +=
array('type' => 'CLOSE',
'crdr' => null,
'account_id' => null,
@@ -296,7 +365,7 @@ class Transaction extends AppModel {
unset($data['Ledger']);
// Add the transaction and carry forward balances
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
$ids = $this->addTransaction($data['control'], $data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['close_id'] = $ids['transaction_id'];
@@ -322,13 +391,18 @@ class Transaction extends AppModel {
function addRefund($data, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
// Set up control parameters
$data += array('control' => array());
$data['control'] +=
array('assign' => true,
);
// Establish the transaction as a Refund. This is just like a
// Payment, except instead of paying out of the account payable,
// it comes from the customer credit in the account receivable.
// Someday, perhaps we'll just issue a Credit Note or similar,
// but for now, a refund means it's time to actually PAY.
$refund =& $data['Transaction'];
$refund +=
$data['Transaction'] +=
array('account_id' => $this->Account->accountReceivableAccountID());
// Also, to make it clear to the user, we flag as a REFUND
@@ -354,9 +428,16 @@ class Transaction extends AppModel {
function addPayment($data, $customer_id, $lease_id = null) {
$this->prEnter(compact('data', 'customer_id', 'lease_id'));
// Set up control parameters
$data += array('control' => array());
$data['control'] +=
array('assign' => false,
'include_ledger_entry' => true,
'include_statement_entry' => true,
);
// Establish the transaction as an payment
$payment =& $data['Transaction'];
$payment +=
$data['Transaction'] +=
array('type' => 'PAYMENT',
'crdr' => 'DEBIT',
'account_id' => $this->Account->accountPayableAccountID(),
@@ -370,7 +451,7 @@ class Transaction extends AppModel {
'crdr' => 'CREDIT',
);
$ids = $this->addTransaction($data['Transaction'], $data['Entry']);
$ids = $this->addTransaction($data['control'], $data['Transaction'], $data['Entry']);
if (isset($ids['transaction_id']))
$ids['payment_id'] = $ids['transaction_id'];
@@ -478,8 +559,8 @@ class Transaction extends AppModel {
*
*/
function addTransaction($transaction, $entries, $subtype = null) {
$this->prEnter(compact('transaction', 'entries', 'subtype'));
function addTransaction($control, $transaction, $entries) {
$this->prEnter(compact('control', 'transaction', 'entries'));
// Verify that we have a transaction and entries
if (empty($transaction) ||
@@ -498,6 +579,14 @@ class Transaction extends AppModel {
$transaction['customer_id'] = $L->field('customer_id');
}
// Some transactions do not have their statement entries
// generated from this function, but they are instead
// created in the final steps during the reconciliation
// phase by the assignCredits function. Keep track of
// what type the statement entries _would_ have been, so
// that the assignCredits function can do the same.
$assign_disbursement_type = null;
// Break each entry out of the combined statement/ledger entry
// and into individual entries appropriate for saving. While
// we're at it, calculate the transaction total as well.
@@ -511,9 +600,6 @@ class Transaction extends AppModel {
// and not here. However, it's a one stop cleanup.
$entry['amount'] = str_replace('$', '', $entry['amount']);
// Add entry amount into the transaction total
$transaction['amount'] += $entry['amount'];
// Set up our comments, possibly using the default 'comment' field
if (empty($entry['ledger_entry_comment'])) {
if ($transaction['type'] != 'INVOICE' && !empty($entry['comment']))
@@ -528,9 +614,10 @@ class Transaction extends AppModel {
$entry['statement_entry_comment'] = null;
}
// Create one half of the Double Ledger Entry (and the Tender)
$le1 =
array_intersect_key($entry,
if (!empty($control['include_ledger_entry']) || !empty($entry['include_ledger_entry'])) {
// Create one half of the Double Ledger Entry (and the Tender)
$le1 =
array_intersect_key($entry,
array_flip(array('ledger_id', 'account_id', 'crdr', 'amount')));
$le1['comment'] = $entry['ledger_entry_comment'];
$le1_tender = isset($entry['Tender']) ? $entry['Tender'] : null;
@@ -550,52 +637,71 @@ class Transaction extends AppModel {
array_flip(array('amount'))) +
array_intersect_key($transaction,
array_flip(array('ledger_id', 'account_id', 'crdr')));
}
}
else
$le1 = $le1_tender = $le2 = null;
// Now that the ledger entries are in place, respect the 'negative' flag
if (!empty($control['negative']))
$entry['amount'] *= -1;
if (!empty($control['include_statement_entry']) || !empty($entry['include_statement_entry'])) {
// Create the statement entry
$se =
array_intersect_key($entry,
array_flip(array('type', 'account_id', 'amount',
'effective_date', 'through_date', 'due_date',
'customer_id', 'lease_id',
'charge_entry_id'))) +
array_intersect_key($transaction,
array_flip(array('customer_id', 'lease_id')));
$se['comment'] = $entry['statement_entry_comment'];
}
else {
if (!empty($control['assign'])) {
if (empty($assign_disbursement_type))
$assign_disbursement_type = $entry['type'];
elseif ($entry['type'] != $assign_disbursement_type)
$this->INTERNAL_ERROR('Multiple disbursement types for this transaction');
}
$se = null;
}
// Create the statement entry
$se =
array_intersect_key($entry,
array_flip(array('type', 'account_id', 'amount',
'effective_date', 'through_date', 'due_date',
'customer_id', 'lease_id',
'charge_entry_id'))) +
array_intersect_key($transaction,
array_flip(array('customer_id', 'lease_id')));
$se['comment'] = $entry['statement_entry_comment'];
if (!empty($entry['se_negative']))
$se['amount'] *= -1;
// (DISBURSEMENTS will have statement entries created below, when
// assigning credits, and DEPOSITS don't have statement entries)
if (empty($transaction['customer_id']) ||
($transaction['account_id'] == $this->Account->accountReceivableAccountID() &&
$transaction['crdr'] == 'CREDIT'))
$se = null;
// NSF transactions don't use LedgerEntries
// REVISIT <AP>: 20090731
// Doesn't seem right... probably doing this because of the
// single A/R entry we add below for NSF
if ($subtype === 'NSF')
$le1 = $le1_tender = $le2 = null;
// Add entry amount into the transaction total
$transaction['amount'] += $entry['amount'];
// Replace combined entry with our new individual entries
$entry = compact('le1', 'le1_tender', 'le2', 'se');
}
if ($subtype === 'NSF') {
// REVISIT <AP>: 20090731
// Should we be doing this, or just doing individual ledger entries
// that were created above before we nulled them out
array_unshift($entries,
array('le1' => array('account_id' => $transaction['account_id'],
'crdr' => 'CREDIT',
'amount' => -1 * $transaction['amount']),
'le2' => array('account_id' => $this->Account->accountReceivableAccountID(),
'crdr' => 'DEBIT',
'amount' => -1 * $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'));
@@ -647,19 +753,13 @@ class Transaction extends AppModel {
}
}
if ($transaction['account_id'] == $this->Account->accountReceivableAccountID()
&& !$ret['error']) {
if (!empty($control['assign']) && !$ret['error']) {
$result = $this->StatementEntry->assignCredits
(null,
($transaction['crdr'] == 'CREDIT'
? $ret['transaction_id']
: null),
($transaction['crdr'] == 'CREDIT' && !empty($transaction['assign_charge_entry_id'])
? $transaction['assign_charge_entry_id']
: null),
(!empty($transaction['disbursement_type'])
? $transaction['disbursement_type']
: null),
(empty($control['assign_receipt']) ? null
: $ret['transaction_id']),
null,
$assign_disbursement_type,
$transaction['customer_id'],
$transaction['lease_id']
);
@@ -691,15 +791,17 @@ class Transaction extends AppModel {
// and recording it in the NSF account. It has nothing to do
// with the customer statement (charges, disbursements, credits, etc).
$bounce_result = $this->addDeposit
(array('Transaction' => array('stamp' => $stamp,
'type' => 'WITHDRAWAL',
'crdr' => 'CREDIT'),
'Entry' => array(array('tender_id' => null,
'account_id' => $this->Account->nsfAccountID(),
'crdr' => 'DEBIT',
'amount' => $tender['LedgerEntry']['amount'],
'se_negative' => true,
))),
(array('Transaction' =>
array('stamp' => $stamp,
'type' => 'WITHDRAWAL',
'crdr' => 'CREDIT'),
'Entry' =>
array(array('tender_id' => null,
'account_id' => $this->Account->nsfAccountID(),
'crdr' => 'DEBIT',
'amount' => $tender['LedgerEntry']['amount'],
))),
$tender['Transaction']['account_id']);
$this->pr(20, compact('bounce_result'));
@@ -734,15 +836,25 @@ class Transaction extends AppModel {
return $this->prReturn(array('error' => true) + $ret);
// Build a transaction to adjust all of the statement entries
$rollback = array('Transaction' => array(), 'Entry' => array());
$rollback =
array('control' =>
array('assign' => false,
'include_ledger_entry' => false,
'include_statement_entry' => true,
),
$rollback['Transaction']['stamp'] = $stamp;
$rollback['Transaction']['type'] = 'RECEIPT';
$rollback['Transaction']['crdr'] = 'CREDIT'; // Unused... keeps verifyTx happy
$rollback['Transaction']['account_id'] = $this->Account->nsfAccountID();
$rollback['Transaction']['customer_id'] = $tender['Tender']['customer_id'];
$rollback['Transaction']['comment'] = $comment;
'Transaction' =>
array('stamp' => $stamp,
'type' => 'RECEIPT',
'crdr' => 'CREDIT',
'account_id' => $this->Account->nsfAccountID(),
'customer_id' => $tender['Tender']['customer_id'],
'comment' => $comment,
),
'Entry' => array());
$summary_amount = 0;
foreach ($nsf_ledger_entry['Transaction']['StatementEntry'] AS $disbursement) {
if ($disbursement['type'] === 'SURPLUS') {
$disbursement['type'] = 'VOID';
@@ -758,13 +870,25 @@ class Transaction extends AppModel {
'lease_id' => $disbursement['lease_id'],
'charge_entry_id' => $disbursement['charge_entry_id'],
);
$summary_amount += $disbursement['amount'];
}
}
// Add the sole ledger entry for this transaction
$rollback['Entry'][] =
array('include_ledger_entry' => true,
'include_statement_entry' => false,
'amount' => $summary_amount,
'account_id' => $this->Account->accountReceivableAccountID(),
'crdr' => 'DEBIT',
);
// Record the transaction, which will un-pay previously paid
// charges, void any credits, and other similar work.
if (count($rollback['Entry'])) {
$rollback_result = $this->addTransaction($rollback['Transaction'], $rollback['Entry'], 'NSF');
$rollback_result = $this->addTransaction($rollback['control'],
$rollback['Transaction'],
$rollback['Entry']);
$this->pr(20, compact('rollback', 'rollback_result'));
$ret['rollback'] = $rollback_result;
if ($rollback_result['error'])
@@ -804,7 +928,7 @@ class Transaction extends AppModel {
/**************************************************************************
**************************************************************************
**************************************************************************
* function: destroy
* function: stats
* - Deletes a transaction and associated entries
* - !!WARNING!! This should be used with EXTREME caution, as it
* irreversibly destroys the data. It is not for normal use,
@@ -817,6 +941,16 @@ class Transaction extends AppModel {
function destroy($id) {
$this->prFunctionLevel(30);
$this->prEnter(compact('id'));
/* $transaction = $this->find */
/* ('first', */
/* array('contain' => */
/* array(// Models */
/* 'StatementEntry', */
/* 'LedgerEntry' => array('Tender'), */
/* ), */
/* 'conditions' => array(array('Transaction.id' => $id)), */
/* )); */
/* pr($transaction); */
$this->id = $id;
$customer_id = $this->field('customer_id');
@@ -825,6 +959,7 @@ class Transaction extends AppModel {
if (!empty($customer_id)) {
$this->StatementEntry->assignCredits
(null, null, null, null, $customer_id, null);
//$this->Customer->update($customer_id);
}
return $this->prReturn($result);