<?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_payment = base64_encode(serialize($payment_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 "Date Range : ".$subtitle ?>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo LOCAL_PATH."/pdf_report/mpdf60/print/summary_sales.php?data=".$safe_string_to_store."&payment_data=".$safe_string_to_payment."&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  rowspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Item 
		</th>
		<th colspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Opening 
		</th>
		<th colspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Receive 
		</th>
		<th colspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Local Sale 
		</th>
		<th colspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Network Sale 
		</th>
		<th colspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Network Delivery 
		</th>
		<th colspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Return
		</th>
		<th colspan="2" style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Closing
		</th>
	</tr>
	<tr>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Qty 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;">
		 Price 
		</th>
		
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Qty 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;">
		 Price 
		</th>
		
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Qty 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;">
		 Price 
		</th>
		
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Qty 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;">
		 Price 
		</th>
		
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Qty 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;">
		 Price 
		</th>
		
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Qty 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;">
		 Price 
		</th>
		
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;">
		 Qty 
		</th>
		<th style="background-color: #207D44; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;">
		 Price 
		</th>
		
	</tr>
    </thead>
    <tbody>
    
    <?php 
    $root_serial=1;
    ksort($data);



    $cat_total_total_qty_opening=0;
    $cat_total_total_amount_opening=0;

    $cat_total_total_qty_receive=0;
    $cat_total_total_amount_receive=0;

    $cat_total_total_qty_local_sale=0;
    $cat_total_total_amount_local_sale=0;

    $cat_total_total_qty_network_sale=0;
    $cat_total_total_amount_network_sale=0;

    $cat_total_total_qty_network_delivery=0;
    $cat_total_total_amount_network_delivery=0;

    $cat_total_total_qty_network_return=0;
    $cat_total_total_amount_network_return=0;

    $cat_total_total_qty_network_closing=0;
    $cat_total_total_amount_network_closing=0;


    $grand_total_discount=0;
    $grand_total_adjustment=0;
    $grand_total_vatable_price=0;
    $grand_total_vat=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;

        $cat_total_qty_receive=0;
        $cat_total_amount_receive=0;

        $cat_total_qty_local_sale=0;
        $cat_total_amount_local_sale=0;

        $cat_total_qty_network_sale=0;
        $cat_total_amount_network_sale=0;

        $cat_total_qty_network_delivery=0;
        $cat_total_amount_network_delivery=0;

        $cat_total_qty_network_return=0;
        $cat_total_amount_network_return=0;

        $cat_total_qty_network_closing=0;
        $cat_total_amount_network_closing=0;

        foreach ($cat_value as $d_key => $d_value) {

        	$closing_qty=0;
        	$closing_amount=0;

        	$grand_total_discount+=$d_value['discount_amount'];
        	$grand_total_discount-=abs($d_value['return_discount_amount']);
        	$grand_total_discount+=$d_value['global_discount_amount'];


        	$grand_total_adjustment+=$d_value['adjustment_amount'];
        	$grand_total_adjustment-=abs($d_value['return_adjustment_amount']);
        	$grand_total_adjustment+=$d_value['global_adjustment_amount'];

        	$grand_total_vatable_price+=$d_value['vat_enable_price'];
        	$grand_total_vatable_price-=abs($d_value['return_vat_enable_price']);
        	$grand_total_vatable_price+=$d_value['global_vat_enable_price'];


        	$grand_total_vat+=$d_value['vat_amount'];
        	$grand_total_vat-=abs($d_value['return_vat_amount']);
        	$grand_total_vat+=$d_value['global_vat_amount'];


        	?>
        <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['opening_qty']){echo $d_value['opening_qty'];}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['opening_price']){echo number_format($d_value['opening_price'],2,'.','');}else{echo "-";}?>
            </td>
            <?php
            $closing_qty+=$d_value['opening_qty'];
            $closing_amount+=number_format($d_value['opening_price'],2,'.','');
            ?>
       
            <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['receive_qty']){echo $d_value['receive_qty'];}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['receive_qty_price']){echo number_format($d_value['receive_qty_price'],2,'.','');}else{echo "-";}?>
            </td>
            
             <?php
             $closing_qty+=$d_value['receive_qty'];
             $closing_amount+=number_format($d_value['receive_qty_price'],2,'.','');
            ?>
            
       
            <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['sales_qty']){echo $d_value['sales_qty'];}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['product_amount']){echo number_format($d_value['product_amount'],2,'.','');}else{echo "-";}?>
            </td>
            
            <?php
            $closing_qty-=$d_value['sales_qty'];
            $closing_amount-=number_format($d_value['product_amount'],2,'.','');
            ?>     

            <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['global_sales_qty']){echo $d_value['global_sales_qty'];}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['global_product_amount']){echo number_format($d_value['global_product_amount'],2,'.','');}else{echo "-";}?>
            </td>
       
            <?php
            //$closing_qty-=$d_value['sales_qty'];
            //$closing_amount-=number_format($d_value['product_amount'],2,'.','');
            ?>  
            
            
            <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['global_delivery_sales_qty']){echo $d_value['global_delivery_sales_qty'];}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['global_delivery_product_amount']){echo number_format($d_value['global_delivery_product_amount'],2,'.','');}else{echo "-";}?>
            </td>
             <?php
             $closing_qty-=$d_value['global_delivery_sales_qty'];
             $closing_amount-=number_format($d_value['global_delivery_product_amount'],2,'.','');
            ?>
            
            <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['return_sales_qty']){echo $d_value['return_sales_qty'];}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['return_product_amount']){echo number_format($d_value['return_product_amount'],2,'.','');}else{echo "-";}?>
            </td>
            <?php
            $closing_qty+=$d_value['return_sales_qty'];
            $closing_amount+=number_format($d_value['return_product_amount'],2,'.','');
            ?>
            
            <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($closing_qty){echo $closing_qty;}else{echo "0";}?>
            </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($closing_amount){echo number_format($closing_amount,2,'.','');}else{echo "0.00";}?>
            </td>
            <?php

            $cat_total_qty_opening+=$d_value['opening_qty'];
            $cat_total_amount_opening+=number_format($d_value['opening_price'],2,'.','');

            $cat_total_qty_receive+=$d_value['receive_qty'];
            $cat_total_amount_receive+=number_format($d_value['receive_qty_price'],2,'.','');

            $cat_total_qty_local_sale+=$d_value['sales_qty'];
            $cat_total_amount_local_sale+=number_format($d_value['product_amount'],2,'.','');

            $cat_total_qty_network_sale+=$d_value['global_sales_qty'];
            $cat_total_amount_network_sale+=number_format($d_value['global_product_amount'],2,'.','');

            $cat_total_qty_network_delivery+=$d_value['global_delivery_sales_qty'];
            $cat_total_amount_network_delivery+=number_format($d_value['global_delivery_product_amount'],2,'.','');

            $cat_total_qty_network_return+=$d_value['return_sales_qty'];
            $cat_total_amount_network_return+=number_format($d_value['return_product_amount'],2,'.','');

            $cat_total_qty_network_closing+=$closing_qty;
            $cat_total_amount_network_closing+=number_format($closing_amount,2,'.','');
            ?>
            
         </tr>
    <?php 	
    $serial_item++;
        }

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

        $cat_total_total_qty_receive+=$cat_total_qty_receive;
        $cat_total_total_amount_receive+=$cat_total_amount_receive;

        $cat_total_total_qty_local_sale+=$cat_total_qty_local_sale;
        $cat_total_total_amount_local_sale+=$cat_total_amount_local_sale;

        $cat_total_total_qty_network_sale+=$cat_total_qty_network_sale;
        $cat_total_total_amount_network_sale+=$cat_total_amount_network_sale;

        $cat_total_total_qty_network_delivery+=$cat_total_qty_network_delivery;
        $cat_total_total_amount_network_delivery+=$cat_total_amount_network_delivery;

        $cat_total_total_qty_network_return+=$cat_total_qty_network_return;
        $cat_total_total_amount_network_return+=$cat_total_amount_network_return;

        $cat_total_total_qty_network_closing+=$cat_total_qty_network_closing;
        $cat_total_total_amount_network_closing+=$cat_total_amount_network_closing;

        ?>
        <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>
        
        	<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_receive;?></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_receive,2,'.','');?></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_local_sale;?></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_local_sale,2,'.','');?></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_network_sale;?></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_network_sale,2,'.','');?></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_network_delivery;?></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_network_delivery,2,'.','');?></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_network_return;?></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_network_return,2,'.','');?></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_network_closing;?></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_network_closing,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>
        
        	<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_receive;?></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_receive,2,'.','');?></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_local_sale;?></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_local_sale,2,'.','');?></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_network_sale;?></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_network_sale,2,'.','');?></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_network_delivery;?></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_network_delivery,2,'.','');?></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_network_return;?></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_network_return,2,'.','');?></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_network_closing;?></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_network_closing,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_grand_total_qty_receive+=$cat_total_total_qty_receive;
   $cat_grand_total_amount_receive+=$cat_total_total_amount_receive;

   $cat_grand_total_qty_local_sale+=$cat_total_total_qty_local_sale;
   $cat_grand_total_amount_local_sale+=$cat_total_total_amount_local_sale;

   $cat_grand_total_qty_network_sale+=$cat_total_total_qty_network_sale;
   $cat_grand_total_amount_network_sale+=$cat_total_total_amount_network_sale;

   $cat_grand_total_qty_network_delivery+=$cat_total_total_qty_network_delivery;
   $cat_grand_total_amount_network_delivery+=$cat_total_total_amount_network_delivery;

   $cat_grand_total_qty_network_return+=$cat_total_total_qty_network_return;
   $cat_grand_total_amount_network_return+=$cat_total_total_amount_network_return;

   $cat_grand_total_qty_network_closing+=$cat_total_total_qty_network_closing;
   $cat_grand_total_amount_network_closing+=$cat_total_total_amount_network_closing;

   
   $cat_total_total_qty_opening=0;
   $cat_total_total_amount_opening=0;

   $cat_total_total_qty_receive=0;
   $cat_total_total_amount_receive=0;

   $cat_total_total_qty_local_sale=0;
   $cat_total_total_amount_local_sale=0;

   $cat_total_total_qty_network_sale=0;
   $cat_total_total_amount_network_sale=0;

   $cat_total_total_qty_network_delivery=0;
   $cat_total_total_amount_network_delivery=0;

   $cat_total_total_qty_network_return=0;
   $cat_total_total_amount_network_return=0;

   $cat_total_total_qty_network_closing=0;
   $cat_total_total_amount_network_closing=0;


   $root_serial++;
    }

    ?>
    
    <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>
        
        	<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_receive;?></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_receive,2,'.','');?></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_local_sale;?></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_local_sale,2,'.','');?></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_network_sale;?></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_network_sale,2,'.','');?></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_network_delivery;?></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_network_delivery,2,'.','');?></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_network_return;?></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_network_return,2,'.','');?></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_network_closing;?></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_network_closing,2,'.','');?></td>
        	
        </tr>   
    </tbody>
    
    
    <tr>
    <td>
    &nbsp;
    </td>
    
    </tr>
