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

$table	="stock";

$kodegr	 =$_POST[kodegr];
$kodest	 =$_POST[kodest];
$namast	 =$_POST[namast];
$satuan	 =$_POST[satuan];
$hgbeli  =$_POST[hgbeli];
$kodesp  =$_POST[kodesp];
$namasp  =$_POST[namasp];
$hgjual  =$_POST[hgjual];
$minstok =$_POST[minstok];


$sql = mysql_query("SELECT * FROM $table WHERE kode_st='$kodest'");
$row = mysql_num_rows($sql);
if ($row>0){
	$input	= "UPDATE $table SET nama_st='$namast',satuan='$satuan',hg_beli='$hgbeli',hb_akhir='$hgbeli',kode_sp='$kodesp',
	nama_sp='$namasp',hg_jual='$hgjual',min_stok='$minstok',lastupdate=now()WHERE kode_st= '$kodest'";
	mysql_query($input);
	
	echo "Data sukses diubah.";
}
else{
	$input = "INSERT INTO $table (kode_gr,kode_st,nama_st,satuan,hg_beli,hb_akhir,kode_sp,nama_sp,hg_jual,min_stok) 
		VALUES('$kodegr','$kodest','$namast','$satuan','$hgbeli','$hgbeli','$kodesp','$namasp','$hgjual','$minstok')";
	mysql_query($input);

	echo "Data sukses disimpan";
}
?>