Fairly decent first pass at determining which ledger entries have not yet been reconciled for an account. I'm using the current ledger only, which I'm sure is not what we want. Since it works though, it's worth checking in.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605@158 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -195,6 +195,63 @@ class Account extends AppModel {
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findUnreconciledLedgerEntries
|
||||
* - Returns summary data from the requested account.
|
||||
*/
|
||||
|
||||
function findUnreconciledLedgerEntries($id = null) {
|
||||
// Look in the Current Ledger only (for now)
|
||||
$unreconciled['debits'] = $this->find
|
||||
('all', array
|
||||
('link' => array
|
||||
('CurrentLedger' => array
|
||||
('fields' => array(),
|
||||
'DebitLedgerEntry' => array
|
||||
('fields' => array('id', 'amount'),
|
||||
'DebitReconciliationLedgerEntry' => array
|
||||
('fields' => array('COALESCE(SUM(Reconciliation.amount),0) AS "reconciled"',
|
||||
'DebitLedgerEntry.amount - COALESCE(SUM(Reconciliation.amount),0) AS "balance"',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'group' => ('DebitLedgerEntry.id' .
|
||||
' HAVING DebitLedgerEntry.amount' .
|
||||
' <> COALESCE(SUM(Reconciliation.amount),0)'),
|
||||
'conditions' => array('Account.id' => $id),
|
||||
'fields' => array(),
|
||||
));
|
||||
|
||||
$unreconciled['credits'] = $this->find
|
||||
('all', array
|
||||
('link' => array
|
||||
('CurrentLedger' => array
|
||||
('fields' => array(),
|
||||
'CreditLedgerEntry' => array
|
||||
('fields' => array('id', 'amount'),
|
||||
'CreditReconciliationLedgerEntry' => array
|
||||
('fields' => array('COALESCE(SUM(Reconciliation.amount),0) AS "reconciled"',
|
||||
'CreditLedgerEntry.amount - COALESCE(SUM(Reconciliation.amount),0) AS "balance"',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'group' => ('CreditLedgerEntry.id' .
|
||||
' HAVING CreditLedgerEntry.amount' .
|
||||
' <> COALESCE(SUM(Reconciliation.amount),0)'),
|
||||
'conditions' => array('Account.id' => $id),
|
||||
'fields' => array(),
|
||||
));
|
||||
|
||||
return $unreconciled;
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user