<?php
session_start();
if($_SESSION['dbName']==""){
header("location:../index.php");
}
include("config.inc.php");
include("Functions_Trans.php");
//include("Forms_DataGrid.php");
include("Forms_RMA_DataGrid.php");

$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($_SESSION['dbName'],$connection) or die("Could not find DB");

//echo"HI";exit;

$actionmode = $_GET['actionmode'];
$search_type = $_GET['search_type'];
$search_location = $_GET['search_location'];
$start = $_GET['start'];
$pagenumber = $_GET['pagenumber'];
$from_date = $_GET['from_date'];
$to_date = $_GET['to_date'];
$rmadt_id = $_GET['rmadt_id'];
$Rmadt_techquotation = $_GET['Rmadt_techquotation'];
$search_rmadt_approved = $_GET['search_rmadt_approved'];
$start_date = $_GET['start_date'];
$end_date = $_GET['end_date'];
$start_time = $_GET['start_time'];
$end_time = $_GET['end_time'];
$rmadt_approved = $_GET['rmadt_approved'];
$rmadt_operatorSpareParts = $_GET['rmadt_operatorSpareParts'];
$rmadt_qcduration = $_GET['rmadt_qcduration'];
$rmadt_qcremark = $_GET['rmadt_qcremark'];
$rmadt_operatoraditionalcomments = $_GET['rmadt_operatoraditionalcomments'];
$rmadt_qcapproved = $_GET['rmadt_qcapproved'];
$rmadt_techquotation2 = $_GET['rmadt_techquotation2'];
$rmadt_DateReceived = $_GET['rmadt_DateReceived'];
$engineerchecked = $_GET['engineerchecked'];	//if(empty($engineerchecked)) $engineerchecked = 0;
$qcchecked = $_GET['qcchecked'];	//if(empty($qcchecked)) $qcchecked = 0;
$operatorchecked = $_GET['operatorchecked'];	//if(empty($operatorchecked)) $operatorchecked = 0;
$userType = $_GET['userType'];
$user_onhand = $_GET['user_onhand'];
$recentUserAccount = $_GET['recentUserAccount'];


$start_date = explode("/", $start_date);
$start_date = $start_date[2]."-".$start_date[1]."-".$start_date[0];

$end_date = explode("/", $end_date);
$end_date = $end_date[2]."-".$end_date[1]."-".$end_date[0];

$rmadt_DateReceived = explode("/", $rmadt_DateReceived);
$rmadt_DateReceived = $rmadt_DateReceived[2]."-".$rmadt_DateReceived[1]."-".$rmadt_DateReceived[0];

