<?php include("../../include/dbconnect.php"); 

$sdate = $today;
$qtyonhand=0;

$tddt = substr($sdate,6,4).'-'.substr($sdate,3,2).'-'.substr($sdate,0,2);
$amt=0;
$totamt=0;
// UPDATE STOCK 

if($qty >0 )
{

	$resu = mysql_query("select bcode,prodcode from product where  record ='$record'  ") or die(mysql_error());
	$row= mysql_fetch_row($resu);
	$bcode = $row[0];
	$prodcode=$row[1];


	$resu = mysql_query("select sum(balance) from purreg where  prodcode = '$prodcode' and bcode ='$bcode'  ") or die(mysql_error());
	$row= mysql_fetch_row($resu);
	$qtyonhand = 0;

	if(is_array($row))
	{
	   $qtyonhand = $row[0];
	   $qtyonhand = $qtyonhand+$qty[$ind];
	}
	if ($qtyonhand > 0)
	{
	   $opbal = $qtyonhand - $qty[$ind];
	}
	else
	{
		$opbal = 0;
	}
	$clbal = $qtyonhand;

	if ($qtyonhand==0)
	{
	   $clbal=$qty[$ind];
	}	

	$query="insert into stktrans values ('$prodcode','$tddt','$bcode','$opbal','$qty','0','$clbal','$bill_no','','$ordno','',NULL)";
	mysql_query($query) or die (mysql_error());

	$stockres = mysql_query("select bcode,prodcode from purreg where prodcode ='$prodcode' and bcode ='$bcode' ")or die(mysql_error());
	$stocksearch= mysql_fetch_row($stockres);
	if(is_array($stocksearch))
	{
		$query = "update purreg set receipt= receipt+$qty,balance = balance+$qty where bcode ='$bcode' and prodcode ='$prodcode' ";
		mysql_query($query) or die (mysql_error());
	}
 	else
	{
		$query="insert into purreg values ('$prodcode','$tddt','$bcode','$qty','','$qty',NULL)";
		mysql_query($query) or die (mysql_error());
	
	}
}
recalc($bcode,$prodcode);

?>
<br>
<br>

<br><br><font size=1><center><a href= "input.php">Make another Entry</center></font>
<br><br><font size=1><center><a href= "/wilson/prgent/orders/receipts/index.html">Return to index page</center></font>
