<?
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 jurbm WHERE kode_bm BETWEEN '$kodeaw' AND '$kodeak' AND posting='P' ORDER BY kode_bm");
$row    = mysql_num_rows($query);
if($row>0){
    while($r1=mysql_fetch_array($query)){
	    $kodebm 	= $r1[kode_bm];
	    $tanggal	= $r1[tanggal];
	    $nobank 	= $r1[nobank];
	    $noakun 	= $r1[noakun];
	    $nobp 		= $r1[nobp];
    	$nofak		= $r1[nofak];
	    $jumlah		= $r1[jumlah];
	    $ket 		= $r1[keterangan];
	    $user 		= $r1[user];
	    $nosubbk	= substr($nobank,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='$nobank'");
	
	    // --->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='$kodebm' ");
	    mysql_query("UPDATE jurbm SET posting='' WHERE kode_bm='$kodebm'");
    }
}
?>