<?php
include "../../inc/inc.koneksi.php";
$kode	= $_POST['kode'];

$sql	= mysql_query("SELECT * FROM interface");
$r 		= mysql_fetch_assoc($sql);
$utang	= $r['hutang_dg'];
$labdit	= $r['laba_dit'];


$sql 	= mysql_query("SELECT * FROM hutang WHERE nofak= '$kode'");
$row	= mysql_num_rows($sql);
if ($row>0){
	$r 		= mysql_fetch_assoc($sql);
	$jumlah	= $r['jumlah'];
	$nobp 	= $utang.$r['kode_sp'];
	
	$input = "DELETE FROM hutang WHERE nofak= '$kode'";
	mysql_query($input);
	
	$sql 	= mysql_query("SELECT * FROM akun_bp WHERE noakun= '$nobp'");
	$r 		= mysql_fetch_assoc($sql);
	$saldo	= $r['saldo']-$jumlah;
	
	$input	= "UPDATE akun_bp SET saldo='$saldo',lastupdate=now() WHERE noakun= '$nobp'";
	mysql_query($input);
	
	$sql 	= mysql_query("SELECT * FROM akun_bb WHERE noakun= '$utang'");
	$r 		= mysql_fetch_assoc($sql);
	$saldo	= $r['saldo']-$jumlah;
	
	$input	= "UPDATE akun_bb SET saldo='$saldo',lastupdate=now() WHERE noakun= '$utang'";
	mysql_query($input);
	
	$sql 	= mysql_query("SELECT * FROM akun_bb WHERE noakun= '$labdit'");
	$r 		= mysql_fetch_assoc($sql);
	$saldo	= $r['saldo']+$jumlah;
	
	$input	= "UPDATE akun_bb SET saldo='$saldo',lastupdate=now() WHERE noakun= '$labdit'";
	mysql_query($input);
	
	echo "Data hutang : $kode sukses dihapus";
}else{
	echo "Maaf, nomor faktur $kode tidak ada";
}
?>