From 2b09f4054f5aacdd5fd42d1f5fe38eeea9b5f6b8 Mon Sep 17 00:00:00 2001 From: abijah Date: Fri, 31 Jul 2009 17:15:17 +0000 Subject: [PATCH] Added some comments, and changed the nsf action to redirect to viewing the tender after creation. git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@453 97e9348a-65ac-dc4b-aefc-98561f571b83 --- controllers/tenders_controller.php | 8 ++---- models/tender.php | 45 ++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/controllers/tenders_controller.php b/controllers/tenders_controller.php index 2509f8b..db104a6 100644 --- a/controllers/tenders_controller.php +++ b/controllers/tenders_controller.php @@ -120,12 +120,8 @@ class TendersController extends AppController { $this->redirect(array('action'=>'index')); } - // REVISIT : 20090713 - // For testing purposes, must be deleted - $stamp = '2009-07-09'; - $stamp = null; - - $this->Tender->nsf($id, $stamp); + $this->Tender->nsf($id); + $this->redirect(array('action'=>'view', $id)); } /************************************************************************** diff --git a/models/tender.php b/models/tender.php index 085753f..4f5978a 100644 --- a/models/tender.php +++ b/models/tender.php @@ -103,7 +103,7 @@ class Tender extends AppModel { */ function nsf($id, $stamp = null) { - $this->prFunctionLevel(30); + //$this->prFunctionLevel(30); $this->prEnter(compact('id')); // Get information about this NSF item. @@ -125,7 +125,10 @@ class Tender extends AppModel { die("Item has not been deposited yet"); // Enter the NSF - $result = $this->DepositTransaction->addDeposit + // This is the transaction pulling money from the bank account + // and recording it in the NSF account. It has nothing to do + // with the customer statement (charges, payments, credits, etc). + $nsf_result = $this->DepositTransaction->addDeposit (array('Transaction' => array(), 'Entry' => array(array('tender_id' => null, 'account_id' => $this->LedgerEntry->Account->nsfAccountID(), @@ -134,17 +137,18 @@ class Tender extends AppModel { $tender['DepositTransaction']['account_id']); $this->pr(20, compact('result')); - if ($result['error']) + if ($nsf_result['error']) die("Unable to save NSF transaction"); - $this->id = $id; - $this->saveField('nsf_transaction_id', $result['transaction_id']); - - + // Since we may have saved the nsf transaction with a null + // timestamp, query it back out of the database to find out + // what timestamp was _really_ specified, for later use. $nsf_deposit = $this->DepositTransaction->find - ('first', array('contain' => false, 'id' => $result['transaction_id'])); + ('first', array('contain' => false, 'id' => $nsf_result['transaction_id'])); $nsf_deposit = $nsf_deposit['DepositTransaction']; - + + // OK, now move into customer realm, finding all statement + // entries that were affected by the bad payment (tender). $nsf_ledger_entry = $this->LedgerEntry->find ('first', array ('contain' => array('Transaction' => @@ -159,6 +163,7 @@ class Tender extends AppModel { $this->pr(20, compact('nsf_ledger_entry')); + // Build a transaction to adjust all of the statement entries $bounce = array('Transaction' => array(), 'Entry' => array()); $bounce['Transaction']['stamp'] = $nsf_deposit['stamp']; @@ -185,12 +190,30 @@ class Tender extends AppModel { } } + // Record the transaction, which will un-pay previously paid + // charges, void any credits, and other similar work. $this->pr(20, compact('bounce')); - $result = $this->NsfTransaction->addNsf($bounce); + $bounce_result = $this->NsfTransaction->addNsf($bounce); - if ($result['error']) + if ($bounce_result['error']) die("Unable to save Bounce transaction"); + + // Flag the tender as NSF, using the transaction created above. + // REVISIT : 20090730 + // For symmetry, it seems like we should be using the nsf_result. + // Thus the tender's deposit_transaction_id would record how the + // money got into the bank account, and the nsf_transaction_id + // would record how the money was taken back out. However, that + // transaction is just not very useful. So, either we ignore + // the fact that the nsf_result is not useful to the user, we + // use the bounce_result instead, or we modify the tender view + // page to reference the bounce_result, and still use nsf_result + // for our nsf_transaction_id. + $this->id = $id; + $this->saveField('nsf_transaction_id', $nsf_result['transaction_id']); + + // Add NSF Charge $result = $this->NsfTransaction->addInvoice (array('Transaction' =>