<?php
session_start();

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
		$cmpmid=$_SESSION['linkarisecmpmid'];
	$brmid=$_SESSION['linkarisebranchid'];
	$umid = $_SESSION['linkariseumid'];

	include("connect.php");
	
	date_default_timezone_set("Asia/Kolkata");
	$mdate1= date('Y-m-d H:i:s');
	$mdate2= date('d-m-Y');
	
	$expno=(int)mysqli_real_escape_string($conn,$_GET['id']);
	
	$expensemmid=0;
	
	$eve1="select * from res_expense_detail where expensemmid=$expno and cmpmid=$cmpmid";
	
	$re1= mysqli_query($conn,$eve1);
	
	if(mysqli_num_rows($re1) > 0)
	{
		while($rt1 = mysqli_fetch_assoc($re1))
		{
			$expensemmid=$rt1['expensemmid'];
		}
	}
	
	$query="delete from res_expense_detail where expensemmid=$expno and cmpmid=$cmpmid";
	$result= mysqli_query($conn, $query) ;
		
	
	$query2="delete from res_paymenttransaction_detail where Paymentrefid=$expensemmid and paymenttype='Expense'";
	$result2= mysqli_query($conn, $query2) ;
		
	$_SESSION['msg'] = "Record deleted successfully";
	header('Location: expensemanagement.php');
	
?>