<?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/price_change.php';

date_default_timezone_set('Asia/Rangoon'); 
session_start();

$database = new Database();
$db = $database->getConnection();
 
$price_change = new PriceChange($db);
$data = json_decode(file_get_contents("php://input"));
	
$price_change->price_change_date = $data->price_change_date;
$price_change->city = $data->city;
$price_change->entry_by = isset($_SESSION['user'])?$_SESSION['user']:"";
$price_change->entry_date_time = date("Y-m-d H:i:s");	
$price_change->deletePC();
    foreach($data->item_details as $p_detail){

        $price_change->package = $p_detail->package;
        $price_change->package_price = $p_detail->package_price;
        $price_change->fee = $p_detail->fee;
        $price_change->mbps = $p_detail->mbps;
        $price_change->days = $p_detail->days;
    
        if(!$price_change->create()){
            $msg_arr = array(
                "message" => "error"
            );
            echo json_encode($msg_arr);
            die();
        }
		}

		$arr = array(
			"message" => "created"
		);


echo json_encode($arr);
?>
