<?php  
	include("../connect.php");
	$par1=$_GET['mobile'];
	$par2=$_GET['password'];
	$pref_id=$_GET['pref_id'];
	$tocompanyid=$_GET['hotelid'];
	
	$response = array();
	$posts = array();
		
	date_default_timezone_set("Asia/Singapore");
	$mdate= date('Y/m/d H:i:s');
	$ddatetime= date('Y-m-d H:i:s');
	$ddate= date('Y-m-d');
	$myear= date('Y');
	
    $eve1 = "SELECT * FROM res_user_master where  userloginid='$par1' and userpassword='$par2' and userstatus='Active' and userdesignation='User' limit 0,1";
	$re1 = mysqli_query($conn,$eve1);
																	
	if(mysqli_num_rows($re1) > 0)
	{
		while($rt1 = mysqli_fetch_assoc($re1))
		{
			$usermid=$rt1['usermid'];
			$fromcompanymid=$rt1['companymid'];
		}	
			$eve17 = "SELECT companyprefix FROM res_company_master where  companymid=$fromcompanymid ";
			$re17 = mysqli_query($conn,$eve17);
																			
			while($rt17 = mysqli_fetch_assoc($re17))
			{
				$companyprefix=$rt17['companyprefix'];
			}
			$maxjobworknumber = 1;
			$eve18 = "SELECT max(jobworknumber) as maxjobworknumber FROM res_jobwork_master where  fromcompanymid=$fromcompanymid ";
			$re18 = mysqli_query($conn,$eve18);
			while($rt18 = mysqli_fetch_assoc($re18))
			{
				$maxjobworknumber=$rt18['maxjobworknumber']+1;
			}
			$displayno = $companyprefix.$maxjobworknumber;
			$evenewpass116 = "select jobworkmid from res_jobwork_detail where orderdrandomid='$pref_id'";
			$renewpass116 = mysqli_query($conn, $evenewpass116);
			if(mysqli_num_rows($renewpass116) > 0)
			{
				$evenewpass = "insert into res_jobwork_master (fromcompanymid,tocompanymid,jobworkyear,jobworkprefix,jobworknumber,jobworknofordisplay,jobworkdate,jobworktype,jobworkstatus,dispatchedby,dispatchedon) values ($fromcompanymid,'$tocompanyid','$myear','$companyprefix','$maxjobworknumber','$displayno','$ddate','Outword','Dispatched','$usermid','$ddatetime')";
				$renewpass = mysqli_query($conn, $evenewpass);
				$jobworkmid = mysqli_insert_id($conn);
				
				$evenewpass111 = "update res_jobwork_detail  set jobworkmid = $jobworkmid where orderdrandomid='$pref_id'";
				$renewpass111 = mysqli_query($conn, $evenewpass111);
				
				$query1 = "select * from res_jobwork_detail where orderdrandomid='$pref_id'";
				$stmt1=mysqli_query($conn,$query1);
				while($rt11 = mysqli_fetch_assoc($stmt1))
				{
					$jobworkdid=$rt11['jobworkdid'];
					$evenewpass11 = "update res_jobworkitem_detail  set jobworkmid = $jobworkmid where jobworkdid=$jobworkdid";
					$renewpass11 = mysqli_query($conn, $evenewpass11);
				}
				$result="1";
				$msg = "Success";
			}
			else
			{
				$result="0";
				$msg = "No Trolley for the Job";
			}
			
				$posts[] = array('result'=> $result,'msg'=> $msg);
				echo stripslashes(json_encode( array('item' => $posts)));

	}
   else
   {
		$result="0";
		$msg="Failure";
		
		$posts[] = array('result'=> $result,'msg'=> $msg);
		echo stripslashes(json_encode( array('item' => $posts)));

   }
	mysqli_close($conn);
?>
