<?php
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';
 
$database = new Database();
$db = $database->getConnection();

$sales = new Sales($db);
$data = json_decode(file_get_contents("php://input")); 

$sales->id = $data->id;
$sales->getOneRow();

$arr = array(
    "invoice_no" =>$sales->invoice_no,
    "date" => $sales->sales_date,
    "name" => $sales->name,
    "id_no" => $sales->id_no,
    "city" =>$sales->city,
    // "package" =>$sales->package,
    "mbps" =>$sales->mbps,
    "months" =>$sales->months,
    "days" =>$sales->days,
    // "payment_type" =>$sales->payment_type,
    "start_date" =>$sales->start_date,
    "end_date" =>$sales->end_date,
    "phone" =>$sales->phone,
    "address" =>$sales->address,
    "caddress" =>$sales->caddress,
    "profile_picture" => $sales->profile_picture,
    "invoice_remark" => $sales->invoice_remark,
    "package" => $sales->mbps . "MB ",
    "price" => number_format($sales->price),
    "fee" => number_format($sales->fee),
    "tax" =>$sales->tax,
    "extra_charges" =>$sales->price_change_charges,
    "tax_charges" => number_format($sales->price*$sales->months*$sales->tax/100),
    "total" =>        number_format($sales->price*$sales->months + $sales->fee + ($sales->price*$sales->tax/100)),
    "total_amount" => number_format($sales->price*$sales->months+ $sales->fee + $sales->price_change_charges + ($sales->price*$sales->tax/100)),
    "all_discount" => number_format($sales->normal_discount + $sales->member_discount + $sales->promotion_discount + $sales->refund_amount),
    "payment" => number_format($sales->payment),
    "balance" => number_format($sales->price*$sales->months + $sales->fee + $sales->price_change_charges + ($sales->price*$sales->tax/100) - $sales->payment - $sales->normal_discount - $sales->member_discount - $sales->promotion_discount - $sales->refund_amount)

);

echo json_encode($arr);
?>