Added effective date to each NSF entry, and fixed the account bug with receipts/payments. There is still a bug/question on how to handle nsf credits. It would be nice to simply delete the credit, since the check bounced, but then the original transaction will not add up. Either we decide that it doesn't need to add up, figure out a different type for the credit, or add a void flag to each statement entry and just void out nsf items. Or instead of a void flag, have an nsf_statement_entry_id which will also tie the payment/credit to the nsf payment/credit.
git-svn-id: file:///svn-source/pmgr/branches/yafr_20090716/site@428 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -145,6 +145,10 @@ class Tender extends AppModel {
|
||||
$this->saveField('nsf_transaction_id', $result['transaction_id']);
|
||||
|
||||
|
||||
$nsf_deposit = $this->DepositTransaction->find
|
||||
('first', array('contain' => false, 'id' => $result['transaction_id']));
|
||||
$nsf_deposit = $nsf_deposit['DepositTransaction'];
|
||||
|
||||
$nsf_ledger_entry = $this->LedgerEntry->find
|
||||
('first', array
|
||||
('contain' => array('Transaction' =>
|
||||
@@ -159,22 +163,22 @@ class Tender extends AppModel {
|
||||
|
||||
pr(compact('nsf_ledger_entry'));
|
||||
|
||||
$bounce = array('Transaction' => array(),
|
||||
'Entry' => array());
|
||||
$bounce = array('Transaction' => array(), 'Entry' => array());
|
||||
|
||||
$bounce['Transaction']['stamp'] = $nsf_deposit['stamp'];
|
||||
$bounce['Transaction']['account_id'] = $this->LedgerEntry->Account->nsfAccountID();
|
||||
$bounce['Transaction']['customer_id'] = $tender['Tender']['customer_id'];
|
||||
$bounce['Transaction']['amount'] = -1 * $tender['LedgerEntry']['amount'];
|
||||
$bounce['Transaction']['amount'] = -1 * $tender['LedgerEntry']['amount'];
|
||||
|
||||
foreach ($nsf_ledger_entry['Transaction']['StatementEntry'] AS $payment) {
|
||||
$bounce['Entry'][] =
|
||||
array('type' => 'PAYMENT',
|
||||
array('type' => $payment['type'],
|
||||
'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 ],
|
||||
'effective_date' => $nsf_deposit['stamp'],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -184,143 +188,10 @@ class Tender extends AppModel {
|
||||
if ($result['error'])
|
||||
die("Unable to save Bounce transaction");
|
||||
|
||||
die();
|
||||
// REVISIT <AP>: 20090730
|
||||
// Add NSF Charge
|
||||
|
||||
$nsf_account_id = $A->nsfAccountID();
|
||||
$nsf_fee_account_id = $A->nsfChargeAccountID();
|
||||
$ar_account_id = $A->accountReceivableAccountID();
|
||||
$receipt_account_id = $A->receiptAccountID();
|
||||
|
||||
$t4_id = null;
|
||||
$t5_id = null;
|
||||
foreach ($source['LedgerEntry'] AS $e3) {
|
||||
// We expect only a single e4 entry
|
||||
$e4 = $e3['CreditReconciliationLedgerEntry'];
|
||||
if (count($e4) < 1)
|
||||
continue;
|
||||
if (count($e4) > 1)
|
||||
die('Too many e4 entries');
|
||||
|
||||
// Pullup e4 from the single member array
|
||||
$e4 = $e4[0];
|
||||
|
||||
// e3 amount
|
||||
$amount = -$e3['amount'];
|
||||
|
||||
// e4 account
|
||||
$bank_account_id = $e4['DebitLedger']['account_id'];
|
||||
|
||||
// post new e5
|
||||
$e5_ids = $A->postLedgerEntry
|
||||
(array('transaction_id' => $t4_id),
|
||||
null,
|
||||
array('debit_ledger_id' => $A->currentLedgerID($bank_account_id),
|
||||
'credit_ledger_id' => $A->currentLedgerID($nsf_account_id),
|
||||
'effective_date' => $stamp,
|
||||
'amount' => $amount,
|
||||
'lease_id' => $e3['lease_id'],
|
||||
'customer_id' => $e3['customer_id'],
|
||||
'comment' => "NSF Bank Reversal; Monetary Source #{$id}",
|
||||
)
|
||||
);
|
||||
|
||||
if ($e5_ids['error'])
|
||||
return null;
|
||||
$t4_id = $e5_ids['transaction_id'];
|
||||
|
||||
pr(array('checkpoint' => 'Posted Ledger Entry e5',
|
||||
compact('e5_ids', 'amount')));
|
||||
|
||||
// post new e6... this will be our crossover point
|
||||
// from typical positive entries to negative entries.
|
||||
// Therefore, no reconciliation on this account.
|
||||
$e6_ids = $A->postLedgerEntry
|
||||
(array('transaction_id' => $t5_id),
|
||||
array('monetary_source_id' => $e3['monetary_source_id']),
|
||||
array('debit_ledger_id' => $A->currentLedgerID($nsf_account_id),
|
||||
'credit_ledger_id' => $A->currentLedgerID($receipt_account_id),
|
||||
'effective_date' => $stamp,
|
||||
'amount' => $amount,
|
||||
'lease_id' => $e3['lease_id'],
|
||||
'customer_id' => $e3['customer_id'],
|
||||
'comment' => "NSF tracker; Monetary Source #{$id}",
|
||||
),
|
||||
array('debit' => array
|
||||
(array('LedgerEntry' =>
|
||||
array('id' => $e5_ids['id'],
|
||||
'amount' => $amount))),
|
||||
)
|
||||
);
|
||||
|
||||
if ($e6_ids['error'])
|
||||
return null;
|
||||
$t5_id = $e6_ids['transaction_id'];
|
||||
|
||||
pr(array('checkpoint' => 'Posted Ledger Entry e6',
|
||||
compact('e6_ids', 'amount')));
|
||||
|
||||
$t6_id = null;
|
||||
foreach ($e3['DebitReconciliationLedgerEntry'] AS $e2) {
|
||||
foreach ($e2['DebitReconciliationLedgerEntry2'] AS $e1) {
|
||||
$amount = -1*$e1['Reconciliation']['amount'];
|
||||
|
||||
// post new e7
|
||||
$e7_ids = $A->postLedgerEntry
|
||||
(array('transaction_id' => $t6_id),
|
||||
null,
|
||||
array('debit_ledger_id' => $A->currentLedgerID($receipt_account_id),
|
||||
'credit_ledger_id' => $A->currentLedgerID($ar_account_id),
|
||||
'effective_date' => $stamp,
|
||||
'amount' => $amount,
|
||||
'lease_id' => $e1['lease_id'],
|
||||
'customer_id' => $e1['customer_id'],
|
||||
'comment' => "NSF Receipt; Monetary Source #{$id}",
|
||||
),
|
||||
array('debit' => array
|
||||
(array('LedgerEntry' =>
|
||||
array('id' => $e6_ids['id'],
|
||||
'amount' => $amount))),
|
||||
|
||||
'credit' => array
|
||||
(array('LedgerEntry' =>
|
||||
array('id' => $e1['id'],
|
||||
'amount' => $amount))),
|
||||
)
|
||||
);
|
||||
|
||||
if ($e7_ids['error'])
|
||||
return null;
|
||||
$t6_id = $e7_ids['transaction_id'];
|
||||
|
||||
pr(array('checkpoint' => 'Posted Ledger Entry e7',
|
||||
compact('e7_ids', 'amount')));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Cheat for now
|
||||
$customer_id = $source['LedgerEntry'][0]['customer_id'];
|
||||
$lease_id = null;
|
||||
|
||||
// post new e8
|
||||
$e8_ids = $A->postLedgerEntry
|
||||
(array('transaction_id' => $t6_id),
|
||||
null,
|
||||
array('debit_ledger_id' => $A->currentLedgerID($ar_account_id),
|
||||
'credit_ledger_id' => $A->currentLedgerID($nsf_fee_account_id),
|
||||
'effective_date' => $stamp,
|
||||
'amount' => 35,
|
||||
'lease_id' => $lease_id,
|
||||
'customer_id' => $customer_id,
|
||||
'comment' => "NSF Fee; Monetary Source #{$id}",
|
||||
)
|
||||
);
|
||||
|
||||
if ($e8_ids['error'])
|
||||
return null;
|
||||
|
||||
pr(array('checkpoint' => 'Posted Ledger Entry e8',
|
||||
compact('e8_ids')));
|
||||
/* $nsf_fee_account_id = $A->nsfChargeAccountID(); */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user