<?php
include '../includes/connection.php';
session_start();
$id_user=$_SESSION['id'];
$branch=$_SESSION['branch_id'];
$business=$_SESSION['business_id'];

$sql = mysqli_query($con,"SELECT * FROM products where id=(select max(id) from products) and AddedBy='$id_user'");
if (mysqli_num_rows($sql) > 0) {
    // output data of each row
    $row = mysqli_fetch_assoc($sql);
      $productid=$row['id'];
      $selling_price=$row['price'];
      $selling_price_whol=$row['price_whole'];
      if (strlen($selling_price_whol)==0) {
       $selling_price_whole=0;
      }else{
        $selling_price_whole=$selling_price_whol;
      }
      $min_quantity=$row['minimum_quantity'];
      $quantity=$row['quantity'];
      $buying_price=$_GET['buying_price'];
    $sql2 = mysqli_query($con,"INSERT INTO stock(product_name,buying_price, selling_price,selling_price_whole,quantity,min_quantity,branch_id,business_id,AddedBy)
      VALUES('$productid','$buying_price','$selling_price','$selling_price_whole','$quantity','$min_quantity','$branch','$business','$id_user' )");
    if($sql2){
      ?><meta http-equiv="refresh" content="0;URL='products.php'" /> <?php
    }
} else {
    echo "0 results";
}


?>