<table class="table table-striped table-condensed table-hover" id="list-table">
	<?php foreach ($o->items_periods() as $rs) : ?>
		<!-- Display our scheduled items first -->
		<?php if (! is_null($rs)) : ?>
				<thead><tr><th colspan="5"><?php echo StaticList_RecurSchedule::get($rs); ?></th></tr></thead>

				<tbody>
					<?php $sids=array(); foreach ($o->items_periods($rs) as $iio) : ?>
						<?php if ($iio->service_id) : ?>
							<!-- So we dont render the same service item over again -->
							<?php if (in_array($iio->service_id,$sids)) continue; array_push($sids,$iio->service_id); ?>
							<tr>
								<th>&nbsp;</th>
								<th colspan="2"><?php echo ($show_id ? HTML::anchor(URL::link('user','service/view/'.$iio->service_id),$iio->service->id()).' ' : '').$iio->title(); ?></th>
								<th>&nbsp;</th>
								<th><div class="text-right"><?php echo $o->service_items_total($iio,TRUE); ?></div></th>
							</tr>

							<?php if ($x=$o->service_items($iio)) : ?>
								<?php foreach ($x as $eiio) : ?>
									<tr>
										<td>&nbsp;</td>
										<td>&nbsp;</td>
										<td><?php echo $eiio->invoice_line().($show_id ? " (<small>{$eiio->trannum()}</small>)" : ''); ?></td>
										<td><div class="text-right"><?php echo $eiio->total(TRUE); ?></div></td>
										<td>&nbsp;</td>
									</tr>
								<?php endforeach ?>
							<?php endif ?>

							<?php if ($x=$o->service_items_extra($iio)) : ?>
								<?php foreach ($x as $eiio) : ?>
									<tr>
										<td colspan="2">&nbsp;</td>
										<td><?php echo $eiio->invoice_line().($show_id ? " (<small>{$eiio->trannum()}</small>)" : ''); ?></td>
										<td><div class="text-right"><?php echo $eiio->total(TRUE); ?></div></td>
										<td>&nbsp;</td>
									</tr>
								<?php endforeach ?>
							<?php endif ?>

						<?php else : ?>
							<tr>
								<th>&nbsp;</th>
								<th colspan="2"><?php echo $iio->title(); ?></th>
								<th>&nbsp;</th>
								<th><div class="text-right"><?php echo $o->service_items_total($iio,TRUE); ?></div></th>
							</tr>

						<?php endif ?>
				<?php endforeach ?>
			</tbody>
		<?php endif ?>
	<?php endforeach ?>

	<!-- Display our other items -->
	<?php if ($x=$o->items_periods(NULL)) : ?>
		<tbody>
			<tr><th colspan="5"><?php echo 'Other Items'; ?></th></tr>

			<?php foreach ($x as $iio) : ?>
				<tr>
					<td>&nbsp;</td>
					<td colspan="3"><?php echo $iio->invoice_line(); ?></td>
					<th><div class="text-right"><?php echo $iio->total(TRUE); ?></div></th>
				</tr>
			<?php endforeach ?>
		</tbody>
	<?php endif ?>
</table>
