<?php

	session_start();
	
	require_once("db/db.php");	
	require_once("common/common.php");
	
	//设置统一语言格式
	//header("Content-type: text/html; charset=gb2312"); 
	
	/*
	chainno: strchainno,
				roomno: strroomno,
				roomprice: strRoomPrice,
				checkdays: intDay,
				checkout: strCheckOut,
				manname: strManName,
				mansex: intSex,		//0男，1女
				telno: strTelNo,
				cardtype: strCardType,
				cardno: strCardNo,
				remarks: strRemarks,
				paytype: strPayType,
				payvalue: strPayValue,
				payText: strPayText
	*/
	$strSelID=trim($_REQUEST['rmdoid']);	//1入住登记，2预订登记
	$strChainNo=trim($_REQUEST['chainno']);	
	$strRoomNo=trim($_REQUEST['roomno']);
	$strRoomPrice=trim($_REQUEST['roomprice']);
	$intCheckDays=trim($_REQUEST['checkdays']);
	$strCheckOut=trim($_REQUEST['checkout']);
	$strManName=trim($_REQUEST['manname']);
	$intManSex=trim($_REQUEST['mansex']);	//0男，1女
	$strTelNo=trim($_REQUEST['telno']);
	$strCardType=trim($_REQUEST['cardtype']);
	$strCardNo=trim($_REQUEST['cardno']);
	$strRemarks=trim($_REQUEST['remarks']);	//备注
	$strPayType=trim($_REQUEST['paytype']);
	$strPayValue=trim($_REQUEST['payvalue']);
	$strPayText=trim($_REQUEST['payText']);

	if(strlen($strRoomPrice)<1)
	{
		$strRoomPrice='0';
	}
	if(strlen($intCheckDays)<1)
	{
		$intCheckDays='1';
	}
	if(strlen($strPayValue)<1)
	{
		$strPayValue='0';
	}
	
	$strTradeMan=trim($_SESSION['username']);
	
	//echo $strRoomNo.'+/+'.$strRoomPrice.'+/+'.$intCheckDays.'+/+'.$strCheckOut.'+/+'.$strManName.'+/+'.$intManSex.'+/+'.$strTelNo.'+/+'.$strCardType.'+/+'.$strCardNo.'**'.$strRemarks.'+/+'.$strPayType.'+/+'.$strPayValue.'+/+'.$strPayText;
	//exit;

	
	
	//判断房间状态是否为锁房状态
	//1.获取客房流水号 ,a.Room_No,a.Keep_Flag,a.Keep_Mark
	$strRListNo=0;	//状态:0空房,1预订房,2在住房,3钟点房,4自用房,5退客房,6维修房,7锁房
	$sql = sprintf("SELECT a.ListNo FROM TR_Room_Inform a,TR_Room_Type b WHERE a.TypeListNo=b.ListNo AND b.Chain_No='%s' And a.Room_No='%s' And a.Room_State=0",$strChainNo,$strRoomNo);
	$result = querySql($sql);
	if($row = fetch_array($result))
	{
		$strRListNo = $row['ListNo'];
	}
	freeResult($result);	//释放数据库
		
	//判断是否有该房间的锁房信息(自助机必须先锁房再入住)
	if($strRListNo<1)
	{
		echo "*0*";	//无此房号,或此房号不是空净房
	}
	else
	{
		//2.开始创建入住登记,根据房间流水号和房间,以及宾客资料创建入住单
		$strRateName='';//iconv('utf-8','gb2312',$strTemp);
		$strTimeFlag=0;
		$strManNation='';//iconv('utf-8','gb2312',$strTemp);
		$strManNationality='';//iconv('utf-8','gb2312',$strTemp);
		$datManBorth='1900-01-01';
		$strManArea='';
		$strManAddress='';
		
		$strRetCode = '';
		$sql = sprintf("EXECUTE TRS_APP_CheckIn '%s',%s,%s,'%s','%s',%s,%s,
				'%s',%s,'%s','%s','%s','%s','%s','%s','%s','%s','%s'",$strChainNo,$strRListNo,$strRoomPrice,$strRateName,$strCheckOut,$intCheckDays,$strTimeFlag,
				$strManName,$intManSex,$strManNation,$strManNationality,$strCardType,$strCardNo,$datManBorth,$strManArea,$strManAddress,$strTelNo,$strTradeMan);
		
		$sql="EXECUTE TRS_APP_CheckIn 'TT001',1654,193,'','2025-11-23 12:00',2,0,'刘涛',2,'','','身份证','4123221988888','1900-01-01','','','13851775555'";
		
		//echo $sql;
		//exit;
		
		$result = querySql($sql);
		if($row = fetch_array($result))
		{
			$strRetCode = $row['RetCode'];
		}
		freeResult($result);	//释放数据库
		closeDb();				//关闭数据库
		
		if(strlen($strRetCode)>1)
		{
			echo '*1*';	//成功
		}
		else
		{
				
			echo '*2*';	//失败
		}
		
	}
	
?>