<?php 

require 'db.php';

if(isset($_GET['sid']) && isset($_GET['token']))
{
    $shop_id = $_GET['sid'];
    $shop_code = $_GET['token'];

    include 'token_check.php';
    
    if($token_check)
    {
        $orders = $con->query("select * from orders where status ='completed' and shop_id='$shop_id' and shop_code='$shop_code'")->num_rows;
        $riders = $con->query("select * from product where status ='1' and shop_id='$shop_id' and shop_code='$shop_code'")->num_rows;
        $users = $con->query("select * from user where status ='1' and shop_id='$shop_id' and shop_code='$shop_code'")->num_rows;
        $total = 0;
        $sels = $con->query("select * from orders where status ='completed' and shop_id='$shop_id' and shop_code='$shop_code'");
        while($rows = $sels->fetch_assoc())
        {
            $total += $rows['total'];
        }
        $sales = $total;
        $rows = array('orders'=>$orders,'products'=>$riders,'users'=>$users,'sales'=>$sales);
        echo json_encode($rows);
    }
    else
    {
        $rows = array('status'=>"",'message' => 'Data Error');
        echo json_encode($rows);
    }
}

?>