<?php
include 'connection.php';
session_start();
if (!isset($_SESSION['is_logged_in'])) {
    header("Location:login.php");
    die();
    }

date_default_timezone_set('Asia/Calcutta');
$today = date("Y-m-d");
$time = date("h:i A"); 
$currentyear = date("Y");

?>
<?php $querylogin = "select * from users where username = '". $_SESSION["LOGIN_NAME"]."' AND password = '".$_SESSION["EMPLOYEE_PASSWORD"]."'";
$resultlogin = mysql_query($querylogin,$conn);
while($row=mysql_fetch_array($resultlogin))
{
$Designation = $row['designation'];
$staff_name = $row['full_name'];
$department_name = $row['department_name'];


}
?>
<?php
function randomPassword() {
    $alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < 5; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = $alphabet[$n];
    }
    return implode($pass); //turn the array into a string
}
$unique_id = randomPassword();
?>
<?php
$customer_id = $_POST['customer_id'];

$acccode = $_POST['acccode'];
$customer_name = $_POST['customer_name'];
$dispname = $_POST['dispname'];
$comptype = $_POST['comptype'];
$website = $_POST['website'];
$paccname = $_POST['paccname'];
$assigned_to = $_POST['assigned_to'];
$credittime = $_POST['credittime'];
$creditlimit = $_POST['creditlimit'];
$lsrc = $_POST['lsrc'];
$turnover = $_POST['turnover'];
$industry = $_POST['industry'];
$subindustry = $_POST['subindustry'];
$notes = $_POST['notes'];

$billing_address = $_POST['baddrl1'];
$bcountry = $_POST['bcountry'];
$bstate = $_POST['bstate'];
$bdistrict = $_POST['bdistrict'];
$bcity = $_POST['bcity'];
$bpin = $_POST['bpin'];
$bemail = $_POST['bemail'];
$bphone = $_POST['bphone'];
$bfax = $_POST['bfax'];
$bstate_code = $_POST['bstate_code'];
$bgst_no = $_POST['bgst_no'];

$shipping_address = $_POST['saddrl1'];
$scountry = $_POST['scountry'];
$sstate = $_POST['sstate'];
$sdistrict = $_POST['sdistrict'];
$scity = $_POST['scity'];
$spin = $_POST['spin'];
$semail = $_POST['semail'];
$sphone = $_POST['sphone'];
$sfax = $_POST['sfax'];
$sstate_code = $_POST['sstate_code'];
$sgst_no = $_POST['sgst_no'];

$pan_no = $_POST['pan_no'];


$created_dept=$_REQUEST['created_dept'];
$segment = $_POST['segment'];

$query = "insert customer_master(customer_name,comptype,pan_no,assigned_to,credittime,creditlimit,turnover,billing_address,bcountry,bstate,bdistrict,bcity,bpin,bemail,bphone,bfax,bstate_code,bgst_no,shipping_address,scountry,sstate,sdistrict,scity,spin,semail,sphone,sfax,sstate_code,sgst_no,unique_id,created_by,created_date,created_dept,entry_by,new_create,customer_id) values ('$customer_name','$comptype','$pan_no','$assigned_to','$credittime','$creditlimit','$turnover','$billing_address','$bcountry','$bstate','$bdistrict','$bcity','$bpin','$bemail','$bphone','$bfax','$bstate_code','$bgst_no','$shipping_address','$scountry','$sstate','$sdistrict','$scity','$spin','$semail','$sphone','$sfax','$sstate_code','$sgst_no','$unique_id','$staff_name','$today','$created_dept','$staff_name','NEW','$customer_id')";

$r=mysql_query($query,$conn);


//$query = "insert customer_master(acccode,customer_name,dispname,comptype,website,paccname,assigned_to,credittime,creditlimit,lsrc,turnover,industry,subindustry,billing_address,bcountry,bstate,bdistrict,bcity,bpin,bemail,bphone,bfax,bstate_code,shipping_address,scountry,sstate,sdistrict,scity,spin,semail,sphone,sfax,sstate_code,unique_id,description,created_by,created_date,created_dept,entry_by,new_create,segment,customer_id) values ('$acccode','$customer_name','$dispname','$comptype','$website','$paccname','$assigned_to','$credittime','$creditlimit','$lsrc','$turnover','$industry','$subindustry','$billing_address','$bcountry','$bstate','$bdistrict','$bcity','$bpin','$bemail','$bphone','$bfax','$bstate_code','$shipping_address','$scountry','$sstate','$sdistrict','$scity','$spin','$semail','$sphone','$sfax','$sstate_code','$unique_id','$notes','$staff_name','$today','$created_dept','$staff_name','NEW','$segment','$customer_id')";

//$r=mysql_query($query,$conn);

//echo $query;





$qry9 = "select * from customer_master where unique_id = '$unique_id' and customer_id='$customer_id'";
$re9 = mysql_query($qry9);
while($row=mysql_fetch_array($re9))
		{  
		$id = $row['id'];
		$customer_name = $row['customer_name'];
		}
		
//echo $qry2;

$saul = $_POST['saul'];
$name = $_POST['name'];
$gender = $_POST['gender'];
$bday = $_POST['bday'];
$department = $_POST['department'];
$designation = $_POST['designation'];
$contact_types = $_POST['contact_types'];
$email = $_POST['email'];
$office_phone = $_POST['office_phone'];
$mobile_no = $_POST['mobile_no'];
$linkedinid = $_POST['linkedinid'];
$twitterid = $_POST['twitterid'];
$remark = $_POST['remark'];
if($name!=''){
$qry3 = "insert into contact_person(id,customer_id,saul,name,gender,bday,department,designation,contact_types,email,office_phone,mobile_no,linkedinid,twitterid,remark,customer_name) values ('$id','$customer_id','$saul','$name','gender','$bday','$department','$designation','$contact_types','$email','$office_phone','$mobile_no','$linkedinid','$twitterid','$remark','$customer_name')";
$r3=mysql_query($qry3,$conn);
}
if($shipping_address!='') { 
$query2fs = "insert into factory_address (id,address,country,state,district,city,pincode,email,phone,fax,suburb,customer_id,sstate_code,gst_no) values ('$id','$shipping_address','$scountry','$sstate','$sdistrict','$scity','$spin','$semail','$sphone','$sfax','$ssuburb','$customer_id','$sstate_code','$sgst_no')";
//echo $query2fs;
$r4s=mysql_query($query2fs,$conn);
}
$query2f = "insert into factory_address (id,address,country,state,district,city,pincode,email,phone,fax,suburb,customer_id,sstate_code,gst_no,biil_address) values ('$id','$billing_address','$bcountry','$bstate','$bdistrict','$bcity','$bpin','$bemail','$bphone','$bfax','$bsuburb','$customer_id','$bstate_code','$bgst_no','YES')";
//echo $query2f;


$r4=mysql_query($query2f,$conn);
//echo $qry3;
//exit();

?> 

<script>
javascript:window.location.href="view_account.php?msg='Accounts added successfully'&&id=<? echo $id;?>&&customer_id=<? echo $customer_id?>";
</script>
