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

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

$action="Channged products in the general store with details <br> product Name: ".$product_name." <br> from Quantity:".$quantity." to Quantity: ".$added;


$sqlst = mysqli_query($con,"UPDATE stores set quantity='$added' where product_name='$product_name' && id='$sid' && business_id='$business'");


if ($sqlst) {
    $elog_sql=mysqli_query($con,"INSERT INTO logs(user_id, activity,branch_id,business_id) VALUES 
('$user_id','$action','$branch','$business')");
    if ($elog_sql) {
        # code...
    }else{
        echo "Error: EE" . $elog_sql . "<br>" . mysqli_error($con);
    }
} 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 stores set added=NULL where business_id='$business'";

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

mysqli_close($conn);
?>