<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
date_default_timezone_set('Asia/Kolkata');
$dt=date("Y-m-d H:i:s");
include_once("test.php");
include_once('opendb.php');
$tbl='tmpallotreceipt'.$brcode.$user;
$brres12=mysqli_query($db,"select max(receiptno) from allotreceipt where brcode='$brcode'");
	$brrow12=mysqli_fetch_array($brres12);
	
	if($brrow12[0]<='')
	    $receiptno = 1;
	else
	    $receiptno = $brrow12[0]+1;
     $alqry=mysqli_query($db,"select * from $tbl where brcode='$brcode' and amtreceived>0");
	    while($alrow=mysqli_fetch_array($alqry))
	    {
	        
		    if($alrow['amtreceived']>=0)
		    {
			    $sql = "insert into allotreceipt (invno,customer,receiptno,invdate,invamount,amtreceived,rec_date,remarks,brcode,user,entrydate,paymenttype,crjvno,biltyp,drjvno,adjamt) values ('$alrow[invno]','$alrow[customer]','$receiptno','$alrow[invdate]','$alrow[invamount]','$alrow[amtreceived]','$alrow[rec_date]','$alrow[remarks]','$brcode','$user','$alrow[entrydate]','$alrow[paymenttype]','$alrow[crjvno]','$alrow[biltyp]','$alrow[drjvno]','$alrow[adjamt]')";
			    print $sql;			
			    //exit;
			    mysqli_query($db,$sql);
		    }
	    }
	    
	    $tbl='tmpallotreceipt'.$brcode.$user;
mysqli_query($db,"drop table IF EXISTS $tbl");
	    print "<script> alert('Updated !!!!');window.close();</script>";
	

?>
