<input type="hidden" id="baseurl" value="<?php echo base_url(); ?>" >
<div class="row">
    <div class="col-md-12">
        <div class="hs_heading medium">
            <h3>Reservations (<?php if(!empty($all_reservation)){ echo count($all_reservation); }else{ echo 0; } ?>)</h3>
        </div>
        <div class="hs_datatable_wrapper">
            <table class="hs_datatable table table-bordered">
                <thead>
                    <tr>
                        <th>#</th>
						<th>Booking Id</th>
						<th>Name</th>
						<th>Occasion</th>
						<th>Preferred Food</th>
                        <th>Reservation Date</th>
						<th>Reservation Time</th>
						<th>No. of peoples</th>
						<th>Booked Table</th>
						<th>Status</th>
						<th>Action</th>
                    </tr>
                </thead>
                <tbody>
				<?php 
				  $i= 0;
				  if(!empty($all_reservation)){
				foreach($all_reservation  as $reservation){ ?>
				 <tr>
                        <td><?php echo ++$i; ?></td>
						<td id="runiqid_<?php echo $reservation->reservation_id; ?>"><?php echo $reservation->reservation_uniqid; ?></td>
						<td id="rname_<?php echo $reservation->reservation_id; ?>"><?php echo $reservation->name; ?></td>
						<?php 
						if($reservation->occasion !=''){
						if($reservation->occasion == 0){ ?>
						<td id="roccasion_<?php echo $reservation->reservation_id; ?>"><?php echo "Other"; ?></td>	
						<?php	}else{
								if(!empty($all_occasions)){ 
									foreach($all_occasions as $occasions){ 
										if($occasions->occasion_id == $reservation->occasion)
										{
						?>
						<td id="roccasion_<?php echo $reservation->reservation_id; ?>"><?php echo $occasions->occasion_name; ?></td>
						<?php    		}
									} 
								} 
							}
						}else{ ?>
							 <td id="roccasion_<?php echo $reservation->reservation_id; ?>"></td>
						<?php } ?>
						
						<?php  
						if(!empty($reservation->preferred_food)){
						if(!empty($prod_details)){ 
							foreach($prod_details as $prod){ 
								if($prod->prod_id == $reservation->preferred_food){
						?>
						<td id="rpname_<?php echo $reservation->reservation_id; ?>"><?php echo $prod->prod_name; ?></td>
						<?php 
							} 
						  }
						 }
						}else{ ?>
							<td id="rpname_<?php echo $reservation->reservation_id; ?>"></td>
						<?php }						
						?>
                        <td id="rdate_<?php echo $reservation->reservation_id; ?>"><?php echo $reservation->reservation_date; ?></td>
						<td id="rtime_<?php echo $reservation->reservation_id; ?>"><?php echo $reservation->reservation_time; ?></td>
						<td id="rpeople_<?php echo $reservation->reservation_id; ?>"><?php echo $reservation->people; ?></td>
						
						<?php if($reservation->booked_table == 0){ ?>
						<td id="rtable_<?php echo $reservation->reservation_id; ?>"><?php echo "Without Table"; ?></td>
						<?php }else{
									$bookedtable_name = $this->Data_access_model->select_data('table_name','hs_table_details',array('table_id' =>$reservation->booked_table,));
										if($bookedtable_name->num_rows() > 0){
											$tabname = $bookedtable_name->row();		
										}
						?>			
							<td id="rtable_<?php echo $reservation->reservation_id; ?>"><?php echo $tabname->table_name; ?></td>		
					<?php } ?>
						  <td>
							<select class="form-control" onchange="change_reservation_status(this.value,<?php echo $reservation->reservation_id; ?>);" >
                                <option value="0"<?php if($reservation->reservation_status == 0) { echo  "selected"; }?> >Pending</option>
								<option value="1"<?php if($reservation->reservation_status == 1) { echo  "selected"; }?> >Confirmed</option>
                                <option value="2" <?php if($reservation->reservation_status == 2) { echo  "selected"; }?>  >Canceled</option>
                            </select>
                        </td>
						<td width="200">
							<a href="javascript:;" class="btn" title="View" onclick="view_reservation_details(<?php echo $reservation->reservation_id; ?>);"><i class="fa fa-eye" aria-hidden="true"></i></a>
                            <a href="<?php echo base_url().'admin/delete_reservation/'.$reservation->reservation_id; ?>" class="btn" title="Delete" onclick="return delete_confirmation();"><i class="fa fa-trash" aria-hidden="true"></i></a>
						<input type="hidden" id="remail_<?php echo $reservation->reservation_id ?>" value="<?php echo $reservation->email; ?>" >
						<input type="hidden" id="rstatus_<?php echo $reservation->reservation_id; ?>" value="<?php if($reservation->reservation_status == 0){ echo  "Pending"; }else if($reservation->reservation_status ==1){ echo "Confirmed";  }else if($reservation->reservation_status == 2){ echo "Canceled"; } ?>" >
						<input type="hidden" id="rmsg_<?php echo $reservation->reservation_id ?>" value="<?php echo $reservation->massage; ?>" >
                        </td>
				</tr>
               <?php
				  }
				} 
				?>				
                </tbody>
            </table>
        </div>
    </div>
</div>

<!-- view reservation popup start -->
<div class="modal_box">
	<div id="view_reservation_info" class="modal fade" role="dialog">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title"><span>Reservations</span> Details</h4>
				</div>
				<div class="modal-body">
					<div class="modal_inner_body">
						 
						<div class="order_block">
							<label>Date -</label>
							<span id="rdate"></span>
						</div>
						<div class="order_block">
							<label>Time -</label>
							<span id="rtime"></span>
						</div>
						<div class="order_block">
							<label>Number of Persons -</label>
							<span id="rpeople"></span>
						</div>
						<div class="order_block">
							<label>Occasion -</label>
							<span id="roccasion"></span>
						</div>
						<div class="order_block">
							<label>Food -</label>
							<span id="rfood"></span>
						</div>
						<div class="order_block">
							<label>Name -</label>
							<span id="rname"></span>
						</div>
						<div class="order_block">
							<label>Email -</label>
							<span id="remail"></span>
						</div>
						<div class="order_block">
							<label>Booked Table -</label>
							<span id="rtable_no"></span>
						</div>
						<div class="order_block">
							<label>Message -</label>
							<span id="rmsg"></span>
						</div>
						<div class="order_block">
							<label>Status -</label>
							<span id="rstatus"></span>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- view reservation popup end -->
