<?php 
	include('config.php');

$autoid 	= $_POST["autoid"];
$jt_no 		= $_POST['jt_no'];
$jt_date 	= dtosql($_POST['jt_date']);
$jt_vcno 	= $conn->real_escape_string($_POST['jt_vcno']);
$jt_vcdate 	= dtosql($_POST['jt_vcdate']);
$jt_notes 	= $conn->real_escape_string($_POST['jt_notes']);
$outlet_autoid 	= $conn->real_escape_string($_POST['outlet_autoid']);
$act 		= $_POST["act"];
$ref_url 	= $_POST["ref_url"];
$logtxt 	= $tableto . " " .$pagename." ".$jt_no;

$ref_url = "index";

if($act=="add"){
$sql = "insert into jtheader
		(jt_autoid,jt_transno,jt_transdate,jt_vcno,jt_vcdate,jt_notes,jt_userentry,jt_dateentry,outlet_autoid)
		values
		('$autoid','$jt_no','$jt_date','$jt_vcno','$jt_vcdate','$jt_notes','$userid',CURRENT_TIMESTAMP(),'$outlet_autoid')";
		
		$conn->query($sql) or die($sql);
		
		$sqlupdate = "update jtdetail set jtd_vcno = '$jt_vcno',jtd_vcdate = '$jt_vcdate' where jt_autoid = '$autoid'";
		$conn->query($sqlupdate) or die($sqlupdate);


$querylog = "insert into userlog (log_userid,log_date,log_action) values ('$userid',CURRENT_TIMESTAMP(),'$logtxt')";
//mysqli_query($conn,$querylog);
	/*
	echo '<script>window.location.href="index.php"</script>';
	*/

}

if($act=="edit"){
	$sql = "update jtheader set 
			jt_vcno = '$jt_vcno',
			jt_vcdate = '$jt_vcdate',
			jt_notes = '$jt_notes',
			jt_userentry = '$userid',
			jt_dateentry = CURRENT_TIMESTAMP()
			where jt_autoid = '$autoid'";
	$conn->query($sql) or die($sql);

	$sqlupdate = "update jtdetail set jtd_vcno = '$jt_vcno',jtd_vcdate = '$jt_vcdate' where jt_autoid = '$autoid'";
	$conn->query($sqlupdate) or die($sqlupdate);

	

}
if($act=="delete"){
	$sql = "update jtheader set jt_flagpost = 'X',jt_userpost = '$userid',jt_datepost = CURRENT_TIMESTAMP()  where jt_autoid='$autoid'";
	$conn->query($sql) or die($sql);

}

if($act=="post"){
	
	$sql = "update jtheader set jt_flagpost = 'Y',jt_userpost = '$userid',jt_datepost = CURRENT_TIMESTAMP()  where jt_autoid='$autoid'";
	$conn->query($sql) or die($sql);
	
}

echo ("<script>window.location='index'</script>");


?>

