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

$jenis  = $_POST[jenis];
$prem	= $_POST[prem];
$solar	= $_POST[solar];
$ptmx	= $_POST[ptmx];
$ptmp	= $_POST[ptmp];
$ptlt	= $_POST[ptlt];
$dex	= $_POST[dex];
$dexlite= $_POST[dexlite];
$solek	= $_POST[solek];
$tanki	= $_POST[tanki];
$tanggal= $_POST[tanggal];

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;
	
$sql= mysql_query("SELECT * FROM stock WHERE kode_st= '$kodest'");
$r  = mysql_fetch_assoc($sql);
if($tanki=='1')		
	$jmlstok=$r[jml_gd1];
else if($tanki=='2')
	$jmlstok=$r[jml_gd2];
else if($tanki=='3')
	$jmlstok=$r[jml_gd3];

	
$sql1   = mysql_query("SELECT sum(masuk) as jmasuk,sum(keluar) as jkeluar FROM rekap_mbr WHERE kode_st='$kodest' AND tanggal>'$tanggal' GROUP BY kode_st");
$r1     = mysql_fetch_assoc($sql1);
$jmasuk = $r1[jmasuk];
$jkeluar= $r1[jkeluar];
$jmlstok= $jmlstok+$jkeluar-$jmasuk;
$data[stok]=$jmlstok;
echo json_encode($data);
?>