<style>
	th {
		border-bottom: 1px solid #EAEAEA !important;
	}
	
</style>
<?php
	extract($_REQUEST);
	include("../../php_crud/my_class.php");
	$obj = new my_class();
	$header = '<table style="font-size: 22px;width: 1000px" 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: 73%;">
						<h3 style="text-align: center;">BWCSRP COMPONENT B: SHEWS</h3>
						<h3 style="text-align: center;">BANGLADESH WATER DEVELOPMENT BOARD (BWDB)</h3>
						<h5>Maintenance History Report of Station: '.$station_id.'</h5>
					</td>
					<td style=" width: 12%; font-size: 12px;">
						<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: 14px; 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>
			<br />
			<br />
	';
	echo $header;
	$table_name =  "AQUATIC.TBLPGCB_MAINTENANCEHISTORY@aquatic227";
	if($device_id!=""){
		$where_cond = "DEVICENAME=$device_id AND SUBSTATIONID='$station_id'";
	} else {
		$where_cond = "SUBSTATIONID='$station_id'";
	} 
	$row=$obj->View_all_data_row_column_By_Cond($table_name,' * ',$where_cond);
	$i = 1;
	
	foreach($row AS $index=>$val){
		$station_id2 = $val['SUBSTATIONID'];
		$station_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_BASICINFOMST@aquatic227","NEW_ID='$station_id2'");
		$func_status=$station_info['STATUS'];
		if($func_status==1){
			$func_status='Functional';
		} else if($func_status==2){
			$func_status='Non Functional';
		}
		
		$division_id2 = $station_info['DIVISIONCODE'];
		$subdivision_id2 = $station_info['SUBDIVISIONCODE'];
		$district_id2 = $station_info['DISTRICTCODE'];
		$upazila_id2 = $station_info['UPAZILACODE'];
		$zone_id2 = $station_info['ZONECODE'];
		$division_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_DIVISIONINFO@aquatic227","ID='$division_id2'");
		$subdivision_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_SUBDIVISIONINFO@aquatic227","ID='$subdivision_id2'");
		$district_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_DISTRICTINFO@aquatic227","ID='$district_id2'");
		$upazila_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_UPAZILA@aquatic227","ID='$upazila_id2'");
		$zone_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_ZONEINFO@aquatic227","ID='$zone_id2'");
		$device_id = $val['DEVICENAME'];
		$device_info = $obj->Details_By_Cond("AQUATIC.TBLGWH_DEVICENAME@aquatic227","ID=$device_id");
		if($val['PREVSOLUTIONHIST']=='Y'){
			$prev_sol_hist = "YES";
		} else if($val['PREVSOLUTIONHIST']=='N'){
			$prev_sol_hist = "NO";
		}
		if($val['PROBLEMSTATUS']=='Y'){
			$problem_status = "YES";
		} else if($val['PROBLEMSTATUS']=='N') {
			$problem_status = "NO";
		}
		
		
		$html .= '<table style="width: 100%" border="0" cellpadding="0" cellspacing="0" id="station_tbl" class="table table-bordered table-striped table-bordered table-hover" style="font-size: 11px !important;">
			<tbody>';
		$html .="
			<tr>  
				<td style='width: 15%; padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Zone</td>
				<td colspan='2' style='width: 35%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$zone_info['ZONENAME']."</td>
				<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Division</td>
				<td colspan='2' style='width: 35%; padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $division_info['DIVISIONNAME']."</td>
			</tr>
			<tr>  
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Sub Division</td>
				<td colspan='2' style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$subdivision_info['SUBDIVISIONNAME']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>District</td>
				<td colspan='2' style=' padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $district_info['DISTRICTNAME']."</td>
			</tr>
			<tr>
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>New ID</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $station_info['NEW_ID']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Old ID</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $station_info['OLD_ID']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Device Sl.</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $station_info['DEVICESLNO']."</td>
			</tr>
			<tr>  
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Station Name/Upazila</td>
				<td colspan='2' style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$upazila_info['UPAZILANAME']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Station Status</td>
				<td colspan='2' style=' padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$func_status."</td>
			</tr>
			<tr>  
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Address </td>
				<td colspan='5' style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$station_info['ADDRESSDETAIL']."</td>
			</tr>
			<tr>
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Lattitude</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $station_info['LATITUDE']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Longitude</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $station_info['LONGITUDE']."</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>PROBLEM TYPE</td>
				<td style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $station_info['PROBLEMTYPE']."</td>
			</tr>
			<tr>  
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Remarks </td>
				<td colspan='5' style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$station_info['REMARKS']."</td>
			</tr>
			<tr>  
				<td style='padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Note </td>
				<td colspan='5' style='padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$station_info['NOTE']."</td>
			</tr>
		</table><br /><br />";
		$html .='<table style="width: 1000px" border="0" cellpadding="0" cellspacing="0" id="station_tbl" class="table table-bordered table-striped table-bordered table-hover" style="font-size: 11px !important;">';
		
		$html .="
			<tbody>
				<tr>
					<td style='width: 15%;padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Visited By</td>
					<td colspan='2' style='width: 35%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". $val['MAINTENANCEBY']."</td>
					<td style='width: 15%;padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Visited Date</td>
					<td colspan='2' style='width: 35%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>". date("j F, Y", strtotime($val['VISITDATE']))."</td>
				</tr>
				<tr>
					<td style='width: 16%;padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Device Name</td>
					<td style='width: 17%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$device_info['DEVICENAME']."</td>
					<td style='width: 16%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Is Problem Solved</td>
					<td style='width: 17%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$problem_status."</td>
					<td style='width: 16%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Is History Available</td>
					<td style='width: 17%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$prev_sol_hist."</td>
				</tr>
				<tr>
					<td style='width: 15%;padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Note Details</td>
					<td colspan='2' style='width: 35%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$val['NOTEDETAIL']."</td>
					<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Remarks</td>
					<td colspan='2' style='width: 35%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$val['REMARKS']."</td>
				</tr>
				
			</tbody>
		</table><br /><br />
			";
			$html .='<table style="width: 1000px" border="0" cellpadding="0" cellspacing="0" id="station_tbl" class="table table-bordered table-striped table-bordered table-hover" style="font-size: 11px !important;">';
			$html .="
					<thead>
						<tr>
							<td style='width: 15%;padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Sl No.</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Date</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Type of Problem/Fault</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Action Taken</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Present Status</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>Comments</td>
						</tr></thead><tbody>";
			$masterid = $val['ID'];
			$table_name_dtl =  "AQUATIC.TBLPGCB_MAINTENANCEHISTDTL@aquatic227";
			$where_cond_dtl = "PROBLEMMASTERID='$masterid'";
			$row_dtl=$obj->View_all_data_row_column_By_Cond($table_name_dtl,' * ',$where_cond_dtl);
			$m=1;
			foreach($row_dtl AS $index=>$value){
				$html .="<tr>
							<td style='width: 15%;padding: 5px;border-left: 1px solid #CCC;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$m."</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".date("j F, Y",strtotime($value['DATETIME']))."</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$value['PROBLEMTYPE']."</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$value['ACTIONTAKEN']."</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$value['PRESENTSTATUS']."</td>
							<td style='width: 15%;padding: 5px;border-right: 1px solid #CCC;border-bottom: 1px solid #CCC;'>".$value['REMARKS']."</td>
						</tr>";
						$m++;
			}
			$html .='</tbody></table>';
			echo $html;

	$i++;
	}
	
	
//==============================================================
//==============================================================
//==============================================================

include("../../asset/mpdf/mpdf.php");
$mpdf=new mPDF('c','A4-P','','',10,10,40,25,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->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');

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


?>