<?php
	//find user id
	$utilityId = $_GET['id'];
	$getRoomId = $_GET['room'];
	$getDate = $_GET['date'];
	$getUtilityTypeId = $_GET['type'];
	$getAmount = $_GET['amount'];

//telegramRoomRentalUpdate(date('Y-m-01'));
?>
<div class="right_col" role="main">
    <div class="">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
					<div class="x_title">
						<h2>Reservation</h2>
						<div class="clearfix"></div>
					</div>

					<div class="x_content">
						<form class="form-horizontal form-label-left" method="post"  enctype="multipart/form-data">
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="night">Room No
								</label>
								<div class="col-md-3 col-sm-3 col-xs-12">
									<input id="night" class="form-control col-md-3 col-xs-12" name="total" type="currency" value="<?php echo getDetailByTable("rooms",getDetailByTable("utilities",$utilityId)['r_id'])['r_no']; ?>" readonly>
								</div>
							</div>

							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="night">Month/Year 
								</label>
								<div class="col-md-3 col-sm-3 col-xs-12">
									<input id="night" class="form-control col-md-3 col-xs-12" name="total" type="currency" value="<?php echo date("F / Y",strtotime(getDetailByTable("utilities",$utilityId)['u_date'])); ?>" readonly>
								</div>
							</div>

							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="night">Utility
								</label>
								<div class="col-md-3 col-sm-3 col-xs-12">
									<input id="night" class="form-control col-md-3 col-xs-12" name="" type="currency" value="<?php echo getDetailByTable('utility_type',getDetailByTable("utilities",$utilityId)['u_type_id'])['uty_title']; ?>" readonly>
								</div>
							</div>

							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="night">Date
								</label>
								<div class="col-md-3 col-sm-3 col-xs-12">
									<input id="night" class="form-control col-md-3 col-xs-12" name="date" type="date" value="<?php echo getDetailByTable("utilities",$utilityId)['u_date']; ?>">
								</div>
							</div>


							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="night">Amount 
								</label>
								<div class="col-md-3 col-sm-3 col-xs-12">
									<input id="night" class="form-control col-md-3 col-xs-12" name="amount" type="currency" value="<?php echo $getAmount; ?>">
								</div>
							</div>

							<div class="ln_solid"></div>

							<div class="form-group">
								<div class="col-md-6 col-md-offset-3">
									<button id="send" type="submit" class="btn btn-success" name="submit">Submit</button>
								</div>
							</div>

						</form>
									
									
					</div>
                </div>
            </div>
        </div>
    </div>
</div>



<?php 

	if(isset($_POST['submit']))
	{
		$postDate = $_POST['date'];
		$postAmount = $_POST['amount'];
		$postMethod = $_POST['method'];
		
		//admin id
		$adminId = $_SESSION['admin']['a_id'];
		
		 mysqli_query($conn, "INSERT INTO utility_payment (uty_id,utyp_amount,utyp_date,utyp_method,utyp_file,a_id) VALUES ($utilityId,'$postAmount','$postDate',1,'$file_name',$adminId)");

		 $adminName = $_SESSION['admin']['a_username'];
		 $roomNo = getDetailByTable("rooms",getDetailByTable("utilities",$utilityId)['r_id'])['r_no'];
		 $propertyTitle = getDetailByTable("properties",getDetailByTable("rooms",getDetailByTable("utilities",$utilityId)['r_id'])['p_id'])['pty_title'];
		 $monthYear = date("F / Y",strtotime(getDetailByTable("utilities",$utilityId)['u_date']));

		 sendMessage2(-1001209156913,$adminName." add ".getDetailByTable('utility_type',$getUtilityTypeId)['uty_title']."'s payment for

Property : ".$propertyTitle."
Room : ".$roomNo."
Month/Year : ".$monthYear."
Paid : RM ".$postAmount."
Date : ".$postDate."
");
		
		utilityLog(0,$getRoomId,$getUtilityTypeId,$_SESSION['admin']['a_username']." add payment RM".$postAmount." for ".$monthYear." on ".$postDate);
		
		if($_SESSION['redirect']){ $redirectUrl = $_SESSION['redirect'];
			header("Location: $redirectUrl");
		}
		
		
	}

function imageResize($imageSrc,$imageWidth,$imageHeight) {

    $newImageWidth =200;
    $newImageHeight =200;

    $newImageLayer=imagecreatetruecolor($newImageWidth,$newImageHeight);
    imagecopyresampled($newImageLayer,$imageSrc,0,0,0,0,$newImageWidth,$newImageHeight,$imageWidth,$imageHeight);

    return $newImageLayer;
}

?>



