<?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");
}




if(trim($current_date)==""){
	$current_date=date("Y-m-d");
}

$current_directory = getcwd();

if (file_exists($current_directory . '\application\config\mrp_config.php')) {
	include('application/config/mrp_config.php');

}else{
	$config_mrp['MRP_ACTIVE']=0;
}

$payment_data_reprint_show=0;
$reprint_adjustment=0;
if($config_mrp['MRP_ACTIVE']==1){

	$same_date_report=0;
	if($start_date==$end_date){
		$same_date_report=1;
	}
	$current_date_report=0;
	if($same_date_report==1){
		if($start_date==$current_date){
			$current_date_report=1;
		}
	}
	if($current_date_report==1){
		$day_name=date('D', strtotime($current_date));
		if($config_mrp['MRP_WEEKEND_REPORT']==$day_name){
			$payment_data_reprint_show=1;
			$payment_data=$payment_data_reprint;
		}
	}
}

$send_data['start_date']=$start_date;
$send_data['end_date']=$end_date;
$send_data['payment_data_reprint_show']=$payment_data_reprint_show;

$safe_string_to_store = base64_encode(serialize($send_data));
//$safe_string_to_payment = base64_encode(serialize($payment_data));
$safe_string_title = base64_encode(serialize($title));
$safe_string_subtitle = base64_encode(serialize($subtitle."#".$vat_enable_price_for_vat));

?>
<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 "Date Range : ".$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/summary_sales.php?data=".$safe_string_to_store."&payment_data=".$safe_string_to_payment."&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  rowspan="2" style="vertical-align: middle;background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Item 
		</th>
		<th colspan="2" style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Opening 
		</th>
		<th colspan="2" style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Receive 
		</th>
		<th colspan="2" style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Local Sale 
		</th>
		<th colspan="2" style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Network Sale 
		</th>
		<th colspan="2" style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Network Delivery 
		</th>
		<th colspan="2" style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Return
		</th>
		<th colspan="2" style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Closing
		</th>
	</tr>
	<tr>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Qty 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Price 
		</th>
		
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Qty 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Price 
		</th>
		
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Qty 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Price 
		</th>
		
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Qty 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Price 
		</th>
		
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Qty 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Price 
		</th>
		
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Qty 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Price 
		</th>
		
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 Qty 
		</th>
		<th style="background-color: #0084C3; color:#FFFFFF;font-size:12px; text-align:center;border: 1px solid #000000;border-collapse: collapse;padding: 2px;">
		 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=" 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;
    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;

        $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+=$d_value['return_vat_amount'];
        	$grand_total_vat+=$d_value['global_vat_amount'];


        	?>
        <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['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']*-1),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=" 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($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']*-1),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=" 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_network_closing,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=" 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>
        
        	<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_receive;?></td>
        	<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 number_format($cat_total_total_amount_receive,2,'.','');?></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_local_sale;?></td>
        	<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 number_format($cat_total_total_amount_local_sale,2,'.','');?></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_network_sale;?></td>
        	<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 number_format($cat_total_total_amount_network_sale,2,'.','');?></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_network_delivery;?></td>
        	<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 number_format($cat_total_total_amount_network_delivery,2,'.','');?></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_network_return;?></td>
        	<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 number_format($cat_total_total_amount_network_return,2,'.','');?></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_network_closing;?></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_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: #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=" 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>
        
        	<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_receive;?></td>
        	<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 number_format($cat_grand_total_amount_receive,2,'.','');?></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_local_sale;?></td>
        	<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 number_format($cat_grand_total_amount_local_sale,2,'.','');?></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_network_sale;?></td>
        	<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 number_format($cat_grand_total_amount_network_sale,2,'.','');?></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_network_delivery;?></td>
        	<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 number_format($cat_grand_total_amount_network_delivery,2,'.','');?></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_network_return;?></td>
        	<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 number_format($cat_grand_total_amount_network_return,2,'.','');?></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_network_closing;?></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_network_closing,2,'.','');?></td>
        	
        </tr>   
    </tbody>
    
    
    <tr>
    <td>
    &nbsp;
    </td>
    
    </tr>
</table>
<div style="height:5px;">&nbsp;</div>
<table id="maintable" width="100%">
<tr>
  <?php

  if($payment_data_reprint_show==1){
  	$total_payment_shawpon_mrp=0;
  	foreach ($payment_data_real as $pay_key => $pay_value) {
  		if($pay_value->payment_type=="Due"){
  			$total_credit+=$pay_value->payment_amoount;
  		}
  		$total_payment_shawpon_mrp+=$pay_value->payment_amoount;
  	}
  	$grand_total_show_mrp=0;

  	$grand_total_show_mrp+=$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_mrp+=$grand_total_adjustment;
  	$grand_total_show_mrp+=$grand_total_vat;
  	$grand_total_show_mrp-=$total_credit;
  	$show_adjustment=$total_payment_shawpon_mrp-$grand_total_show_mrp+round($grand_total_discount);
  }





  $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;

  if($payment_data_reprint_show==0){
  	$show_adjustment=$total_payment_shawpon-$grand_total_show+round($grand_total_discount);
  }


        ?>

