<?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'];
if(isset($_POST['invoicemid'])){
$invoicemid1 =(int)mysqli_real_escape_string($conn,$_POST['invoicemid']);}
	else{
		$invoicemid1=(int)mysqli_real_escape_string($conn,$_GET['id']);
	}
	
	
	 $eve15="SELECT * FROM res_paymentin_master WHERE receiptrefrenceid=$invoicemid1 and cmpmid=$cmpmid";
	
	$re15 = mysqli_query($conn, $eve15);
	if(mysqli_num_rows($re15) > 0)
	{
			$_SESSION['msg1'] = "Payment Already Receipt So Record Can't be Deleted";
	}
	else
	{	
			$eve="delete from res_item_detail where itransactiontype='Invoice Out' and itemtranmid=".$invoicemid1;
			$re = mysqli_query($conn, $eve);

			$query0="delete from res_invoice_detail where invoicemid=$invoicemid1";
			$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_invoice_master where invoicemid=$invoicemid1";
			$result1= mysqli_query($conn, $query1) or die("Error3");
			$_SESSION['msg'] = "Invoice Deleted";
	}
	header('Location: retailinvoice.php');
?>