<?PHP
echo $txnid= $_GET['txnId'];




			session_start();


if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
	header ("Location: ../login.php");
}
		


?>


<?php
require 'config.php';

			 $db_handle = mysqli_connect(DB_SERVER, DB_USER, DB_PASS);
			 $database = $_SESSION['database'];
			$db_found = mysqli_select_db($db_handle, $database);





	
	

$SQLcash = "SELECT * FROM product_table where product_id= $txnid";
												$resul = mysqli_query($db_handle, $SQLcash);
											$db_cash = mysqli_fetch_assoc($resul);
											
										echo	$product_name = $db_cash['product_name'];
		
			


  if($db_found){
	 


	
	$SQL = "DELETE FROM product_table WHERE product_id=$txnid";
   $query_del = mysqli_query($db_handle, $SQL);
	
	  
	  
 $date = date("Y-m-d");
	
	 $time = date("h-i-s");
	  
	  $description =   'Deleted '.$product_name.' by '.$_SESSION['name'].' as at '.$date;
	  
	  
	  
	  
	  
	  
	  
	  
	  $db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database );

	$SQL = $db_found->prepare("INSERT INTO bmhistory (product_name, time, date, user_id, branch_key, app_code) VALUES (?,?,?,?,?,?)");
			$SQL->bind_param('ssssss', $description, $time, $date, $_SESSION['user_id'], $_SESSION['branch_key'], $_SESSION['app_code']);
			$SQL->execute();


	  
	  
	  
	  
	  
	  
	  
	  
	 header ("Location: inventory_ac.php");

	  
  }
	
else{
	
	echo "database not found";
}

	  

?>






	<html>
		
			<title>Delete_script</title>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
<!--===============================================================================================-->	
		 <link href="css/bootstrap-4.4.1.css" rel="stylesheet">
		
		
		
	<head>



	</head>
	<body>


		

			
	<div class="jumbotron" style="text-align: center">
		
		
		<h3><b><span style="color: #EC0408">Are you sure you want to DELETE this transaction?</b></h3>
		</span> <br> Transaction ID<?php echo $txnid;?>
		
		
		
			<table style="margin: auto;width: 100%" >
					<form action="record_delete.php" method="post">
		
	<tr>
				<td>
				
		 				<input type="submit" value="NO" class="btn btn-danger" style= "width:100%; height: 70px" name = "NO" >
					
				</td>
					
				<td>
					
		 			<a href="delet.php">	<input type="button"  value="YES" class="btn btn-danger" style= "width:100%; height: 70px"  > </a>
				</td>
	
	</tr>
	</form>
			
			</table>
	
		
			</div>
			
	

	</body>
	</html>
