<?
session_start();
include("../opendb.php");
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);

$dob=$y1.'-'.$m1.'-'.$d1;
$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);

$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());
$sql="insert into ledger values('$acname','Sundry Debtors','$op','Dr','$code','$brcode')";
mysqli_query($db,$sql) or die('<b>Ledger creation error:'.mysqli_error());

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