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

$kode	=$_POST[kode];
$tanggal=$_POST[tanggal];
$kodetk =$_POST[kodetk];
$kodest =$_POST[kodest];
$jmlunit=$_POST[jmlunit];

$sql	= mysql_query("SELECT * FROM stock WHERE kode_st='$kodest'");
$r		= mysql_fetch_assoc($sql);
$jstok	= $r[jml_stok]+$jmlunit;
	
mysql_query("UPDATE stock SET jml_stok='$jstok' WHERE kode_st='$kodest'");

$sql  = mysql_query("SELECT * FROM jurpsb WHERE kode_ps='$kode' AND kode_tk='$kodetk' ORDER BY no_urut ");
while($r=mysql_fetch_array($sql)){
	$nourut=$r[no_urut];
	$kodest1=$r[kode_st1];
	$jmlunit1=$r[jml_unit1];
	$harga1=$r[harga1];
	
	$sql1 = mysql_query("SELECT * FROM stock WHERE kode_st='$kodest1'");
	$r1	  = mysql_fetch_assoc($sql1);
	$jstok= $r1[jml_stok]-$jmlunit1;
	mysql_query("UPDATE stock SET jml_stok='$jstok' WHERE kode_st='$kodest1'");	
}

mysql_query("UPDATE jurpsb SET batal='BATAL' WHERE kode_ps='$kode' AND kode_tk='$kodetk'");
mysql_query("DELETE FROM rekap_mbr WHERE kode_tr='$kode' AND kode_tk='$kodetk'");
?>