<?
session_start();
include_once('includes/top.php');
include_once('opendb.php');

$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
$level=$_SESSION['level'];
$scode=$_REQUEST['sapcode'];

$cname=$_REQUEST['cname'];
$d=$_REQUEST['d'];
$m=$_REQUEST['m'];
$y=$_REQUEST['y'];
$d1=$_REQUEST['d1'];
$m1=$_REQUEST['m1'];
$y1=$_REQUEST['y1'];
$addr1=$_REQUEST['addr1'];
$dist1=$_REQUEST['dist1'];
$state1=$_REQUEST['state1'];
$pin1=$_REQUEST['pin1'];
$phone1=$_REQUEST['phone1'];
$phone2=$_REQUEST['phone2'];
$mob=$_REQUEST['mob'];
//$dob=$_REQUEST['dob'];
$email=$_REQUEST['email'];
$cst=$_REQUEST['cst'];
$kgst=$_REQUEST['kgst'];
if(strlen($cname)<=0)
{
 print "<script> alert('Invalid Customer Name'); history.go(-1) ; </script>";
 return;
}
if(strlen($scode)<=0)
{
 
//$scode=substr($cname,0,3).date(ymds);
$scode="TEMP".date(ymds);
$scode=str_replace(' ','-',$scode);
}
$dob=$y1.'-'.$m1.'-'.$d1;
$crdate=$y.'-'.$m.'-'.$d;

$acname1=$acname.' ('.$scode.')';
$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 partymaster  where gst='$cst' ");
if(mysqli_num_rows($res)>0)
{
 print "<script> alert('Duplicate GST NUMBER'); history.go(-1) </script>";
 return;
}
//$cname=strtoupper($cname);
//$acname=strtoupper($acname);

$sql="insert into partymaster values('$brcode','$scode', '$crdate','$cname','$addr1', '$dist1','$state1','$pin1','$phone1','$phone2','$mob','0000-00-00','$email','text','00','$cst','$kgst','0')";
//echo $sql;
mysqli_query($db,$sql)or die("party err".mysqli_error($db));

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