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
This commit is contained in:
@@ -120,12 +120,8 @@ class TendersController extends AppController {
|
|||||||
$this->redirect(array('action'=>'index'));
|
$this->redirect(array('action'=>'index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// REVISIT <AP>: 20090713
|
$this->Tender->nsf($id);
|
||||||
// For testing purposes, must be deleted
|
$this->redirect(array('action'=>'view', $id));
|
||||||
$stamp = '2009-07-09';
|
|
||||||
$stamp = null;
|
|
||||||
|
|
||||||
$this->Tender->nsf($id, $stamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class Tender extends AppModel {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function nsf($id, $stamp = null) {
|
function nsf($id, $stamp = null) {
|
||||||
$this->prFunctionLevel(30);
|
//$this->prFunctionLevel(30);
|
||||||
$this->prEnter(compact('id'));
|
$this->prEnter(compact('id'));
|
||||||
|
|
||||||
// Get information about this NSF item.
|
// Get information about this NSF item.
|
||||||
@@ -125,7 +125,10 @@ class Tender extends AppModel {
|
|||||||
die("Item has not been deposited yet");
|
die("Item has not been deposited yet");
|
||||||
|
|
||||||
// Enter the NSF
|
// 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(),
|
(array('Transaction' => array(),
|
||||||
'Entry' => array(array('tender_id' => null,
|
'Entry' => array(array('tender_id' => null,
|
||||||
'account_id' => $this->LedgerEntry->Account->nsfAccountID(),
|
'account_id' => $this->LedgerEntry->Account->nsfAccountID(),
|
||||||
@@ -134,17 +137,18 @@ class Tender extends AppModel {
|
|||||||
$tender['DepositTransaction']['account_id']);
|
$tender['DepositTransaction']['account_id']);
|
||||||
$this->pr(20, compact('result'));
|
$this->pr(20, compact('result'));
|
||||||
|
|
||||||
if ($result['error'])
|
if ($nsf_result['error'])
|
||||||
die("Unable to save NSF transaction");
|
die("Unable to save NSF transaction");
|
||||||
|
|
||||||
$this->id = $id;
|
// Since we may have saved the nsf transaction with a null
|
||||||
$this->saveField('nsf_transaction_id', $result['transaction_id']);
|
// timestamp, query it back out of the database to find out
|
||||||
|
// what timestamp was _really_ specified, for later use.
|
||||||
|
|
||||||
$nsf_deposit = $this->DepositTransaction->find
|
$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'];
|
$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
|
$nsf_ledger_entry = $this->LedgerEntry->find
|
||||||
('first', array
|
('first', array
|
||||||
('contain' => array('Transaction' =>
|
('contain' => array('Transaction' =>
|
||||||
@@ -159,6 +163,7 @@ class Tender extends AppModel {
|
|||||||
|
|
||||||
$this->pr(20, compact('nsf_ledger_entry'));
|
$this->pr(20, compact('nsf_ledger_entry'));
|
||||||
|
|
||||||
|
// Build a transaction to adjust all of the statement entries
|
||||||
$bounce = array('Transaction' => array(), 'Entry' => array());
|
$bounce = array('Transaction' => array(), 'Entry' => array());
|
||||||
|
|
||||||
$bounce['Transaction']['stamp'] = $nsf_deposit['stamp'];
|
$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'));
|
$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");
|
die("Unable to save Bounce transaction");
|
||||||
|
|
||||||
|
|
||||||
|
// Flag the tender as NSF, using the transaction created above.
|
||||||
|
// REVISIT <AP>: 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
|
// Add NSF Charge
|
||||||
$result = $this->NsfTransaction->addInvoice
|
$result = $this->NsfTransaction->addInvoice
|
||||||
(array('Transaction' =>
|
(array('Transaction' =>
|
||||||
|
|||||||
Reference in New Issue
Block a user