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

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

/*shawpon modify for online*/
$title = unserialize(base64_decode($_GET['title']));
$subtitle = unserialize(base64_decode($_GET['subtitle']));
		
/*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);

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_grameenshamogree.png" width="126px" /></td>
	</tr>
	<tr>
		<td width="100%" colspan=3 align="center" style="font-size: 17px; color:#000000;">'.LOCATION_NAME.'</td>
	</tr>
	<tr>
		<td  width ="33%" align="left" style="font-size: 17px; color:#000000;"><b>Upto : </b> '.$subtitle.'</td>
		<td width ="33%" align="center" style="font-size: 12px; color:#000000;">'.$title.'</td>
		<td width ="33%" align="right" style="font-size: 17px; color:#000000;"><b>Print Date : </b>'.date("d/m/Y").'</td>
	</tr>
</table>
';



$html='<table width="100%" style="color: #000000;border: 1px solid #000000; border-collapse: collapse;">
    <thead>
        <tr>
		<th style="background-color:#CBC8C8;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 style="background-color:#CBC8C8;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;">
		 Quantity 
		</th>
		<th style="background-color:#CBC8C8;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;">
		 Total Price 
		</th>
	</tr>
    </thead>
    <tbody>';

$root_serial=1;
ksort($data);

$cat_total_total_qty_opening=0;
$cat_total_total_amount_opening=0;

foreach ($data as $key => $value) {

	$html.='<tr>';
	$html.='<td  colspan=3 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: 14pt; " >&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=3 style="background-color:#E0DBDB;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: 13pt; " >&nbsp;'.$root_serial.'.'.str_pad($root_serial_cat, 2, "0", STR_PAD_LEFT).'&nbsp;'.$cat_key.'</td>';
		$html.='</tr>';

		$serial_item=1;
		$cat_total_qty_opening=0;
		$cat_total_amount_opening=0;
		ksort($cat_value);

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

			$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: 10pt;" >&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.'&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: 10pt; " >';
			if($d_value['qty_total']){
				$html.=$d_value['qty_total'];
			}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: 10pt; " >';
			if($d_value['price_total']){
				$html.=number_format($d_value['price_total'],2,'.','');
			}else{
				$html.="-";
			}
			$html.='</td>';


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

			$html.='</tr>';

			$serial_item++;

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


		$html.='<tr>';
		$html.='<td style="background-color:#E0DBDB;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: 10pt;" >Sub-Total ('.$cat_key.')&nbsp;</td>';

		$html.='<td style="background-color:#E0DBDB;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: 10pt; " >'.$cat_total_qty_opening.'</td>';
		$html.='<td style="background-color:#E0DBDB;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: 10pt;" >'.number_format($cat_total_amount_opening,2,'.','').'</td>';

		$html.='</tr>';


		$root_serial_cat++;
	}


	$html.='<tr>';
	$html.='<td style="background-color:#CBC8C8;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: 10pt;" >Total ('.$key.')&nbsp;</td>';

	$html.='<td style="background-color:#CBC8C8;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: 10pt; " >'.$cat_total_total_qty_opening.'</td>';
	$html.='<td style="background-color:#CBC8C8;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: 10pt;" >'.number_format($cat_total_total_amount_opening,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_total_total_qty_opening=0;
	$cat_total_total_amount_opening=0;

	$root_serial++;
}


$html.='<tr>';
$html.='<td style="background-color:#E0DBDB;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: 10pt;" >Grand Total&nbsp;</td>';

$html.='<td style="background-color:#E0DBDB;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: 10pt; " >'.$cat_grand_total_qty_opening.'</td>';
$html.='<td style="background-color:#E0DBDB;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: 10pt;" >'.number_format($cat_grand_total_amount_opening,2,'.','').'</td>';

$html.='</tr>';

$html.='</tbody></table>';



$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,35,20);

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

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

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

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

$mpdf->WriteHTML($html);

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

exit;
?>