<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
    print "<script> alert('Session timed out'); parent.document.location='../index.php'; </script>";
    return;
}
include("opendb.php");
$invno=$_REQUEST['invno']; 
$customer=$_REQUEST['sup'];
$d1=$_REQUEST['d1'];
$d2=$_REQUEST['d2'];
$d3=$_REQUEST['d3'];
$entrydt=$d3.'-'.$d2.'-'.$d1;
$RadioGroup1=$_REQUEST['RadioGroup1'];
$outstanding=$_REQUEST['outstanding'];
$brnchtp=$_REQUEST['brnchtp'];
$downamt=$_REQUEST['down_amt'];
$crnoteno=$_REQUEST['crnoteno'];
//echo $RadioGroup1;

if($downamt>0)
{
  $crquery=mysqli_query($db,"select * from crnote where brcode='$brcode' and partic='$customer' and dbno='$crnoteno'");
  $crrow=mysqli_fetch_array($crquery);
  if($downamt>$crrow[cramt])
  {
     echo "<script>alert('Invalid amount');document.location='acposting_220819.php';</script>"; 
  }
  else
  {
  $dwnqry="insert into downpayment(invno,customer,amt,date,brcode,jvno,typ,remark,trno) values('$invno','$customer','$downamt','$entrydt','$brcode','111','$brnchtp','$invoicedat','$crnoteno')";
  		//echo $dwnqry;
		//echo "<br>";
	    mysqli_query($db,$dwnqry) or die("Err 1".mysqli_error($db));
    
   
    print "<font color=black>Data has been posted</font><br>";
    echo "<script> document.location='acposting_220819.php';</script>";
  }
}
else
{
    echo "<script>alert('Invalid amount');document.location='acposting_220819.php';</script>";
}
?>