<?php
$path_to_root="../../../";

include($path_to_root.'/application/config/config.php');

/*shawpon modify for online*/
//$data = unserialize(base64_decode($_GET['data']));
if(substr(LOCAL_PATH, -1)=="/"){
	$filename = LOCAL_PATH.unserialize(base64_decode($_GET['data']));
}else{
	$filename = LOCAL_PATH."/".unserialize(base64_decode($_GET['data']));
}

$data=array();
$string_data = file_get_contents($filename);
$data = unserialize($string_data);

/*shawpon modify for online*/
$title = unserialize(base64_decode($_GET['title']));
$subtitle = unserialize(base64_decode($_GET['subtitle']));
$payment_data = unserialize(base64_decode($_GET['payment_data']));

include_once($path_to_root . "/pdf_report/mpdf60/print/custom_function.php");

$header = '
<table width="100%" style="border-bottom: 1px solid #000000;">
	<tr>
		<td colspan=3 width="100%" align="center"><img src="logo_rn_healthcare_pharma.png" width="250px" /></td>
	</tr>
	<tr>
		<td width="100%" colspan=3 align="center" style="font-size: 17px; color:#000000;">'.LOCATION_NAME.'</td>
	</tr>
	<tr>
		<td  width ="30%" align="left" style="font-size: 12px; color:#000000;"><b>Date Range : </b> '.$subtitle.'</td>
		<td width ="40%" align="center" style="font-size: 13px; color:#000000;font-weight:bold;">'.$title.'</td>
		<td width ="30%" align="right" style="font-size: 12px; color:#000000;"><b>Print Date : </b>'.date("d/m/Y h:m:i A").'</td>
	</tr>
</table>
';




$html='<table width="100%" style="color: #000000;border: 1px solid #000000; border-collapse: collapse;">
    <thead>
        <tr>
		<th  rowspan="2" style="width:450px;background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Item 
		</th>
		<th colspan="2" style="width:100px;background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Opening 
		</th>
		<th colspan="2" style="width:100px;background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Receive 
		</th>
		<th colspan="2" style="width:100px;background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Local Sale 
		</th>
		<th colspan="2" style="width:100px;background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Return
		</th>
		<th colspan="2" style="width:100px;background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Closing
		</th>
	</tr>
	<tr>
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Qty 
		</th>
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Price 
		</th>
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Qty 
		</th>
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Price 
		</th>
		
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Qty 
		</th>
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Price 
		</th>
		
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Qty 
		</th>
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Price 
		</th>
		
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Qty 
		</th>
		<th style="background-color:#ACA6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px;">
		 Price 
		</th>
		
	</tr>
    </thead>
    <tbody>';

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

$gender_array=array();

foreach ($data as $key => $value) {
	$gender_array[]=$key;

	$html.='<tr>';
	$html.='<td  colspan=11 style="background-color:#A6A6A6;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:left;font-size: 15px;font-weight:bold;" >&nbsp;'.$root_serial.'&nbsp;'.$key.'&nbsp;</td>';
	$html.='</tr>';

	$root_serial_cat=1;
	ksort($value);
	foreach ($value as $cat_key => $cat_value) {

		$html.='<tr>';
		$html.='<td  colspan=11 style="background-color:#E1E0E0;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:left;font-size: 13px;font-weight:bold;" >&nbsp;'.$root_serial.'.'.str_pad($root_serial_cat, 3, "0", STR_PAD_LEFT).'&nbsp;'.$cat_key.'</td>';
		$html.='</tr>';

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

		ksort($cat_value);

		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'];


			$html.='<tr>';
			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:left;font-size: 12px;" >&nbsp;'.$root_serial.'.'.str_pad($root_serial_cat, 3, "0", STR_PAD_LEFT).'.'.str_pad($serial_item, 3, "0", STR_PAD_LEFT).' &nbsp;'.$d_key.'&nbsp;</td>';

			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px; " >';
			if($d_value['opening_qty']){
				$html.=$d_value['opening_qty'];
			}else{
				$html.="-";
			}
			$html.='</td>';


			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 12px; " >';
			if($d_value['opening_price']){
				$html.=number_format($d_value['opening_price'],2,'.','');
			}else{
				$html.="-";
			}
			$html.='</td>';

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



			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px; " >';
			if($d_value['receive_qty']){
				$html.=$d_value['receive_qty'];
			}else{
				$html.="-";
			}
			$html.='</td>';


			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 12px; " >';
			if($d_value['receive_qty_price']){
				$html.=number_format($d_value['receive_qty_price'],2,'.','');
			}else{
				$html.="-";
			}
			$html.='</td>';


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



			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px; " >';
			if($d_value['sales_qty']){
				$html.=$d_value['sales_qty'];
			}else{
				$html.="-";
			}
			$html.='</td>';


			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 12px; " >';
			if($d_value['product_amount']){
				$html.=number_format($d_value['product_amount'],2,'.','');
			}else{
				$html.="-";
			}
			$html.='</td>';

			$closing_qty-=$d_value['sales_qty'];
			$closing_amount-=number_format($d_value['product_amount'],2,'.','');

			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px; " >';
			if($d_value['return_sales_qty']){
				$html.=$d_value['return_sales_qty'];
			}else{
				$html.="-";
			}
			$html.='</td>';


			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 12px; " >';
			if($d_value['return_product_amount']){
				$html.=number_format(($d_value['return_product_amount']*-1),2,'.','');
			}else{
				$html.="-";
			}
			$html.='</td>';

			$closing_qty+=$d_value['return_sales_qty'];
			$closing_amount+=number_format(($d_value['return_product_amount']*-1),2,'.','');


			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 12px; " >';
			if($closing_qty){
				$html.=$closing_qty;
			}else{
				$html.="0";
			}
			$html.='</td>';


			$html.='<td style="background-color:#FFFFFF;color: #000000;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 12px; " >';
			if($closing_amount){
				$html.=number_format($closing_amount,2,'.','');
			}else{
				$html.="0.00";
			}
			$html.='</td>';



			$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,'.','');


			$html.='</tr>';

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



		$html.='<tr>';
		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 13px;" >Sub-Total ('.$cat_key.')&nbsp;</td>';

		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 13px; " >'.$cat_total_qty_opening.'</td>';
		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 13px;" >'.number_format($cat_total_amount_opening,2,'.','').'</td>';

		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 13px; " >'.$cat_total_qty_receive.'</td>';
		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 13px;" >'.number_format($cat_total_amount_receive,2,'.','').'</td>';

		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 13px; " >'.$cat_total_qty_local_sale.'</td>';
		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 13px;" >'.number_format($cat_total_amount_local_sale,2,'.','').'</td>';

		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 13px; " >'.$cat_total_qty_network_return.'</td>';
		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 13px;" >'.number_format($cat_total_amount_network_return,2,'.','').'</td>';

		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 13px; " >'.$cat_total_qty_network_closing.'</td>';
		$html.='<td style="background-color:#E1E0E0;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 13px;" >'.number_format($cat_total_amount_network_closing,2,'.','').'</td>';

		$html.='</tr>';
		$root_serial_cat++;
	}
	
	
