<?php 

error_reporting(0);

function ADD_CUSTOMER($fname,$lname,$full,$email,$add,$pan,$gst,$mobile){
	include '../Admin_config/connection.php';
	
	$desc="SELECT (MAX(cust_id)) AS `last_id` FROM sc_customers";
	$desc_res=mysqli_query($conn,$desc);
	$row = mysqli_fetch_assoc($desc_res);
	$temp = explode('_', $row['last_id']);
	$getId = end($temp);
	$incId = $getId + 1;

	if ($incId < 10) {
		$newId = "cs_0".$incId;
	}else{
		$newId = "cs_".$incId;
	}

    $sql= "INSERT INTO `sc_customers`(`cust_id`, `cust_fname`, `cust_lname`, `cust_fullname`,`cust_email`, `cust_address`, `cust_pan`, `cust_gst`, `cust_mobile`) VALUES ('$newId','$fname','$lname','$full','$email','$add','$pan','$gst','$mobile')";
	$result=mysqli_query($conn,$sql);

	if ($result) {
	    echo 'yes';
		echo '<script type="text/javascript">alert("Customer Added Successfully");';
		echo 'window.location.href = "../views/index.php";';
		echo '</script>';
	}
}

function CUSTOMER_FETCH(){
	include '../Admin_config/connection.php';
	$sql= "SELECT * FROM `sc_customers`";
	$result=mysqli_query($conn,$sql);
	$count=mysqli_num_rows($result);

	if ($count > 0) {
		$cust=array();
			while($row = mysqli_fetch_assoc($result))
			{
				$cust[] = $row;
			}
	}
	return($cust);
}

?>
