Changed the unreconciled transaction list to always include 'debit' or 'credit', even if the user specifically requests one or the other. Handling it as a special case everywhere was bothering me.
git-svn-id: file:///svn-source/pmgr/branches/ledger_transactions_20090605/site@162 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
@@ -262,9 +262,6 @@ class Account extends AppModel {
|
||||
));
|
||||
$balance = 0;
|
||||
foreach ($unreconciled[$fund]['entries'] AS &$entry) {
|
||||
//$balance += $entry[0]['balance'];
|
||||
/* $entry["LedgerEntry"] += $entry[0]; */
|
||||
/* unset($entry[0]); */
|
||||
$entry = array_merge(array_diff_key($entry["LedgerEntry"], array(0=>true)),
|
||||
$entry[0]);
|
||||
$balance += $entry['balance'];
|
||||
@@ -272,10 +269,6 @@ class Account extends AppModel {
|
||||
$unreconciled[$fund]['balance'] = $balance;
|
||||
}
|
||||
|
||||
// pull up to the top level if only one fundamental type
|
||||
if ($fundamental_type)
|
||||
$unreconciled = $unreconciled[$fundamental_type];
|
||||
|
||||
return $unreconciled;
|
||||
}
|
||||
|
||||
@@ -294,37 +287,38 @@ class Account extends AppModel {
|
||||
* whatever algorithm is simplest.
|
||||
*/
|
||||
|
||||
function reconcileNewLedgerEntry($id, $fund, $amount) {
|
||||
function reconcileNewLedgerEntry($id, $fundamental_type, $amount) {
|
||||
$ofund = $this->fundamentalOpposite($fundamental_type);
|
||||
$unreconciled = array($ofund => array('entries'=>array(), 'balance'=>0));
|
||||
$applied = 0;
|
||||
|
||||
// if there is no money in the entry, it can reconcile nothing
|
||||
// don't bother wasting time sifting ledger entries.
|
||||
if ($amount <= 0)
|
||||
return array('unapplied' => 0);
|
||||
if ($amount > 0) {
|
||||
$unreconciled = $this->findUnreconciledLedgerEntries($id, $ofund);
|
||||
|
||||
$fund = $this->fundamentalOpposite($fund);
|
||||
$unreconciled = $this->findUnreconciledLedgerEntries($id, $fund);
|
||||
foreach ($unreconciled[$ofund]['entries'] AS $i => &$entry) {
|
||||
// Determine if amount is sufficient to cover the entry
|
||||
if ($amount > $entry['balance'])
|
||||
$apply = $entry['balance'];
|
||||
elseif ($amount > 0)
|
||||
$apply = $amount;
|
||||
else {
|
||||
unset($unreconciled[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$applied = 0;
|
||||
foreach ($unreconciled['entries'] AS $i => &$entry) {
|
||||
// Determine if amount is sufficient to cover the entry
|
||||
if ($amount > $entry['balance'])
|
||||
$apply = $entry['balance'];
|
||||
elseif ($amount > 0)
|
||||
$apply = $amount;
|
||||
else {
|
||||
unset($unreconciled[$i]);
|
||||
continue;
|
||||
$entry['applied'] = $apply;
|
||||
$entry['reconciled'] += $apply;
|
||||
$entry['balance'] -= $apply;
|
||||
$applied += $apply;
|
||||
$amount -= $apply;
|
||||
}
|
||||
|
||||
$entry['applied'] = $apply;
|
||||
$entry['reconciled'] += $apply;
|
||||
$entry['balance'] -= $apply;
|
||||
$applied += $apply;
|
||||
$amount -= $apply;
|
||||
}
|
||||
|
||||
$unreconciled['unapplied'] = $amount;
|
||||
$unreconciled['applied'] = $applied;
|
||||
$unreconciled['balance'] -= $applied;
|
||||
$unreconciled[$ofund]['unapplied'] = $amount;
|
||||
$unreconciled[$ofund]['applied'] = $applied;
|
||||
$unreconciled[$ofund]['balance'] -= $applied;
|
||||
return $unreconciled;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user