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

$kode	=$_POST[kode];
$tanggal=$_POST[tanggal];
$jenis	=$_POST[jenis];
$tanki 	=$_POST[tanki];
$jmlstok=$_POST[jmlstok];
$jmlstik=$_POST[jmlstik];
$jmlsls =$_POST[jmlsls];
$hgbeli =$_POST[hgbeli];
$nilai  =$_POST[nilai];
$user	=$_SESSION[namauser];

$sql	= mysql_query("SELECT * FROM interface");
$r 		= mysql_fetch_assoc($sql);
$persed = $r[persed];
$labapb = $r[laba_pb];
$biuap  = $r[biaya_uap];
$labarugi= $r[laba_rugi];
$prem   = $r[premium];
$solar  = $r[solar];
$ptmx   = $r[pertamax];
$ptmp   = $r[ptm_plus];
$ptlt   = $r[pertalite];
$dex    = $r[ptmn_dex];
$dexlite= $r[dexlite];
$solek  = $r[solar_eko];
$nosubps= substr($persed,0,3);
$nosublp= substr($labapb,0,3);
$nosubbi= substr($biuap,0,3);
$nosublr= substr($labarugi,0,3);

if($jenis=='Premium')
	$kodest=$prem;
else if($jenis=='Bio Solar')
	$kodest=$solar;
else if($jenis=='Pertamax')
	$kodest=$ptmx;
else if($jenis=='Pertamax Plus')
	$kodest=$ptmp;
else if($jenis=='Pertalite')
	$kodest=$ptlt;
else if($jenis=='Pertamina Dex')
	$kodest=$dex;
else if($jenis=='Dexlite')
	$kodest=$dexlite;
else
	$kodest=$solek;

$bpuap= $biuap.substr(kodest,2,4);

$input = "INSERT INTO penguapan (kode_ls,tanggal,jenis,tanki,jml_stok,jml_stik,jml_sls,hg_beli,nilai_sls,user) VALUES('$kode','$tanggal','$jenis',
'$tanki','$jmlstok','$jmlstik','$jmlsls','$hgbeli','$nilai','$user')";
mysql_query($input);

// update stok
$sql1 = mysql_query("SELECT * FROM stock WHERE kode_st='$kodest' ORDER BY kode_st");
$r1=mysql_fetch_assoc($sql1);
if($tanki=='1'){
	$stok=$r1[jml_gd1]-$jmlsls;
	$input1 = "UPDATE stock SET jml_gd1='$stok' WHERE kode_st='$kodest'";
}else if($tanki=='2'){
	$stok=$r1[jml_gd2]-$jmlsls;
	$input1 = "UPDATE stock SET jml_gd2='$stok' WHERE kode_st='$kodest'";
}else if($tanki=='3'){
	$stok=$r1[jml_gd3]-$jmlsls;
	$input1 = "UPDATE stock SET jml_gd3='$stok' WHERE kode_st='$kodest'";
}else{
	$stok=$r1[jml_gd4]-$jmlsls;
	$input1 = "UPDATE stock SET jml_gd4='$stok' WHERE kode_st='$kodest'";
}
mysql_query($input1);

// buat kartu stok
$input1 = "INSERT INTO rekap_mbr (kode_tr,jurnal,tanggal,no_bukti,kode_st,keterangan,gudang,keluar,harga,user) VALUES('$kode','LOB','$tanggal','$kode','$kodest','Penguapan $jenis','$tanki','$jmlsls','$hgbeli','$user')";
mysql_query($input1);

// update akun persediaan
$sql = mysql_query("SELECT noakun,mutasi_kd FROM akun_bb WHERE noakun='$persed' ");
$r = mysql_fetch_assoc($sql);
$kredit= $r[mutasi_kd]+$nilai;

$input	= "UPDATE akun_bb SET mutasi_kb='$kredit' WHERE noakun='$persed'";
mysql_query($input);

// buat buku besar persediaan
mysql_query("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,noakun,nosub,kredit,keterangan,user) VALUES('$kode','LOS','$tanggal','$kode','$persed','$nosubps','$nilai','Penguapan $jenis tanki $tanki $jmlsls liter','$user')");

// update akun biaya penguapan
$sql = mysql_query("SELECT noakun,mutasi_db FROM akun_bb WHERE noakun='$biuap' ");
$r = mysql_fetch_assoc($sql);
$debet = $r[mutasi_db]+$nilai;

$input	= "UPDATE akun_bb SET mutasi_db='$debet' WHERE noakun='$biuap";
mysql_query($input);

// update akun bp biaya penguapan
$sql = mysql_query("SELECT noakun,mutasi_db FROM akun_bp WHERE noakun='$bpuap' ");
$r = mysql_fetch_assoc($sql);
$debet= $r[mutasi_db]+$nilai;

$input	= "UPDATE akun_bp SET mutasi_db='$debet' WHERE noakun='$bpuap'";
mysql_query($input);

// buat buku besar biaya penguapan
mysql_query("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,noakun,nosub,nobp,debet,keterangan,user) VALUES('$kode','LOS','$tanggal','$kode','$biuap','$nosubdo','$bpuap','$nilai','Penguapan $jenis tanki $tanki $jmlsls liter','$user')");

// update akun laba periode berjalan
$sql = mysql_query("SELECT noakun,mutasi_db FROM akun_bb WHERE noakun='$labapb' ");
$r = mysql_fetch_assoc($sql);
$debet = $r[mutasi_db]+$nilai;

$input	= "UPDATE akun_bb SET mutasi_db='$debet' WHERE noakun='$labapb";
mysql_query($input);

// buat buku besar laba periode berjalan
mysql_query("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,noakun,nosub,debet,keterangan,user) VALUES('$kode','LOS','$tanggal','$kode','$labapb','$nosublp','$nilai','Penguapan $jenis tanki $tanki $jmlsls liter','$user')");

// update akun laba rugi
$sql = mysql_query("SELECT noakun,mutasi_kd FROM akun_bb WHERE noakun='$labarugi' ");
$r = mysql_fetch_assoc($sql);
$kredit = $r[mutasi_kd]+$nilai;

$input	= "UPDATE akun_bb SET mutasi_kd='$kredit' WHERE noakun='$labarugi";
mysql_query($input);

// buat buku besar laba periode berjalan
mysql_query("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,noakun,nosub,kredit,keterangan,user) VALUES('$kode','LOS','$tanggal','$kode','$labarugi','$nosublr','$nilai','Penguapan $jenis tanki $tanki $jmlsls liter','$user')");
?>
