<? include $_SERVER["DOCUMENT_ROOT"] . "/common/classes/AdminRent.php" ?>
<? include $_SERVER["DOCUMENT_ROOT"] . "/admin/inc/php/popupHeader.php" ?> 

<?
	$obj		= new AdminRent($_REQUEST, "");
	$info		= $obj->getInfoOfRoom();
	$user_list	= $obj->getListOfUserForRoom();
	$bill_info  = $obj->getInfoOfBill();
	
	$rurl		= pack("H*", $_REQUEST["rurl"]) ;
?>

<script type="text/javascript">
	var _rurl = "<?=$rurl?>";
	var _no = "<?=$_REQUEST[no]?>";


	$(document).ready(function(){

		//=====프레입웤 변수들==================================================================================//
		var FORM_TARGET_CLS_NM		= ".data"	;		// 폼을 동적 wrap 할 타겟 ID이름
		var FORM_NAME				= "alf"		;		// 폼이름
		var FORM_METHOD				= "POST"		;		// 폼 메쏘드
		var FORM_USE_FILE			= false		;		// 파일폼 사용 여부
		var FORM_ACTION				= "/action_front.php" ; 
		
		
		var NEXT_CMD				= ""		;		// 다은 수행 할 cmd
		//=====================================================================================================//

		var jForm = $(FORM_TARGET_CLS_NM).mf({ "name" : FORM_NAME , "method" : FORM_METHOD , "action" : FORM_ACTION , "useFile" : FORM_USE_FILE }) ;

		var dates = $('.jRsvDate').datepicker({
			showMonthAfterYear:true,
			inline: true,
			changeMonth: true,
			changeYear: true,   
			dateFormat : 'yy-mm-dd',
			dayNamesMin:['일', '월', '화', '수', '목', '금', ' 토'],
			monthNames:['1월','2월','3월','4월','5월','6월','7 월','8월','9월','10월','11월','12월'],
			monthNamesShort:['1월','2월','3월','4월','5월','6월','7월','8월','9월','10월','11월','12월'],
			showButtonPanel: true, currentText: '오늘 ' , closeText: '닫기',   
			onSelect: function(selectedDate) {
		}
	});
		

		$(".jCancel").click2(function(){
			location.href = _rurl;
		});

		$(".jClose").click2(function(){
			window.close();
		});

		$(".jMod").click2(function(){

			var data = $("#jData").serialize();

			$.ajax({
				url : "/action_front.php?cmd=AdminRent.saveRoom",
				async : false,
				cache : false,
				dataType : "json",
				data : data,
				success : function(data){
					alert(data.returnMessage);
					location.href=_rurl;
					/*
					if(_no != "")
						location.reload();
					else
						location.href = _rurl;
					*/
				}
			});
			
		});

	}) ;

</script>

