<?php


	$sql_chk = "SELECT * FROM soheader where so_autoid = '$autoid'";
	$dcon_chk 	= $conn->query($sql_chk) or die($sql_chk);
	$rschk = $dcon_chk->fetch_assoc();
	
	
	if($rschk['so_status']==2){
					header('Location:index?src=2');
		return false;

		}

	$sql = "SELECT * FROM soheader a, sodetail b WHERE a.so_autoid = b.so_autoid AND a.so_autoid = '$autoid'";
	$dcon 	= $conn->query($sql) or die($sql);
	while($rs 	= $dcon->fetch_array()){
	
	$transno 		= $rs['so_transno'];
	$transdate 		= ($rs['so_transdate']);
	
	$cust_name 	= ($rs['cust_name']);
	
	$gtotal 	= $rs['so_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['sd_qtyp'];
	$qtyr 		= $rs['sd_qtyr'];
	/*
	if($qtyr>0){
	$itt_autoid = 102;
	$itt_desc 	= $conn->real_escape_string("Stok Masuk - Retur Penjualan - ".$cust_name);		
		}else{
	$itt_autoid = 101;
	$itt_desc 	= $conn->real_escape_string("Stok Keluar - Penjualan - ".$cust_name);
	}
	*/
	$itt_autoid = 101;
	$itt_desc 	= $conn->real_escape_string("Stok Keluar - Penjualan - ".$cust_name);
	$ums_price = $rs['sd_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','Kg', '$itt_desc','$ums_price','$price','$outlet', 'SALES')";
if($qty>0){$conn->query($sql_in);}
				
	//			 curr_stok_update($pm_autoid,$qty,$outlet,$conn,"Y");

	}
	$sql_update = "UPDATE soheader set so_status = 2 WHERE so_autoid = '$autoid'";
	$conn->query($sql_update);
				header('Location:index?src=2');
?>