$html.='<tr>';
$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 15px;" >Total ('.$key.')&nbsp;</td>';

$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 15px; " >'.$cat_total_total_qty_opening.'</td>';
$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 15px;" >'.number_format($cat_total_total_amount_opening,2,'.','').'</td>';

$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 15px; " >'.$cat_total_total_qty_receive.'</td>';
$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 15px;" >'.number_format($cat_total_total_amount_receive,2,'.','').'</td>';

$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 15px; " >'.$cat_total_total_qty_local_sale.'</td>';
$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 15px;" >'.number_format($cat_total_total_amount_local_sale,2,'.','').'</td>';

$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 15px; " >'.$cat_total_total_qty_network_return.'</td>';
$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 15px;" >'.number_format($cat_total_total_amount_network_return,2,'.','').'</td>';

$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 15px; " >'.$cat_total_total_qty_network_closing.'</td>';
$html.='<td style="background-color:#CECDCD;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 15px;" >'.number_format($cat_total_total_amount_network_closing,2,'.','').'</td>';

$html.='</tr>';



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

 $gender_array_str=implode(",",$gender_array);

$html.='<tr>';
$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 16px;" >Grand Total ('.$gender_array_str.')&nbsp;</td>';

$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 16px; " >'.$cat_grand_total_qty_opening.'</td>';
$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 16px;" >'.number_format($cat_grand_total_amount_opening,2,'.','').'</td>';

$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 16px; " >'.$cat_grand_total_qty_receive.'</td>';
$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 16px;" >'.number_format($cat_grand_total_amount_receive,2,'.','').'</td>';

$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 16px; " >'.$cat_grand_total_qty_local_sale.'</td>';
$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 16px;" >'.number_format($cat_grand_total_amount_local_sale,2,'.','').'</td>';

$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 16px; " >'.$cat_grand_total_qty_network_return.'</td>';
$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 16px;" >'.number_format($cat_grand_total_amount_network_return,2,'.','').'</td>';

$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:center;font-size: 16px; " >'.$cat_grand_total_qty_network_closing.'</td>';
$html.='<td style="background-color:#ACA6A6;color: #000000;font-weight:bold;border-top: 1px solid black; border-left: 1px solid black; border-bottom: 1px solid black; border-right: 1px solid black; border-collapse: collapse; text-align:right;font-size: 16px;" >'.number_format($cat_grand_total_amount_network_closing,2,'.','').'</td>';

$html.='</tr>';

$html.='</tbody></table><div>&nbsp;</div>';

$footer = '<p align="center" style="border-top: 1px solid #000000;">'.REPORT_FOOTER_LINE_1.'<br />'.REPORT_FOOTER_LINE_2.'&nbsp;&nbsp;&nbsp;&nbsp;<font style="font-style: italic;font-weight:bold;font-size:11px;">Page {PAGENO} of {nb}</font></p>';

include("../mpdf.php");

$mpdf=new mPDF('utf-8', 'A4',0,'',10,10,32,20);

$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);

$mpdf->autoScriptToLang = true;
$mpdf->baseScript = 1;
$mpdf->autoVietnamese = true;
$mpdf->autoArabic = true;

$mpdf->SetWatermarkImage('rn_healthcare_pharma_wm.png', 0.10, 'D');

$mpdf->showWatermarkImage = true;
$mpdf->autoLangToFont = true;

$mpdf->WriteHTML($html);

$mpdf->Output('stock_transaction_summary_report_'.LOCATION_CODE.'_'.$subtitle.'.pdf','I');

exit;
?>