<?php 
require 'db.php';
 
$data = json_decode(file_get_contents('php://input'), true);


$rid = $data['rid'];
if ($rid == '')
{
$returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went wrong  try again !");
}
else 
{
	$pok = array();
	$p =0 ;
	$riderdata = $con->query("select * from rider where id=".$rid."")->fetch_assoc();
	$pok['total_complete_order'] = $riderdata['complete'];
	$pok['total_reject_order'] = $riderdata['reject'];
	$pok['rider_status'] = $riderdata['a_status'];
	$pok['total_orders'] = $riderdata['complete'] + $riderdata['reject'];
	
	$sale = $con->query("select sum(`total`) as total_earn, from orders where rid=".$rid." and status='completed'")->fetch_assoc();
     if($sale['total_earn'] == '')
	 {
		 $p = 0;
	 }
	 else 
	 {
		 $p = $sale['total_earn'];
	 }
	 $pok['total_sale'] = $p;
	 
	 $pay_d = $con->query("select count(`p_method`) as pay_method, sum(`total`) as pay_total from orders where rid=".$rid." and status='completed' and p_method='Pay on Delivery'")->fetch_assoc();
     if($pay_d['pay_method'] == '')
	 {
		 $pay = 0;
		 $pay_total = 0;
	 }
	 else 
	 {
		 $pay = $pay_d['pay_method'];
		 $pay_total = $pay_d['pay_total'];
	 }
	 
	 $pok['total_cod_order'] = $pay;
	 $pok['total_cod_amount'] = $pay_total;
	 
	 $upi_d = $con->query("select count(`p_method`) as pay_method,sum(`total`) as pay_total from orders where rid=".$rid." and status='completed' and p_method='UPI'")->fetch_assoc();
     if($upi_d['pay_method'] == '')
	 {
		 $upi = 0;
		 $upi_total = 0;
	 }
	 else 
	 {
		 $upi = $upi_d['pay_method'];
		 $upi_total = $upi_d['pay_total'];
	 }
	 
	 $pok['total_upi_order'] = $upi;
	 $pok['total_upi_amount'] = $upi_total;
	 
	 $returnArr = array("order_data"=>$pok,"ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Order Status Get Successfully!");    
}
echo json_encode($returnArr);
mysqli_close($con);
?>
