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

$kode=$_POST[kode];

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

$jenis	=$r[jenis];
$jmlstok=$r[jml_stok];
$hjlama =$r[hj_lama];
$hjbaru =$r[hj_baru];
$hblama =$r[hb_lama];
$hbbaru =$r[hb_baru];
$selisih=$r[selisih];

$sql	= mysql_query("SELECT * FROM interface");
$r 		= mysql_fetch_assoc($sql);
$persed = $r[persed];
$labapb = $r[laba_pb];
$labauh = $r[laba_uh];
$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];

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 if($jenis=='Solar Keekonomian')
	$kodest=$solek;
$bplabauh=$labauh.substr($kodest,2,4);

// update stok
mysql_query("UPDATE stock SET hg_beli='$hblama',hb_akhir='$hblama',hg_jual='$hjlama' WHERE kode_st='$kodest'");

// update akun persediaan
mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$selisih WHERE noakun='$persed'");
// update akun laba perubahan harga bbm

mysql_query("UPDATE akun_bb SET mutasi_kd=mutasi_kd-$selisih WHERE noakun='$labauh'");
mysql_query("UPDATE akun_bp SET mutasi_kd=mutasi_kd-$selisih WHERE noakun='$bplabauh'");

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

// update akun laba rugi
mysql_query("UPDATE akun_bb SET mutasi_db=mutasi_db-$selisih WHERE noakun='$labarugi'");
mysql_query("UPDATE ubah_hg SET batal='BATAL' WHERE kode_uh='$kode'");
mysql_query("DELETE FROM rekapjur WHERE kode_tr='$kode'");
?>
