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

$sql	= mysql_query("SELECT * FROM interface");
$r 		= mysql_fetch_assoc($sql);
$piut	= $r[piutang];
$labdit	= $r[laba_dit];


$sql 	= mysql_query("SELECT * FROM piutang WHERE nofak= '$kode'");
$row	= mysql_num_rows($sql);
if ($row>0){
	$r 		= mysql_fetch_assoc($sql);
	$jumlah	= $r[jumlah];
	$nobp 	= $piut.$r[kode_pl];
	
	$input = "DELETE FROM piutang 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= '$piut'");
	$r 		= mysql_fetch_assoc($sql);
	$saldo	= $r[saldo]-$jumlah;
	
	$input	= "UPDATE akun_bb SET saldo='$saldo',lastupdate=now() WHERE noakun= '$piut'";
	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 piutang : $kode sukses dihapus";
}else{
	echo "Maaf, nomor faktur $kode tidak ada";
}
?>