<style>
	th {
		border-bottom: 1px solid #EAEAEA !important;
	}
	hr {
		margin-bottom: 0;
	}
	
</style>
<?php
	extract($_REQUEST);
	$from_month = date("m-Y",strtotime($from_date));
	$to_month = date("m-Y",strtotime($to_date));
	$from_date_to_show = date("F, Y", strtotime($from_date));
	$to_date_to_show = date("F, Y", strtotime($to_date));
	
	$curr_date = date("j F, Y");
	//$daterange = $from_date.' to '.$to_date;
	include("../../php_crud/my_class.php");
	$obj = new my_class();
	$header = '<table style="width: 1400px" border="0" cellpadding="0" cellspacing="0" id="station_tbl" class="table table-bordered table-striped table-bordered table-hover">
				<tr>
					<td style="text-align: center; width: 15%">
						<img src="../../asset/custom/site_images/BWDB-LOGO.jpg" width="100px" />
					</td>
					<td style="text-align: center; width: 70%; font-size: 20px;">
						<h3 style="text-align: center;">BWCSRP COMPONENT B: SHEWS</h3>
						<h3 style="text-align: center;">BANGLADESH WATER DEVELOPMENT BOARD (BWDB)</h3>
						<h5>Ground Water Monthly Maximun, Minimum & Average Data From '.$from_date_to_show.' to '.$to_date_to_show.'</h5>
					</td>
					<td style=" width: 15%; font-size: 11px;">
						<table style="width: 100%;" border="0" cellpadding="0" cellspacing="0" class="table table-bordered table-striped table-bordered table-hover">
							<tr>
								<td style="font-size: 13px; border-right: 1px solid #CCC">
									<p>Legend: <br>
									<br>
									1. F=Functioning<br>
									2. NF=Non Functioning<br>
									3. PH=Parapet Height<br>
									4. m=meter<br>
									5. inc=inches
									</p>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			<hr />
			<table style="width: 1400px" border="0" cellpadding="0" cellspacing="0" id="station_tbl" class="table table-bordered table-striped table-bordered table-hover">
				<tr>
					<td style="text-align: left; width: 15%"><b> Report No: </b></td>
					<td style="text-align: center; width: 70%; font-size: 20px;"></td>
					<td style=" width: 15%; font-size: 16px; text-align: right;"><b>Date: </b>'.$curr_date.'</td>
				</tr>
			</table><br />';
			
	
	$html .= '<table style="width: 1500px" border="0" cellpadding="0" cellspacing="0" id="station_tbl3" class="table table-bordered table-striped table-bordered table-hover" style="font-size: 11px !important;">
    <thead>
        <tr style="">
            <th style="padding: 5px;border-top: 1px solid #CCC;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">SL.</th>
			<th style="width: 150px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">New Id (Station)</th>
			<th style="width: 150px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">Old Id (Station)</th>
			<th style="width: 150px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">District</th>
			<th style="width: 150px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">Upazila</th>
			<th style="width: 150px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">Month</th>
			<th style="width: 90px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">Min WL (m)</th>
			<th style="width: 90px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">Max WL (m)</th>
			<th style="width: 90px;padding: 5px;border-top: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;">AVG WL (m)</th>			
        </tr>
    </thead><tbody>';
	$table_name = "AQUATIC.TBLGWH_BASICINFOMST@aquatic227 ST LEFT JOIN
                      AQUATIC.TBLGWH_SUBDIVISIONINFO@aquatic227 SDV ON ST.SUBDIVISIONCODE = SDV.ID LEFT JOIN
                      AQUATIC.TBLGWH_DIVISIONINF@aquatic227 DIV ON ST.DIVISIONCODE = DIV.ID LEFT JOIN
                      AQUATIC.TBLGWH_ZONEINFO@aquatic227 ZN ON ST.ZONECODE = ZN.ID LEFT JOIN
                      AQUATIC.TBLGWH_DISTRICTINFO@aquatic227 DT ON ST.DISTRICTCODE = DT.ID LEFT JOIN
		      AQUATIC.TBLGWH_UPAZILA@aquatic227 UPZ ON ST.UPAZILACODE = UPZ.ID LEFT JOIN
                      AQUATIC.TBLGWH_GWHDATADTL@aquatic227 GWT ON ST.NEW_ID = GWT.STATIONID";
	$column = "TO_CHAR(GWT.DATETIME,'RRRR') YEAR,TO_CHAR(GWT.DATETIME,'MM') MONTH,DT.DISTRICTNAME,UPZ.UPAZILANAME,ST.NEW_ID,ST.OLD_ID,ST.SENSORTYPE, MAX(GWT.WATERLEVEL) MAX_WL, MIN(GWT.WATERLEVEL) MIN_WL, AVG(GWT.WATERLEVEL) AVG_WL";
	if($zone_id!=''){
		$where_cond2 = "ZN.ID='$zone_id' AND GWT.DATETIME BETWEEN TO_DATE('$from_month','MM-YYYY') AND TO_DATE('$to_month','MM-YYYY') AND WATERLEVEL IS NOT NULL";
	} else if($division_id!=''){
		$where_cond2 = "DIV.ID='$division_id' AND GWT.DATETIME BETWEEN TO_DATE('$from_month','MM-YYYY') AND TO_DATE('$to_month','MM-YYYY') AND WATERLEVEL IS NOT NULL";
	} else if($subdivision_id!=''){
		$where_cond2 = "SDV.ID='$subdivision_id' AND GWT.DATETIME BETWEEN TO_DATE('$from_month','MM-YYYY') AND TO_DATE('$to_month','MM-YYYY') AND WATERLEVEL IS NOT NULL";
	} else if($district_id!=''){
		$where_cond2 = "DT.ID='$district_id' AND GWT.DATETIME BETWEEN TO_DATE('$from_month','MM-YYYY') AND TO_DATE('$to_month','MM-YYYY') AND WATERLEVEL IS NOT NULL";
	} else if($problem_type_id!=''){
		$where_cond2 = "PT.ID='$problem_type_id' AND GWT.DATETIME BETWEEN TO_DATE('$from_month','MM-YYYY') AND TO_DATE('$to_month','MM-YYYY') AND WATERLEVEL IS NOT NULL";
	} else if($signal_strength_id!=''){
		$where_cond2 = "SR.ID='$signal_strength_id' AND GWT.DATETIME BETWEEN TO_DATE('$from_month','MM-YYYY') AND TO_DATE('$to_month','MM-YYYY') AND WATERLEVEL IS NOT NULL";
	} else {
		$where_cond2 = "GWT.DATETIME BETWEEN TO_DATE('$from_month','MM-YYYY') AND TO_DATE('$to_month','MM-YYYY') AND WATERLEVEL IS NOT NULL";
	}
	
	$group_by = "ST.NEW_ID,ST.OLD_ID,ST.SENSORTYPE,DT.DISTRICTNAME,UPZ.UPAZILANAME,TO_CHAR(GWT.DATETIME,'RRRR'),TO_CHAR(GWT.DATETIME,'MM')";
	//$where_cond2 = "GWT.DATETIME BETWEEN TO_DATE('$from_date','DD-MM-YYYY') AND TO_DATE('$to_date','DD-MM-YYYY') GROUP BY ST.NEW_ID,ST.OLD_ID,ST.SENSORTYPE,DT.DISTRICTNAME, UPZ.UPAZILANAME,GWT.DATETIME  ORDER BY ST.NEW_ID,DATETIME DESC ";
	$row=$obj->View_all_data_row_column_By_Cond($table_name,$column,$where_cond2,$group_by);
	$i = 1;
	foreach($row AS $index=>$val){
		$datetime = $val['YEAR']."-".$val['MONTH'];
		
		//$id=$val['ID'];
		/*$html .="<tr>  
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$i."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'></td>
				
			</tr>";*/
		$html .="<tr>  
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$i."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $val['NEW_ID']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $val['OLD_ID']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $val['DISTRICTNAME']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $val['UPAZILANAME']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $datetime."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $val['MIN_WL']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $val['MAX_WL']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". number_format($val['AVG_WL'],3)."</td>
			</tr>";
		$i++;
	}
	$html .= '</tbody></table>';
	$footer = '<table style="width: 1400px;" border="0" cellpadding="0" cellspacing="0" id="station_tbl_footer" class="table table-bordered table-striped table-bordered table-hover">
				<tr>
					<td style="text-align: left; width: 15%"><b> Prepared By </b></td>
					<td style="text-align: center; width: 70%; font-size: 20px;"></td>
					<td style=" width: 15%; font-size: 16px; text-align: right;"><b>Approved By</b></td>
				</tr></table>
			<br />';
//==============================================================
//==============================================================
//==============================================================



include("../../asset/mpdf/mpdf.php");
$mpdf=new mPDF('c','A4-L','','',10,10,45,35,10,13); 
$mpdf->simpleTables = true;
$mpdf->packTableData = true;
$mpdf->keep_table_proportions = TRUE;
$mpdf->shrink_tables_to_fit=1;
$mpdf->SetDisplayMode('fullpage');
$mpdf->SetHTMLHeader($header);
$mpdf->SetHTMLFooter($footer);
$mpdf->list_indent_first_level = 0;	// 1 or 0 - whether to indent the first level of a list

// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyletables.css');
$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text

$mpdf->WriteHTML($html,2);

$mpdf->Output('mpdf.pdf','I');

//==============================================================
//==============================================================
//==============================================================


?>