<?php 
//OJB: Check if for excel export process
if($export_excel == 1){
	ob_start();
	$this->load->view("partial/header_excel");
}else{
	$this->load->view("partial/header");
}


$safe_string_to_store = base64_encode(serialize($data));
$safe_string_title = base64_encode(serialize($title));
$safe_string_subtitle = base64_encode(serialize($subtitle));

?>
<div id="page_title" style="margin-bottom:8px;"><?php echo $title ?></div>
<div id="page_subtitle" style="margin-bottom:8px;"><?php echo "Upto : ".$subtitle ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo LOCAL_PATH."/pdf_report/mpdf60/print/summary_inventory_item.php?data=".$safe_string_to_store."&title=".$safe_string_title."&subtitle=".$safe_string_subtitle; ?>" target="_blank">PRINT</a>

</div>

<style>
thead{
    background-color:white;
}
table tr td:first-child::after {
   content: "";
   display: inline-block;
   vertical-align: middle;
   min-height: 22px;
}
table tr th:first-child::after {
   content: "";
   display: inline-block;
   vertical-align: middle;
   min-height: 22px;
}
</style>
<script type="text/javascript" language="javascript">
function moveScroll(){
	var scroll = $(window).scrollTop();
	var anchor_top = $("#maintable").offset().top;
	var anchor_bottom = $("#bottom_anchor").offset().top;
	if (scroll>anchor_top && scroll<anchor_bottom) {
		clone_table = $("#clone");
		if(clone_table.length == 0){
			clone_table = $("#maintable").clone();
			clone_table.attr('id', 'clone');
			clone_table.css({position:'fixed',
			'pointer-events': 'none',
			top:0});
			clone_table.width($("#maintable").width());
			$("#table-container").append(clone_table);
			$("#clone").css({visibility:'hidden'});
			$("#clone thead").css({'visibility':'visible','pointer-events':'auto'});
		}
	} else {
		$("#clone").remove();
	}
}
$(window).scroll(moveScroll);
</script>

<div id="table-container" style="width:100%">
<table id="maintable" width="100%">
    <thead>
        <tr>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Item 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Quantity 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Total Price 
		</th>
	</tr>
	
    </thead>
    <tbody>
    
    <?php 
    $root_serial=1;
    ksort($data);

    $cat_total_total_qty_opening=0;
    $cat_total_total_amount_opening=0;

    foreach ($data as $key => $value) {
    ?>	
    	<tr>
            <td colspan="15" style=" font-size:14px; font-weight:bold;background-color: #ECAD2E; color:#000000;font-size:12px; text-align:left;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "&nbsp;".$root_serial." &nbsp;".$key;?></td>
        </tr>
    	
    <?php 
    $root_serial_cat=1;
    foreach ($value as $cat_key => $cat_value) {
    	?>
    	<tr>
            <td colspan="15" style=" font-size:14px; font-weight:bold;background-color: #E6CC97; color:#000000;font-size:12px; text-align:left;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "&nbsp;".$root_serial.".".str_pad($root_serial_cat, 2, "0", STR_PAD_LEFT)." &nbsp;".$cat_key;?></td>
        </tr>
    	
        
        <?php 
        $serial_item=1;

        $cat_total_qty_opening=0;
        $cat_total_amount_opening=0;

        foreach ($cat_value as $d_key => $d_value) {
        	?>
        <tr>
            <td style=" font-size:14px; font-weight:bold;background-color: #FFFFFF; color:#000000;font-size:12px; text-align:left;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "&nbsp;".$root_serial.".".str_pad($root_serial_cat, 2, "0", STR_PAD_LEFT).".".str_pad($serial_item, 2, "0", STR_PAD_LEFT)." &nbsp;".$d_key;?></td>

            
            <td style=" font-size:14px; font-weight:bold;background-color: #FFFFFF; color:#000000;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;"> 
            <?php if($d_value['qty_total']){echo $d_value['qty_total'];}else{echo "-";}?>
            </td>
       		<td style=" font-size:14px; font-weight:bold;background-color: #FFFFFF; color:#000000;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> 
            <?php if($d_value['price_total']){echo number_format($d_value['price_total'],2,'.','');}else{echo "-";}?>
            </td>
            
            <?php

            $cat_total_qty_opening+=$d_value['qty_total'];
            $cat_total_amount_opening+=number_format($d_value['price_total'],2,'.','');
            ?>
            
         </tr>
    <?php 	
    $serial_item++;
        }

        $cat_total_total_qty_opening+=$cat_total_qty_opening;
        $cat_total_total_amount_opening+=$cat_total_amount_opening;

        ?>
        <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #D2D2D2; color:#000000;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Sub-Total (".$cat_key.")&nbsp;"?></td>
        	
        	<td style=" font-size:14px; font-weight:bold;background-color: #D2D2D2; color:#000000;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;"> <?php echo $cat_total_qty_opening;?></td>
        	<td style=" font-size:14px; font-weight:bold;background-color: #D2D2D2; color:#000000;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($cat_total_amount_opening,2,'.','');?></td>
        	
        </tr>
        
        
        <?php
        $root_serial_cat++;
    }

    ?>	
    <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #FBE0E0; color:#000000;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total (".$key.")&nbsp;"?></td>
        	
        	<td style=" font-size:14px; font-weight:bold;background-color: #FBE0E0; color:#000000;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;"> <?php echo $cat_total_total_qty_opening;?></td>
        	<td style=" font-size:14px; font-weight:bold;background-color: #FBE0E0; color:#000000;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($cat_total_total_amount_opening,2,'.','');?></td>
        </tr>   
    
     
   <?php


   $cat_grand_total_qty_opening+=$cat_total_total_qty_opening;
   $cat_grand_total_amount_opening+=$cat_total_total_amount_opening;

   $root_serial++;

   $cat_total_total_qty_opening=0;
   $cat_total_total_amount_opening=0;
    }

    ?>
    
    <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Grand Total &nbsp;"?></td>
        	
        	<td style=" font-size:14px; font-weight:bold;background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;"> <?php echo $cat_grand_total_qty_opening;?></td>
        	<td style=" font-size:14px; font-weight:bold;background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($cat_grand_total_amount_opening,2,'.','');?></td>
        	
        </tr>   
    </tbody>
    
    <tr>
    <td>
    &nbsp;
    </td>
    
    </tr>
</table>

<div id="bottom_anchor"></div>
</div>
<?php
$this->load->view("partial/footer");
?>
