<?php
include('config.php');
$autoid = $_POST['autoid'];

	$sql = "SELECT * FROM posheader a, posdetail b WHERE a.pos_autoid = b.pos_autoid AND a.pos_autoid = '$autoid'";
	$dcon 	= $conn->query($sql) or die($sql);
	while($rs 	= $dcon->fetch_array()){
	
	$transno 		= $rs['pos_transno'];
	$transdate 		= ($rs['pos_transdate']);
	$order_type 	= ($rs['pos_order_type']);
	$table_no 		= ($rs['pos_tableno']);

	$gtotal = $rs['pos_gtotal'];
	$outlet 	= $rs['outlet_autoid'];
	$pm_autoid 	= $rs['pm_autoid'];
	$pm_code 	= $conn->real_escape_string($rs['pm_code']);
	$pm_name 	= $conn->real_escape_string($rs['pm_name']);
	$qty 		= $rs['posd_qty'];
	$itt_autoid = 101;
	$itt_desc 	= "Stok Keluar - Penjualan Outlet";
	$ums_price = $rs['posd_price'];
	
				$sql_in = "INSERT INTO invlog 
					(log_refno,log_refdate,log_refautoid,pm_autoid,pm_code,
					pm_name,log_outqty,whs_autoid,log_userentry,log_dateentry,log_reftype,
					itt_autoid,log_ums,itt_desc,log_price,log_avg_price,outlet_id,itt_code) 
					VALUES 
					('$transno','$transdate','$autoid','$pm_autoid','$pm_code',
					'$pm_name','$qty','$outlet','$userid',CURRENT_TIMESTAMP(),'SALES','
					$itt_autoid','$ums', '$itt_desc','$ums_price','$price','$outlet', 'SALES')";

				if (!$conn->query($sql_in) === TRUE) { echo "Error: " . $$sql_in . "<br>" . $conn->error;return false;}	
	//			 curr_stok_update($pm_autoid,$qty,$outlet,$conn,"Y");

	}
	$sql_update = "UPDATE posheader set pos_status = 2 WHERE pos_autoid = '$autoid'";
	$conn->query($sql_update);
?>
