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

$kode		=$_POST[kode];
$nomorsa	=$_POST[nomorsa];
$kodesp 	=$_POST[kodesp];
$tunit		=$_POST[tunit];
$total		=$_POST[total];

$sql			= mysql_query("SELECT * FROM interface");
$r				= mysql_fetch_assoc($sql);

$persed	= $r[persed];
$umpbl		= $r[um_pbl];
$kodelpg	= $r[kode_lpg];
$nobpump	= $umpbl.$kodesp;

$sql = mysql_query("SELECT * FROM surat_jln WHERE kode_pj='$kode' AND batal='' ORDER BY no_urut");
$row= mysql_num_rows($sql);
if($row>0){
	mysql_query("UPDATE stock SET jml_stok=jml_stok-$tunit WHERE kode_st='$kodelpg'");
	
	mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$total WHERE noakun='$persed' ");
	
	mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$total WHERE noakun='$umpbl'");
	mysql_query("UPDATE akun_bp SET mutasi_kd=mutasi_kd-$total WHERE noakun='$nobpump' ");
	
	mysql_query("DELETE FROM rekap_mbr WHERE kode_tr='$kode'");
	mysql_query("DELETE FROM rekapjur WHERE kode_tr='$kode'");
	
	mysql_query("UPDATE surat_jln SET batal='BATAL' WHERE kode_sj='$kode'");

	echo "Surat jalan nomor $kode telah dibatalkan !";
}
?>