<?
session_start();
require_once('functions.php');
require_once('mysql.php');
$id=$_POST['id'];
$qty=$_POST['qty'];
$date=$_SESSION['date'];
$sup=$_SESSION['sup'];
//$total=$_POST['TOTALL'];
//$price=$_POST['price'];
$totall=$qty*$price;
//$invoi=$_POST['CODE'];
$nom=$_SESSION['invc'];
$iss=$_POST['iss'];
$pname=$_POST['PNAME'];
		$user=$_SESSION['user'];
//$supplier=$_SESSION['supplier'];
$mat=$_SESSION['expe'];
$date=$_SESSION['da'];
//$dim=mysqli_real_escape_string($dbc,$_POST['dim']);
//$others=mysqli_real_escape_string($dbc,$_POST['other']);
$jk="select product_id,category,left_p,price from products where p_name='$pname'";
$sq=mysqli_query($dbc,$jk);
$di=mysqli_fetch_array($sq);
$i=$di['product_id'];
$cat=$di['category'];
$by=$di['price'];
$tot=$by*$qty;
$lf=$di['left_p'];
$x=$_SESSION['SESSION'];
$Ri="SELECT * FROM inv where p_name='$pname'";
   if($qty<=$lf){
$d="insert into trans(product_id,p_name,qty,category,price,date,user,cod,dest,tot)
values('$i','$pname','$qty','$cat','$by',NOW(),'$user','$nom','$sup','$tot')";
$dd=mysqli_query($dbc,$d);
$j="update products set left_p=left_p-'$qty' where product_id ='$i' limit 1";
 $lk=mysqli_query($dbc,$j);
 
   }else{
	   echo'<p>Quantity transfered can not be greater than qty in shop</p>';
   }
 //$ji="update stocking set qty=qty-'$qty' where product_id ='$i' limit 1";
 //$lkk=mysqli_query($dbc,$ji);
header("location: invii.php");
?>