<div id="Contents"  class="notice">
	<h1>호실등록(수정)</h1>

	
	<div class="data" style="width:100%;">
		
		<form id="jData">
		<input type="hidden" name="no" value="<?=$_REQUEST[no]?>" />
		<input type="hidden" name="building_fk" value="<?=$_GET["Bno"]?>" />
		<input type="hidden" name="current_contractor" value="<?=$info["user_fk"]?>" />
		<h3>호실정보</h3>
		<table class="datav" style="width:100%;">
			<colgroup>
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
			</colgroup>
			<tr>
				<!-- 호실 -->
				<th style="height:25px;">호실</th>
				<td class="center">
					<input type="text" name="name" class="wm" value="<?=$info["name"]?>" />
				</td>
				
				<!-- 관리유형 -->
				<th style="height:25px;">관리유형</th>
				<td class="center">
					<select name="manage_type" class="wm">
					<option value="">선택</option>
						<option value="<?=$obj->BUILDING_MANAGE_TYPE_LONG_CONS?>" <?=$info["manage_type"] == $obj->BUILDING_MANAGE_TYPE_LONG_CONS ? "SELECTED" : ""?>>장기위탁</option>
						<option value="<?=$obj->BUILDING_MANAGE_TYPE_SHORT_CONS?>" <?=$info["manage_type"] == $obj->BUILDING_MANAGE_TYPE_SHORT_CONS ? "SELECTED" : ""?>>단기위탁</option>
						<option value="<?=$obj->BUILDING_MANAGE_TYPE_LONG_SELF?>" <?=$info["manage_type"] == $obj->BUILDING_MANAGE_TYPE_LONG_SELF ? "SELECTED" : ""?>>장기자기</option>
						<option value="<?=$obj->BUILDING_MANAGE_TYPE_SHORT_SELF?>" <?=$info["manage_type"] == $obj->BUILDING_MANAGE_TYPE_SHORT_SELF ? "SELECTED" : ""?>>단기자기</option>
					</select>
				</td>
				
				<!-- 호실비번 -->
				<th style="height:25px;">호실비번</th>
				<td class="center">
					<input type="text" name="pw" class="wm" value="<?=$info["pw"]?>" />
				</td>
				
				<!-- 관리유형 -->
				<th style="height:25px;">계약진행상황</th>
				<td class="center">
					<select name="contract_status" class="wm">
					<option value="">선택</option>
						<option value="<?=$obj->ROOM_TYPE_RESIDENT?>" <?=$info["contract_status"] == $obj->ROOM_TYPE_RESIDENT ? "SELECTED" : ""?>>입주</option>
						<option value="<?=$obj->ROOM_TYPE_EMPTY?>" <?=$info["contract_status"] == $obj->ROOM_TYPE_EMPTY ? "SELECTED" : ""?>>공실</option>
						<option value="<?=$obj->ROOM_TYPE_UNDER_CONTRACT?>" <?=$info["contract_status"] == $obj->ROOM_TYPE_UNDER_CONTRACT ? "SELECTED" : ""?>>협의중</option>
						<option value="<?=$obj->ROOM_TYPE_CONTRACT_EXTENSION?>" <?=$info["contract_status"] == $obj->ROOM_TYPE_CONTRACT_EXTENSION ? "SELECTED" : ""?>>계약연장</option>
					</select>
				</td>
			</tr>
		</table>
		
		<h3>입주자정보</h3>
		<table class="datav" style="width:100%;">
			<colgroup>
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
			</colgroup>
			<tr>
				<!-- 입주자 -->
				<th style="height:25px;">입주자</th>
				<td class="center">
					<select name="contractor_name" class="wm">
					<option value="">선택</option>
						<?if($info["contractor_name"]){?>
						<option value='<?=$info["user_fk"]?>' selected><?=$info["contractor_name"]?></option>
						<? } ?>
						<? for($i=0; $i<sizeof($user_list); $i++){ ?>
						<option value='<?=$user_list[$i]["no"]?>' <?=$info["contractor_name"] == $user_list[$i]["name"] ? "SELECTED" : ""?>><?=$user_list[$i]["name"]?></option>
						<? } ?>
						
					</select>
				</td>
				
				<!-- 연락처 -->
				<th style="height:25px;">연락처</th>
				<td class="center">
					<input type="text" name="contractor_tel" class="wm" value="<?=$info["contractor_tel"]?>" />
				</td>
				
				<!-- 반환계좌 / 입금주 -->
				<th style="height:25px;">반환계좌 <br>- 입금주</th>
				<td class="center" colspan='3'>
					<select name="contractor_account_bank" class="wm">
					<option value="">선택</option>
						<option value="<?="우리"?>" <?=$info["contractor_account_bank"] == "우리" ? "SELECTED" : ""?>>우리</option>
						<option value="<?="경남"?>" <?=$info["contractor_account_bank"] == "경남" ? "SELECTED" : ""?>>경남</option>
						<option value="<?="광주"?>" <?=$info["contractor_account_bank"] == "광주" ? "SELECTED" : ""?>>광주</option>
						<option value="<?="국민"?>" <?=$info["contractor_account_bank"] == "국민" ? "SELECTED" : ""?>>국민</option>
						<option value="<?="기업"?>" <?=$info["contractor_account_bank"] == "기업" ? "SELECTED" : ""?>>기업</option>
						<option value="<?="농협"?>" <?=$info["contractor_account_bank"] == "농협" ? "SELECTED" : ""?>>농협</option>
						<option value="<?="대구"?>" <?=$info["contractor_account_bank"] == "대구" ? "SELECTED" : ""?>>대구</option>
						<option value="<?="도이치"?>" <?=$info["contractor_account_bank"] == "도이치" ? "SELECTED" : ""?>>도이치</option>
						<option value="<?="부산"?>" <?=$info["contractor_account_bank"] == "부산" ? "SELECTED" : ""?>>부산</option>
						<option value="<?="비엔피파리"?>" <?=$info["contractor_account_bank"] == "비엔피파리" ? "SELECTED" : ""?>>비엔피파리</option>
						<option value="<?="산림"?>" <?=$info["contractor_account_bank"] == "산림" ? "SELECTED" : ""?>>산림</option>
						<option value="<?="산업"?>" <?=$info["contractor_account_bank"] == "산업" ? "SELECTED" : ""?>>산업</option>
						<option value="<?="상호저축"?>" <?=$info["contractor_account_bank"] == "상호저축" ? "SELECTED" : ""?>>상호저축</option>
						<option value="<?="새마을금고"?>" <?=$info["contractor_account_bank"] == "새마을금고" ? "SELECTED" : ""?>>새마을금고</option>
						<option value="<?="수춯입"?>" <?=$info["contractor_account_bank"] == "수출입" ? "SELECTED" : ""?>>수출입</option>
						<option value="<?="수협"?>" <?=$info["contractor_account_bank"] == "수협" ? "SELECTED" : ""?>>수협</option>
						<option value="<?="신용협동"?>" <?=$info["contractor_account_bank"] == "신용협동" ? "SELECTED" : ""?>>신용협동</option>
						<option value="<?="신한"?>" <?=$info["contractor_account_bank"] == "신한" ? "SELECTED" : ""?>>신한</option>
						<option value="<?="우체국"?>" <?=$info["contractor_account_bank"] == "우체국" ? "SELECTED" : ""?>>우체국</option>
						<option value="<?="전북"?>" <?=$info["contractor_account_bank"] == "전북" ? "SELECTED" : ""?>>전북</option>
						<option value="<?="제주"?>" <?=$info["contractor_account_bank"] == "제주" ? "SELECTED" : ""?>>제주</option>
						<option value="<?="중국공상"?>" <?=$info["contractor_account_bank"] == "중국공상" ? "SELECTED" : ""?>>중국공상</option>
						<option value="<?="케이뱅크"?>" <?=$info["contractor_account_bank"] == "케이뱅크" ? "SELECTED" : ""?>>케이뱅크</option>
						<option value="<?="펀드온라인코리아"?>" <?=$info["contractor_account_bank"] == "펀드온라인코리아" ? "SELECTED" : ""?>>펀드온라인코리아</option>
						<option value="<?="한국씨티"?>" <?=$info["contractor_account_bank"] == "한국씨티" ? "SELECTED" : ""?>>한국씨티</option>
						<option value="<?="BOA"?>" <?=$info["contractor_account_bank"] == "BOA" ? "SELECTED" : ""?>>BOA</option>
						<option value="<?="HSBC"?>" <?=$info["contractor_account_bank"] == "HSBC" ? "SELECTED" : ""?>>HSBC</option>
						<option value="<?="JP모간체이스"?>" <?=$info["contractor_account_bank"] == "JP모간체이스" ? "SELECTED" : ""?>>JP모간체이스</option>
						<option value="<?="KEB하나"?>" <?=$info["contractor_account_bank"] == "KEB하나" ? "SELECTED" : ""?>>KEB하나</option>
						<option value="<?="SC"?>" <?=$info["contractor_account_bank"] == "SC" ? "SELECTED" : ""?>>SC</option>
					</select>
					
					<input type="text" name="contractor_account_no" class="wm" value="<?=$info["contractor_account_no"]?>" />
					-
					<input type="text" name="contractor_account_owner" class="wt7" value="<?=$info["contractor_account_owner"]?>" />
				</td>
			</tr>
			<tr>
				<!-- 계약일 -->
				<th style="height:25px;">계약일</th>
				<td class="center">
					<?php 
					$formattedDate = date('Y-m-d', strtotime($info["contract_date"]));
					if($formattedDate == "1970-01-01") $formattedDate = "";
					?>
					<input type="text" name="contract_date" value="<?=$formattedDate?>" class="jRsvDate" />
				</td>
				
				<!-- 입주일 -->
				<th style="height:25px;">입주일</th>
				<td class="center">
					<?php 
					$formattedDate = date('Y-m-d', strtotime($info["move_in_date"]));
					if($formattedDate == "1970-01-01") $formattedDate = "";
					?>
					<input type="text" name="move_in_date" value="<?=$formattedDate?>" class="jRsvDate"  />
				</td>
				
				<!-- 계약만료일 -->
				<th style="height:25px;">계약만료일</th>
				<td class="center">
					<?php 
					$formattedDate = date('Y-m-d', strtotime($info["contract_expire_date"]));
					if($formattedDate == "1970-01-01") $formattedDate = "";
					?>
					<input type="text" name="contract_expire_date" value="<?=$formattedDate?>" class="jRsvDate" />
				</td>
				
				<!-- 차량번호 -->
				<th style="height:25px;">차량번호</th>
				<td class="center">
					<input type="text" name="contractor_car_no" class="wm" value="<?=$info["contractor_car_no"]?>" />
				</td>
			</tr>
		</table>
		
		<h3>기타정보</h3>
		<table class="datav" style="width:100%;">
			<colgroup>
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
			</colgroup>
			<tr>
				<!-- 보증금 -->
				<th style="height:25px;">보증금</th>
				<td class="center">
					<input type="text" name="deposit" class="wm" value="<?=$info["deposit"]?>" />
				</td>
				
				<!-- 예치금 -->
				<th style="height:25px;">예치금</th>
				<td class="center">
					<input type="text" name="balance" class="wm" value="<?=$info["balance"]?>" />
				</td>
				
				<!-- 건물주 입금액-->
				<th style="height:25px;">건물주 입금액</th>
				<td class="center">
					<input type="text" name="payment_owner" class="wm" value="<?=$info["payment_owner"]?>" />
				</td>
				
				<!-- 월세-->
				<th style="height:25px;">월세</th>
				<td class="center">
					<input type="text" name="monthly_rent" class="wm" value="<?=$info["monthly_rent"]?>" />
				</td>
			</tr>
			<tr>
				<!-- 기본관리비 -->
				<th style="height:25px;">기본관리비</th>
				<td class="center">
					<input type="text" name="maintenance_fee" class="wm" value="<?=$info["maintenance_fee"]?>" />
				</td>
				
				<!-- 케이블 -->
				<th style="height:25px;">케이블</th>
				<td class="center">
					<input type="text" name="cable" class="wm" value="<?=$info["cable"]?>" />
				</td>
				
				<!-- 인터넷-->
				<th style="height:25px;">인터넷</th>
				<td class="center">
					<input type="text" name="internet" class="wm" value="<?=$info["internet"]?>" />
				</td>
				
				<!-- 렌트1-->
				<th style="height:25px;">렌트1</th>
				<td class="center">
					<input type="text" name="rent_1" class="wm" value="<?=$info["rent_1"]?>" />
				</td>
			</tr>
			<tr>
				<!-- 렌트2 -->
				<th style="height:25px;">렌트2</th>
				<td class="center">
					<input type="text" name="rent_2" class="wm" value="<?=$info["rent_2"]?>" />
				</td>
				
				<!-- 기타 -->
				<th style="height:25px;">기타</th>
				<td class="center">
					<input type="text" name="etc" class="wm" value="<?=$info["etc"]?>" />
				</td>
				
				<!-- 월세입금일-->
				<th style="height:25px;">월세입금일</th>
				<td class="center">
					<select name="monthly_rent_date" class="wm">
						<? for($i=1; $i<=31; $i++){ ?>
						<option value='<?=$i?>' <?=$info["monthly_rent_date"] == $i ? "SELECTED" : ""?>><?=$i?></option>
						<? } ?>
					</select>
				</td>
				
				<!-- 건물주송금일-->
				<th style="height:25px;">건물주송금일</th>
				<td class="center">
					<select name="payment_owner_date" class="wm">
						<? for($i=1; $i<=31; $i++){ ?>
						<option value='<?=$i?>' <?=$info["payment_owner_date"] == $i ? "SELECTED" : ""?>><?=$i?></option>
						<? } ?>
					</select>
				</td>
			</tr>
			<tr>
				<!-- 전기 검침일-->
				<th style="height:25px;">전기 검침일</th>
				<td class="center">
					<select name="electricity_check_date" class="wm">
						<? for($i=1; $i<=31; $i++){ ?>
						<option value='<?=$i?>' <?=$info["electricity_check_date"] == $i ? "SELECTED" : ""?>><?=$i?></option>
						<? } ?>
					</select>
				</td>
				
				<!-- 가스 검침일-->
				<th style="height:25px;">가스 검침일</th>
				<td class="center">
					<select name="gas_check_date" class="wm">
						<? for($i=1; $i<=31; $i++){ ?>
						<option value='<?=$i?>' <?=$info["gas_check_date"] == $i ? "SELECTED" : ""?>><?=$i?></option>
						<? } ?>
					</select>
				</td>
				
				<!-- 수도 검침일-->
				<th style="height:25px;">수도 검침일</th>
				<td class="center">
					<select name="water_check_date" class="wm">
						<? for($i=1; $i<=31; $i++){ ?>
						<option value='<?=$i?>' <?=$info["water_check_date"] == $i ? "SELECTED" : ""?>><?=$i?></option>
						<? } ?>
					</select>
				</td>
				
				<!-- 공과금 납입일-->
				<th style="height:25px;">공과금 납입일</th>
				<td class="center">
					<select name="billing_date" class="wm">
						<? for($i=1; $i<=31; $i++){ ?>
						<option value='<?=$i?>' <?=$info["billing_date"] == $i ? "SELECTED" : ""?>><?=$i?></option>
						<? } ?>
					</select>
				</td>
			</tr>
		</table>
		
		<h3>공과금</h3>
		<table class="datav" style="width:100%;">
			<colgroup>
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
				<col width="10%" />
				<col width="15%" />
			</colgroup>
			<tr>
				<!-- 가스(검침/금액) -->
				<th style="height:25px;">가스(검침/금액)</th>
				<td class="center">
					<input type="text" name="gas_charge" class="wm" value="<?=$bill_info["gas_check_date"]."/".$bill_info["gas_charge"]?>" readonly/>
				</td>
				
				<!-- 전기(검침/금액) -->
				<th style="height:25px;">전기(검침/금액)</th>
				<td class="center">
					<input type="text" name="electricity_charge" class="wm" value="<?=$bill_info["electricity_check_date"]."/".$bill_info["electricity_charge"]?>" readonly/>
				</td>
				
				<!-- 수도(검침/금액)-->
				<th style="height:25px;">수도(검침/금액)</th>
				<td class="center">
					<input type="text" name="water_charge" class="wm" value="<?=$bill_info["water_check_date"]."/".$bill_info["water_charge"]?>" readonly/>
				</td>
				
				<!-- 공용전기료(검침/금액)-->
				<th style="height:25px;">공용전기료(검침/금액)</th>
				<td class="center">
					<input type="text" name="community_electricity_charge" class="wm" value="<?=$bill_info["community_electricity_check_date"]."/".$bill_info["community_electricity_charge"]?>" readonly/>
				</td>
			</tr>
			<tr>
				<!-- 공용수도료(검침/금액) -->
				<th style="height:25px;">공용수도료(검침/금액)</th>
				<td class="center">
					<input type="text" name="community_water_charge" class="wm" value="<?=$bill_info["community_water_check_date"]."/".$bill_info["community_water_charge"]?>" readonly/>
				</td>
			</tr>
		</table>
		
		<h3>입실/퇴실예정</h3>
		<table class="datav" style="width:50%; empty-cells: hide;border-collapse: separate;">
			<colgroup>
				<col width="20%" />
				<col width="30%" />
				<col width="20%" />
				<col width="30%" />
			</colgroup>
			
			<tr>
				<!-- 입실예정일 -->
				<th style="height:25px;">입실예정일</th>
				<td class="center">
				
				<?php 
					$formattedDate = date('Y-m-d', strtotime($info["entering_due_date"]));
					if($formattedDate == "1970-01-01") $formattedDate = "";
				?>
					<input type="text" name="entering_due_date" value="<?=$formattedDate?>" class="jRsvDate"  />
				</td>
				
				<!-- 퇴실예정일 -->
				<th style="height:25px;">퇴실예정일</th>
				<td class="center">
				
				<?php 
					$formattedDate = date('Y-m-d', strtotime($info["leaving_due_date"]));
					if($formattedDate == "1970-01-01") $formattedDate = "";
				?>
					<input type="text" name="leaving_due_date" value="<?=$formattedDate?>" class="jRsvDate"  />
				</td>
			</tr>
		</table>
		
		<h3>특약</h3>
		<table class="datav" style="width:100%; empty-cells: hide;border-collapse: separate;">
			<colgroup>
				<col width="10%" />
				<col width="90%" />
			</colgroup>
			<tr>
				<!-- 입실예정일 -->
				<th style="height:25px;">특약</th>
				<td class="center">
					<textarea name="special_contract" rows="5" style="width:100%;resize:vertical;"><?=$info["special_contract"]?></textarea>
				</td>
			</tr>
		</table>
		</form>

		<div class="btngroupcenter">
			<span class="button bigrounded blue jCancel btnleft_y">목록으로 </span>
			<span class="button bigrounded blue jClose btnleft_y">닫기 </span>
			<span class="button bigrounded blue jMod btnright_y" >저장</span>
		</div>

	</div>
</div>