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

	// mobile password 
	$par1=$_GET['mobile']; //username
	$par2=$_GET['password']; //password
	$par3=$_GET['pref_id']; //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'];
				
				
				$tt = " where orderdrandomid = $par3 OR (addedbyID = $umid and jobworkmid = 0 )";	
					
				  $eve11 = "select * from res_jobwork_detail $tt";
	
				 $re11 = mysqli_query($conn, $eve11);
				 if(mysqli_num_rows($re11) > 0)
				   {
						 while($rt11 = mysqli_fetch_assoc($re11))
						 {
							 $jobworkdid=$rt11['jobworkdid'];
							 $trolleymid=$rt11['trolleymid'];
							 $trolleygrossweight=$rt11['trolleygrossweight'];
							 $trolleytareweight=$rt11['trolleytareweight'];
							 $trolleynetweight=$rt11['trolleynetweight'];
							 $tocompanyID =$rt11['tocompanyID'];
							 $orderdrandomid =$rt11['orderdrandomid'];
							 
							 if($par3 != '0')
							 {
								  $evenewpass111 = "UPDATE res_jobwork_detail set orderdrandomid = '$par3'  where orderdrandomid!='$par3' and  jobworkdid=$jobworkdid";
								 $renewpass111 = mysqli_query($conn, $evenewpass111);
							 }
							
							 
							 $query1 = "select trolleynumber,trolleycolor from res_trolley_master where trolleymid=$trolleymid";
							$stmt1=mysqli_query($conn,$query1);
								while($rt1 = mysqli_fetch_assoc($stmt1))
								{
									$trolleyno=$rt1['trolleynumber'];
									$trolleycolor=$rt1['trolleycolor'];
									
								}
							 $newResponse1 = array();
							   $eve12 = "select * from res_jobworkitem_detail where jobworkdid=$jobworkdid and itemid!= 0";
							 $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'=>  $trolleygrossweight,'trolleytweight'=>  $trolleytareweight,'trolleynweight'=>  $trolleynetweight,'trolleycolor'=>$trolleycolor,'tocompanyid'=>$tocompanyID,'pref_id'=>$orderdrandomid,'itemlist'=>$newResponse1);
						}
				   }
				   else
				   {
					  	$result="0";
						$msg="No Data";
						$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('p1'=> $result,'p2'=> $msg);
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
   }
   
	mysqli_close($conn);
	
	
?>