Very, very messy and broken. It does work somewhat, but I can see just what a mess it's going to be to carry it out, so I'm abandoning.
git-svn-id: file:///svn-source/pmgr/branches/reconcile_entry_to_receipt_20090629@187 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -14,6 +14,14 @@ class Transaction extends AppModel {
|
||||
'LedgerEntry',
|
||||
);
|
||||
|
||||
var $hasAndBelongsToMany = array(
|
||||
'ReconciledLedgerEntry' => array(
|
||||
'className' => 'LedgerEntry',
|
||||
'joinTable' => 'reconciliations',
|
||||
'foreignKey' => 'ledger_entry_id',
|
||||
'associationForeignKey' => 'transaction_id',
|
||||
),
|
||||
);
|
||||
|
||||
function beforeSave() {
|
||||
|
||||
@@ -24,5 +32,40 @@ class Transaction extends AppModel {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**************************************************************************
|
||||
**************************************************************************
|
||||
**************************************************************************
|
||||
* function: findReconciledLedgerEntries
|
||||
* - Returns ledger entries that are reconciled by the given
|
||||
* transaction (such as charges reconciled by a receipt)
|
||||
*/
|
||||
|
||||
function findReconciledLedgerEntries($id = null) {
|
||||
$reconciled['LedgerEntry'] = $this->find
|
||||
('all', array
|
||||
('link' => array
|
||||
('ReconciledLedgerEntry' => array
|
||||
('fields' => array
|
||||
('id',
|
||||
"COALESCE(SUM(Reconciliation.amount),0) AS 'reconciled'",
|
||||
"ReconciledLedgerEntry.amount - COALESCE(SUM(Reconciliation.amount),0) AS 'balance'",
|
||||
),
|
||||
),
|
||||
),
|
||||
'group' => ('ReconciledLedgerEntry.id'),
|
||||
'conditions' => array('Transaction.id' => $id),
|
||||
'fields' => array(),
|
||||
));
|
||||
//pr($reconciled);
|
||||
$balance = 0;
|
||||
foreach ($reconciled['LedgerEntry'] AS &$entry) {
|
||||
$entry = array_merge($entry["ReconciledLedgerEntry"], $entry[0]);
|
||||
$balance += $entry['balance'];
|
||||
}
|
||||
$reconciled['balance'] = $balance;
|
||||
|
||||
return $reconciled;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user