Fixed a bug with deposit, which prevented update to the deposited tenders. Added INTERNAL_ERROR when an error occurs. Since the module and callers make no effort to roll back changes when an error occurs, it's probably best to just halt. We may need to remove some of these checks, especially in the verifyTransaction function, which is intended to catch errors before they create a problem in the database.

git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@805 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-28 16:41:17 +00:00
parent c21cdcd9a2
commit 5b5707df5e

View File

@@ -350,10 +350,14 @@ class Transaction extends AppModel {
if (isset($ids['transaction_id']))
$ids['deposit_id'] = $ids['transaction_id'];
if (!empty($ids['deposit_id']) && !empty($control['update_tender'])) {
$this->pr(21, array_intersect_key($ids, array('deposit_id'=>1))
+ array_intersect_key($data['control'], array('update_tender'=>1)));
if (!empty($ids['deposit_id']) && !empty($data['control']['update_tender'])) {
$this->pr(21, compact('tender_groups'));
foreach ($tender_groups AS $group => $tender_ids) {
$entry_id = $ids['entries'][$group]['DoubleEntry']['Entry2']['ledger_entry_id'];
$this->pr(10, compact('group', 'tender_ids', 'entry_id'));
$this->pr(19, compact('group', 'tender_ids', 'entry_id'));
$this->LedgerEntry->Tender->updateAll
(array('Tender.deposit_transaction_id' => $ids['deposit_id'],
'Tender.deposit_ledger_entry_id' => $entry_id),
@@ -530,6 +534,8 @@ class Transaction extends AppModel {
(in_array($transaction['type'], array('INVOICE', 'RECEIPT'))
&& empty($transaction['customer_id']))
) {
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Transaction verification failed');
return $this->prReturn(false);
}
@@ -545,6 +551,8 @@ class Transaction extends AppModel {
}
if (!empty($se) &&
!$this->StatementEntry->verifyStatementEntry($se)) {
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Transaction entry verification failed');
return $this->prReturn(false);
}
}
@@ -584,8 +592,11 @@ class Transaction extends AppModel {
// Save transaction to the database
$this->create();
if (!$this->save($transaction))
if (!$this->save($transaction)) {
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Failed to save Transaction');
return $this->prReturn(array('error' => true) + $ret);
}
$ret['transaction_id'] = $transaction['id'] = $this->id;
// Add the entries
@@ -661,6 +672,11 @@ class Transaction extends AppModel {
if (!empty($transaction['customer_id'])) {
$this->Customer->update($transaction['customer_id']);
}
if (!empty($ret['error']))
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Failed to save Transaction');
return $this->prReturn($ret);
}
@@ -681,8 +697,11 @@ class Transaction extends AppModel {
$this->prEnter(compact('control', 'transaction', 'entries', 'split'));
// Verify that we have a transaction
if (empty($transaction['id']))
if (empty($transaction['id'])) {
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Invalid Transaction ID for adding entries');
return $this->prReturn(array('error' => true));
}
// If the entries are not already split, do so now.
if ($split) {
@@ -742,6 +761,10 @@ class Transaction extends AppModel {
}
}
if (!empty($ret['error']))
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Failed to save Transaction Entries');
return $this->prReturn($ret);
}
@@ -762,8 +785,11 @@ class Transaction extends AppModel {
// Verify that we have a transaction and entries
if (empty($transaction) ||
(empty($entries) && empty($control['allow_no_entries'])))
(empty($entries) && empty($control['allow_no_entries']))) {
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Split Entries failed to validate');
return $this->prReturn(array('error' => true));
}
// set ledger ID as the current ledger of the specified account
if (empty($transaction['ledger_id']))
@@ -972,8 +998,11 @@ class Transaction extends AppModel {
));
$this->pr(20, compact('nsf_ledger_entry'));
if (!$nsf_ledger_entry)
if (!$nsf_ledger_entry) {
// REVISIT <AP>: 20090828; Callers are not yet able to handle errors
$this->INTERNAL_ERROR('Failed to locate NSF ledger entry');
return $this->prReturn(array('error' => true) + $ret);
}
// Build a transaction to adjust all of the statement entries
$rollback =