<?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/bank_in_out.php';
date_default_timezone_set('Asia/Rangoon'); 
session_start();
$database = new Database();
$db = $database->getConnection();
 
$bank_in_out = new BankInOut($db);
$data = json_decode(file_get_contents("php://input"));

$bank_in_out->city = $data->city;
$bank_in_out->date = $data->date;
$bank_in_out->description = $data->description;
$bank_in_out->amount = $data->amount;
$bank_in_out->remark = $data->remark;
$bank_in_out->entry_by = $_SESSION['user'];
$bank_in_out->entry_date_time = date("Y-m-d H:i:s");	



if($data->id){
	$bank_in_out->id = $data->id;
	if($bank_in_out->update()){
		$msg_arr = array(
			"message" => "updated"
		);
	}else{
		$msg_arr = array(
			"message" => "errorIU"
		);
	}
}else{
	if($bank_in_out->exist()){
        $msg_arr = array(
            "message" => "duplicate"
        );
    }else if($bank_in_out->create()){
		$msg_arr = array(
			"message" => "created",
			"id" => $bank_in_out->id
		);
	}else{
		$msg_arr = array(
			"message" => "errorc"
		);	
	}
}
echo json_encode($msg_arr);
?>	