<?php  
	
	
	include ('includes/db1config.php');
	include ('../includes/mysql_connect.php');
	
	$query    = "DELETE FROM customer_invoices WHERE recordkey =".$_POST['id'];

	mysql_query($query); // query executed

	$getQuery = "SELECT * from customer_invoices where customer_id = ".$_POST['custid']." and master_record = 0 and invoice_number = '".$_POST['invoiceno']."' ";
	
	$rt       = mysql_query($getQuery); 
	
	while ( $row = mysql_fetch_assoc($rt) ) {
		
		$deleteLinked  = "DELETE FROM customer_invoices WHERE recordkey =".$row['recordkey'];
		mysql_query($deleteLinked); // query executed	
	}
		

	if( mysql_affected_rows() ){
		echo json_encode( array( 'msg' => 1 ) );
	} else {
		echo mysql_error();
	}
?>