<?php
session_start();
include '../includes/connection.php';
$id=base64_decode($_GET['id']);
$business=$_SESSION['business_id'];
$branch=$_SESSION['branch_id'];
$sqledit=mysqli_fetch_array(mysqli_query($con,"select * from consumable_items where id='$id'"));
$quantity=$sqledit['quantity'];
$name=$sqledit['name'];
if ($quantity>0) {
	echo"<script>alert('Failed: The Item cannot be deleted when it is in stock'),history.go(-1);
	window.location='consumables.php';
	</script>";
	}else{
$delete = mysqli_query($con,"update consumable_items set status =0 where id='$id'");

if($delete){
	$id_user=$_SESSION['id'];
  $activity="Deleted a consumable item ".$name;
  $log_sql=mysqli_query($con,"INSERT INTO logs(user_id, activity,branch_id,business_id) VALUES ('$id_user','$activity','$branch','$business')");
if($log_sql){
	echo"
	<script> alert('Item deleted successfully');
	window.location='consumables.php'</script>
	";
}
}
}
?>