
<?php
session_start();
include '../includes/connection.php';
$branch=$_SESSION['branch_id'];
$sql = "SELECT * from stock where Actual_quantity>=0 && branch_id='$branch'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        $product_id=$row['product_name'];
        $quantity=$row['quantity'];
        $Actual_quantity=$row['Actual_quantity'];
        $user_id=$_SESSION['id'];
        




$sqlst = mysqli_query($con,"UPDATE stock set quantity='$Actual_quantity' where product_name='$product_id'");
$sqlps = mysqli_query($con,"update products set quantity='$Actual_quantity' where id='$product_id'");

if ($sqlst) {
    
} else {
    echo "Error: EE" . $sqlst . "<br>" . mysqli_error($con);
}

//mysqli_close($con);



//insert data


    }
} else {
    echo "0 results". mysqli_error($con);
}

//mysqli_close($conn);
?>




<?php
//delete everything from temp table

// Create connection

// sql to delete a record
$sql = " UPDATE stock set Actual_quantity=NULL where branch_id='$branch'";

if (mysqli_query($conn, $sql)) {
    echo "<script> window.location='reconcile.php';</script>";
   
    
} else {
    echo "Error deleting record: " . mysqli_error($conn);
}

mysqli_close($conn);
?>