<?php 

error_reporting(0);

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


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

function BRANCH_ADD($branch,$cc_charge,$docs,$cc_vvp,$mobNo){
	include '../Admin_config/connection.php';
	
	$desc="SELECT (MAX(branch_id)) AS `last_id` FROM sc_branch";
	$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 = "br_0".$incId;
	}else{
		$newId = "br_".$incId;
	}

	$sql= "INSERT INTO `sc_branch`(`branch_id`, `branch_name`, `br_parcel`, `br_docs`, `br_vvp`,`mobNo`) VALUES ('$newId','$branch','$cc_charge','$docs','$cc_vvp','$mobNo')";
	$result=mysqli_query($conn,$sql);

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

function BRANCH_EDIT($branch,$cc,$docs,$cc_vvp){
	include '../Admin_config/connection.php';
	
	$sql= "UPDATE `sc_branch` SET `br_parcel`='$cc',`br_docs`='$docs',`br_vvp`='$cc_vvp' WHERE `branch_name`='$branch'";
	$result=mysqli_query($conn,$sql);

	if ($result) {
		echo '<script type="text/javascript">alert("Charges Edited Successfully");
		window.location.href="../views/couriercharges.php";
		</script>';
	}
	return($branch_edit);
}

?>
