<?php  
	//session_start(); 
	include("../connect.php");

	// mobile password 
	$par1=$_GET['mobile']; //username
	$par2=$_GET['password']; //password
	
	
	date_default_timezone_set("Asia/Singapore");
	$mdate= date('Y/m/d H:i:s');
	$mdate2= date('Y-m-d H:i:s');
	$mdate1= date('d-m-Y');
	
	
	
	
	 $eve = "select * from res_user_master where userloginid='$par1' and usersecurepasword='$par2' and userstatus='Active' and userdesignation='User' limit 0,1";
	
	$re = mysqli_query($conn, $eve);

	$response = array();
	$posts = array();
	
	$result="0";
	
   if(mysqli_num_rows($re) > 0)
   {
		 while($rt = mysqli_fetch_assoc($re))
		 {
				$result="1";
				
				$cmpmid = $rt['companymid'];
				$umid = $rt['usermid'];
				
				 
				 $eve1 = "select * from res_jobwork_master where tocompanymid=$cmpmid and jobworkstatus = 'Dispatched' ORDER BY jobworkmid DESC";
				
				 $re1 = mysqli_query($conn, $eve1);
				 if(mysqli_num_rows($re1) > 0)
				   {
						 while($rt1 = mysqli_fetch_assoc($re1))
						 {
							 $jobworkmid = $rt1['jobworkmid'];
							 $jobworknofordisplay = $rt1['jobworknofordisplay'];
							$dispatchedby=$rt1['dispatchedby'];
							$jobworkdate=date("d-m-Y",strtotime($rt1['jobworkdate']));
								$fromcompanymid=$rt1['fromcompanymid'];
				$jobworktype=$rt1['jobworktype'];
				$jobworkstatus=$rt1['jobworkstatus'];
				$jobworknofordisplay=$rt1['jobworknofordisplay'];
							 
							 $companyname="";
$cpname="";
$cpmobile="";
				$eve71="select * from res_company_master where companymid=$fromcompanymid";
					$re71 = mysqli_query($conn, $eve71);
					while($rt71 = mysqli_fetch_assoc($re71))
					{
						$companyname=$rt71['companyname'];
						$cpname=$rt71['companycontactperson'];
						$cpmobile=$rt71['companycontectno'];
						
					}

$dispatchedbyname="";
				$eve72="select * from res_user_master where usermid=$dispatchedby";
					$re72 = mysqli_query($conn, $eve72);
					while($rt72 = mysqli_fetch_assoc($re72))
					{
						$dispatchedbyname=$rt72['username'];
				
						
					}
							 
							 $result="1";
							 
								$newResponse[] = array('result'=> $result,'msg'=> 'Success','jobmid'=>  $jobworkmid,'jobno'=>  $jobworknofordisplay,'cname'=>$companyname,'jdate'=>$jobworkdate,'jstatus'=>$jobworkstatus,'cperson'=>$cpname,'cpmobile'=>$cpmobile,'jdispatchedby'=>$dispatchedbyname);
								
								$posts = ["item" => $newResponse];
						 }
				   }
				   else
						{
							$result="0";
							$msg="Failure";
							
							$newResponse[] = array('result'=> $result,'msg'=> $msg);
						$posts = ["item" => $newResponse];
						}
			
		 }
		
	
		$response['posts'] = $posts;
		//echo stripslashes(json_encode( array('item' => $posts)));
		echo stripslashes(json_encode( $posts));
		
   }
   else
   {
		$result="0";
		$msg="Invalid Error";
		
		$newResponse[] = array('p1'=> $result,'p2'=> $msg);
	$posts = ["item" => $newResponse];
		$response['posts'] = $posts;
		echo stripslashes(json_encode( $posts));
   }
   
	mysqli_close($conn);
	
	
?>