<?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'] == 'delete')

	{

		$tr_id = $_POST['tr_id'];

		$sql = "DELETE FROM adjusted_stock WHERE tr_id = '".$tr_id."' ";

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

            $statement->execute(); // no need to add `$sql` here, you can take that out

   

		



		$sql = "SELECT jv_id FROM jv WHERE source = 'TR Item' and ref_id = '".$tr_id."' ";

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

            $statement->execute(); // no need to add `$sql` here, you can take that out

            $jv_id = $statement->fetchColumn();

            



             $sql = "DELETE FROM jv WHERE jv_id = '".$jv_id."' ";

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

            $statement->execute();



            $sql = "DELETE FROM jv_detail WHERE jv_id = '".$jv_id."' ";

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

            $statement->execute();

            



		

		//$result = $statement->fetchAll();	

		

	}

}



?>