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

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


$sql 	= mysql_query("SELECT * FROM piut_bg WHERE nobg= '$nobg'");
$row	= mysql_num_rows($sql);
if ($row>0){
	$r 		= mysql_fetch_assoc($sql);
	$jumlah	= $r[jumlah];
	$nobp 	= $piut.$r[kode_pl];
	
	$input = "DELETE FROM piut_bg WHERE nobg= '$nobg'";
	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 BG : $kode sukses dihapus";
}else{
	echo "Maaf, nomor BG $kode tidak ada";
}
?>