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

$table		="retur_pb";
$kode		=$_POST[kode];

$sql = mysql_query("SELECT * FROM $table WHERE kode_rb='$kode' ORDER BY kode_rb");

while ($r=mysql_fetch_array($sql)){
	$kodest=$r[kode_st];
	$junit=$r[jml_unit];
	
	$sql1 = mysql_query("SELECT * FROM stock WHERE kode_st='$kodest' ORDER BY kode_st ");
	while ($r1=mysql_fetch_array($sql1)){
		$jstok=$r1[jml_stok];
	}
	$stok_akhir=$jstok+$junit;
	
	$input1= "UPDATE stock SET jml_stok='$stok_akhir' WHERE kode_st='$kodest' ORDER BY kode_st ";
	mysql_query($input1);
}

$input	= "UPDATE $table SET batal='BATAL' WHERE kode_rb='$kode' ORDER BY kode_rb";
mysql_query($input);

$input2= "UPDATE rekap_mbr SET batal='BATAL' WHERE kode_tr='$kode' ORDER BY kode_tr";
mysql_query($input2);
echo "Retur pembelian kode $kode telah dibatalkan.";
?>