<?php
include('connection/conn.php');
if(isset($_GET['purchase_id']))
{
	$id=$_GET['purchase_id'];
	
	echo $a="select * from `purchase_fatura_item` where `p_f`=$id ";
	$gett=$conn->query($a);
	while($get_row=mysqli_fetch_array($gett)){
		$code=$get_row['p_f_i_code'];
		$set=$get_row['p_f_i_set'];
		
		$gett2=$conn->query("select * from `item_set` where `i_s_barcode`='$code' ");
		$get_row2=mysqli_fetch_array($gett2);
		$old_num=$get_row2['i_set_number'];
		$new_num=$old_num-$set;
		
		$up=$conn->query("update item_set set `i_set_number`='$new_num' where `i_s_barcode`='$code' ");
		$del="delete from  `purchase_fatura_item` where `p_f_i_code`='$code'";
		$conn->query($del);
	}
	
	
	$del2="delete from  `purchase_fatura` where `p_f_id`=$id";
	$conn->query($del2);
	$del2="delete from  `purchase_inv` where `inv_code`=$id and `inv_type`='purchase'";
	$conn->query($del2);
	echo "<script type='text/javascript'>window.location.href = 'purchase.php'</script>";	
}
?>