<?php
	$id=$_GET['rvid'];
	$result=mysqli_query($conn,"SELECT * FROM reservation WHERE rv_id=$id") or dir(mysql_error());
	$row=mysqli_fetch_array($result);
?>

<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>Payment Detail</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">

						<form class="form-horizontal form-label-left" method="post">

							<div class="item form-group">
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="amount" class="form-control col-md-7 col-xs-12" name="rvid" type="text" 
									value="<?php echo $row['rv_id'];?>" hidden>
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="amount">Amount <span class="required">*</span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<input id="amount" class="form-control col-md-7 col-xs-12" name="amount" type="text" 
									value="<?php
												$amount = $row['rv_amount'];
												$totalNights = $row['rv_night'];
												$tax = $row['rv_tax'];
												echo number_format($total=(($amount*$totalNights)*(1.0+($tax/100))),2);
											?>" required>
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="paymethod">Payment method
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<select class="form-control" name='paymethod'>
										<option value="Cash" checked>Cash</option>
										<option value="Bank In">Bank In</option>
										<option value="Transfer">Transfer</option>
										<option value="Transfer">Airbnb</option>
									</select>
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="paydate">Date
								</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
								<?php  $today=date("Y-m-d");?>
									<input id="paydate" class="form-control col-md-4 col-xs-12" name="paydate" type="date" value="<?php echo $today;?>">
								</div>
							</div>
							<div class="item form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12" for="note">Note</span>
								</label>
								<div class="col-md-6 col-sm-6 col-xs-12">
									<textarea id="message" class="form-control" name="note"></textarea>
								</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>
									<button type="submit" class="btn btn-primary" onclick="javascript:window.location='index.php?pagecontent=guestid'">Cancel</button>
								</div>
							</div>
						</form>
					</div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php 
	if (isset($_POST['submit']))
	{
	    $pyNo = date('Ymdhis');
		$rvid=$_POST['rvid'];
		$amount=$_POST['amount'];
		$paymethod=$_POST['paymethod'];
		$date=$_POST['paydate'];
		$note=$_POST['note'];
		
		mysqli_query($conn,"INSERT INTO payment (rv_id, py_no, py_amount, py_method, py_date, py_note) 
		VALUES ('$rvid', '$pyNo', '$amount', '$paymethod', '$date', '$note')")or die (mysql_error());
		
		header('Location: index.php?pagecontent=reservationid&rvid='.$id);	
	}
?>