<?
 session_start();
 include("opendb.php");
 $group=getGroup($item);
$code=substr($depof,0,3).substr(time(),7,3);
$code=str_replace(' ','-',$code);
$dt=$y."-".$m."-".$d;
$result=mysqli_query($db,"select * from stock where item='$item' and depot='$depot'");
if(mysqli_num_rows($result)>0)
	$sql="update stock set qty=(qty+$qty) where item='$item' and depot='$depot'";
else
	$sql="insert into stock values('$item','$depot','$qty')";
mysqli_query($db,$sql) or die(mysqli_error());

$result=mysqli_query($db,"select * from stock where item='$item' and depot='$depof'");
if(mysqli_num_rows($result)>0)
{
  $sql="update stock set qty=(qty-$qty) where item='$item' and depot='$depof'";
  mysqli_query($db,$sql) or die(mysqli_error());
}

 $sql="insert into trans values('$code','$depof','$depot','$item','$qty','$group','$dt')";
 mysqli_query($db,$sql) or die(mysqli_error());
?>
