Just updated the comments, and added e2a and e1 into the query. No functional change yet.

git-svn-id: file:///svn-source/pmgr/branches/invoice_receipt_20090629@330 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-07-14 21:44:19 +00:00
parent 60f43efdb7
commit 1d8ef76efa

View File

@@ -26,16 +26,16 @@ class MonetarySource extends AppModel {
* *
* FEE RENT A/R RECEIPT CHECK NSF BANK * FEE RENT A/R RECEIPT CHECK NSF BANK
* ------- ------- ------- ------- ------- ------- ------- * ------- ------- ------- ------- ------- ------- -------
* | |50 50| | | | | t1 * | |50 50| | | | | e1
* | | | | | | | * | | | | | | |
* | | |50 50| | | | t2a * | | |50 50| | | | e2a
* | | | |50 50| | | t2b * | | | |50 50| | | e2b
* | | | | | | | * | | | | | | |
* | | | | |50 | 50| t3 * | | | | |50 | 50| e3
* | | | | | | | * | | | | | | |
* | | | | | 50| |50 t4a * | | | | | 50| |50 e4
* | | 50| | | |50 | t4b * | | 50| | | |50 | e5a
* |35 | 35| | | | | t4b * |35 | 35| | | | | e5b
* - NOTE * - NOTE
* The above example is great, except it leave no way to resolve * The above example is great, except it leave no way to resolve
@@ -43,17 +43,17 @@ class MonetarySource extends AppModel {
* perhaps we need to run a negative credit to A/R, which we can * perhaps we need to run a negative credit to A/R, which we can
* use to reconcile against the Rent<->A/R double entry: * use to reconcile against the Rent<->A/R double entry:
* *
* | | | | | 50| |50 t4a * | | | | | 50| |50 e4
* | | |-50 | | -50| | t4b * | | |-50 | | -50| | e5a
* |35 | 35| | | | | t4b * |35 | 35| | | | | e5b
* OR perhaps even a negative entry all the way through to the * OR perhaps even a negative entry all the way through to the
* bank, making the NSF appear not as a withdrawal, but as a * bank, making the NSF appear not as a withdrawal, but as a
* negative deposit (i.e, and adjustment, just like it really is): * negative deposit (i.e, and adjustment, just like it really is):
* *
* | | | | | |-50 -50| t4a * | | | | | |-50 -50| e4
* | | |-50 | | -50| | t4b * | | |-50 | | -50| | e5a
* |35 | 35| | | | | t4b * |35 | 35| | | | | e5b
* *
*/ */
@@ -67,17 +67,18 @@ class MonetarySource extends AppModel {
$source = $this->find $source = $this->find
('first', ('first',
array('contain' => array('contain' =>
array(/* t2b */ array(/* e2b */
'LedgerEntry' => 'LedgerEntry' =>
array('Transaction.id', array('Transaction.id',
'MonetarySource.id', 'MonetarySource.id',
'Customer.id', 'Customer.id',
'Lease.id', 'Lease.id',
/* e.g. CHECK */ /* e2b debit */
'DebitLedger' => 'DebitLedger' => /* e.g. CHECK Ledger */
array('fields' => array(), array('fields' => array(),
'Account' =>
'Account' => /* e.g. CHECK Account */
array('fields' => array('id', 'name'), array('fields' => array('id', 'name'),
'conditions' => 'conditions' =>
/* array(array('Account.payable' => 1), */ /* array(array('Account.payable' => 1), */
@@ -87,22 +88,50 @@ class MonetarySource extends AppModel {
), ),
), ),
/* e.g. RECEIPT */ /* e2b credit */
'CreditLedger' => 'CreditLedger' => /* i.e. RECEIPT Ledger */
array('fields' => array('id'), array('fields' => array('id'),
'Account' => 'Account' => /* i.e. RECEIPT Account */
array('fields' => array('id', 'name'), array('fields' => array('id', 'name'),
'conditions' => 'conditions' =>
array('Account.id' => $A->receiptAccountID()), array('Account.id' => $A->receiptAccountID()),
), ),
), ),
/* t3 */ /* e2a */
'DebitReconciliationLedgerEntry' =>
array(/* e2a credit */
'CreditLedger' => /* i.e. A/R Ledger */
array('fields' => array(),
'Account' => /* i.e. A/R Account */
array('fields' => array(),
'conditions' =>
array('Account.id' => $A->accountReceivableAccountID()),
),
),
/* e1 */
'DebitReconciliationLedgerEntry' =>
array(/* e1 credit */
'CreditLedger' => /* e.g. Rent Ledger */
array('fields' => array(),
'Account' => /* e.g. Rent Account */
array('fields' => array(),
'conditions' =>
array('Account.id' => $A->accountReceivableAccountID()),
),
),
),
),
/* e3 */
'CreditReconciliationLedgerEntry' => 'CreditReconciliationLedgerEntry' =>
array(/* e.g. BANK */ array(/* e3 debit */
'DebitLedger' => 'DebitLedger' => /* e.g. BANK Ledger */
array('fields' => array('id'), array('fields' => array('id'),
'Account' => 'Account' => /* e.g. BANK Account */
array('fields' => array('id', 'name'), array('fields' => array('id', 'name'),
'conditions' => 'conditions' =>
array('Account.depositable' => 1), array('Account.depositable' => 1),
@@ -127,19 +156,24 @@ class MonetarySource extends AppModel {
$nsf_rec_ids = array(); $nsf_rec_ids = array();
$transaction_id = null; $transaction_id = null;
// FOR EACH e2b
foreach ($source['LedgerEntry'] AS $entry) { foreach ($source['LedgerEntry'] AS $entry) {
// Count number of e3 entries
if (count($entry['CreditReconciliationLedgerEntry']) < 1) if (count($entry['CreditReconciliationLedgerEntry']) < 1)
continue; continue;
if (count($entry['CreditReconciliationLedgerEntry']) > 1) if (count($entry['CreditReconciliationLedgerEntry']) > 1)
die('Too many CRLEs'); die('Too many CRLEs');
// e2b amount
$amount = $entry['amount']; $amount = $entry['amount'];
// e3 account
$bank_account_id = $entry['CreditReconciliationLedgerEntry'][0]['DebitLedger']['account_id']; $bank_account_id = $entry['CreditReconciliationLedgerEntry'][0]['DebitLedger']['account_id'];
pr(array('checkpoint' => 'outerloop', pr(array('checkpoint' => 'outerloop',
compact('id', $amount, 'bank_account_id', $entry))); compact('id', $amount, 'bank_account_id', $entry)));
// post new e4
$ids = $A->postLedgerEntry $ids = $A->postLedgerEntry
(array('transaction_id' => $transaction_id), (array('transaction_id' => $transaction_id),
null, null,
@@ -173,6 +207,7 @@ class MonetarySource extends AppModel {
$lease_id = $source['LedgerEntry'][0]['lease_id']; $lease_id = $source['LedgerEntry'][0]['lease_id'];
$customer_id = $source['LedgerEntry'][0]['customer_id']; $customer_id = $source['LedgerEntry'][0]['customer_id'];
// post new e5a
$ids = $A->postLedgerEntry $ids = $A->postLedgerEntry
(null, (null,
null, null,
@@ -195,6 +230,7 @@ class MonetarySource extends AppModel {
$tid = $ids['transaction_id']; $tid = $ids['transaction_id'];
// post new e5b
$ids = $A->postLedgerEntry $ids = $A->postLedgerEntry
(array('transaction_id' => $tid), (array('transaction_id' => $tid),
null, null,