<?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 userpassword='$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 jobworkmid, sum(trolleynetweight) as dirtycloth from res_jobwork_detail where jobworkmid in (select jobworkmid from res_jobwork_master where fromcompanymid=$cmpmid)";
				
				 $re1 = mysqli_query($conn, $eve1);
				 if(mysqli_num_rows($re1) > 0)
				   {
						 while($rt1 = mysqli_fetch_assoc($re1))
						 {
							 $jobworkmid = $rt1['jobworkmid'];
							 $dirtycloth = $rt1['dirtycloth'];
							$cleancloth=0;
							  $eve11 = "select sum(trolleynetweight) as cleancloth from res_jobwork_detail where jobworkmid in (select jobworkmid from res_jobwork_master where tocompanymid=$cmpmid and jobworkstatus='Received')";
				
				 $re11 = mysqli_query($conn, $eve11);
				 if(mysqli_num_rows($re11) > 0)
				   {
						 while($rt11 = mysqli_fetch_assoc($re11))
						 {
							 
							 $cleancloth = $rt11['cleancloth'];
							 
						 } 
				   }
							 $result="1";
								$newResponse[] = array('result'=> $result,'msg'=> 'Success','totaldirty'=>  $dirtycloth." Kgs",'totalclean'=>$cleancloth." Kgs");
								$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);
	
	
?>