<div class="span5">
	<fieldset>
		<legend>Service Information</legend>

		<div class="dl-horizontal">
			<dt>Account</dt>
			<dd><?php printf('%s (%s)',$o->account->name(),$o->account->accnum()); ?></dd>

			<?php if ($o->external_billing) : ?>
				<dt>External Billed</dt>
				<dd><?php echo $o->display('external_billing'); ?></dd>
 
			<?php else : ?>
				<dt>Service Active</dt>
				<dd><?php echo $o->display('status'); ?></dd>

				<dt>Billing Period</dt>
				<dd><?php echo $o->display('recur_schedule');?></dd>

				<dt>Cost</dt>
				<dd><?php echo (! is_null($o->price_override) ? sprintf('<strike>%s</strike> ',$o->price(TRUE,TRUE,TRUE)) : ''). $o->price(TRUE,TRUE); if ($o->pending_change()) echo ' *'; ?></dd>

<!-- @todo -->
				<?php if (is_null($o->price) OR ($o->price<=$o->product->price($o->price_group,$o->recur_schedule,'base'))) : ?>
					<dt>Service</dt>
					<dd><?php echo HTML::anchor('product/view/'.$o->product_id,$o->product->title()); ?></dd>
				<?php endif ?>

				<dt>Invoiced To</dt>
				<dd><?php echo $o->invoiced_to(TRUE); ?></dd>

				<dt>Paid To</dt>
				<dd><?php echo $o->paid_to(TRUE); ?></dd>

				<dt>Date Next Invoice</dt>
				<dd><?php printf($o->suspend_billing ? '<strike>%s</strike>' : '%s',$o->display('date_next_invoice')); ?></dd>

				<dt>Current Invoices Due</dt>
				<dd><?php echo $o->due(TRUE); ?></dd>
			<?php endif ?>
		</div> <!-- /dl-horizontal -->
	</fieldset>

	<?php echo $o->product->feature_summary(); ?>
</div> <!-- /span -->

<div class="span5">
	<?php echo $o->service_view(); ?>
</div> <!-- /span -->

<?php if ($o->service_billing->loaded()) : ?>
	<div class="span5">
		<fieldset>
			<legend>Automatic Payment Details</legend>

			<div class="dl-horizontal">
				<dt>Direct Payment</dt>
				<dd><?php echo $o->service_billing->checkout->display('name'); ?></dd>
			</div> <!-- /dl-horizontal -->
		</fieldset>
	</div> <!-- /span -->
<?php endif ?>

<?php if ($o->charges()) : ?>
	<div class="span5">
		<fieldset>
			<legend>Service Charges to Bill: <?php echo $o->charges(TRUE,TRUE); ?></legend>

			<?php echo Table::factory()
				->data($o->charge_list(TRUE))
				->columns(array(
					'date_orig'=>'Date',
					'description'=>'Description',
					'total(TRUE)'=>'Amount',
				)); ?>
		</fieldset>
	</div> <!-- /span -->
<?php endif ?>

<?php if ($o->status AND ! $o->external_billing) : ?>
	<div class="span5">
		<fieldset>
			<legend>Next Invoice Charges</legend>

			<?php echo Invoice::instance()->add_service($o)->render('html','body',array('noid'=>TRUE)); ?>
		</fieldset>
	</div> <!-- /span -->
<?php endif ?>

<div class="span5">
	<fieldset>
		<legend>Invoices for this Service</legend>

		<?php echo Table::factory()
			->data($o->invoice_list())
			->columns(array(
				'id'=>'ID',
				'void'=>'Void',
				'date_orig'=>'Date',
				'due_date'=>'Due',
				'total(TRUE)'=>'Amount',
				'due(TRUE)'=>'Due',
			))
			->prepend(array(
				'id'=>array('url'=>URL::link('user','invoice/view/')),
			)); ?>
	</fieldset>
</div> <!-- /span -->

<?php $x=$o->service_memo->find_all(); if ($x->count()) : ?>
	<div class="span5">
		<fieldset>
			<legend>Service Memos</legend>

			<?php echo Table::factory()
				->data($x)
				->columns(array(
					'id'=>'ID',
					'date_orig'=>'Date',
					'account->name()'=>'Account',
					'memo'=>'Memo',
				)); ?>
		</fieldset>
	</div> <!-- /span -->
<?php endif ?>

<?php $x=$o->email()->find_all(); if ($x->count()) : ?>
	<div class="span5">
		<fieldset>
			<legend>Emails about this service</legend>

			<?php echo Table::factory()
				->data($x)
				->columns(array(
					'id'=>'ID',
					'date_orig'=>'Date',
					'resolve("subject")'=>'Subject',
				))
				->prepend(array(
					'id'=>array('url'=>URL::link('user','email/view/')),
				))
				->postproc(array(
					'resolve("subject")'=>array('trim'=>45),
				)); ?>
		</fieldset>
	</div> <!-- /span -->
<?php endif ?>
