<?
	$this->title = 'Dashboard';
	$this->titleicon = 'dashboard';
	$this->titleLink = '/';
	
	$this->title2 = 'Marketing events';
	$this->title2icon = 'bullhorn';

	$data = $this->data;

?>
<div class="container-fluid padded">
	<div class="row-fluid">
		<div class="span12">
			<div class="box">
				<div class="box-header">
					<span class="title">Marketing events</span>
				</div>
				<div class="box-content padded">
				
				<table cellpadding="0" cellspacing="0" border="0" class="table table-normal">
					<tr>
						<th rowspan="2" style="text-align:center !important;vertical-align:middle !important;">Group</th>
						<th rowspan="2" style="text-align:center !important;vertical-align:middle !important;">Date</th>
						<th rowspan="2" style="text-align:center !important;vertical-align:middle !important;">Range</th>
						<th rowspan="2" style="text-align:center !important;vertical-align:middle !important;">Community</th>
						<th rowspan="2" style="text-align:center !important;vertical-align:middle !important;">Promotion Type</th>
						
						<th colspan="4" style="text-align:center !important;vertical-align:middle !important;border-right:1px solid #eaebef;border-left:1px solid #eaebef;">Gift cards</th>
						<th style="text-align:center !important;vertical-align:middle !important;border-right:1px solid #eaebef;">Users</th>
						<th style="text-align:center !important;vertical-align:middle !important;border-right:1px solid #eaebef;">Active users</th>
						<th style="text-align:center !important;vertical-align:middle !important;">Man/Hour</th>
						<th colspan="2" style="text-align:center !important;vertical-align:middle !important;border-right:1px solid #eaebef;border-left:1px solid #eaebef;">Orders</th>
						<th rowspan="2" style="text-align:center !important;vertical-align:middle !important;border-left:1px solid #eaebef;" class="hightlight">CAC</th>
					</tr>
					<tr>
						<th>Total</th>
						<th>Used</th>
						<th class="hightlight">Used %</th>
						<th style="border-right:1px solid #eaebef;">Redeemed</th>
						<th style="border-right:1px solid #eaebef;">New Users</th>
						<th style="border-right:1px solid #eaebef;">30 days</th>
						<th>Hours</th>
						<th style="border-left:1px solid #eaebef;">Total Orders</th>
						<th>Orders per New User</th>
					</tr>
				<?php 
				foreach ( $data as $group ) {
?>
					<tr>
						<td><?php echo $group[ 'name' ]; ?></td>
						<td><?php echo $group[ 'date' ]; ?></td>
						<td><?php echo $group[ 'report' ][ 'range' ]; ?></td>
						<td><?php echo $group[ 'community' ]; ?></td>
						<td><?php echo $group[ 'promotion_type' ]; ?></td>
						
						<td><?php echo $group[ 'report' ][ 'giftcards' ][ 'total' ]; ?></td>
						<td><?php echo $group[ 'report' ][ 'giftcards' ][ 'used' ]; ?></td>
						<td class="hightlight"><?php echo number_format( $group[ 'report' ][ 'giftcards' ][ 'used_percent' ], 2 ); ?>%</td>
						<td><?php echo $group[ 'report' ][ 'giftcards' ][ 'redeemed' ]; ?></td>

						<td><?php echo $group[ 'report' ][ 'users' ][ 'new' ]; ?></td>

						<td><?php echo $group[ 'report' ][ 'users' ][ 'active' ][ '30' ]; ?></td>
						<td><?php echo $group[ 'man_hours' ]; ?></td>
						<td><?php echo $group[ 'report' ][ 'orders' ][ 'total' ]; ?></td>
						<td><?php echo number_format( $group[ 'report' ][ 'orders' ][ 'per_new_users' ] , 3 ); ?></td>
						<td class="hightlight">
							<?php 
							if( $group[ 'man_hours' ] > 0 && $group[ 'report' ][ 'users' ][ 'new' ] > 0 ) { 
								// ( Man-Hours x $15 + Total x $0.10 ) / New Users
								$result = ( ( ( $group[ 'man_hours' ] * 15 ) + ( $group[ 'report' ][ 'giftcards' ][ 'total' ] * 0.10 ) ) / $group[ 'report' ][ 'users' ][ 'new' ] );
								echo number_format( $result , 2 );
							} else {
								echo '0';
							}
							?>
						</td>
					</tr>
				<?php
				}
				?>
					
				</table>
				</div>
			</div>
		</div>
	</div>
</div>
<style type="text/css">
	.hightlight{
		background: #ffefc6;
	}
</style>