<?
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;
}
include("../opendb.php");
$cname=$_REQUEST['cname'];
if(strlen($cname)<=0)
{
 print "<script> alert('Invalid Customer Name'); history.go(-1) ; </script>";
 return;
}
$code=substr($cname,0,3).date(ymds);
$code=str_replace(' ','-',$code);
$d=$_REQUEST['d'];
$m=$_REQUEST['m'];
$y=$_REQUEST['y'];

$d1=$_REQUEST['d1'];
$m1=$_REQUEST['m1'];
$y1=$_REQUEST['y1'];
$acname=$_REQUEST['acname'];
if($d1>0)
{
$dob=$y1.'-'.$m1.'-'.$d1;
}
else
{
$dob='0000-00-00';
}
$crdate=$y.'-'.$m.'-'.$d;
$chk=mysqli_query($db,"select * from ledger where led='$acname'");
 if(mysqli_num_rows($chk)>0)
 {
    print "<script> alert('Duplicate Ledger'); history.back(1); </script>";
    return;
 }

$res=mysqli_query($db,"select * from customer where acname='$acname'");
if(mysqli_num_rows($res)>0)
{
 print "<script> alert('Duplicate A/c Head'); history.go(-1) </script>";
 return;
}
$cname=strtoupper($cname);
$acname=strtoupper($acname);
$corp=$_REQUEST['corp'];
$addr1=$_REQUEST['addr1'];
$dist1=$_REQUEST['dist1'];
$state1=$_REQUEST['state1'];

$pin1=$_REQUEST['pin1'];
$phone1=$_REQUEST['phone1'];
$state2=$_REQUEST['state2'];
$addr2=$_REQUEST['addr2'];
$dist2=$_REQUEST['dist2'];

$pin2=$_REQUEST['pin2'];
$phone2=$_REQUEST['phone2'];
$mob=$_REQUEST['mob'];
$relation=$_REQUEST['relation'];
$father=$_REQUEST['father'];

$email=$_REQUEST['email'];
$web=$_REQUEST['web'];
$tin=$_REQUEST['tin'];
$cst=$_REQUEST['cst'];
$kgst=$_REQUEST['kgst'];
$op=$_REQUEST['op'];
$sql="insert into customer values('$brcode','$code', '$crdate','$cname','$corp','$acname','$addr1', '$dist1','$state1','$pin1','$phone1','$addr2','$dist2','$state2','$pin2','$phone2','$mob','$relation', '$father','$dob','$email','$web','$tin','$cst','$kgst','0','0')";

mysqli_query($db,$sql)or die(mysqli_error($db));
if($op<=0)
{
$op='0.00';
}
$sql="insert into ledger values('$acname','Sundry Debtors','$op','Dr','$code','$brcode')";
mysqli_query($db,$sql) or die('<b>Ledger creation error:'.mysqli_error($db));

$cname="";
print "<font color=green> Data has been saved</font>";
include("custmaster.php");
?>
