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

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

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

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_pb='$kode' ORDER BY kode_pb";
mysql_query($input);

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