<?php 
session_start();
include('../includes/dbcon.php');

$str=" ";


$cusname= mysqli_real_escape_string($con,trim($_POST['cusname']));
$address= mysqli_real_escape_string($con,trim($_POST['address']));
$tel= mysqli_real_escape_string($con,trim($_POST['tel']));
$email= mysqli_real_escape_string($con,trim($_POST['email']));
//$web= trim($_POST['web']);
$notes=mysqli_real_escape_string($con,trim($_POST['notes']));
$city=mysqli_real_escape_string($con,trim($_POST['city']));
$edate=date("Y-m-d");
$userid=$_SESSION['rm_id'];
$cus_code=mysqli_real_escape_string($con,$_POST['custcode']);
$custvat=mysqli_real_escape_string($con,$_POST['custvat']);
$vat_invoice=mysqli_real_escape_string($con,$_POST['vat_invoice']);



if (empty($_SESSION['custcode'])) {
    $cus_code = '';
}


$vat_invoice = isset($_POST['vat_invoice']) ? 1 : 0;


$query=mysqli_query($con," select * from customer_master where cus_name='$cusname'  ")or die(mysqli_error($con));
    $count=mysqli_num_rows($query);
if ($count>0)
{
	echo "<script type='text/javascript'>alert('Exsisting Customer!');</script>";
	echo "<script>document.location='admin_company.php'</script>"; 
}

else {
    
    //$pp="INSERT INTO customer_master(cus_name,add1,telephone,email,cus_active,city,notes,edate,userid,cus_code) 
			                                // VALUES('$cusname','$address','$tel','$email',1,'$city','$notes',$edate,$userid,$cus_code)  ";
    //echo $pp;

		if ( mysqli_query($con,"INSERT INTO customer_master(cus_name,add1,telephone,email,cus_active,city,notes,edate,userid,cus_code,vat_required,vat_number) 
			                                 VALUES('$cusname','$address','$tel','$email',1,'$city','$notes',$edate,$userid,1,$vat_invoice,'$custvat')  ")or die(mysqli_error($con)))
	        if (!$result) {
                    echo "<script>document.location='admin_customer.php'</script>";
            } else {
    
                    echo "Data inserted successfully!";
                }
}		

?>