<?
include "../../inc/inc.koneksi.php";

$kodeaw=$_POST[kodeaw];
$kodeak	=$_POST[kodeak];

$sql		= mysql_query("SELECT * FROM interface");
$r          = mysql_fetch_assoc($sql);
$piut	    = $r[piutang];
$labapb     = $r[laba_pb];
$labrug     = $r[laba_rugi];
$nosublpb   = substr($labapb,0,3);
$nosublr    = substr($labrug,0,3);

$query  = mysql_query("SELECT * FROM jurkm WHERE kode_km BETWEEN '$kodeaw' AND '$kodeak' AND posting='P' ORDER BY kode_km");
$row    = mysql_num_rows($query);
if($row>0){
while($r1=mysql_fetch_array($query)){
	$kodekm = $r1[kode_km];
	$tanggal= $r1[tanggal];
	$nokas 	= $r1[nokas];
	$noakun = $r1[noakun];
	$nobp 	= $r1[nobp];
	$nofak	= $r1[nofak];
	$jumlah	= $r1[jumlah];
	$ket 	= $r1[keterangan];
	$user 	= $r1[user];
	$nosubbk= substr($nokas,0,3);
	$nosubak= substr($noakun,0,3);
	$kelakun= (int) substr($noakun,0,1);
	
	// --->debet kas bertambah
	mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$jumlah WHERE noakun='$nokas'");
	
	// --->jika kode akun buku besar adalah piutang dagang, kurangi saldo piutang
	if($noakun==$piut){
	    $kodepl = substr($nobp,5,4);
		mysql_query("UPDATE piutang SET jumlah=jumlah+$jumlah WHERE kode_pl='$kodepl' AND nofak='$nofak'");
	}
	
	// --->kredit akun bertambah
	mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$jumlah WHERE noakun='$noakun'");
		
	if(!($nobp=='')){
		mysql_query("UPDATE akun_bp SET mutasi_kd=mutasi_kd-$jumlah WHERE noakun='$nobp'");
	}
	
	if($kelakun>3){
		// --->laba rugi debet
		mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$jumlah WHERE noakun='$labrug'");

		// --->laba periode berjalan kredit
		mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$jumlah WHERE noakun='$labapb'");
	}
	mysql_query("DELETE FROM rekapjur WHERE kode_tr='$kodekm' ");
} 
} 
mysql_query("UPDATE jurkm SET posting='' WHERE kode_km BETWEEN '$kodeaw' AND '$kodeak'");
?>