<?php
if(isset($_GET['id'])){
  include '../includes/connection.php';
    $id = $_GET['id'];
    session_start(); 
date_default_timezone_set("Africa/Kampala");
$myid=$_SESSION['id'];
$id_user=$_SESSION['id'];
$branch=$_SESSION['branch_id'];
$role=$_SESSION['role'];
$business=$_SESSION['business_id'];
$sql = mysqli_query($con,"SELECT category as cate,(select categoryName from expense_categories where id=cate)as name, amount from expenses where id='$id'");
$row=mysqli_fetch_array($sql);
$ename = $row['name'];
$amount = number_format($row['amount']);
$activity="Deleted an expense made on $ename for  $amount";
  $log_sql=mysqli_query($con,"INSERT INTO logs(user_id, activity,branch_id,business_id) VALUES 
('$id_user','$activity','$branch','$business')");
if($log_sql){
    $delete = mysqli_query($con,"DELETE from expenses where id='$id'");
    if($delete){
      echo "<script>
                        alert('expense has been deleted successfully');
                        window.location='expenses.php'
                        </script>";
    }
}
}
?>