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

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

$stock_in->stock_in_date = $data->stock_in_date;
$stock_in->voucher_no = $data->voucher_no;
$stock_in->store = $data->store;
$stock_in->item_code = $data->item_code;
$stock_in->item_name = $data->item_name;
$stock_in->quantity = $data->quantity;
$stock_in->price = $data->price;
$stock_in->entry_by = isset($_SESSION['user']) ? $_SESSION['user'] : "";

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

if($stock_in->create()){
    $item->updateCapital();
    echo 'created';
}else{
    echo 'error';
}

?>