<?php
ob_start();
include_once 'classes/common.php';
include_once 'classes/DB.class.php';
include_once 'session/admin-session.php';
//ini_set("display_errors", 0);
$db = new DB();
$com = new common();

$admin_id = $_SESSION['rcuesr_room_admin_id'];

// Getting the List Of Compnay
$RoomBookListArr = $db->selectWithCols("rcuesr_room_booking_tbl", "*", "1 AND book_status='2' ORDER BY departure_date_time ASC");
?>
<div class="row">
    <div class="col-md-12 col-sm-12 col-xs-12 ">
        <h3>Live Booking List</h3>
        <div class="box box-primary">
            <div class="box-body">
                <div class="table-responsive ">
                    <table class="table table-striped table-hover table-bordered table-condensed" id="tbl_booking_id">
                        <thead>
                            <tr>
                                <th width="3%">
                                    #
                                </th>
                                <th width="20%">
                                    Room Number
                                </th>
                                <th width="25%">
                                    Booking User Details
                                </th>
                                <th>
                                    ID
                                </th>
                                <th>
                                    Amount
                                </th>
                                <th>
                                    Check In
                                </th>
                                <th>
                                    Expected Check Out
                                </th>
                                <th>
                                    Action
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $c = 1;
                            foreach ($RoomBookListArr as $RBLA) {
                                $BookingDetails = "<b>" . common::StrFromDb($RBLA['applicant_name']) . "</b>";
                                if (!empty($RBLA['applicant_post'])) {
                                    $BookingDetails .= "/" . common::StrFromDb($RBLA['applicant_post']);
                                }
                                if (!empty($RBLA['department'])) {
                                    $BookingDetails .= "/" . common::StrFromDb($RBLA['department']);
                                }
                                if (!empty($RBLA['mobile_number'])) {
                                    $BookingDetails .= "<br/>" . common::StrFromDb($RBLA['mobile_number']);
                                }
                                
                                
                                if($RBLA['sharing_check'] == "YES"){
                                      $BookingDetails .= "<br/>& <b>" . common::StrFromDb($RBLA['applicant_name_second']) . "</b>";
                                if (!empty($RBLA['applicant_post_second'])) {
                                    $BookingDetails .= "/" . common::StrFromDb($RBLA['applicant_post_second']);
                                }
                                if (!empty($RBLA['applicant_department_second'])) {
                                    $BookingDetails .= "/" . common::StrFromDb($RBLA['applicant_department_second']);
                                }
                                if (!empty($RBLA['mobile_number_second'])) {
                                    $BookingDetails .= "<br/>" . common::StrFromDb($RBLA['mobile_number_second']);
                                }
                                }
                                
                                
                                
                                
                                $proposed_amount = $RBLA['proposed_amount'];
                                $CheckInDateTime = DATE('d/m/Y H:i', strtotime($RBLA['arrival_date_time']));
                                $CheckOutDateTime = DATE('d/m/Y H:i', strtotime($RBLA['departure_date_time']));
                                $bookingUserId = "";
                                $bookingUserId = $RBLA['id_type'] . ":" . $RBLA['id_number'];
                                if ($RBLA['upload_file']) {
                                    $upload_file_str = "<br/><a href='../updoc/" . $RBLA['upload_file'] . "' target='_blank'>Download</a>";
                                    $bookingUserId .= $upload_file_str;
                                }
                                ?>
                                <tr id="room_book_id_<?php echo $RBLA['room_book_pk_id']; ?>">
                                    <td><?php echo $c; ?></td>
                                    <td><?php echo common::StrFromDb($RBLA['room_number']); ?></td>
                                    <td><?php echo common::StrFromDb($BookingDetails); ?></td>
                                    <td><?php echo $bookingUserId; ?></td>
                                    <td><i class="fa fa-inr"></i><?php echo common::DecimalTwoPlace($proposed_amount); ?></td>
                                    <td><?php echo $CheckInDateTime; ?></td>
                                    <td><?php echo $CheckOutDateTime; ?></td>
                                    <td>
                                        <label>Received Amount</label>
                                        <input type="decimal" id="received_amount_<?php echo $RBLA['room_book_pk_id']; ?>" value="<?php echo $com->DecimalTwoPlace($proposed_amount); ?>" class="form-control"/>
                                        <a href="javascript:void(0);" class="btn btn-danger" onclick="FunCheckOut('<?php echo $RBLA['room_book_pk_id']; ?>');">Check Out</a>
                                    </td>
                                </tr>
                                <?php
                                $c = $c + 1;
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>

        </div>
    </div>
</div>
<div class="clearfix"></div><br/><br/>
<?php
$mainpagecontent = ob_get_contents();
ob_clean();
include 'admin-master.php';
?>
<script type="text/javascript">
    function FunCheckOut(RoomBookId) {
        if (confirm("Confirm CheckOut?")) {
            var received_amount = $("#received_amount_" + RoomBookId).val();
            $.ajax({
                type: "POST",
                url: "server/action-post.php",
                data: "received_amount=" + received_amount + "&RoomBookId=" + RoomBookId + "&action=FunCheckOut",
                success: function (data) {
                    if (data.res_status == 1) {
                        alert("CheckOut Successfully!")
                        $("#room_book_id_"+RoomBookId).hide();
                    } else {
                        alert(data.res_msg);

                    }
                }
            });
        }
    }
</script>