</table>

<table id="maintable" width="100%">
<tr>
  <?php
  $total_credit=0;
  $total_payment_shawpon=0;
  foreach ($payment_data as $pay_key => $pay_value) {
  	if($pay_value->payment_type=="Due"){
  		$total_credit+=$pay_value->payment_amoount;
  	}
  	$total_payment_shawpon+=$pay_value->payment_amoount;
  }
  $grand_total_show=0;

  $grand_total_show+=$cat_grand_total_amount_local_sale-$cat_grand_total_amount_network_return+$cat_grand_total_amount_network_sale;
  //$grand_total_show-=$grand_total_discount;
  $grand_total_show+=$grand_total_adjustment;
  $grand_total_show+=$grand_total_vat;
  $grand_total_show-=$total_credit;

        ?>

<td width="50%" align="left">
	<table id="maintable" width="60%">
         <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #728C7C; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Sale &nbsp;"?></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 echo number_format($cat_grand_total_amount_local_sale-$cat_grand_total_amount_network_return+$cat_grand_total_amount_network_sale,2,'.','');?></td>
        	
        </tr>  
        <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #728C7C; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Discount &nbsp;"?></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 echo number_format($grand_total_discount,2,'.','');?></td>
        	
        </tr> 
        <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #728C7C; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Adjustment &nbsp;"?></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 echo number_format($total_payment_shawpon-$grand_total_show,2,'.','');?></td>
        	
        </tr> 
        <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #728C7C; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total VAT &nbsp;"?></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 echo number_format($grand_total_vat,2,'.','');?></td>
        	
        </tr>   

      
        
       <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #728C7C; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Credit &nbsp;"?></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 echo number_format($total_credit,2,'.','');?></td>
        	
        </tr>   

       <tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #728C7C; 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: #FFFFFF; color:#000000;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($total_payment_shawpon,2,'.','');?></td>
        	
        </tr>
     </table>      
    </td>
    
    
<td width="50%" align="right">
	<table id="maintable" width="60%">
	   <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 "Payment Type &nbsp;"?></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 echo "Amount";?></td>
        	
        </tr> 
        <?php
        $total_payment=0;

        foreach ($payment_data as $pay_key => $pay_value) {

        ?>	
		<tr>
        	<td style=" font-size:14px; font-weight:bold;background-color: #728C7C; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo $pay_value->payment_type."&nbsp;"?></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 echo number_format($pay_value->payment_amoount,2,'.','');?></td>
        	
        </tr>
        <?php	
        $total_payment+=$pay_value->payment_amoount;
        }
        ?>
     </table>      
    </td>
    
    
    
</tr>

</table>

<div id="bottom_anchor"></div>
</div>





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