<?php include 'load.php'; 

if(isset($_POST['delete_return'])){
    $rno = $_GET['rno'];

    $purchase_order_items = mysqli_query($conn, "SELECT * FROM tbl_return_items WHERE return_id='$rno'");

    if ($purchase_order_items->num_rows > 0) {
        while($row = $purchase_order_items->fetch_assoc()) {
            $qty = $row['qty'];
            $product_id = $row['prid'];
            $sql3 = "UPDATE tbl_stock SET qty = qty + $qty WHERE prid = '$product_id'";
            if ($conn->query($sql3) === TRUE) {
                $sql = "DELETE FROM tbl_return_items WHERE return_id='$rno'";
                if ($conn->query($sql) === TRUE) {
                    $sql1 = "DELETE FROM tbl_return WHERE return_id ='$rno'";
                    if ($conn->query($sql1) === TRUE) {
                        header("Location: return-list.php");
                    }
                }

            }

        }
    }
}


?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Eat More Resturant   | Pos & Invetory System | Dashboard
">
<meta name="keywords" content="Eat More Resturant   | Pos & Invetory System | Dashboard
">
<meta name="author" content="Eat More Resturant   | Pos & Invetory System | Dashboard
">
<meta name="robots" content="noindex, nofollow">

<title>Delete Return | Eat More Resturant   | Pos & Invetory System | Dashboard
</title>


<?php
require_once 'headercss.php';
?>
</head>
<body>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>

<div class="main-wrapper">
<?php
require_once 'header.php';
?>

<?php
require_once 'navbar.php';
?>

<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Purchase Order Management</h4>
<h6>Delete Return</h6>
</div>

					





</div>

<div class="card">
<div class="card-body">

									<?php

									if(isset($errMSG)){

									?>
			
									<div class="alert alert-danger alert-dismissible alert-alt solid fade show">
									<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i class="mdi mdi-close"></i></span></button>
									<strong>Error!</strong> <?php echo $errMSG; ?>
									</div>

									<?php

									}
	
									else if(isset($successMSG)){

									?>
			
									<div class="alert alert-success alert-dismissible alert-alt solid fade show">
									<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i class="mdi mdi-close"></i></span></button>
									<strong>Success!</strong> <?php echo $successMSG; ?>.
									</div>

									<?php

									}

									?>
<div class="row">
<form action="" method="post">
<h3 class="mb-2">Your are going to delete Return?</h3>
<div class="col-lg-12">
   
                     <input type="submit" name="delete_return" class="btn btn-danger" value="Delete Return">
                     
                     <a class="btn btn-primary" href="return-list.php">Back</a>
                </div>    
                </form>









</div>
</div>
</div>


<script src="assets/js/jquery-3.6.0.min.js"></script>

<script src="assets/js/feather.min.js"></script>

<script src="assets/js/jquery.slimscroll.min.js"></script>

<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/dataTables.bootstrap4.min.js"></script>

<script src="assets/js/bootstrap.bundle.min.js"></script>

<script src="assets/plugins/select2/js/select2.min.js"></script>

<script src="assets/plugins/sweetalert/sweetalert2.all.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalerts.min.js"></script>

<script src="assets/js/script.js"></script>

<script>
	$(document).ready(function(){
		$('.select2').select2();
		loaditems();

		$(".add").click(function(){
			var product = $('.product').val(); 
			var supplier = $('#inputsupplier').val(); 
			var qty = $('.qty').val();
			var invoice_no = $('#invoice_no').val();
			$.ajax({
           		type: "POST",
				data: {product:product,qty:qty,supplier:supplier,invoice_no:invoice_no},
				url: "add-prodcut-to-list.php",
					success: function(data){
						loaditems();
					}
				});
  		});

		 
		  
	});

	
</script>


</body>
</html>