diff --git a/views/elements/ledger.ctp b/views/elements/ledger.ctp index 3e16b9a..7e7cf04 100644 --- a/views/elements/ledger.ctp +++ b/views/elements/ledger.ctp @@ -201,58 +201,51 @@ if (isset($ledger['receipts'])) { if (isset($ledger['mix'])) { $headers = array(/*'Charge/Receipt'*/'ID', 'Date', /*'Through',*/ 'Type', 'Comment', 'Amount', 'Total'); - $receipts = array(); - foreach ($lease['Charge'] AS $charge) { - foreach($charge['Receipt'] AS $receipt) { - if (!isset($receipts[$receipt['id']])) { - $receipts[$receipt['id']] = $receipt; - $receipts[$receipt['id']]['amount'] = 0; - unset($receipts[$receipt['id']]['ChargesReceipt']); - unset($receipts[$receipt['id']]['Payment']); - } - $receipts[$receipt['id']]['amount'] += $receipt['ChargesReceipt']['amount']; - } - } - - $mix = array_merge($lease['Charge'], $receipts); - usort($mix, - create_function('$a, $b', - '$adate = TimeHelper::toUnix(isset($a["charge_date"]) ? $a["charge_date"] : $a["stamp"]); ' . - '$bdate = TimeHelper::toUnix(isset($b["charge_date"]) ? $b["charge_date"] : $b["stamp"]); ' . - 'return strcmp($adate, $bdate);') - ); +/* $mix = array_merge($lease['Charge'], $receipts); */ +/* usort($mix, */ +/* create_function('$a, $b', */ +/* '$adate = TimeHelper::toUnix(isset($a["charge_date"]) ? $a["charge_date"] : $a["stamp"]); ' . */ +/* '$bdate = TimeHelper::toUnix(isset($b["charge_date"]) ? $b["charge_date"] : $b["stamp"]); ' . */ +/* 'return strcmp($adate, $bdate);') */ +/* ); */ $rows = array(); $row_class = array(); $running_total = 0; - foreach ($mix AS $row) { - if (isset($row['charge_date'])) { - $controller = 'charges'; - $class = 'charge'; - $rowdate = datefmt($row['charge_date']) .' - '. datefmt($row['charge_to_date']); - $name = $row['ChargeType']['name']; - $amount = $row['total']; - } - else { - $controller = 'receipts'; - $class = 'receipt'; - $rowdate = ' -- ' . datefmt($row['stamp']); - $name = 'Payment Applied'; - $amount = -1 * $row['amount']; - } + foreach ($transactions AS $transaction) { + $transaction_date = datefmt($transaction['stamp']); + if (isset($transaction['through_date'])) + $transaction_date .= ' - '. datefmt($transaction['through_date']); - $running_total += $amount; - $rows[] = array($html->link('#'.$row['id'], - array('controller' => $controller, - 'action' => 'view', - $row['id'])), - $rowdate, - $name, - $row['comment'], - currency($amount), - currency($running_total)); - $row_class[] = $class; + $comment = $transaction['comment']; + + foreach ($transaction['Entry'] AS $entry) { + if ($entry['DebitAccount']['name'] === 'A/R') { + $name = $entry['CreditAccount']['name']; + $amount = $entry['amount']; + $class = 'charge'; + } + elseif ($entry['CreditAccount']['name'] === 'A/R') { + $name = 'Payment'; + $amount = -1 * $entry['amount']; + $class = 'payment'; + } + else + continue; + + $running_total += $amount; + $rows[] = array($html->link('#'.$transaction['id'], + array('controller' => 'transactions', + 'action' => 'view', + $transaction['id'])), + $transaction_date, + $name, + $comment, + currency($amount), + currency($running_total)); + $row_class[] = $class; + } } echo ('