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

$kode		=$_POST[kode];
$tanggal	=$_POST[tanggal];
$nomorsa	=$_POST[nomorsa];
$kodesp 	=$_POST[kodesp];
$namasp	=$_POST[namasp];
$user 		=$_POST[user];
$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];
$nosubps	= substr($persed,0,3);
$nosubump= substr($umpbl,0,3);
$nobpump	= $umpbl.$kodesp;

$sql = mysql_query("SELECT * FROM surat_jln WHERE kode_sj='$kode' AND posting='' 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("INSERT INTO rekap_mbr (kode_tr,jurnal,tanggal,no_bukti,no_urut,kode_st,keterangan,masuk,user) VALUES('$kode','SRJ','$tanggal','$nomorsa','1','$kodelpg','Pengambilan $tunit tabung LPG $namasp','$tunit','$user')");

	mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db+$total WHERE noakun='$persed' ");
	mysql_query("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,noakun,nosub,debet,keterangan,user) VALUES('$kode','SRJ','$tanggal','$nomorsa','$persed','$nosubps','$total','Pengambilan $tunit tabung LPG $namasp','$user')");

	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("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,noakun,nosub,nobp,kredit,keterangan,user) VALUES('$kode','SRJ','$tanggal','$nomorsa','$umpbl','$nosubump','$nobpump','$total','Pengambilan $tunit tabung LPG $namasp','$user')");
	
	mysql_query("UPDATE tebus_do SET jml_real=jml_real+$tunit WHERE nomor_sa='$nomorsa' ");
	mysql_query("UPDATE surat_jln SET posting='P' WHERE kode_sj='$kode'");

	echo "Data sukses disimpan";
}
?>