<?php
    include("../connection.php");
    include("../user.php");
        ini_set('display_errors', '1');
    ini_set('display_startup_errors', '1');
    error_reporting(E_ALL);
?>
<?php
    $cur_date=date('Y-m-d H:i:s');
    $sys_date=date('Y-m-d');
    $user=$_SESSION['user'];
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        // Safe to access $_POST data now
        $so_date = $_POST['so_date'] ?? '';
    	$department=$_POST['department'] ?? '';
    	$branch=$_POST['branch'] ?? '';
    	$store=$_POST['store'] ?? '';
    	$qty=$_POST['qty'] ?? '';
    	$mr_no=$_POST['mr_no'] ?? '';
    	$ticket_no=$_POST['ticket_no'] ?? '';
    	$value=$_POST['value'] ?? '';
    	$amount=$_POST['amount'] ?? '';
    	$total_amount=$_POST['amount'] ?? '';
    	$material_name=$_POST['material_name'] ?? '';
    	$qum=$_POST['qum'] ?? '';
    	$technician=$_POST['technician'] ?? '';
    	$approved_by=$_POST['approved_by'] ?? '';
    	$purpose=$_POST['purpose'] ?? '';
    	$id=$_POST['id'];
	    $outward_table_query = $con->query("UPDATE `outward_master` SET 
    `so_date` = '$so_date',
    `ticket_no` = '$ticket_no',
    `department` = '$department',
    `branch` = '$branch',
    `division` = '$store',
    `material_name` = '$material_name',
    `mr_no` = '$mr_no',
    `qty` = '$qty',
    `amount` = '$amount',
    `qum` = '$qum',
    `technician` = '$technician',
    `purpose` = '$purpose',
    `value` = '$value',
    `approved_by` = '$approved_by',
    `total_amount` = '$total_amount',
    `status` = '0',
    `modified_on` = NOW() 
    WHERE `id` = '$id'");


	
    if ($query) {
        $response['success'] = true;
        $response['message'] = "Outward entry updated successfully.";
    } else {
        $response['message'] = "Update failed. Check database or query.";
    }
}

echo json_encode($response);
?>