<?php









//user_action.php









include('db_con.php');




if (isset($_SESSION['user_id'])) {




		$user_type = $_SESSION['user_type'];




		$user_id = $_SESSION['user_id'];




		$user_name = $_SESSION['user_name'];




		$branch_id = $_SESSION['branch_id'];




		$branch_name = $_SESSION['branch_name'];




		$store_id = $_SESSION['store_id'];




    $store_name = $_SESSION['store_name'];




}else{




	header('Location: login');




	die();




}



















if(isset($_POST['btn_action']))









{









	if($_POST['btn_action'] == 'Add')




	{




		




		$query="select IFNULL(MAX(uom_id),10) from item_uom";




		$statement = $connect->prepare($query);




		$statement->execute();




		$uom_id = $statement->fetchColumn();




		if($uom_id < 9){$uom_id=10;}




		$uom_id++;



















		




		$query = "




		INSERT INTO item_uom(uom_id,uom_name,user_id,status)




        VALUES ('".$uom_id."','".$_POST["uom_name"]."','".$user_id."','".$_POST["status"]."')




    ";	




		$statement = $connect->prepare($query);




		$statement->execute();




			




		$result = $statement->fetchAll();




		if(isset($result))




		{




			echo 'New UOM Added';




		}




	}




	if($_POST['btn_action'] == 'fetch_single')




	{




		$query = "




		SELECT * FROM item_uom WHERE uom_id = :uom_id";




		




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




				':uom_id'	=>	$_POST["uom_id"]




			)




		);




		$result = $statement->fetchAll();




		foreach($result as $row)




		{




			




			




			//$output['dated']          =  $row['dated'];




          $output['uom_name']          =  $row['uom_name'];




        




          




          $output['status']       =  $row["status"];




          




		}




		echo json_encode($output);




	}




	if($_POST['btn_action'] == 'Edit')




	{




		




		




			$query = "




			UPDATE item_uom SET




				




				uom_name = '".$_POST["uom_name"]."',




				




				user_id = '".$user_id."',													




				status = '".$_POST["status"]."'




				WHERE uom_id = '".$_POST["uom_id"]."'




			";




		




		$statement = $connect->prepare($query);




		$statement->execute();




		$result = $statement->fetchAll();




		if(isset($result))




		{




			echo 'Item UOM Edited';




		}




	}




	if($_POST['btn_action'] == 'delete')




	{




		$status = 'Inactive';




		if($_POST['status'] == 'Active')




		{




			$status = 'Inactive';




		}




		$query = "




		UPDATE item_uom




		SET status = :status 




		WHERE uom_id = :uom_id




		";




		$statement = $connect->prepare($query);




		$statement->execute(




			array(




				':status'	=>	$status,




				':uom_id'		=>	$_POST["uom_id"]




			)




		);	




		$result = $statement->fetchAll();	




		if(isset($result))




		{




			echo 'UOM Status change to ' . $status;




		}




	}




}









?>