<?php require_once('../auth/auth.php'); 
	$debitor_id=mysqli_fetch_assoc(mysqli_query($conn,"SELECT ac_g_catid FROM ac_sub_g_category WHERE   coid='$coid' AND g_type='su-deb' LIMIT 1 "))['ac_g_catid']; 

	$creditor_id=mysqli_fetch_assoc(mysqli_query($conn,"SELECT ac_g_catid FROM ac_sub_g_category WHERE   coid='$coid' AND g_type='su-cre' LIMIT 1 "))['ac_g_catid'];
 ?>
<?php 
 // Customer Number check 
	if(!empty($_POST["cus_ac_number"])) {
	$customer_result = mysqli_query($conn,"SELECT count(*) FROM accounts WHERE coid='$coid' AND bid='$bid'  AND gcatid='$debitor_id' AND ac_number='" . $_POST["cus_ac_number"] . "'");
	$row_cus = mysqli_fetch_row($customer_result);
	$cus_count = $row_cus[0];
	if($cus_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}
 // supplier Number check
	if(!empty($_POST["ac_number"])) {
	$supplier_result = mysqli_query($conn,"SELECT count(*) FROM accounts WHERE coid='$coid' AND bid='$bid'  AND gcatid='$creditor_id' AND ac_number='" . $_POST["ac_number"] . "'");
	$row_supp = mysqli_fetch_row($supplier_result);
	$sup_count = $row_supp[0];
	if($sup_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}
// Customer And Supplier Outlet Id check 
	if(!empty($_POST["outlet_id"])) {
	$outlet_result = mysqli_query($conn,"SELECT count(*) FROM accounts WHERE coid='$coid' AND bid='$bid' AND outlet_id='" . $_POST["outlet_id"] . "'");
	$row_out = mysqli_fetch_row($outlet_result);
	$out_count = $row_out[0];
	if($out_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}

?>


<?php
 // company Number check
	if(!empty($_POST["co_number"])) {
	$result_co = mysqli_query($conn,"SELECT count(*) FROM company WHERE  co_phone='" . $_POST["co_number"] . "'");
	$row_co = mysqli_fetch_row($result_co);
	$co_phone_count = $row_co[0];
	if($co_phone_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}
 // username check
	if(!empty($_POST["username"])) {
	$result_user = mysqli_query($conn,"SELECT count(*) FROM user WHERE  username='" . $_POST["username"] . "'");
	$row_user = mysqli_fetch_row($result_user);
	$user_count = $row_user[0];
	if($user_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}
?>

<?php
 // Item Model check
	if(!empty($_POST["model_name"])) {
	$result_item_name = mysqli_query($conn,"SELECT count(*) FROM item WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND  item_name='" . $_POST["model_name"] . "'");
	$row_mod = mysqli_fetch_row($result_item_name);
	$model_count = $row_mod[0];
	if($model_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}
//  item code check
	if(!empty($_POST["item_code"])) {
	$result_item_code = mysqli_query($conn,"SELECT count(*) FROM item WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND  item_code='" . $_POST["item_code"] . "'");
	$row_code = mysqli_fetch_row($result_item_code);
	$code_count = $row_code[0];
	if($code_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}
	
//  item IMEI code check
	if(!empty($_POST["imei_number_check"])) {
	$result_item_imeicode = mysqli_query($conn,"SELECT count(*) FROM imei_tracker WHERE coid='$coid' AND bid='$bid' AND brid='$brid' AND  imei_code='" . $_POST["imei_number_check"] . "'");
	$row_imei = mysqli_fetch_row($result_item_imeicode);
	$imei_count = $row_imei[0];
	if($imei_count>0) echo "<strong style='color:red;margin-left:8px;'> Already Exists .</strong>";
	else echo "<strong style='color:green;margin-left:8px;'> Available.</strong>";
	}
?>