<?php
// required headers
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

include_once '../config/database.php';
include_once '../objects/sales.php';
date_default_timezone_set('Asia/Rangoon');
session_start();
$database = new Database();
$db = $database->getConnection();
 
$sales = new Sales($db);
$data = json_decode(file_get_contents("php://input"));

// $ont->expire_date = $data->expire_date;   
$sales->city = $data->city;
$sales->df = $data->df;
$sales->dt = $data->dt;
// $sales->invoice_no = $data->invoice_no;
// $sales->id_no = $data->id_no;
// $sales->name = $data->name;
$sales->package = $data->package;
// $sales->p_type = $data->p_type;
// $sales->S_R = $data->S_R;

$stmt = $sales->searchForPromo();
$num = $stmt->rowCount();

$arr=array();
$arr["records"]=array();
$total_amountF = $refundF = $paymentF = $balanceF = 0;
if($num>0){
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
        extract($row);
        $detail=array( 
            "id" => $id,
            "sales_date" => ($name)?$sales_date:"",
            "invoice_no" => ($invoice_no)?$invoice_no:"",
            "id_no" => ($id_no)?$id_no:"",
            "name" => ($name)?$name:"",
            "city" => ($city)?$city:"",
            "phone" => ($phone)?$phone:"",
            "package" => ($package)?$package:"",
            "start_date" => ($start_date)?$start_date:"",
            "end_date" => ($end_date)?$end_date:""
            // "promo_days" => $promo_days,	
            // "promo_mbps" => $promo_mbps,	
        );  

        array_push($arr["records"], $detail);
    }
}

echo json_encode($arr);
?>