<?php

	session_start();
	
	require_once("db/db.php");	
	require_once("common/common.php");
	
	//设置统一语言格式
	//header("Content-type: text/html; charset=gb2312"); 
	
	$strorderno=trim($_REQUEST['tbno']);	//住房流水号订单号
	
	$strDoWithResault = '预订转入住...';
	$strselchainno = '';
	
	//得到单号的分店号
	$sql = sprintf("SELECT Chain_No FROM TR_Order_Inform WHERE Order_No='%s'",$strorderno);
	$result = querySql($sql);
	$row = fetch_array($result);

	$strselchainno = $row['Chain_No'];
	freeResult($result);	//释放数据集
	
	
	//开始执行整单接待入住操作
	//1.先判断预定单中的房间是否有在住的房间或已经预定的排房的房间
	$intRoomCount = 0;
	
	$sql = sprintf("SELECT COUNT(b.ListNo)AS RoomCount FROM TR_Order_Inform a,TR_Order_Room_List b WHERE a.Order_No=b.Order_No 
					And a.Chain_No='%s' And a.Order_State<2 And b.Room_BillState=2 And a.Order_No<>'%s' And b.Room_No In(
					SELECT Room_No FROM TR_Order_Room_List WHERE Order_No='%s' And (Room_BillState<2))",$strselchainno,$strorderno,$strorderno);

	$result = querySql($sql);
	$row = fetch_array($result);
	$intRoomCount = $row['RoomCount'];
	
	if($intRoomCount>0)
	{
		//房间被占用不能继续入住
		$strDoWithResault = '选择的房间被占用，不能入住！';
	}
	else
	{
		//2.调用存储过程完成动作
		$sql = sprintf("EXECUTE TRS_WebBookToCheckIn '%s'",$strorderno);
		$result = querySql($sql);
		$row = fetch_array($result);

		$intretval = $row['RetVal'];
			
		if($intretval == '0')
		{
			$strDoWithResault = '办理入住成功！';
		}
		else
		{
			//办理入住失败
			$strDoWithResault = '办理入住失败！';
		}
					
		freeResult($result);
	}
	
	closeDb();	//关闭数据库

?>

<html>
<head>
	<meta charset="gb2312">	
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
	<meta name="apple-mobile-web-app-capable" content="1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=0">
	<meta name="apple-touch-fullscreen" content="1">
	<title>微信预订转入住</title>
	<script src="jsp4/jquery.js"></script>
	<link rel="stylesheet" href="css/mycss.css"> 
	
	<script>
		setTimeout("window.location='orderlist.php'",1000);
	</script>

	<script language="JavaScript"> 
		//不允许进行后退
		javascript:window.history.forward(0); 
	</script>
</head>

<body leftmargin="0" rightmargin="0" topmargin="0" bottommargin="0">
&nbsp;<br>
<center><span style='color:green;font-size:22px'><b><?php echo 	$strDoWithResault;?></b></span></center>
<p>
</body>

</html>