<?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)
    {
        $i=0;
        $sels = $con->query("select uid,p_method,total,datesloat,item_total,d_charge,tax_amount,discount_amount from orders where status = 'completed' and shop_id='$shop_id' and shop_code='$shop_code' Order by id DESC");
        while($rows = $sels->fetch_assoc())
        {
            $cat =  $con->query("select name from user where id=".$rows['uid']." and shop_id='$shop_id' and shop_code='$shop_code'");
        	if($row = $cat->fetch_assoc())
        	{
        	    $p['name'] = $row['name'];
        	}
        	$p['s_no'] = $i+1;
        	$p['order_date'] = $rows['datesloat'];
        	$p['pay_mode'] = $rows['p_method'];
        	$p['item_total'] = $rows['item_total'];
        	$p['d_charge'] = $rows['d_charge'];
        	$p['tax_amount'] = $rows['tax_amount'];
        	$p['discount_amount'] = $rows['discount_amount'];
        	$p['amount'] = $rows['total'];
        	$cp[] = $p;
        	$i++;
        }
        echo json_encode($cp);
    }
    else
    {
        $rows = array('status'=>"",'message' => 'Data Error');
        echo json_encode($rows);
    }
}


?>