<?
	$this->title = 'Orders';
	$this->subtitle = 'people order shit! then eat it!';
	$this->titleicon = 'truck';
	$orders = $this->orders;
	$config = $this->config;
?>
<!-- content -->
<div class="container-fluid padded">
	<div class="row-fluid">
		<div class="box">

			<div class="box-content">
				<div class="row-fluid">
					<div class="span6 separate-sections">
						<ul class="padded separate-sections">
							<li>
								<span class="span3">Last send: </span>
								<span class="span8 pull-right">
									<?php $date = $config->date(); ?>
									<?=$date->format('D, M jS Y, H:i:s (T)');?>
								</span>
							</li>
							<li>
								<span class="span3">Email will be send to: </span>
								<span class="span8 pull-right">
									<?php echo $config->email_to; ?>
								</span>
							</li>
							<?php if( $orders && $orders->count() > 0 ) { ?>
							<li>
								<span class="span3"></span>
								<span class="span8 pull-right">
									<a href="/orders/newusers/sendemail" class="btn btn-small btn-blue">Send email</a>
								</span>
							</li>
							<?php } ?>
						</ul>	
					</div>
				</div>
			</div>
		</div>

		<div class="box">
			<div class="box-header">
				<span class="title">Results</span>
				<ul class="box-toolbar">
					<li><span class="label label-blue"><?php echo $orders->count(); ?></span></li>
				</ul>
			</div>
			<div class="box-content">
				<?php if( $orders && $orders->count() > 0 ) { ?>
					<table class="list-orders table table-normal">
						<thead>
							<tr>
								<td>Order info</td>
								<td>Dishes</td>
								<td>User info</td>
								<td>Payment info</td>
							</tr>
						</thead>
					<?php
					foreach ( $orders as $order ) {
						$user = $order->user();
						$restaurant = $order->restaurant();
						?>
							<tr>
								<td valign="top">
									<?php $date = $order->date();?>
									<?=$date->format('M jS Y')?> <?=$date->format('g:i:s A')?> 
									<br/>
									Restaurant: <?php echo $restaurant->name; ?>
									<br/>
									Delivery:  <?php echo $order->delivery_type; ?>
									<br/>
									Estimated delivery: <?php if( $order->restaurant()->delivery_estimated_time ){ echo $order->restaurant()->delivery_estimated_time . ' min.'; } else { echo '-'; } ?>
									<br/>
									# <?php echo $order->id_order; ?>
								</td>
								<td valign="top">
									<ul>
										<?php foreach ($order->dishes() as $dish) : ?>
										<li>
											<?
												$food = $dish->dish()->name;
												$cartPrice = $dish->dish()->price;
												$options = $dish->options();?>
												<?=$food?>

										</li>
										<? endforeach ; ?>
									</ul>
								</td>
								<td valign="top">
									Name: <?php echo $user->name; ?> 
									<br/>
									Phone: <?php echo $user->phone; ?> 
									<br/>
									<?php if( $user->email ){ ?>
										Email: <?php echo $user->email; ?> 
										<br/>
									<?php } ?>
									Address: <?php echo $order->address; ?>
								</td>
								<td valign="top">
									Type: <?php echo $order->pay_type; ?>
									<br />
									Tip: $<?=$order->tip()?> <?php if( $order->tip_type != Crunchbutton_Order::TIP_NUMBER ) { echo '(' . $order->tip . '%)'; } ?>
									<br />
									Total: $<?=number_format($order->final_price,2)?>
								</td>
							</tr>
						<?
					}
				?>
				</table>
				<?php } ?>
			</div>
		</div>
	</div>
</div>