<?php
    session_start();

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

    $stock_id = $_POST['stock_id'];
    $movein_quantity = $_POST['movein_quantity'];
    $total_available_quantity = $_POST['total_available_quantity'];
    //$total_movein_value = $_POST['total_movein_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','$movein_quantity','$taken_by','$used_by','move_in','$timestamp')";
    //var_dump($sql);
    //die();
    $sql2 = "update stocks set quantity='$total_available_quantity' where id='$stock_id'";
    if ($conn->query($sql)) {
        $conn->query($sql2);
        $_SESSION['success'] = "Stock Move In successfully";
    } else {
        $_SESSION['error'] = "Error updating record: " . $conn->error;
    }
    
    header('location: ../stocks_listing.php');
?>