'.__('Ledger',true).''; $headers = array('Transaction', 'Entry', 'Date', 'Customer', 'Comment', 'Debit', 'Credit', 'Total'); $column_class = array(); foreach (array_intersect($headers, array('Transaction', 'Entry')) AS $k => $v) { $column_class[$k] = array($column_class[$k], 'id'); } foreach (array_intersect($headers, array('Debit', 'Credit', 'Total')) AS $k => $v) { $column_class[$k] = array($column_class[$k], 'currency'); } foreach (array_intersect($headers, array('Comment')) AS $k => $v) { $column_class[$k] = 'slack'; } $rows = array(); $running_total = 0; foreach($entries AS $entry) { $transaction = $entry['Transaction']; $customer = $entry['Customer']; $credit = $debit = null; $running_total += $entry['balance']; if (isset($entry['debit'])) $debit = $entry['debit']; if (isset($entry['credit'])) $credit = $entry['credit']; // Now that we've extracted top level 'entry' data // move our variable to the meat of 'LedgerEntry' for clarity $entry = $entry['LedgerEntry']; $rows[] = array($html->link('#'.$transaction['id'], array('controller' => 'transactions', 'action' => 'view', $transaction['id'])), $html->link('#'.$entry['id'], array('controller' => 'ledger_entries', 'action' => 'view', $entry['id'])), FormatHelper::date($transaction['stamp']), $html->link($customer['name'], array('controller' => 'customers', 'action' => 'view', $customer['id'])), FormatHelper::comment(array($transaction['comment'], $entry['comment'])), FormatHelper::currency($debit), FormatHelper::currency($credit), FormatHelper::currency($running_total) ); } echo $this->element('table', array('class' => 'item account ledger list', 'caption' => isset($caption) ? $caption : null, 'headers' => $headers, 'rows' => $rows, 'column_class' => $column_class)); ?>