<?php
include("../connection.php");
include("../user.php");
// ini_set('display_errors', '1');
// ini_set('display_startup_errors', '1');
// error_reporting(E_ALL);
$user = $_SESSION['user'];
?>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $po_date = $_POST['po_date'] ?? '';
  $material_name = $_POST['material_name'] ?? '';
  $vendor_name = $_POST['vendor_name'] ?? '';
  $billno = $_POST['billno'] ?? '';
  $gatentry = $_POST['gatentry'] ?? '';
  $qty = $_POST['qty'] ?? '';
  $qum = $_POST['qum'] ?? '';

  $department = $_POST['department'] ?? '';
  $branch = $_POST['branch'] ?? '';
  $store = $_POST['store'] ?? '';

  $value = $_POST['value'] ?? '';
  $amount = $_POST['amount'] ?? '';
  $gst_percentage = $_POST['gst_percentage'] == '' ? 0 : $_POST['gst_percentage'];
  $total_amount = $_POST['total_amount'] == '' ? 0 : $_POST['total_amount'];
  $discount = $_POST['discount'] == '' ? 0 : $_POST['discount'];
  $id = $_POST['id'];

  $inward_table_query = $con->query("UPDATE `item_master` SET `po_date`='$po_date',`department`='$department',`branch`='$branch',`division`='$store',`material_name`='$material_name',`vendor_name`='$vendor_name',`billno`='$billno',`gatentry`='$gatentry',`quantity`='$qty',`value`='$value',`amount`='$amount',`gst_percentage`='$gst_percentage',`total_amount`='$total_amount',`discount` = '$discount',`status`=0,`modified_on`= now(),`qum`='$qum' WHERE `id`='$id'");





if ($inward_table_query) {
        $response['success'] = true;
        $response['message'] = "Inward entry updated successfully.";
    } else {
        $response['message'] = "Update failed. Check database or query.";
    }
}
echo json_encode($response);
?>