<?php
    session_start();

    require("../includes/database_connect.php");

    $stock_id = $_POST['stock_id'];
    $moveout_quantity = $_POST['moveout_quantity'];
    $total_available_quantity = $_POST['total_available_quantity'];
    //$total_moveout_value = $_POST['total_moveout_value'];
    $taken_by = $_POST['taken_by'];
    $used_by = $_POST['used_by'];
    $timestamp =date('Y-m-d H:i:s');

    // var_dump($_POST);
    // die();
   
    $sql = "insert into logs (stock_id, quantity, taken_by, used_by,  type, created_at) values ('$stock_id','$moveout_quantity','$taken_by', '$used_by','move_out','$timestamp')";
    $sql2 = "update stocks set quantity='$total_available_quantity' where id='$stock_id'";
    if ($conn->query($sql)) {
        $conn->query($sql2);
        $_SESSION['success'] = "Stock Move Out successfully";
    } else {
        $_SESSION['error'] = "Error updating record: " . $conn->error;
    }
    
    header('location: ../stocks_listing.php');
?>