<?php

require 'db.php';

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
if(isset($postdata) && !empty($postdata))
{
    
$order_id = mysqli_real_escape_string($con, trim($request->value->order_id));
if(isset($_GET['sid']) && isset($_GET['token']))
{
    $shop_id = $_GET['sid'];
    $shop_code = $_GET['token'];

    include 'token_check.php';
    
    if($token_check)
    {
       $sql = "SELECT * FROM orders where order_id = '$order_id' and shop_id='$shop_id' and shop_code='$shop_code'";
        $result = mysqli_query($con,$sql);
        while($rows = mysqli_fetch_assoc($result))
        {
            $cat =  $con->query("select name,mobile from user where id=".$rows['uid']."");
        	if($row = $cat->fetch_assoc())
        	$p['name'] = $row['name'];
        	$p['mobile'] = $row['mobile'];
        	$p['order_id'] = $rows['order_id'];
        	$p['date'] = $rows['order_date'];
        	$p['time'] = $rows['timesloat'];
        	$p['d_charge'] = $rows['d_charge'];
        	$p['pay_mode'] = $rows['p_method'];
        	$p['product_name'] = $rows['pname'];
        	$p['product_price'] = $rows['pprice'];
        	$p['product_type'] = $rows['ptype'];
        	$p['product_qty'] = $rows['qty'];
        	$p['total_amount'] = $rows['total'];
        	$p['tax_amount'] = $rows['tax_amount'];
        	$p['discount'] = $rows['discount_amount'];
        	$p['cooking'] = $rows['cooking_ins'];
        	$p['coupon_code'] = $rows['coupon_code'];
        	$p['d_date'] = $rows['d_date'];
        	$p['d_time'] = $rows['d_time'];
        	$p['rider_status'] = $rows['r_status'];
        	$rid = $rows['rid'];
        	$rt =  $con->query("select name from assist_details where deli_code='$rid'");
        	if($row = $rt->fetch_assoc())
        	$p['rider_name'] = $row['name'];
        	$p['address'] = $rows['address'];
            $completed_orders[] = $p;
        }
        $rows = array('order_details'=>$completed_orders);
        echo json_encode($rows);
    }
    else
    {
        $rows = array('status'=>false,'message' => 'Data Error');
        echo json_encode($rows);
    }
}
}


?>