<?php
include "../../inc/inc.koneksi.php";
include '../../inc/fungsi_tanggal.php';
session_start();

$kode		=$_POST[kode];
$tanggal	=$_POST[tanggal];
$kodepl 	=$_POST[kodepl];
$tbayar 	=$_POST[tbayar];

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

$query = mysql_query("SELECT * FROM jurppi WHERE kode_ppi='$kode'");

while($data=mysql_fetch_array($query)){
	$nofak	= $data[nofak];	
	$dibayar= $data[dibayar];
	
	mysql_query("UPDATE piutang SET jumlah=jumlah+$dibayar WHERE kode_pl='$kodepl' AND nofak='$nofak'");
}

// --->debet kas bertambah
mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$tbayar WHERE noakun='$kas'");
	
// --->kredit piutang bertambah
mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$tbayar WHERE noakun='$piut'");
mysql_query("UPDATE akun_bp SET mutasi_kd=mutasi_kd-$tbayar WHERE noakun='$nobppi'");

mysql_query("UPDATE jurppi SET batal='BATAL' WHERE kode_ppi='$kode'");
mysql_query("DELETE FROM rekapjur WHERE kode_tr='$kode'");
?>