
<?php
// delete invoice , reciepts
include 'includes/database.php';
$db=new MySQLDatabase();
$db->open_connection();
if(isset($_REQUEST['d'])){
 $insno = $_REQUEST['d'];
 $sql = mysqli_query($db->connection, "SELECT * FROM insrecs WHERE insno = '$insno';") or die (mysqli_error($db->connection) );
 if ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
    $billno = $row['billno'];	$billno1 = $row['billno1'];		$billno2 = $row['billno2'];		$billno3 = $row['billno3'];
	$invno = $row['invno'];		$invno1 = $row['invno1'];		$invno2 = $row['invno2'];		$invno3 = $row['invno3'];
	$dsql = mysqli_query($db->connection, "SELECT * FROM insinvoices WHERE invno = '$invno';") or die (mysqli_error($db->connection) );
	if ($rowr = mysqli_fetch_array($dsql, MYSQLI_ASSOC)){ $recpno = $rowr['recpno'];  
										   $dsql = mysqli_query($db->connection, "DELETE FROM recptrans WHERE recpno = '$recpno';") or die (mysqli_error($db->connection) );
										  }
	$dsql = mysqli_query($db->connection, "DELETE FROM insrecs WHERE insno = '$insno';") or die (mysqli_error($db->connection) );
	$dsql = mysqli_query($db->connection, "DELETE FROM insinvoices WHERE invno = '$invno';") or die (mysqli_error($db->connection) );
	if ($invno1 !=='0'){ $dsql = mysqli_query($db->connection, "DELETE FROM insinvoices WHERE invno = '$invno1';") or die (mysqli_error($db->connection) ); }
	if ($invno2 !=='0'){ $dsql = mysqli_query($db->connection, "DELETE FROM insinvoices WHERE invno = '$invno2';") or die (mysqli_error($db->connection) ); }
	if ($invno3 !=='0'){ $dsql = mysqli_query($db->connection, "DELETE FROM insinvoices WHERE invno = '$invno3';") or die (mysqli_error($db->connection) ); }
	if ($billno1 !=='0'){ $dsql = mysqli_query($db->connection, "DELETE FROM insbills WHERE billno = '$billno1';") or die (mysqli_error($db->connection) ); }
	if ($billno2 !=='0'){ $dsql = mysqli_query($db->connection, "DELETE FROM insbills WHERE billno = '$billno2';") or die (mysqli_error($db->connection) ); }
	if ($billno3 !=='0'){ $dsql = mysqli_query($db->connection, "DELETE FROM insbills WHERE billno = '$billno3';") or die (mysqli_error($db->connection) ); }	
    }
 
 $db->close_connection(); 	
 echo "Insurance Deleted!";
}
?>
