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

$income->date = $data->date;
$income->voucher_no = $data->voucher_no;
$income->income_reason = $data->income_reason;
$income->particular = $data->particular;
$income->quantity = $data->quantity;
$income->amount = $data->amount;
$income->income_by = $data->income_by;
$income->city = $data->city;
$income->accounting_view = isset($_SESSION['accounting_view'])?$_SESSION['accounting_view']:"";
$income->entry_by = isset($_SESSION['user'])?$_SESSION['user']:"";
$income->entry_date_time = date("Y-m-d H:i:s");

if($data->id){
	$income->id = $data->id;
	if($income->update()){
		$msg_arr = array(
			"message" => "updated"
		);
	}else{
		$msg_arr = array(
			"message" => "errorIU"
		);
	}
}else{
	if($income->create()){
		$msg_arr = array(
			"message" => "created"
		);
	}else{
		$msg_arr = array(
			"message" => "errorc"
		);	
	}
}


echo json_encode($msg_arr);
?>	