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

	// mobile password 
	$par1=$_GET['mobile']; //username
	$par2=$_GET['password']; //password
	$jobworkmid=$_GET['jobworkmid']; //jobworkmid
	
	
	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 userpassword='$par2' and userstatus='Active' and userdesignation='User' limit 0,1";
	
	$re = mysqli_query($conn, $eve);

	$response = array();
	$posts = array();
	$itemlist = 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_detail where jobworkmid=$jobworkmid";
				
				 $re1 = mysqli_query($conn, $eve1);
				 if(mysqli_num_rows($re1) > 0)
				   {
					   
						 while($rt1 = mysqli_fetch_assoc($re1))
						 {
							 $jobworkdid = $rt1['jobworkdid'];
							 $trolleymid = $rt1['trolleymid'];
							$trolleygrossweight=$rt1['trolleygrossweight'];
							$trolleytareweight=$rt1['trolleytareweight'];
							$trolleynetweight=$rt1['trolleynetweight'];
							$trolleyreceived=$rt1['trolleyreceived'];
							$trolleyreceivedgrossweight=$rt1['trolleyreceivedgrossweight'];
							$trolleyStatus = "Pending";
							$trolletnetdiff = 0;
							if($trolleyreceived == 1 )
							{
								$trolleyStatus = "Done";
								$trolleyreceivedgrossweight= $trolleyreceivedgrossweight - $trolleytareweight;
								$trolleynetweight = sprintf('%0.2f', $trolleynetweight);
								$trolleyreceivedgrossweight = sprintf('%0.2f', $trolleyreceivedgrossweight);
								$trolletnetdiff = $trolleyreceivedgrossweight - $trolleynetweight;
								$trolletnetdiff = sprintf('%0.2f', $trolletnetdiff);
								//$trolleyreceivedgrossweight = number_format((float)$$trolleyreceivedgrossweight, 2, '.', '');
							}
							$eve70="select trolleynumber,trolleycolor from res_trolley_master where trolleymid=$trolleymid";
							$re70 = mysqli_query($conn, $eve70);
							
							while($rt70 = mysqli_fetch_assoc($re70))
							{
								$trolleynumber=$rt70['trolleynumber'];
								$trolleycolor=$rt70['trolleycolor'];
							}
								$itemlist = array();	
							$eve71="select * from res_jobworkitem_detail where jobworkmid=$jobworkmid and jobworkdid = $jobworkdid";
							$re71 = mysqli_query($conn, $eve71);
							while($rt71 = mysqli_fetch_assoc($re71))
							{
								$itemid=$rt71['itemid'];
								$itemname=$rt71['itemname'];
								$itemdetail=$rt71['itemdetail'];
								$itemqty=$rt71['itemqty'];
								$itemlist[] = array('itemid'=> $itemid,'itemname'=> $itemname,'itemdetail'=>  $itemdetail,'itemqty'=>  $itemqty);
								
							}
							 $result="1";
							 
								$posts[] = array('result'=> $result,'msg'=> 'Success','jobworkdid'=>  $jobworkdid,'trolleymid'=>  $trolleymid,'trolleynumber'=>  $trolleynumber,'tcolor'=>$trolleycolor,'trolleygrossweight'=>  $trolleygrossweight,'trolleytareweight'=>$trolleytareweight,'trolleynetweight'=>$trolleynetweight,'trolleyStatus'=>$trolleyStatus,'trolleyreceivedgrossweight'=>$trolleyreceivedgrossweight,'trolletnetdiff'=>$trolletnetdiff,'itemlist'=>$itemlist);
								
						 }
				   }
				   else
					{
						$result="0";
						$msg="No Data";
						
						$posts[] = array('result'=> $result,'msg'=> $msg);
					}
		 }
		echo stripslashes(json_encode( array('item' => $posts)));
		
   }
   else
   {
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
		echo stripslashes(json_encode( array('item' => $posts)));
   }
   
	mysqli_close($conn);
	
	
?>