<?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");

date_default_timezone_set('Asia/Rangoon');
$data = json_decode(file_get_contents("php://input"));

if($data->current_expire_date){
    if($data->current_expire_date<$data->sales_date){
            $select_date = $data->sales_date;
            for ($x = 1; $x <= $data->days; $x++) {
               $select_date = date('Y-m-d', strtotime("+1 month", strtotime($select_date)));
            }
                $select_date = date('Y-m-d', strtotime("+" . ($data->extra) . " days", strtotime($select_date)));
                $arr = array(
                    "start_date" => $data->sales_date,
                    "end_date" => $select_date
                );
    }else{
            $select_date = $data->current_expire_date;
            for ($x = 1; $x <= $data->days; $x++) {
               $select_date = date('Y-m-d', strtotime("+1 month", strtotime($select_date)));
            }
                $select_date = date('Y-m-d', strtotime("+" . ($data->extra) . " days", strtotime($select_date)));
                $arr = array(
                    "start_date" => date('Y-m-d', strtotime("+1 days", strtotime($data->current_expire_date))),
                    "end_date" => $select_date
                );
    }
}else{
    $select_date = $data->select_date;
    for ($x = 1; $x <= $data->days; $x++) {
       $select_date = date('Y-m-d', strtotime("+1 month", strtotime($select_date)));
    }
        $select_date = date('Y-m-d', strtotime("+" . ($data->extra) . " days", strtotime($select_date)));
        $arr = array(
            "start_date" => $data->select_date,
            "end_date" => $select_date
        );

}


echo json_encode($arr);	
?>