Fixed bug with NSF, which was failing to locate the nsf_entry_id. To resolve this, I added the original data into the return structure for each item, instead of just the created IDs. Also, added NsfTender to the Transaction model to locate which Tender an NSF transaction relates to.

git-svn-id: file:///svn-source/pmgr/branches/surplus_account_20090815@583 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-16 18:59:16 +00:00
parent a1a68f3209
commit 754cdb8522
4 changed files with 36 additions and 16 deletions

View File

@@ -82,9 +82,7 @@ class DoubleEntry extends AppModel {
$double_entry['credit_entry_id'] = $double_entry['credit_entry_id'] =
($entry1['crdr'] === 'CREDIT') ? $ret['Entry1']['ledger_entry_id'] : $ret['Entry2']['ledger_entry_id']; ($entry1['crdr'] === 'CREDIT') ? $ret['Entry1']['ledger_entry_id'] : $ret['Entry2']['ledger_entry_id'];
/* pr(array('DoubleEntry::addDoubleEntry' => */ $ret['data'] = $double_entry;
/* array('checkpoint' => 'Pre-Save') */
/* + compact('double_entry'))); */
$this->create(); $this->create();
if (!$this->save($double_entry)) if (!$this->save($double_entry))

View File

@@ -125,13 +125,10 @@ class StatementEntry extends AppModel {
function addStatementEntry($entry) { function addStatementEntry($entry) {
$this->prEnter(compact('entry')); $this->prEnter(compact('entry'));
$ret = array(); $ret = array('data' => $entry);
if (!$this->verifyStatementEntry($entry)) if (!$this->verifyStatementEntry($entry))
return $this->prReturn(array('error' => true, 'verify_data' => $entry) + $ret); return $this->prReturn(array('error' => true, 'verify_data' => $entry) + $ret);
$this->pr(20, array('checkpoint' => 'Pre-Save')
+ compact('entry'));
$this->create(); $this->create();
if (!$this->save($entry)) if (!$this->save($entry))
return $this->prReturn(array('error' => true, 'save_data' => $entry) + $ret); return $this->prReturn(array('error' => true, 'save_data' => $entry) + $ret);

View File

@@ -101,7 +101,7 @@ class Tender extends AppModel {
function addTender($tender) { function addTender($tender) {
$this->prEnter(compact('tender')); $this->prEnter(compact('tender'));
$ret = array(); $ret = array('data' => $tender);
if (!$this->verifyTender($tender)) if (!$this->verifyTender($tender))
return $this->prReturn(array('error' => true) + $ret); return $this->prReturn(array('error' => true) + $ret);

View File

@@ -7,6 +7,13 @@ class Transaction extends AppModel {
'Ledger', 'Ledger',
); );
var $hasOne = array(
'NsfTender' => array(
'className' => 'Tender',
'foreignKey' => 'nsf_transaction_id',
),
);
var $hasMany = array( var $hasMany = array(
'LedgerEntry' => array( 'LedgerEntry' => array(
'dependent' => true, 'dependent' => true,
@@ -467,7 +474,7 @@ class Transaction extends AppModel {
$this->pr(20, compact('transaction', 'entries')); $this->pr(20, compact('transaction', 'entries'));
// Move forward, verifying and saving everything. // Move forward, verifying and saving everything.
$ret = array(); $ret = array('data' => $transaction);
if (!$this->verifyTransaction($transaction, $entries)) if (!$this->verifyTransaction($transaction, $entries))
return $this->prReturn(array('error' => true) + $ret); return $this->prReturn(array('error' => true) + $ret);
@@ -475,10 +482,10 @@ class Transaction extends AppModel {
$this->create(); $this->create();
if (!$this->save($transaction)) if (!$this->save($transaction))
return $this->prReturn(array('error' => true) + $ret); return $this->prReturn(array('error' => true) + $ret);
$transaction['id'] = $this->id; $ret['transaction_id'] = $transaction['id'] = $this->id;
// Add the entries // Add the entries
$ret = $this->addTransactionEntries($control, $transaction, $entries, false); $ret += $this->addTransactionEntries($control, $transaction, $entries, false);
// If the caller requests 'assign'=>true, they really // If the caller requests 'assign'=>true, they really
// want to do a credit assignment, and _then_ create // want to do a credit assignment, and _then_ create
@@ -589,7 +596,6 @@ class Transaction extends AppModel {
// Set up our return array // Set up our return array
$ret = array(); $ret = array();
$ret['transaction_id'] = $this->id;
$ret['entries'] = array(); $ret['entries'] = array();
$ret['error'] = false; $ret['error'] = false;
@@ -601,7 +607,7 @@ class Transaction extends AppModel {
extract($entry); extract($entry);
if (!empty($le1) && !empty($le2)) { if (!empty($le1) && !empty($le2)) {
$le1['transaction_id'] = $le2['transaction_id'] = $ret['transaction_id']; $le1['transaction_id'] = $le2['transaction_id'] = $transaction['id'];
if (isset($le1_tender)) if (isset($le1_tender))
$le1_tender['customer_id'] = $transaction['customer_id']; $le1_tender['customer_id'] = $transaction['customer_id'];
$result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender); $result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender);
@@ -613,7 +619,7 @@ class Transaction extends AppModel {
} }
if (!empty($se)) { if (!empty($se)) {
$se['transaction_id'] = $ret['transaction_id']; $se['transaction_id'] = $transaction['id'];
if (empty($se['effective_date'])) if (empty($se['effective_date']))
$se['effective_date'] = $transaction['stamp']; $se['effective_date'] = $transaction['stamp'];
$result = $this->StatementEntry->addStatementEntry($se); $result = $this->StatementEntry->addStatementEntry($se);
@@ -937,9 +943,28 @@ class Transaction extends AppModel {
if ($charge_result['error']) if ($charge_result['error'])
return $this->prReturn(array('error' => true) + $ret); return $this->prReturn(array('error' => true) + $ret);
if (!empty($ret['rollback'])) {
foreach ($ret['rollback']['entries'] AS $rentry) {
if (!empty($rentry['DoubleEntry'])) {
if (!empty($rentry['DoubleEntry']['error']))
continue;
foreach (array('Entry1', 'Entry2') AS $n) {
$entry = $rentry['DoubleEntry'][$n];
if ($entry['data']['account_id'] == $this->Account->nsfAccountID()) {
if (!empty($ret['nsf_ledger_entry_id']))
$this->INTERNAL_ERROR("More than one NSF LE ID");
$ret['nsf_ledger_entry_id'] = $entry['ledger_entry_id'];
}
}
}
}
}
if (empty($ret['rollback']['error']) && empty($ret['nsf_ledger_entry_id']))
$this->INTERNAL_ERROR("NSF LE ID not found under rollback entries");
$ret['nsf_transaction_id'] = $ret['bounce']['transaction_id']; $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'];
return $this->prReturn($ret + array('error' => false)); return $this->prReturn($ret + array('error' => false));
} }