<?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_to_store = base64_encode(serialize($filename));
$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>

<table style="width:100%">
<tr>
<td style="background-color:#327789;text-align:center;font-weight:bold;font-size: 17px;padding-top: 5px;padding-bottom: 5px;padding-left: 100px;color:#FFFFFF;">
<?php echo "Upto : ".$subtitle ?>
</td>
<td style="background-color:#327789;text-align:right;font-weight:bold;font-size: 17px;padding: 5px;color:#FFFFFF;width:10%;padding-right:20px;">
<a class="notificationContainerReport" href="<?php echo LOCAL_PATH."/pdf_report/mpdf60/print/details_inventory.php?data=".$safe_string_to_store."&title=".$safe_string_title."&subtitle=".$safe_string_subtitle; ?>" target="_blank">
</a>
</td>
</tr>
</table>

<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:-13});
			clone_table.width($("#maintable").width()+3);
			$("#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" style='border-collapse: collapse; border: 2px solid #318ee1;width: 97%;margin: 12px;box-shadow: 0px 8px 8px #000;'>
     <thead>
        <tr>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:15px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 6px;">
		 Item 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:15px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 6px;">
		 Quantity 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:15px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 6px;">
		 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=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #37ABF2; 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;
    ksort($value);
    foreach ($value as $cat_key => $cat_value) {
    	?>
    	<tr>
            <td colspan="15" style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #A5DDFF; 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;
        ksort($cat_value);
        foreach ($cat_value as $d_key => $d_value) {
        	?>
        <tr>
            <td style=" padding-left: 5px;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=" padding-right: 5px;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="  padding-right: 5px;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: #33748E; color:#FFFFFF;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: #33748E; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;"> <?php echo $cat_total_total_qty_opening;?></td>
        	<td style="  padding-right: 5px;font-size:14px; font-weight:bold;background-color: #33748E; color:#FFFFFF;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;

   $cat_total_total_qty_opening=0;
   $cat_total_total_amount_opening=0;

   $root_serial++;
    }

    ?>
    
    <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #0084C3; 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: #0084C3; 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="  padding-right: 5px;font-size:14px; font-weight:bold;background-color: #0084C3; 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>
<div style="height:20px;">&nbsp;</div>
<?php
$this->load->view("partial/footer");
?>
