<?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");
session_start();
date_default_timezone_set('Asia/Rangoon');
include_once '../../config/database.php';
include_once '../../objects/item.php';
include_once '../../objects/item_sales.php';

$database = new Database();
$db = $database->getConnection();
 
$item = new Item($db);
$item_sales = new ItemSales($db);
$data = json_decode(file_get_contents("php://input"));  

$item->item_code = $data->item_code;
$item->sales_price = $data->price;

$item_sales->sales_date = $data->sales_date;
$item_sales->store = $data->store;
$item_sales->buyer = $data->buyer;
$item_sales->item_code = $data->item_code;
$item_sales->item_name = $data->item_name;
$item_sales->quantity = $data->quantity;
$item_sales->price = $data->price;
$item_sales->entry_by = isset($_SESSION['user'])?$_SESSION['user']:"";
$item_sales->entry_date_time = date("Y-m-d H:i:s");

$item->updateSalesPrice();

if($item_sales->create()){
    echo 'created';
}else{
    echo 'error';
}

?>