Preliminary work on NSF. It's far from working, but we're headed in the right direction.

git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@426 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-30 06:29:41 +00:00
parent 3e715bae9f
commit 7450d2a98e
3 changed files with 226 additions and 16 deletions

View File

@@ -87,8 +87,8 @@ class Tender extends AppModel {
*
* Steps:
* - Get information from Check (C1); for amount $A
* - New Transaction (T1)
* - Find Bank Deposit matching to Tender
* - New Transaction (T1)
* - New Bank Deposit (D1)
* - New Tender (N1); NSF; D1,
* - Add new LedgerEntry (L1a); T1; debit:bank; -$A
@@ -121,7 +121,68 @@ class Tender extends AppModel {
));
//'conditions' => array(array('Tender.id' => $id)),
pr($tender);
return;
if (!empty($tender['NsfTransaction']['id']))
die("Item has already been set as NSF");
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'), */
/* )); */
$nsf_ledger_entry = $this->LedgerEntry->find
('first', array
('contain' => array('Transaction' =>
array(//'fields' => array(),
'StatementEntry' =>
array(//'fields' => array(),
),
),
),
'conditions' => array('LedgerEntry.id' => $tender['LedgerEntry']['id']),
));
pr(compact('nsf_ledger_entry'));
$bounce = array('Transaction' => array(),
'Entry' => array());
$bounce['Transaction']['account_id'] = $tender['DepositTransaction']['account_id'];
$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'],
//'effective_date' => $tender[ stamp ],
);
}
pr(compact('bounce'));
$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();
$nsf_account_id = $A->nsfAccountID();
$nsf_fee_account_id = $A->nsfChargeAccountID();