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:
@@ -82,9 +82,7 @@ class DoubleEntry extends AppModel {
|
||||
$double_entry['credit_entry_id'] =
|
||||
($entry1['crdr'] === 'CREDIT') ? $ret['Entry1']['ledger_entry_id'] : $ret['Entry2']['ledger_entry_id'];
|
||||
|
||||
/* pr(array('DoubleEntry::addDoubleEntry' => */
|
||||
/* array('checkpoint' => 'Pre-Save') */
|
||||
/* + compact('double_entry'))); */
|
||||
$ret['data'] = $double_entry;
|
||||
|
||||
$this->create();
|
||||
if (!$this->save($double_entry))
|
||||
|
||||
@@ -125,13 +125,10 @@ class StatementEntry extends AppModel {
|
||||
function addStatementEntry($entry) {
|
||||
$this->prEnter(compact('entry'));
|
||||
|
||||
$ret = array();
|
||||
$ret = array('data' => $entry);
|
||||
if (!$this->verifyStatementEntry($entry))
|
||||
return $this->prReturn(array('error' => true, 'verify_data' => $entry) + $ret);
|
||||
|
||||
$this->pr(20, array('checkpoint' => 'Pre-Save')
|
||||
+ compact('entry'));
|
||||
|
||||
$this->create();
|
||||
if (!$this->save($entry))
|
||||
return $this->prReturn(array('error' => true, 'save_data' => $entry) + $ret);
|
||||
|
||||
@@ -101,7 +101,7 @@ class Tender extends AppModel {
|
||||
function addTender($tender) {
|
||||
$this->prEnter(compact('tender'));
|
||||
|
||||
$ret = array();
|
||||
$ret = array('data' => $tender);
|
||||
if (!$this->verifyTender($tender))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
|
||||
@@ -7,6 +7,13 @@ class Transaction extends AppModel {
|
||||
'Ledger',
|
||||
);
|
||||
|
||||
var $hasOne = array(
|
||||
'NsfTender' => array(
|
||||
'className' => 'Tender',
|
||||
'foreignKey' => 'nsf_transaction_id',
|
||||
),
|
||||
);
|
||||
|
||||
var $hasMany = array(
|
||||
'LedgerEntry' => array(
|
||||
'dependent' => true,
|
||||
@@ -467,7 +474,7 @@ class Transaction extends AppModel {
|
||||
$this->pr(20, compact('transaction', 'entries'));
|
||||
|
||||
// Move forward, verifying and saving everything.
|
||||
$ret = array();
|
||||
$ret = array('data' => $transaction);
|
||||
if (!$this->verifyTransaction($transaction, $entries))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
|
||||
@@ -475,10 +482,10 @@ class Transaction extends AppModel {
|
||||
$this->create();
|
||||
if (!$this->save($transaction))
|
||||
return $this->prReturn(array('error' => true) + $ret);
|
||||
$transaction['id'] = $this->id;
|
||||
$ret['transaction_id'] = $transaction['id'] = $this->id;
|
||||
|
||||
// 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
|
||||
// want to do a credit assignment, and _then_ create
|
||||
@@ -589,7 +596,6 @@ class Transaction extends AppModel {
|
||||
|
||||
// Set up our return array
|
||||
$ret = array();
|
||||
$ret['transaction_id'] = $this->id;
|
||||
$ret['entries'] = array();
|
||||
$ret['error'] = false;
|
||||
|
||||
@@ -601,7 +607,7 @@ class Transaction extends AppModel {
|
||||
extract($entry);
|
||||
|
||||
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))
|
||||
$le1_tender['customer_id'] = $transaction['customer_id'];
|
||||
$result = $this->LedgerEntry->DoubleEntry->addDoubleEntry($le1, $le2, $le1_tender);
|
||||
@@ -613,7 +619,7 @@ class Transaction extends AppModel {
|
||||
}
|
||||
|
||||
if (!empty($se)) {
|
||||
$se['transaction_id'] = $ret['transaction_id'];
|
||||
$se['transaction_id'] = $transaction['id'];
|
||||
if (empty($se['effective_date']))
|
||||
$se['effective_date'] = $transaction['stamp'];
|
||||
$result = $this->StatementEntry->addStatementEntry($se);
|
||||
@@ -937,9 +943,28 @@ class Transaction extends AppModel {
|
||||
if ($charge_result['error'])
|
||||
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'];
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user