diff --git a/site/models/tender.php b/site/models/tender.php index 6be0001..31351c3 100644 --- a/site/models/tender.php +++ b/site/models/tender.php @@ -128,17 +128,22 @@ class Tender extends AppModel { if (empty($tender['DepositTransaction']['id'])) die("Item has not been deposited yet"); -/* $payments = $this->LedgerEntry->Transaction->StatementEntry->find */ -/* ('all', array */ -/* ('contain' => array('Transaction' => */ -/* array('fields' => array(), */ -/* 'LedgerEntry */ -/* 'conditions' => array('StatementEntry.transaction_id' => xx, */ - -/* array('LedgerEntry', */ -/* 'DepositTransaction', */ -/* 'NsfTransaction'), */ -/* )); */ + // Enter the NSF + $result = $this->DepositTransaction->addDeposit + (array('Transaction' => array(), + 'Entry' => array(array('tender_id' => null, + 'account_id' => $this->LedgerEntry->Account->nsfAccountID(), + 'amount' => -1 * $tender['LedgerEntry']['amount'], + ))), + $tender['DepositTransaction']['account_id']); + pr(compact('result')); + + if ($result['error']) + die("Unable to save NSF transaction"); + + $this->id = $id; + $this->saveField('nsf_transaction_id', $result['transaction_id']); + $nsf_ledger_entry = $this->LedgerEntry->find ('first', array @@ -157,18 +162,18 @@ class Tender extends AppModel { $bounce = array('Transaction' => array(), 'Entry' => array()); - $bounce['Transaction']['account_id'] = $tender['DepositTransaction']['account_id']; + $bounce['Transaction']['account_id'] = $this->LedgerEntry->Account->nsfAccountID(); $bounce['Transaction']['customer_id'] = $tender['Tender']['customer_id']; $bounce['Transaction']['amount'] = -1 * $tender['LedgerEntry']['amount']; foreach ($nsf_ledger_entry['Transaction']['StatementEntry'] AS $payment) { $bounce['Entry'][] = - array('type' => 'PAYMENT', - 'amount' => -1 * $payment['amount'], - 'account_id' => $payment['account_id'], - 'customer_id' => $payment['customer_id'], - 'lease_id' => $payment['lease_id'], - 'charge_entry_id' => $payment['charge_entry_id'], + array('type' => 'PAYMENT', + 'amount' => -1 * $payment['amount'], + 'account_id' => $this->LedgerEntry->Account->nsfAccountID(), + 'customer_id' => $payment['customer_id'], + 'lease_id' => $payment['lease_id'], + 'charge_entry_id' => $payment['charge_entry_id'], //'effective_date' => $tender[ stamp ], ); } @@ -177,10 +182,7 @@ class Tender extends AppModel { $result = $this->NsfTransaction->addNsf($bounce); if ($result['error']) - die("Unable to save NSF transaction"); - - $this->id = $id; - $this->saveField('nsf_transaction_id', $result['transaction_id']); + die("Unable to save Bounce transaction"); die(); diff --git a/site/models/transaction.php b/site/models/transaction.php index f53a027..f1a33ab 100644 --- a/site/models/transaction.php +++ b/site/models/transaction.php @@ -549,8 +549,6 @@ class Transaction extends AppModel { array('checkpoint' => 'Pre Transaction Save') + compact('transaction'))); - pr(compact('data')); - // Save transaction to the database $this->create(); if (!$this->save($transaction)) @@ -567,7 +565,6 @@ class Transaction extends AppModel { $le1_tender = null; $le2 = null; $se = null; - pr(compact('entry')); extract($entry); if (!empty($le1) && !empty($le2)) { @@ -591,7 +588,6 @@ class Transaction extends AppModel { continue; } } - pr(compact('ret')); } /* if (($transaction['type'] == 'INVOICE' || */