<div class="right_col" role="main">
	<div class="">
		<div class="page-title">
			<div class="title_left">
				<table>
					<tr>
						<td width="150px"><h3>Router - Apartment</h3></td>
						<td><a href="index.php?pagecontent=router_apartment_new"><button type="button" class="btn btn-dark">Add</button></a></td>
					</tr>
				</table>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_content">
						<table id="datatable" class="table table-striped table-bordered">
							<thead>
								<tr>
									<th>Unit No</th>
									<th>Property</th>
									<th>Title</th>
									<th>Action</th>
								</tr>
							</thead>
							<tbody>
								<?php
									$result=mysqli_query($conn, "SELECT * FROM router_apartment WHERE deleted_at IS NULL ORDER BY ra_id ASC");
									while($row = mysqli_fetch_array($result))
									{
										$rid = $row['r_id'];
                                        $roomNo = getDetailByTable('rooms',$rid)['r_no'];
                                        $propertyId = getDetailByTable('rooms',$rid)['p_id'];
                                        $propertyName = getDetailByTable('properties',$propertyId)['pty_title'];
								?>
								<tr>
									<td><a href="?pagecontent=report_profit_room&room=<?php echo $row['r_id']; ?>"><?php echo $roomNo; ?></a></td>
									<td><?php echo $propertyName; ?></td>
									<td><?php echo $row['ra_title']; ?></td>
						
									<td>
										<a href="?pagecontent=router_apartment_new&update=<?php echo $row['ra_id']; ?>"><button class="btn btn-xs btn-primary">Update</button></a>
										<a href="?pagecontent=router_apartment&remove=<?php echo $row['ra_id']; ?>"><button class="btn btn-xs btn-danger">Remove</button></a>
									</td>
								</tr>
								<?php
									}
								?>
						</table>
					</div>
				</div>
			</div>
        </div>
    </div>
</div>

<?php
	if(isset($_REQUEST['remove'])){
		
		$routerApartmentId = $_REQUEST['remove'];
		
		// mysqli_query($conn,"DELETE FROM router_apartment WHERE ra_id=$routerApartmentId");
        $currentDate = date('Y-m-d');
		mysqli_query($conn,"UPDATE router_apartment SET deleted_at=$currentDate WHERE ra_id=$routerApartmentId");
		
		header('Location: ?pagecontent=router_apartment');  
	}
?>