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

$kode=$_POST[kode];

$sql = mysql_query("SELECT * FROM penguapan WHERE kode_ls='$kode' ");
$r = mysql_fetch_assoc($sql);

$jenis	=$r[jenis];
$tanki 	=$r[tanki];
$jmlsls =$r[jml_sls];
$nilai  =$r[nilai_sls];

$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);

// 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);

// update akun persediaan
mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$nilai WHERE noakun='$persed'");

// update akun biaya penguapan
mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$nilai WHERE noakun='$biuap'");

// update akun bp biaya penguapan
mysql_query("UPDATE akun_bp SET mutasi_db=mutasi_db-$nilai WHERE noakun='$bpuap'");

// update akun laba periode berjalan
mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$nilai WHERE noakun='$labapb'");

// update akun laba rugi
mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$nilai WHERE noakun='$labarugi'");

mysql_query("UPDATE penguapan SET batal='BATAL' WHERE kode_ls='$kode'");

mysql_query("DELETE FROM rekapjur WHERE kode_tr='$kode'");
mysql_query("DELETE FROM rekap_mbr WHERE kode_tr='$kode'");
?>