<?
session_start();
if(strlen($brcode)<=0)
{
  print "<script> alert('Invalid User'); parent.document.location='ind.php' </script>";
  return;
}

if($dr==$cr)
{
 print "<script> alert('Invalid Entry'); history.back(1); </script>";
 return;
}

if(strtoupper($dr)=='PURCHASE')
{
 print "<script> alert('Invalid Entry-Purchase'); history.back(1); </script>";
 return;
}
if(strlen($amt)<=0||!is_numeric($amt)||$amt<=0)
{
 print "<script> alert('Insufficient/Invalid Amount'); history.back(1); </script>";
 return;
}
if(!checkdate($m,$d,$y))
{
 print "<script>alert('Invalid Date'); history.back(1);</script>";
 return;
}

include("opendb.php");
$dt=$y.'-'.$m.'-'.$d;

$dtcheck1=mysqli_query($db,'select acfrom,acto from acperiod') or die(mysqli_error());
$dtrow=mysqli_fetch_array($dtcheck1);
 $sssq="select to_days('$dt')-to_days('$dtrow[0]'),to_days('$dtrow[1]')-to_days('$dt')";

$dtcheck2=mysqli_query($db,$sssq) or die(mysqli_error());
 $dtrow2=mysqli_fetch_row($dtcheck2) or die(mysqli_error());

 if($dtrow2[0]<0 || $dtrow2[1]<0)
 {
   print "<script>alert('Invalid date, Check a/c Period'); history.back(1);</script>";
   return;
 }



$code=substr($dr,0,3).substr(time(),7,3);
$code=str_replace(' ','-',$code);

$sq="insert into actrans (code,ledger,dt,payment,dr,cr,amt,vouch,narr,brcode,usercode) values('$code','$dr', '$dt','$amt','$dr','$cr','$amt','$vouch','$narr','$brcode','$user')";
mysqli_query($db,$sq) or die(mysqli_error());
print "<font color=green>Data has been saved</font>";
include("purch.php");
?>