if($actionmode == "searchrmalocation"){
	//echo $to_date;
	drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, "", $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
	echo "[BRK]";
}
else
	if($actionmode == "moveprev" || $actionmode == "movenext"){
		drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, "", $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
	    echo "[BRK]";
	}
	else
		if($actionmode == "searchbydate"){
	drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, "", $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
	echo "[BRK]";
}
else
	if($actionmode == "chkupdate"){
		$query_updatechk  = "update rmadt set rmadt_techcheckupdate = 1, 
		                                      rmadt_techcheckupdatedate = now()
							 where rmadt_id = '$rmadt_id'";
		$result_updatechk = mysql_query($query_updatechk, $connection);
		if($result_updatechk){
			$response = 1;
		}
		else{
			$response = 0;
		}
		echo $response;
		echo "[BRK]";
		drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
	    echo "[BRK]";
	}
	else
		if($actionmode == "editrmadt"){
			$query_select  = "SELECT rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, rmadt_techcheckupdate as ChkUpdate, rmadt_techquotation as EngQuotation, rmadt_approved, rmadt_operatorSpareParts, rmadt_qcremark, rmadt_qcduration, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as StartDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as StartDate2, date_format(rmadt_repStartDateTime, '%H:%i:%s') as StartTime, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as EndDate, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as EndDate2, date_format(rmadt_repEndDateTime, '%H:%i:%s') as EndTime, rmadt_operatoraditionalcomments, rmadt_qcapproved, date_format(rmadt_qcStartDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime, date_format(rmadt_qcEndDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime, date_format(rmadt_qcStartDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime2, date_format(rmadt_qcEndDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime2, if(rmadt_qcduration is null, '', concat(rmadt_qcduration, ' minute(s)')) as  rmadt_qcduration, if(rmadt_qcduration2 is null, '', concat(rmadt_qcduration2, ' minute(s)')) as  rmadt_qcduration2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2  
			                  from rmadt
							  where rmadt_id = '$rmadt_id'";
			$result_select = mysql_query($query_select, $connection);
			$row_select    = mysql_fetch_array($result_select);
			extract($row_select);
			//if($StartDate == "") $StartDate = date("d/m/Y");
			//if($StartTime == "") $StartTime = date("H:i:00");
			
			//if($EndDate == "") $EndDate = date("d/m/Y");
			//if($EndTime == "") $EndTime = date("H:i:59");
			
			$query_isengineer  = "SELECT user_engineer from ".$_SESSION['dbLabel'].".users where User_account='".$_SESSION['useraccount']."'";
	        //echo $query_isengineer;
	        $result_isengineer = mysql_query($query_isengineer, $connection);
            $row_isengineer    = mysql_fetch_array($result_isengineer);
            extract($row_isengineer);
			
			if($user_engineer == 1){
				$label = "<table width=100% style='margin-left: 40px; margin-bottom: 15px;'>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
				</tr>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$StartDate</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$EndDate</td>
				</tr>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
				</tr>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$StartDate2</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$EndDate2</td>
				</tr>
				</table>";
			}
			else
				if($user_engineer == 3){
					$label = "<table width=100% style='margin-left: 40px; margin-bottom: 15px;'>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 1)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 1)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration</td>
				</tr>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime2</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime2</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration2</td>
				</tr>
				</table>";
				}
				else
					if($user_engineer == 2){
						$label = "<table width=100% style='margin-left: 40px; margin-bottom: 15px;'>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Quotation (Process 1)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_techquotation</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Quotation Date (Process 1)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$ramdt_techquotationdate</td>
				</tr>
				<tr>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Quotation (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_techquotation2</td>
				<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Quotation Date (Process 2)</td>
				<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_techquotationdate2</td>
				</tr>
				</table>";
					}
			
			echo $ChkUpdate;
			echo "[BRK]";
			echo $EngQuotation;
			echo "[BRK]";
			echo $rmadt_approved;
			echo "[BRK]";
			echo $rmadt_operatorSpareParts;
			echo "[BRK]";
			echo $rmadt_qcremark;
			echo "[BRK]";
			echo $rmadt_qcduration;
			echo "[BRK]";
			echo $StartDate;
			echo "[BRK]";
			echo $StartTime;
			echo "[BRK]";
			echo $EndDate;
			echo "[BRK]";
			echo $EndTime;
			echo "[BRK]";
			echo $rmadt_operatoraditionalcomments;
			echo "[BRK]";
			echo $rmadt_qcapproved;
			echo "[BRK]";
			echo $label;
			echo "[BRK]";
			echo $rmadt_techquotation2;
			echo "[BRK]";
		}
		else
			if($actionmode == "updatequotation"){
				$query_updatequotation  = "UPDATE rmadt set rmadt_techquotation = '$Rmadt_techquotation',
															ramdt_techquotationdate = now(), 
															user_onhand='$user_onhand'
										   where rmadt_id = '$rmadt_id'";
				$result_updatequotation = mysql_query($query_updatequotation, $connection);
				//echo $query_updatequotation;
				$query_approvalStatus="SELECT rmadt_approved from rmadt where rmadt_id = '$rmadt_id'";
				$result_approvalStatus = mysql_query($query_approvalStatus, $connection);
				$row_approvalStatus    = mysql_fetch_array($result_approvalStatus);
				extract($row_approvalStatus);

				if($rmadt_approved == 1){
					$query_updateApprovalStatus  = "UPDATE rmadt set rmadt_approved = null,
															rmadt_approveddate = null
										   where rmadt_id = '$rmadt_id'";
					$result_updateApprovalStatus = mysql_query($query_updateApprovalStatus, $connection);
				}

				$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2   
						                 from rmadt 
										 where rmadt_id = '$rmadt_id'";
						$result_check = mysql_query($query_check, $connection);
                        $row_check    = mysql_fetch_array($result_check);
                        extract($row_check);
						$label = "<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
							<tr>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
							</tr>
							<tr>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
							</tr>
							<tr>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
							</tr>
							<tr>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
							<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
							<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
							</tr>
							</table>";
				echo "[BRK]";
				//echo $query_updatequotation;exit;
				echo $label;
				echo "[BRK]";
				drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, -1, -1);
			}
			else
				if($actionmode == "searchstatus"){
					drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
					echo "[BRK]";
				}
				else
					if($actionmode == "savestartendduration"){
						$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2   
						                 from rmadt 
										 where rmadt_id = '$rmadt_id'";
						$result_check = mysql_query($query_check, $connection);
                        $row_check    = mysql_fetch_array($result_check);
                        extract($row_check);		
                        
                        if($checkStartDate == ""){
							$response = 0;
						}
                        else{
							if($checkEndDate != ""){
								$response = 0;
							}
							else{
								$response = 1;
								
								$query_update = "update rmadt set rmadt_repEndDateTime = now(), 
												user_onhand = '$user_onhand' 
											where rmadt_id = '$rmadt_id'";
								$result_update = mysql_query($query_update, $connection);
								$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2   
												from rmadt 
												where rmadt_id = '$rmadt_id'";
								$result_check = mysql_query($query_check, $connection);
								$row_check    = mysql_fetch_array($result_check);
								extract($row_check);
							}
						}							
						$label = "<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
									</tr>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
									</tr>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
									</tr>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
									</tr>
								</table>";
						
						drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, 1, -1, 1);
					    //echo $query_update;
						echo "[BRK]";
						echo $response;
						echo "[BRK]";
						echo $label;
						echo "[BRK]";
					}
					else
						if($actionmode == "savestartduration"){
							$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2 
							                 from rmadt 
											 where rmadt_id = '$rmadt_id'";
						$result_check = mysql_query($query_check, $connection);
                        $row_check    = mysql_fetch_array($result_check);
                        extract($row_check);		
                        
                        if($checkStartDate != "" || $rmadt_techquotation ==""){
							$response = 0;
						}
                        else{
							$response = 1;
							$query_update = "update rmadt set rmadt_repStartDateTime = now()
										     where rmadt_id = '$rmadt_id'";
						    $result_update = mysql_query($query_update, $connection);
							$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2  
							                 from rmadt 
											 where rmadt_id = '$rmadt_id'";
							$result_check = mysql_query($query_check, $connection);
							$row_check    = mysql_fetch_array($result_check);
							extract($row_check);
							}
							$label = "<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
									</tr>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
									</tr>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
									</tr>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
									</tr>
								</table>";
							//drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
					        echo "[BRK]";
							echo $response;
							echo "[BRK]";
							echo $label;
							echo "[BRK]";
						}
						else
							if($actionmode == "startqcprocess"){
								$query_check  = "select rmadt_qcStartDateTime as checkStartDate, rmadt_qcEndDateTime as checkEndDate, date_format(rmadt_qcStartDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime, date_format(rmadt_qcEndDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime, date_format(rmadt_qcStartDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime2, date_format(rmadt_qcEndDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime2 
								                 from rmadt 
												 where rmadt_id = '$rmadt_id'";
								$result_check = mysql_query($query_check, $connection);
								$row_check    = mysql_fetch_array($result_check);
								extract($row_check);
								if($checkStartDate != ""){
									$response = 0;
								}
								else{
									$response = 1;
									$query_update  = "UPDATE rmadt set rmadt_qcStartDateTime = now()
													where rmadt_id = '$rmadt_id'";
									$result_update = mysql_query($query_update, $connection);
									$query_check  = "select rmadt_qcStartDateTime as checkStartDate, rmadt_qcEndDateTime as checkEndDate, date_format(rmadt_qcStartDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime, date_format(rmadt_qcEndDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime, date_format(rmadt_qcStartDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime2, date_format(rmadt_qcEndDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime2, if(rmadt_qcduration is null, '', concat(rmadt_qcduration, ' minute(s)')) as  rmadt_qcduration, if(rmadt_qcduration2 is null, '', concat(rmadt_qcduration2, ' minute(s)')) as  rmadt_qcduration2
														from rmadt 
														where rmadt_id = '$rmadt_id'";
									$result_check = mysql_query($query_check, $connection);
									$row_check    = mysql_fetch_array($result_check);
									extract($row_check);
								}
								$label = "<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 1)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 1)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration</td>
									</tr>
									<tr>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime2</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 2)</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime2</td>
									<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
									<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration2</td>
									</tr>
								</table>";
								//drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
								echo "[BRK]";
								echo $response;
								echo "[BRK]";
								echo $label;
								echo "[BRK]";
							}
							else
								if($actionmode == "endqcprocess"){
									$query_check  = "select rmadt_qcStartDateTime as checkStartDate, rmadt_qcEndDateTime as checkEndDate from rmadt where rmadt_id = '$rmadt_id'";
						            $result_check = mysql_query($query_check, $connection);
                                    $row_check    = mysql_fetch_array($result_check);
                                    extract($row_check);
									if($checkStartDate == ""){
							            $response = 0;
						            }
									else{
										if($checkEndDate != ""){
											$response = 0;
										}
										else{
											$response = 1;
											$query_update  = "update rmadt set rmadt_qcEndDateTime = now(),
																			   rmadt_qcduration = TIMESTAMPDIFF(Minute,  rmadt_qcStartDateTime,rmadt_qcEndDateTime)
							                                  where rmadt_id = '$rmadt_id'";
						                    $result_update = mysql_query($query_update, $connection);
											$query_check  = "select rmadt_qcStartDateTime as checkStartDate, rmadt_qcEndDateTime as checkEndDate, date_format(rmadt_qcStartDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime, date_format(rmadt_qcEndDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime, date_format(rmadt_qcStartDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime2, date_format(rmadt_qcEndDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime2, if(rmadt_qcduration is null, '', concat(rmadt_qcduration, ' minute(s)')) as  rmadt_qcduration, if(rmadt_qcduration2 is null, '', concat(rmadt_qcduration2, ' minute(s)')) as  rmadt_qcduration2
								                 from rmadt 
												 where rmadt_id = '$rmadt_id'";
						$result_check = mysql_query($query_check, $connection);
                        $row_check    = mysql_fetch_array($result_check);
                        extract($row_check);
											
										}
									}
									$label = "<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
												<tr>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 1)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 1)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration</td>
												</tr>
												<tr>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 2)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime2</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 2)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime2</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration2</td>
												</tr>
											</table>";
									//drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
					                echo "[BRK]";
							        echo $response;
							        echo "[BRK]";
									echo $label;
							        echo "[BRK]";
								}
					else
						if($actionmode == "submitapproval"){
							$query_update = "update rmadt set ";
							if($rmadt_approved == ""){
								$query_update = $query_update." rmadt_approved = null, ";
							}
							else{
							$query_update = $query_update." rmadt_approved = '$rmadt_approved', ";
							}
							$query_update = $query_update." rmadt_operatorSpareParts = '$rmadt_operatorSpareParts',
															rmadt_operatoraditionalcomments = '$rmadt_operatoraditionalcomments', 
															user_onhand = '$user_onhand'";
							if($rmadt_approved == 1){
								$query_update = $query_update.", rmadt_approveddate = now()";
							}
							else{
								$query_update = $query_update.", rmadt_approveddate = null";
							}
							$query_update = $query_update." where rmadt_id = '$rmadt_id'";
							$result_update = mysql_query($query_update, $connection);
							drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, 1, -1, $operatorchecked);
					        echo "[BRK]";							
						}
						else
							if($actionmode == "submitqc"){
								$query_chk  = "select rmadt_qcEndDateTime as chkQcEndDate from rmadt where rmadt_id = '$rmadt_id'";
								$result_chk = mysql_query($query_chk, $connection); 
								$row_chk    = mysql_fetch_array($result_chk);
								extract($row_chk);
								
								if($chkQcEndDate == ""){
									$response = 0;
								}
								else{
									$response = 1;
								    $query_update = "update rmadt set rmadt_qcremark = '$rmadt_qcremark',";
									if($rmadt_qcapproved == ""){
										$query_update = $query_update." rmadt_qcapproved = null";
									}
									else{
							        	$query_update = $query_update." rmadt_qcapproved = '$rmadt_qcapproved'";
									}
								    if($rmadt_qcapproved == 1){					
								      $query_update = $query_update." ,rmadt_qcapproveddate = now() ";
								    }
								    $query_update = $query_update."	where rmadt_id = '$rmadt_id'";
								    $result_update = mysql_query($query_update, $connection);
								}
								
								drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, 1, $qcchecked, 1);
								echo "[BRK]";
								//echo $query_update;
								echo $response;
								echo "[BRK]";
							}
							else
								if($actionmode == "startengprocess2"){
									$query_chk  = "select rmadt_repStartDateTime2 as chkStartDate, rmadt_techquotation2 from rmadt where rmadt_id = '$rmadt_id'";
									$result_chk = mysql_query($query_chk, $connection); 
									$row_chk    = mysql_fetch_array($result_chk);
									extract($row_chk);
									
									if($chkStartDate != ""){
										$response = 0;
									}
									else
										if($rmadt_techquotation2 == ""){
											$response = 0;
										}
									else{
										$response = 1;
										$query_update  = "UPDATE rmadt set rmadt_repStartDateTime2 = now() where rmadt_id = '$rmadt_id'";
										$result_update = mysql_query($query_update, $connection);
										$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2 
							                 from rmadt 
											 where rmadt_id = '$rmadt_id'";
						                $result_check = mysql_query($query_check, $connection);
                                        $row_check    = mysql_fetch_array($result_check);
                                        extract($row_check);
                                        										
									}
									$label = "<table width=100% style='margin-left: 40px; margin-bottom: 15px;'>
											<tr>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
											</tr>
											<tr>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
											</tr>
											<tr>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
											</tr>
											<tr>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
											<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
											<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
											</tr>
										</table>";
									//drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
					                echo "[BRK]";
								    echo $response;
								    echo "[BRK]";
									echo $label;
									echo "[BRK]";
								}
								else
								if($actionmode == "endengprocess2"){
									$query_chk  = "select rmadt_repStartDateTime2 as chkStartDate from rmadt where rmadt_id = '$rmadt_id'";
									$result_chk = mysql_query($query_chk, $connection); 
									$row_chk    = mysql_fetch_array($result_chk);
									extract($row_chk);
									
									if($chkStartDate == ""){
										$response = 0;
									}
									else{
										$response = 1;
										$query_update  = "update rmadt set rmadt_repEndDateTime2 = now(), user_onhand = '$user_onhand' where rmadt_id = '$rmadt_id'";
										$result_update = mysql_query($query_update, $connection);
										$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2 
							                 from rmadt 
											 where rmadt_id = '$rmadt_id'";
						                $result_check = mysql_query($query_check, $connection);
                                        $row_check    = mysql_fetch_array($result_check);
                                        extract($row_check);
                                        										
									}
									$label = "<table width=100% style='margin-left: 40px; margin-bottom: 15px;'>
												<tr>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
												</tr>
												<tr>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
												</tr>
												<tr>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
												</tr>
												<tr>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
												<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
												<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
												</tr>
											</table>";
									drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, 1, 1);
					                echo "[BRK]";
								    echo $response;
								    echo "[BRK]";
									echo $label;
									echo "[BRK]";
								}
								else
									if($actionmode == "startqcprocess2"){
										$query_check  = "select rmadt_qcStartDateTime2 as checkStartDate, rmadt_qcEndDateTime2 as checkEndDate, rmadt_repStartDateTime2, rmadt_repEndDateTime2, rmadt_qcapproved from rmadt where rmadt_id = '$rmadt_id'";
						                $result_check = mysql_query($query_check, $connection);
                                        $row_check    = mysql_fetch_array($result_check);
                                        extract($row_check);
										if($checkStartDate != ""){
											$response = 0;
										}
										else
										if($rmadt_qcapproved == 0 && $rmadt_repEndDateTime2 != ""){
											$response = 1;
											$query_update  = "update rmadt set rmadt_qcStartDateTime2 = now()
											                  where rmadt_id = '$rmadt_id'";
											$result_update = mysql_query($query_update, $connection);
											$query_check  = "select rmadt_qcStartDateTime as checkStartDate, rmadt_qcEndDateTime as checkEndDate, date_format(rmadt_qcStartDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime, date_format(rmadt_qcEndDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime, date_format(rmadt_qcStartDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime2, date_format(rmadt_qcEndDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime2, if(rmadt_qcduration is null, '', concat(rmadt_qcduration, ' minute(s)')) as  rmadt_qcduration, if(rmadt_qcduration2 is null, '', concat(rmadt_qcduration2, ' minute(s)')) as  rmadt_qcduration2
								                 from rmadt 
												 where rmadt_id = '$rmadt_id'";
											$result_check = mysql_query($query_check, $connection);
											$row_check    = mysql_fetch_array($result_check);
											extract($row_check);
										}
										else{
											$response = 0;
										}
										$label = "<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
													<tr>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 1)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 1)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration</td>
													</tr>
													<tr>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 2)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime2</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 2)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime2</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration2</td>
													</tr>
												</table>";
										//drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
					                    echo "[BRK]";
								        echo $response;
								        echo "[BRK]";
										echo $label;
										echo "[BRK]";
									}
			                     else
									if($actionmode == "endqcprocess2"){
										$query_check  = "select rmadt_qcStartDateTime2 as checkStartDate, rmadt_qcEndDateTime2 as checkEndDate, rmadt_repStartDateTime2, rmadt_repEndDateTime2, rmadt_qcapproved from rmadt where rmadt_id = '$rmadt_id'";
						                $result_check = mysql_query($query_check, $connection);
                                        $row_check    = mysql_fetch_array($result_check);
                                        extract($row_check);
									if($checkStartDate == "" || $checkEndDate != ""){
											$response = 0;
										}
										else{
											$response = 1;
											$query_update  = "update rmadt set rmadt_qcEndDateTime2 = now(),
											                                   rmadt_qcduration2 = TIMESTAMPDIFF(Minute,  rmadt_qcStartDateTime2,rmadt_qcEndDateTime2)
											                  where rmadt_id = '$rmadt_id'";
											$result_update = mysql_query($query_update, $connection);
											$query_check  = "select rmadt_qcStartDateTime as checkStartDate, rmadt_qcEndDateTime as checkEndDate, date_format(rmadt_qcStartDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime, date_format(rmadt_qcEndDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime, date_format(rmadt_qcStartDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime2, date_format(rmadt_qcEndDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime2, if(rmadt_qcduration is null, '', concat(rmadt_qcduration, ' minute(s)')) as  rmadt_qcduration, if(rmadt_qcduration2 is null, '', concat(rmadt_qcduration2, ' minute(s)')) as  rmadt_qcduration2
								                 from rmadt 
												 where rmadt_id = '$rmadt_id'";
											$result_check = mysql_query($query_check, $connection);
											$row_check    = mysql_fetch_array($result_check);
											extract($row_check);
										}
										$label = "<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
													<tr>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 1)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 1)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration</td>
													</tr>
													<tr>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 2)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime2</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 2)</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime2</td>
													<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
													<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration2</td>
													</tr>
												</table>";
										drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, 1, $qcchecked, 1);
					                    echo "[BRK]";
								        echo $response;
								        echo "[BRK]";
										echo $label;
										echo "[BRK]";
									}
									else
										if($actionmode == "addquotation2"){
											$query_check  = "select rmadt_repEndDateTime, rmadt_qcapproved
											                 from rmadt
															 where rmadt_id = '$rmadt_id'";
											$result_check = mysql_query($query_check, $connection);
											$row_check    = mysql_fetch_array($result_check);
											extract($row_check);
											if($rmadt_qcapproved != 0 || $rmadt_repEndDateTime == ""){
												$response = 0;
											}
											else{
												$response = 1;
												$query_update  = "UPDATE rmadt set rmadt_techquotation2 = '$rmadt_techquotation2',
																				   rmadt_techquotationdate2 = now(), 
																				   user_onhand = '$user_onhand' 
																  where rmadt_id = '$rmadt_id'";
												$result_update = mysql_query($query_update, $connection);
												$result_update = mysql_query($query_update, $connection);
											    $query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2 
							                 from rmadt 
											 where rmadt_id = '$rmadt_id'";
						                $result_check = mysql_query($query_check, $connection);
                                        $row_check    = mysql_fetch_array($result_check);
                                        extract($row_check);
											}
											$label = "<table width=100% style='margin-left: 40px; margin-bottom: 15px;'>
														<tr>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
														</tr>
														<tr>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
														</tr>
														<tr>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
														</tr>
														<tr>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
														<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
														<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
														</tr>
													</table>";
											echo $response;
											echo "[BRK]";
											echo $label;
											echo "[BRK]";
											//drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);
											echo "[BRK]";
										}
										else
											if($actionmode == "receivermadt"){
												$query_check  = "select rmadt_approved, rmadt_qcapproved
												                 from rmadt
																 where rmadt_id = '$rmadt_id'";
												$result_check = mysql_query($query_check, $connection);
												$row_check    = mysql_fetch_array($result_check);
												extract($row_check);
												if($rmadt_approved == 0 || $rmadt_qcapproved == 1){
													$response = 1;
													$query_update  = "update rmadt set rmadt_receivedby = '".$_SESSION['useraccount']."',
													                                   rmadt_DateReceived = '$rmadt_DateReceived'
																	 where rmadt_id = '$rmadt_id'";
													$result_update = mysql_query($query_update, $connection);
												}
												else{
													$response = 0;
												}
												echo $response;
												echo "[BRK]";
												drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, 1, 1, $operatorchecked);
											    echo "[BRK]";
											}
                                            else
                                                if ($actionmode == "searchChecked") {
                                                    echo "[BRK]";
                                                   	drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);	
												   	echo "[BRK]";
												} 
												else
													if ($actionmode == "searchQcChecked") {
														echo "[BRK]";
														drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);	
														echo "[BRK]";
													}
													else
														if ($actionmode == "searchOperatorChecked") {
															echo "[BRK]";
															drawRMALocation($connection, $search_type, $search_location, $start, $pagenumber, $from_date, $to_date, $rmadt_id, $search_rmadt_approved, $engineerchecked, $qcchecked, $operatorchecked);	
															echo "[BRK]";
														}
														else
															if($actionmode == "showAllocators"){
																echo "[BRK]";
																drawListOfUsers($connection, $userType);	
																echo "[BRK]";
															}
															else
																if($actionmode == "checkOperator"){
																	$query_operator = "SELECT User_Name as userName, User_account as userAccount from ".$_SESSION['dbLabel'].".users where user_engineer='2'";
																	$result_operator = mysql_query($query_operator, $connection);
																	$label = "<fieldset>
																				<legend>Quotation Process 1</legend>
																				<select name='operator' id='operator' style='width: 200px; height: 25px;'>";
																	while($row_operator = mysql_fetch_array($result_operator)){
																		extract($row_operator);
																		$label .= "<option value='$userAccount'>$userName</option>";
																	}

																	$query_check  = "select rmadt_techquotation, date_format(ramdt_techquotationdate, '%d/%m/%Y %H:%i:%s') as ramdt_techquotationdate, date_format(rmadt_repStartDateTime, '%d/%m/%Y %H:%i:%s') as checkStartDate, date_format(rmadt_repEndDateTime, '%d/%m/%Y %H:%i:%s') as checkEndDate, date_format(rmadt_repStartDateTime2, '%d/%m/%Y %H:%i:%s') as checkStartDate2, date_format(rmadt_repEndDateTime2, '%d/%m/%Y %H:%i:%s') as checkEndDate2, rmadt_techquotation2, date_format(rmadt_techquotationdate2, '%d/%m/%Y %H:%i:%s') as rmadt_techquotationdate2   
																					from rmadt 
																					where rmadt_id = '$rmadt_id'";
																	$result_check = mysql_query($query_check, $connection);
																	$row_check    = mysql_fetch_array($result_check);
																	extract($row_check);
																	
																	if($search_rmadt_approved != 2)
																		$label .= "</select>
																				Quotation <input type='text' name='Rmadt_techquotation' id='Rmadt_techquotation' value='$rmadt_techquotation' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"updateQuotation()\"><span><span>Add Quotation</span></span></button><br>
																				</fieldset>
																				<table width=100% style='margin-left: 40px; margin-bottom: 15px;'>
																					<tr>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation</td>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$ramdt_techquotationdate</td>
																					</tr>
																					<tr>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 1)</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate</td>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 1)</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate</td>
																					</tr>
																					<tr>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation (Process 2)</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotation2</td>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Quotation Date (Process 2)</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$rmadt_techquotationdate2</td>
																					</tr>
																					<tr>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>Start Date & Time (Process 2)</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkStartDate2</td>
																					<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=25%>End Date & Time (Process 2)</td>
																					<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=25%>$checkEndDate2</td>
																					</tr>
																				</table>";
																	else
																		$label .= "</select>
																				Quotation 2 <input type='text' name='Rmadt_techquotation2' id='Rmadt_techquotation2' style='width: 500px' />&nbsp;&nbsp;<button onclick=\"addQuotation2()\"><span><span>Add Quotation</span></span></button><br>";
																	echo "[BRK]";
																	//echo $query_oldQuotation;exit;
																	echo $label;	
																	echo "[BRK]";
																}
																else
																	if($actionmode == "checkQC"){
																		$query_QC = "SELECT User_Name as userName, User_account as userAccount from ".$_SESSION['dbLabel'].".users where user_engineer='3'";
																		$result_QC = mysql_query($query_QC, $connection);
																		$label = "<select name='qc' id='qc' style='width: 200px; height: 25px;'>";
																		while($row_QC = mysql_fetch_array($result_QC)){
																			extract($row_QC);
																			$label .= "<option value='$userAccount'>$userName</option>";
																		}

																		$query_check  = "select rmadt_qcStartDateTime as checkStartDate, rmadt_qcEndDateTime as checkEndDate, date_format(rmadt_qcStartDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime, date_format(rmadt_qcEndDateTime, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime, date_format(rmadt_qcStartDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcStartDateTime2, date_format(rmadt_qcEndDateTime2, '%d/%m/%Y %H:%i:%s') as rmadt_qcEndDateTime2, if(rmadt_qcduration is null, '', concat(rmadt_qcduration, ' minute(s)')) as  rmadt_qcduration, if(rmadt_qcduration2 is null, '', concat(rmadt_qcduration2, ' minute(s)')) as  rmadt_qcduration2
																								from rmadt 
																								where rmadt_id = '$rmadt_id'";
																		$result_check = mysql_query($query_check, $connection);
																		$row_check    = mysql_fetch_array($result_check);
																		extract($row_check);
																		if($search_rmadt_approved!=2)
																			$label .= "</select>
																					<button onclick=\"startQcProcess()\"><span><span>Start QC</span></span></button><button onclick=\"endQcProcess()\"><span><span>End Process</span></span></button>";
																		else
																			$label .= "</select>
																					<button onclick=\"startEngProcess2()()\"><span><span>Start 2nd QC</span></span></button><button onclick=\"endEngProcess2()\"><span><span>End 2nd Process</span></span></button>";
																		$label .=	"<table width=90% style='margin-left: 40px; margin-bottom: 15px;'>
																						<tr>
																						<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 1)</td>
																						<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime</td>
																						<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 1)</td>
																						<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime</td>
																						<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
																						<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration</td>
																						</tr>
																						<tr>
																						<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Start Date & Time (Process 2)</td>
																						<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcStartDateTime2</td>
																						<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>End Date & Time (Process 2)</td>
																						<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcEndDateTime2</td>
																						<td style='font-weight: bold; font-size: 14px; background: #d3d3d3; padding: 5px;' width=16.67%>Duration</td>
																						<td style='font-weight: bold; font-size: 14px; padding: 5px;' width=16.67%>$rmadt_qcduration2</td>
																						</tr>
																					</table>";
																		echo "[BRK]";
																		echo $label;	
																		echo "[BRK]";
																	}
																	else 
																		if($actionmode == "bypass"){
																			$query_techQuot = "SELECT rmadt_techquotation as techq from rmadt where rmadt_id = $rmadt_id";
																			$result_techQuot = mysql_query($query_techQuot, $connection);
																			$row_techQuot = mysql_fetch_array($result_techQuot);
																			extract($row_techQuot);
																			if($techq=="")
																				echo "0";
																			else{
																				$query_bypass = "UPDATE rmadt SET rmadt_techquotation=CONCAT($techq,', bypassed'), bypass='1', bypassUser='$recentUserAccount', bypassDate=now() where rmadt_id = $rmadt_id";
																				$result_bypass = mysql_query($query_bypass, $connection);
																				$query_opRecieved = "UPDATE rmadt set rmadt_operatorrecieved = '1', rmadt_operatorrecieved_date = now() where rmadt_id = $rmadt_id";
																				$result_opRecieved = mysql_query($query_oprecieved, $connection);
																				//echo $query_bypass;
																				echo "1";
																			}
																			echo "[BRK]";
																		}
																	
?>