<?php 
session_start();
include '../db.php';
include("../all_query.php");
 
 
           $table = $_POST['table'];
          $record_ids = json_decode(stripslashes($_POST['record_ids']));
          $record_idsArray = json_decode(stripslashes($_POST['record_ids']));
		  $record_ids = implode(",",$record_ids);
		  
		  mysqli_query($conn,"delete from `$table` where id in ($record_ids) ");
		  
		  
		   if($table == 'leads')
		  {
			  
			   mysqli_query($conn,"delete from `reminder_notification` where lead_id in ($record_ids) ");
		  
			  
		  }
		  
		  
		  if($table == 'invoice')
		  {
			   
		
		$qry=mysqli_query($conn,"delete from `invoice_particular_details` where invoice_id in ($record_ids) ");
		$qry=mysqli_query($conn,"delete from `payments` where invoice_id in ($record_ids) ");
		
		
			foreach($record_idsArray as $id)
			{
				 $invoiceQ  = mysqli_query($conn,"select *from `invoice` where id = $id ");
				 $invoiceData = mysqli_fetch_assoc($invoiceQ);
				 $lead_no = $invoiceData['lead_no'];
				 
				 $leadQ = mysqli_query($conn,"select *from `leads` where lead_no = '$lead_no' ");
				 $leadData = mysqli_fetch_assoc($leadQ);
				 $lead_id = $leadData['id'];	
				 
				  mysqli_query($conn,"update leads set lead_status = 'counseling_done'  , p_lead_status = 'counseling_done'    where id = $lead_id ");

				
				
			}
	
		 
		  }
		  
		  if($table == 'tax_invoice')
		  {
			   
		
		$qry=mysqli_query($conn,"delete from `tax_invoice_particular_details` where invoice_id in ($record_ids) ");
		$qry=mysqli_query($conn,"delete from `ier_payments` where invoice_id in ($record_ids) ");
	
		 
		  }
		  
		  
		  
		  echo "Record Deleted Successfully";
            
 
 
 ?>