diff --git a/site/models/account.php b/site/models/account.php index add07bf..9538803 100644 --- a/site/models/account.php +++ b/site/models/account.php @@ -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; + } + + /************************************************************************** ************************************************************************** **************************************************************************