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


if(strlen($ledg)<=0)
{
 print "<script> alert('Insufficient Entry'); history.back(1); </script>";
 return;
}
 
if($dr==$mode)
{
 print "<script> alert('Dr & Cr should not be same'); 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());
// print $dtrow2[0].','.$dtrow2[1];
 if($dtrow2[0]<0 || $dtrow2[1]<0)
 {
   print "<script>alert('Invalid date, Check a/c Period'); history.back(1);</script>";
   return;
 }



 $result=mysqli_query($db,"select grp from ledger where led='$ledg' and brcode='$brcode'")or die(mysqli_error());
 $row=mysqli_fetch_row($result);
$group=$row[0];
  $result=mysqli_query($db,"select nature from acgroups where gname='$group'")or die(mysqli_error());
  $row=mysqli_fetch_row($result);
$nature = $row[0];

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

$sql="insert into actrans (code,grp,nature,vouch,dt,ledger,receipt,narr,mode,cr,dr,amt,brcode,usercode) values('$code','$group','$nature','$vouch','$dt','$ledg','$amt','$narr','$mode','$ledg','$mode','$amt','$brcode','$user')";
mysqli_query($db,$sql) or die(mysqli_error());
print "<font face=verdana color=green>Entry has been posted</font>";
include("rec.php");

?>
