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

$kode	=$_POST[kode];

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

$kodedo     =$r[kode_do];
$jenis		=$r[jenis];
$jmlliter 	=$r[jml_liter];
$jumlah 	=$r[jumlah];
$hgbeli 	=$r[hg_beli];
$tanki 	    =$r[tanki];

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

$persed	    = $r[persed];
$dobbm	    = $r[do_bbm];
$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];

if($jenis=='Premium')
	$kodest=$prem;
else if($jenis=='Bio Solar')
	$kodest=$solar;
else if($jenis=='Pertamax')
	$kodest=$ptmx;
else if($jenis=='Pertamax Turbo')
	$kodest=$ptmp;
else if($jenis=='Pertalite')
	$kodest=$ptlt;
else if($jenis=='Pertamina Dex')
	$kodest=$dex;
else if($jenis=='Dexlite')
	$kodest=$dexlite;
else
	$kodest=$solek;
$bpdo = $dobbm.substr($kodest,2,4);

// update stok
if($tanki=='1'){
	mysql_query("UPDATE stock SET jml_gd1=jml_gd1-$jmlliter WHERE kode_st='$kodest' ");
}else if($tanki=='2'){
	mysql_query("UPDATE stock SET jml_gd2=jml_gd2-$jmlliter WHERE kode_st='$kodest' ");
}else{
	mysql_query("UPDATE stock SET jml_gd3=jml_gd3-$jmlliter WHERE kode_st='$kodest' ");
}

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

// update akun uang muka pembelian
mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$jumlah WHERE noakun='$dobbm'");
mysql_query("UPDATE akun_bp SET mutasi_kd=mutasi_kd-$jumlah WHERE noakun='$bpdo'");

// buat buku besar uang muka pembelian
mysql_query("UPDATE stock_do SET jml_liter=jml_liter+$jmlliter,jumlah=jumlah+$jumlah WHERE kode_do='$kodedo' ");

mysql_query("UPDATE terima_bbm SET batal='BATAL' WHERE kode_tb='$kode'");

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