<?php 
include 'load.php'; 

if(isset($_GET['gid'])){
    $gid = $_GET['gid'];
    $result = mysqli_query($conn, "SELECT * FROM grn_item WHERE grn_no='$gid'");

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
            $quantity = $row['qty'];
            $productid = $row['product_id'];
            $sql3 = "UPDATE tbl_stock SET qty = qty - $quantity WHERE prid='$productid'";
                    $conn->query($sql3);
        }
    }


    $sql = "DELETE FROM grn_item WHERE grn_no='$gid'";
    if ($conn->query($sql) === TRUE) {
         $sql1 = "DELETE FROM grn WHERE grn_no='$gid'";
          if ($conn->query($sql1) === TRUE) {
                 header("location: list-grn.php");
          }
    }

}


?>