<?php
	session_start();

	if(!isset($_SESSION['linkarisecrm']))
	{
		header('Location: index.php');
		return;
	}
	date_default_timezone_set("Asia/Kolkata");
	$mdate= date('Y-m-d');
	include("connect.php");
	
	
	$cmpmid=$_SESSION['linkarisecmpmid'];
	$brmid=$_SESSION['linkarisebranchid'];
	$umid = $_SESSION['linkariseumid'];

	$grnmid1 =(int)mysqli_real_escape_string($conn,$_GET['id']);
	
	 $eve15="SELECT * FROM res_paymentout_master WHERE outrefrenceid=$grnmid1 and cmpmid=$cmpmid";
	
	$re15 = mysqli_query($conn, $eve15);
	if(mysqli_num_rows($re15) > 0)
	{
			$_SESSION['msg1'] = "Payment Already Received So Record Can't be Deleted";
	}
	else
	{	
			$eve="delete from res_item_detail where itransactiontype='GRN In' and itemtranmid=".$grnmid1;
			$re = mysqli_query($conn, $eve);

			$query0="delete from res_grn_detail where grnmid=$grnmid1";
			$result= mysqli_query($conn, $query0) or die("Error1");

			/* echo $query2="delete from res_followup_detail where followuptype='GRN' and frefid=$grnmid";
			$result2= mysqli_query($conn, $query2) or die("Error2");
			 */
			$query1="delete from res_grn_master where grnmid=$grnmid1";
			$result1= mysqli_query($conn, $query1) or die("Error3");
			$_SESSION['msg'] = "GRN Deleted";
	}
	header('Location: grn.php');
?>