<?php $pag = new Pagination(array('total_items'=>count($result))); ?>
<?php echo (string)$pag; ?>

<table class="table table-striped table-condensed table-hover span6" id="list-table">
	<thead><tr>
		<th>Date</th>
		<th>Type</th>
		<th>Amt</th>
		<th>Total</th>
	</tr></thead>

	<tbody>
		<?php $i=0;foreach ($result as $o) :
			$adjust = 0;

			if ($o instanceof Model_Invoice)
				$adjust = $o->total();
			elseif ($o instanceof Model_Payment)
				$adjust = -$o->total();

			$total = Currency::round($total-$adjust);

			if (++$i < $pag->current_first_item())
				continue;
			elseif ($i > $pag->current_last_item())
				break;
		?>

			<tr>
				<?php if ($o instanceof Model_Invoice) : ?>
					<td><?php echo $o->display('date_orig'); ?></td>
					<td><?php echo 'Invoice '.HTML::anchor(URL::link('user','invoice/view/'.$o->id),$o->id()); ?></td>
				<?php elseif ($o instanceof Model_Payment) : ?>
					<?php $adjust = -$o->total(); ?>
					<td><?php echo $o->display('date_payment'); ?></td>
					<td><?php printf('Payment %s (%s)',$o->id,$o->checkout->display('name')); ?></td>
				<?php else : ?>
					<td>-</td>
					<td><?php echo 'Unknown '.$o->id; ?></td>
				<?php endif ?>

				<td class="text-right"><?php echo $o->total(TRUE); ?></td>
				<td class="text-right"><?php echo Currency::display($total+$adjust); ?></td>
			</tr>
		<?php endforeach ?>
	</tbody>
</table>
