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

	// mobile password 
	$par1=$_GET['mobile']; //username
	$par2=$_GET['password']; //password
	$par3=$_GET['tbarcode']; //password
	$jobmid=$_GET['jobmid']; //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();
	$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'];
				
				
				 $eve122 = "select trolleynumber,trolleycolor from res_trolley_master where trolleyqrcode='$par3'";
				
				 $re122 = mysqli_query($conn, $eve122);
				 if(mysqli_num_rows($re122) > 0)
				   {
						 while($rt122 = mysqli_fetch_assoc($re122))
						 {
							 $trolleynumber = $rt122['trolleynumber'];
							 $trolleycolor = $rt122['trolleycolor'];
						 }
				   }
				
				 $eve1 = "select * from res_jobwork_detail where trolleyqrcode='$par3' and jobworkmid = $jobmid";
				
				 $re1 = mysqli_query($conn, $eve1);
				 if(mysqli_num_rows($re1) > 0)
				   {
						 while($rt1 = mysqli_fetch_assoc($re1))
						 {
							 $trolleymid = $rt1['trolleymid'];
							 $trolleygrossweight = $rt1['trolleygrossweight'];
							  $trolleytareweight=$rt1['trolleytareweight'];
							 $trolleynetweight=$rt1['trolleynetweight'];
							 $jobworkdid = $rt1['jobworkdid'];
							
							 
							 $result="1";
							 
							$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'=>  $trolleynumber,'tcolor'=>$trolleycolor,'trolleyweight'=>  $trolleygrossweight,'jobworkdid'=>  $jobworkdid,'trolleytareweight'=>  $trolleytareweight,'trolleynetweight'=>  $trolleynetweight,'itemlist'=>$newResponse1);

						}
				   }  
				   else
						{
							$result="0";
							$msg="Trolley not in this job";
							
							$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 Error";
		
		$posts[] = array('result'=> $result,'msg'=> $msg);
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
   }
   
	mysqli_close($conn);
	
	
?>