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

	// mobile password 
	$par1=$_GET['mobile']; //username
	$par2=$_GET['password']; //password
	$par3=$_GET['tbarcode']; //password
	$par4=$_GET['pref_id']; //pref_id
	
	
	date_default_timezone_set("Asia/India");
	$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();
	$itemlist = array();
	$newResponse1 = array();
	
	$result="0";
	
   if(mysqli_num_rows($re) > 0)
   {
		 while($rt = mysqli_fetch_assoc($re))
		 {
				$result="1";
				
				$cmpmid = $rt['companymid'];
				$umid = $rt['usermid'];
				$updatejobworkdid = -1;
				$diffinMinutes = -100;
				
				  $eve117 = "select jobworkdid,updatedon,jobworkmid from res_jobwork_detail where trolleyqrcode='$par3' and orderdrandomid != '$par4' and trolleyreceived = '0'ORDER BY jobworkdid DESC";
				  $re117 = mysqli_query($conn, $eve117);
				 if(mysqli_num_rows($re117) > 0)
				 {
						$result="0";
						$msg="Trolley is in another job";
						$posts[] = array('result'=> $result,'msg'=> $msg);
				 }
				 else
				 { 
					$eve111 = "select * from res_item_master";
					
					 $re111 = mysqli_query($conn, $eve111);
					 if(mysqli_num_rows($re111) > 0)
					   {
							 while($rt111 = mysqli_fetch_assoc($re111))
							 {
								 $itemmid=$rt111['itemmid'];
								 $itemname=$rt111['itemname'];
								 $itemdetail=$rt111['itemdetail'];
								 $itemunit=$rt111['itemunit'];
								 
								 $itemlist[] = array('itemid'=> $itemmid,'itemname'=>$itemname,'itemdetail'=>$itemdetail,'itemunit'=>$itemunit);
							 }
					   }				
					 $eve1 = "select * from res_trolley_master where trolleyqrcode='$par3'";
					
					 $re1 = mysqli_query($conn, $eve1);
					 if(mysqli_num_rows($re1) > 0)
					   {
							 while($rt1 = mysqli_fetch_assoc($re1))
							 {
								 $trolleymid = $rt1['trolleymid'];
								 $trolleyno = $rt1['trolleynumber'];
								 $trolleyqrcode = $rt1['trolleyqrcode'];
								 $trolleytareweight = $rt1['trolleytareweight'];
								 $trolleycolor = $rt1['trolleycolor'];
								
								 
								 $result="1";
								 
								  $eve11 = "select * from res_jobwork_detail where trolleymid=$trolleymid and orderdrandomid = $par4";
					
								 $re11 = mysqli_query($conn, $eve11);
								 if(mysqli_num_rows($re11) > 0)
								   {
										 while($rt11 = mysqli_fetch_assoc($re11))
										 {
											 $jobworkdid=$rt11['jobworkdid'];
											 
											  $eve12 = "select * from res_jobworkitem_detail where jobworkdid=$jobworkdid";
											 $re12 = mysqli_query($conn, $eve12);
											  while($rt12 = mysqli_fetch_assoc($re12))
											 {
												$itemid=$rt12['itemid'];
												$itemname=$rt12['itemname'];
												$itemdetail=$rt12['itemdetail'];
												$itemqty=$rt12['itemqty'];
												 
												 $newResponse1[] = array('itemid'=> $itemid,'itemname'=>$itemname,'itemdetail'=>$itemdetail,'itemqty'=>$itemqty);
											 
											 }
										}
								   }
									$posts[] = array('result'=> $result,'msg'=> 'Success','trolleyid'=>$trolleymid,'trolleyno'=>  $trolleyno,'trolleyweight'=>  $trolleytareweight,'trolleycolor'=>  $trolleycolor,'itemlist'=>$newResponse1,'itemlistavl'=>$itemlist);

							}
					   }  
					   else
							{
								$result="0";
								$msg="QR Code not found";
								
								$posts[] = array('result'=> $result,'msg'=> $msg);
						
							}
					 }				
		 }	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
		//echo stripslashes(json_encode( $posts));
		
   }
   else
   {
		$result="0";
		$msg="Invalid User Credentials";
		
		$posts[] = array('result'=> $result,'msg'=> $msg);
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
   }
   
	mysqli_close($conn);
	
	
?>