<STYLE type="text/css">
	.tableTd {
	   	border-width: 0.5pt; 
		border: solid; 
	}
	.tableTdContent{
		border-width: 0.5pt; 
		border: solid;
	}
	#titles{
		font-weight: bolder;
		background-color:#ccc;
	}   
</STYLE>
<h2 class="title"><?php echo __('Summary Report per Depot (From %s to %s)',$d1, $d2) ?></h2>

<?php if($depots): ?>
<table class="tbl-list" cellpadding="0" cellspacing="0" border="1">
	<tr>
		<th>#</th>
		<th><?php echo __('Depot');?></th>
		<th><?php echo __('Brand');?></th>
		<th><?php echo __('Sales Quantity in Cases'); ?> </th>
		<th><?php echo __('Sales Value per Brand');?></th>
		<th><?php echo __('Total Sales Value');?></th>
		<th><?php echo __('Expenses');?></th>
		<th><?php echo __('Payments');?></th>
	</tr>			
	
	<?php 				
	
	$i = 0;
	foreach($depots as $depot): 
		$did = $depot['Depot']['id'];
		$dtype = 2;//$depot['Depot']['type'];
		$brandFirst = array();
		$brandRest = array();
		if($dtype == 1){
			$rows = isset($reportData[$did]['rdsales']['brand'])?count($reportData[$did]['rdsales']['brand']):1;
			if(isset($reportData[$did]['rdsales']['brand'])){
				$brandFirst = array_slice($reportData[$did]['rdsales']['brand'],0, 1, true);
				$brandRest = array_slice($reportData[$did]['rdsales']['brand'], 1,$rows, true);
			}
			$indkey = 'rdsales';
		}elseif($dtype == 2){
			$rows = isset($reportData[$did]['sales']['brand'])?count($reportData[$did]['sales']['brand']):1;
			if(isset($reportData[$did]['sales']['brand'])){
				$brandFirst = array_slice($reportData[$did]['sales']['brand'],0, 1, true);
				$brandRest = array_slice($reportData[$did]['sales']['brand'], 1,$rows, true);
			}
			$indkey = 'sales';
		}else{
			$rows = isset($reportData[$did]['sale_redis_add']['brand'])?count($reportData[$did]['sale_redis_add']['brand']):1;
			if(isset($reportData[$did]['sale_redis_add']['brand'])){
				$brandFirst = array_slice($reportData[$did]['sale_redis_add']['brand'],0, 1, true);
				$brandRest = array_slice($reportData[$did]['sale_redis_add']['brand'], 1,$rows, true);
			}
			$indkey = 'sale_redis_add';
		}
		
	?>
	<tr>
		<td <?php echo ($rows > 1)?"rowspan='$rows'":""?> ><?php echo ++$i; ?></td>
		<td <?php echo ($rows > 1)?"rowspan='$rows'":""?> ><?php echo $depot['Depot']['title']; ?></td>				
		<?php 
		if(!empty($brandFirst)):
		foreach($brandFirst as $bidF => $brandF): ?>
		<td class="no-lborder"><?php echo isset($brands[$bidF])?$brands[$bidF]:"" ?></td>
		<td align="right"><?php echo isset($brandF['total_qty'])? number_format($brandF['total_qty'], QTY_DECIMALS) :"" ?></td>
		<td align="right"><?php echo isset($brandF['total_amt'])? number_format($brandF['total_amt'], AMT_DECIMALS) :"" ?></td>	
		<?php endforeach; else: ?>
		<td class="no-lborder"></td>
		<td></td>
		<td></td>
		<?php endif; ?>
		<td <?php echo ($rows > 1)?"rowspan='$rows'":""?> align="right" ><?php echo isset($reportData[$did][$indkey]['sales_value'])? number_format($reportData[$did][$indkey]['sales_value'],2) :"" ; ?></td>
		<td <?php echo ($rows > 1)?"rowspan='$rows'":""?> align="right"><?php echo isset($reportData[$did]['expense']['total_amt'])? number_format($reportData[$did]['expense']['total_amt'],AMT_DECIMALS) :"" ?></td>
		<td <?php echo ($rows > 1)?"rowspan='$rows'":""?> align="right"><?php echo isset($reportData[$did]['payment']['total_amt'])? number_format($reportData[$did]['payment']['total_amt'],AMT_DECIMALS) :"" ?></td>
	</tr>	
	<?php 
	if($rows > 1): 
	foreach($brandRest as $bidR=>$brandR): ?>
	
	<tr>
		<td class="no-lborder"><?php echo isset($brands[$bidR])?$brands[$bidR]:"" ?></td>
		<td align="right"><?php echo isset($brandR['total_qty'])? number_format($brandR['total_qty'], QTY_DECIMALS) :"" ?></td>
		<td align="right"><?php echo isset($brandR['total_amt'])? number_format($brandR['total_amt'], AMT_DECIMALS) :"" ?></td>				
	</tr>	
	
	
	<?php
		endforeach; endif;?>
		
	
	<?php endforeach; ?>

</table>
	
	
<?php else: ?>
	<p><?php echo __('Data not found') ?></p>
<?php endif; ?>