<td width="50%" align="left">
<table id="maintable" style='border-collapse: collapse; border: 2px solid #318ee1;width: 70%;margin: 12px;box-shadow: 0px 8px 8px #000;'>
         <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #5091C1; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Sale &nbsp;"?></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 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=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #38617F; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total VATable Sale &nbsp;"?></td>
        	<td style=" padding-right: 5px;font-size:14px; font-weight:bold;background-color: #FFFFFF; color:#FF0000;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($vat_enable_price_for_vat,2,'.','');?></td>
        	
        </tr>  
        
        <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #5091C1; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Adjustment &nbsp;"?></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 echo number_format($show_adjustment,2,'.','');?></td>
        	
        </tr> 
        <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #38617F; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total VAT &nbsp;"?></td>
        	<?php if(intval($vat_show_dummy)){?>
        	<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($vat_show_dummy,2,'.','');?></td>
        	<?php }else{?>
        	
        	<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 echo number_format($grand_total_vat,2,'.','');?></td>
        	<?php }?>
        </tr>   

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

       <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #38617F; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Grand Total &nbsp;"?></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 echo number_format($total_payment_shawpon+round($grand_total_discount),2,'.','');?></td>
        	
        </tr>
     </table>      
    </td>
    
    
<td width="50%" align="right">
	<table id="maintable" style='border-collapse: collapse; border: 2px solid #318ee1;width: 70%;margin: 12px;box-shadow: 0px 8px 8px #000;'>
	   <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #135270; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Payment/Discount Type &nbsp;"?></td>
        	<td style=" padding-right: 5px;font-size:14px; font-weight:bold;background-color: #135270; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Amount";?></td>
        	
        </tr> 
        <?php
        $total_payment=0;
        $total_cash_and_others_payment=0;
        $total_sales_discount=0;
        $sales_discount_array=array();



        foreach ($payment_data as $pay_key => $pay_value) {
        	if(trim($pay_value->payment_type)!=""){
        		$payment_type_show=$pay_value->payment_type;

        		if($pay_value->payment_type=="Purchase Discount"){
        			$payment_type_show="Sales Discount";

        			$sales_discount_array[$pay_value->payment_type]['name']=$payment_type_show;
        			$sales_discount_array[$pay_value->payment_type]['amount']=$pay_value->payment_amoount;

        			$total_sales_discount+=$pay_value->payment_amoount;

        		}elseif($pay_value->payment_type=="Purchase Bonus"){
        			$payment_type_show="Special Sales Discount";

        			$sales_discount_array[$pay_value->payment_type]['name']=$payment_type_show;
        			$sales_discount_array[$pay_value->payment_type]['amount']=$pay_value->payment_amoount;
        			$total_sales_discount+=$pay_value->payment_amoount;
        		}else{
        			$total_cash_and_others_payment+=$pay_value->payment_amoount;
        ?>	
		<tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #639CB2; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo $payment_type_show." &nbsp;"?></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 echo number_format($pay_value->payment_amoount,2,'.','');?></td>
        	
        </tr>
        <?php	
        		}
        		$total_payment+=$pay_value->payment_amoount;
        	}
        }
        ?>
        <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #962F07; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Payment &nbsp;"?></td>
        	<td style=" padding-right: 5px;font-size:14px; font-weight:bold;background-color: #962F07; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($total_cash_and_others_payment,2,'.','');?></td>
        	
        </tr>
        
        
        <?php
        if(round($grand_total_discount)){
        	$sales_discount_array["Dealer/Clearance Discount"]['name']="Dealer/Clearance Discount";
        	$sales_discount_array["Dealer/Clearance Discount"]['amount']=round($grand_total_discount);
        	$total_sales_discount+=round($grand_total_discount);
        	$total_payment+=round($grand_total_discount);
        }

        foreach ($sales_discount_array as $key => $value) {
        	?>
        	 <tr>
	        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #0E8DBF; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo $value['name']." &nbsp;"?></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 echo number_format($value['amount'],2,'.','');?></td>
        	</tr>
        	
        <?php	
        }
        ?>
         <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #962F07; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Discount &nbsp;"?></td>
        	<td style=" padding-right: 5px;font-size:14px; font-weight:bold;background-color: #962F07; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($total_sales_discount,2,'.','');?></td>
        	
        </tr>
        
        
         <tr>
        	<td style=" padding-left: 5px;font-size:14px; font-weight:bold;background-color: #135270; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo "Total Payment & Discount &nbsp;"?></td>
        	<td style=" padding-right: 5px;font-size:14px; font-weight:bold;background-color: #135270; color:#FFFFFF;font-size:12px; text-align:right;border: 1px solid #000000;border-collapse: collapse;"> <?php echo number_format($total_payment,2,'.','');?></td>
        	
        </tr>
     </table>      
    </td>
    
</tr>

</table>

<div id="bottom_anchor"></div>
</div>
<div style="height:20px;">&nbsp;</div>
<?php
$this->load->view("partial/footer");
?>
