<div class="container-fluid" style="padding-bottom: 2rem;">
    <div class="row">
        <div class="col-md-8">
            <div class="card bg-light-transparent" style="margin-bottom: 2rem;">
                <div class="card-header bg-white">
                    <div class="float-left">
                        <h5 class="card-title">Calendar</h5>
                    </div>
                </div>
                <div class="card-body">
                    <div class="card bg-white no-shadow">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-2">
                                    <?php foreach ($room_type as $type) { ?>
                                        <br><div data-trigger="hover" data-tooltip="tooltip" title="<?php echo $type['room']; ?>" class="text-center mt-2 text-white" style="background-color: <?php echo '#'.$type['color_code']; ?>;-webkit-border-radius:8px; -moz-border-radius:8px; border-radius:8px; border:1px solid #ccc; height:28px;"><?php echo $type['short_name']; ?></div>
                                    <?php } ?>
                                </div>
                                <div class="col-10">
                                    <div id="calendar"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-md-4">
            <div class="card bg-light-transparent" style="margin-bottom: 2rem;">
                <div class="card-header bg-white">
                    <h5 class="card-title">Room Booking Summary</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-12">
                            <a class="btn btn-block btn-dark add-shadow" href="<?php echo base_url('hr/serviceform/meeting_form'); ?>" style="padding-top: 1rem; padding-bottom: 1rem;">New Booking</a>
                        </div>
                    </div>
                    <br>
                    <div class="card bg-white no-shadow">
                        <div class="card-body">
                            <h6>Total Booking (<?php echo date('Y') ?>)</h6>
                            <br>
                            <div class="row">
                                <table id="table_types" class="table table-bordered table-striped table-hover mx-1">
                                    <thead class="text-center">
                                        <th>Room</th>
                                        <th>Total Booking</th>
                                    </thead>
                                    <tbody class="text-center">
                                        <?php foreach($room_type as $type): ?>
                                            <tr>
                                                <td class="text-uppercase" data-trigger="hover" data-tooltip="tooltip" title="<?php echo $type['room']; ?>"><?php echo $type['room']; ?></td>
                                                <td><?php echo $type['total_booking']; ?></td>
                                            </tr>
                                        <?php endforeach; ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="card bg-light-transparent">  
        <div class="card-header bg-white">
            <div class="float-left">
                <h4>Meeting & Training Booking List</h4>
                <a href="<?php echo base_url('hr/serviceform/meeting_form'); ?>" class="btn btn-outline-dark btn-sm" title="Add New Booking" ><i class="fa fa-plus"></i> Add New Booking</a>

                <a href="<?php echo base_url('hr/Serviceform_report/meeting_room_print')?>" target="_blank" class="btn btn-outline-dark btn-sm" title="Print"><i class="fa fa-print"></i>Print</a>

                <a id="btnShowFilters" type="button" class="btn btn-outline-dark btn-sm collapsed" data-trigger="hover" title="Show Filters Box" data-toggle="collapse" data-target="#collapseFilter" aria-expanded="false"><i class="fas fa-filter"></i>Show Filters</a>
            </div>
        </div>

        <div class="collapse" id="collapseFilter">
            <div class="card-header">
                <div class="row">
                    <div class="col">
                        <div class="card no-shadow">
                            <div class="card-body">
                                <input type="hidden" name="user_id" id="user_id" value="<?php echo $_SESSION['user']['id']; ?>">
                                <?php if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4){ ?>
                                    <div class="form-group row">
                                        <label for="sv_room_booking_filter_dept" class="col-lg-3">
                                            Department
                                        </label>                           
                                        <div class="col-lg-4" >
                                            <select class="custom-select" name="sv_room_booking_filter_dept" id="sv_room_booking_filter_dept">
                                                <option value="-1">[All]</option>
                                                <?php if($departments) foreach($departments as $row){ ?>
                                                    <option value="<?php echo $row['id']; ?>"><?php echo $row['name'].' ['.$row['branch_name'].']'; ?></option> 
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                <?php } ?>
                                <div class="form-group row">
                                    <label for="filterRoom" class="col-lg-3">
                                        Room
                                    </label>
                                    <div class="col-lg-4">    
                                        <select class='custom-select' id="sv_room_booking_filter_room" name="sv_room_booking_filter_room">
                                            <option value="-1">[All]</option>
                                            <?php foreach ($room_type as $key => $type): ?>
                                                <option value="<?php echo $type['ID'];?>"><?php echo $type['room'];?></option>
                                            <?php endforeach ?>
                                            <option value="7">Other</option>
                                        </select>
                                    </div>                                         
                                </div>
                                <div class="form-group row">
                                    <label for="sv_room_booking_filter_status" class="col-lg-3">
                                        Status
                                    </label>                           
                                    <div class="col-lg-4" >
                                        <select class="custom-select" id="sv_room_booking_filter_status" name="sv_room_booking_filter_status">
                                            <option value="-1">[All]</option>
                                            <option value="Pending">Pending</option>
                                            <option value="In_progress">In Progress</option>
                                            <option value="Verified">Verified</option>
                                            <option value="Completed">Completed</option>
                                            <option value="Rejected">Rejected</option>
                                            <option value="Cancel">Cancel</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="sv_room_booking_filter_year" class="col-lg-3">
                                        Year
                                    </label>                           
                                    <div class="col-lg-4" >
                                        <input type="text" name="sv_room_booking_filter_year" id="sv_room_booking_filter_year" class="form-control datepicker-yyyy">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="sv_room_booking_filter_month" class="col-lg-3">
                                        Requested Month
                                    </label>                           
                                    <div class="col-lg-4" >
                                        <input type="text" name="sv_room_booking_filter_month" id="sv_room_booking_filter_month" class="form-control datepicker-mm">
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col d-print-none">
                                        <button class="btn btn-info" id="searchBtn">Search</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="tab-content">
            <div class="tab-pane fade active show" id="tableView" role="tabpanel" aria-labelledby="nav-table-tab">
                <div class="card-body">
                    <div class="card no-shadow">
                        <div class="card-body">
                            <div class="table-responsive">
                                <table id="filter_table_meeting" class="table table-bordered p-0 m-0">
                                    <thead>
                                        <th class="text-center" width="1%">#</th>
                                        <th class="text-center" width="8%">Packages</th>
                                        <th class="text-center" width="10%">Meeting Room</th>
                                        <th class="text-center"  width="8%">Equipment</th>
                                        <th class="text-center"  width="10%">Event</th>
                                        <th class="text-center"  width="9%">Meal</th>
                                        <th class="text-center"  width="7%">Date Start </th>
                                        <th class="text-center"  width="7%">Date End</th>
                                        <th class="text-center"  width="5%">Status</th>
                                        <th class="text-center" width="2%">Action</th>           
                                    </thead>
                                    <tbody id="list_booking_room">
                                        <?php $i = 1; if(!empty($booking_room)) { foreach($booking_room as $key => $row) { ?>
                                            <tr>
                                                <td class="text-center"><?php echo $i++; ?></td>
                                                <td><?php echo (!empty($row['package']) && $row['package'] != '-- Please Select --' && $row['package_id'] > 0)?$row['package'].' = RM'.number_format($row['package_price'],2).' per pax':''; ?></td>
                                                <td>
                                                    <?php 
                                                    if(!empty($row['other_room']))
                                                    {
                                                        echo $row['other_room'];
                                                    }else{
                                                        echo $row['room'];
                                                    }

                                                    if($row['pax'] > 0)
                                                    {
                                                        echo '<br>('.$row['pax'].' pax)';
                                                    }else{
                                                        echo '';
                                                    }

                                                    if(!empty($row['table_setup']) && $row['table_setup'] != "-- Please Select --")
                                                    {
                                                        echo '<br>['.$row['table_setup'].']';
                                                    }else{
                                                        echo '';
                                                    }
                                                    ?>
                                                </td>
                                                <td><?php if(!empty($row['equipment']))
                                                    {
                                                        $equipment = explode(',',$row['equipment']);

                                                        foreach($equipment as $eqpt) {
                                                            echo '<li>'.$eqpt.'</li>'; 
                                                        }

                                                    } else {
                                                        echo '';
                                                    } ?>
                                                </td>
                                                <td>
                                                    Title : <?php echo $row['event_title']; ?><br>
                                                    Host : <?php echo $row['dept_name'].'/'.$row['branchName']; ?><br>
                                                    Client : <?php echo $row['client']; ?>
                                                </td>
                                                <td>
                                                    <?php 
                                                    if(!empty($row['breakfast']) && $row['breakfast'] != '-- Please Select --')
                                                    { 
                                                        echo '<input type="checkbox" disabled name="breakfast" id="breakfast value="1" checked> Breakfast <br>';
                                                    } else {
                                                        echo '<input type="checkbox" disabled name="breakfast" id="breakfast value="1"> Breakfast <br>';
                                                    }

                                                    if(!empty($row['lunch'] || $row['other_menu']) && $row['lunch'] != '-- Please Select --')
                                                    {
                                                        echo '<input type="checkbox" disabled name="lunch" id="lunch value="1" checked> Lunch <br>';
                                                    } else {
                                                        echo '<input type="checkbox" disabled name="lunch" id="lunch value="1"> Lunch <br>';
                                                    }

                                                    if(!empty($row['hi_tea']) && $row['hi_tea'] != '-- Please Select --')
                                                    { 
                                                        echo '<input type="checkbox" disabled name="hi_tea" id="hi_tea value="1" checked> Hi-Tea <br>';
                                                    } else {
                                                        echo '<input type="checkbox" disabled name="hi_tea" id="hi_tea value="1"> Hi-Tea <br>';
                                                    }

                                                    if(!empty($row['special_request']))
                                                    {
                                                        echo '<input type="checkbox" disabled name="special_request" id="special_request value="1" checked> Special Request';
                                                    } else {
                                                        echo '<input type="checkbox" disabled name="special_request" id="special_request value="1"> Special Request';
                                                    }
                                                    ?>
                                                </td>
                                                <td class="text-center">
                                                    <?php echo date ('d-m-Y',strtotime($row['start_date'])) . ' / ' . $row['start_time']; ?>        
                                                </td>
                                                <td class="text-center">
                                                    <?php echo date('d-m-Y',strtotime($row['end_date'])) . ' / ' . $row['end_time']; ?>
                                                </td>
                                                <td class="text-center">
                                                    <?php 
                                                        if(($row['status_app']==null || $row['status_app']=='Pending'))
                                                        {
                                                            $status = 'Pending <i class="fa fa-exclamation-circle" style="color: #FFC107;"></i>';
                                                            $disabled = '';
                                                        }
                                                        if($row['status_app'] == 'In_progress')
                                                        {
                                                            $status = str_replace('_', ' ', $row['status_app']).' <i class="fa fa-hourglass-start" style="color: grey;"></i>';
                                                            $disabled = 'disabled style="cursor: not-allowed;"';
                                                        }
                                                        if($row['status_app'] == 'Verified')
                                                        {
                                                            $status = $row['status_app'].' <i class="fa fa-check-circle" style="color: green;"></i><p style="font-style: italic; font-size: 13px;">'.$row['status_reason'].'</p>';
                                                            $disabled = '';
                                                        }
                                                        if($row['status_app'] == 'Completed')
                                                        {
                                                            $status = $row['status_app'].' <i class="fa fa-check-circle" style="color: green;"></i>';
                                                            $disabled = 'disabled style="cursor: not-allowed;"';
                                                        }
                                                        if($row['status_app'] == 'Rejected')
                                                        {
                                                            $status = $row['status_app'].' <i class="fa fa-times-circle" style="color: red;"></i>';
                                                            $disabled = 'disabled style="cursor: not-allowed;"';
                                                        }
                                                        if($row['status_app'] == 'Cancel')
                                                        {
                                                            $status = $row['status_app'].' <i class="fa fa-times-circle" style="color: red;"></i>';
                                                            $disabled = 'disabled style="cursor: not-allowed;"';
                                                        }

                                                        echo $status;
                                                    ?> 
                                                </td>
                                                <td class="text-center">
                                                    <div class="btn-group btn-group-sm" role="group">
                                                        <button type="button" class="btn btn-outline-dark" data-toggle="modal" data-target="#viewDetails" data-trigger="hover" data-tooltip="tooltip" 
                                                        title="View Detail"
                                                        data-name="<?php echo $row['name']; ?>" 
                                                        data-dept="<?php echo $row['dept_name'].'/'.$row['branchName']; ?>" data-datereq="<?php echo date('d-m-Y',strtotime($row['createdTS'])); ?>"
                                                        data-eventtitle="<?php echo $row['event_title']; ?>"
                                                        data-client="<?php echo $row['client']; ?>"
                                                        data-datestart="<?php echo date('d-m-Y',strtotime($row['start_date'])); ?>"
                                                        data-dateend="<?php echo date('d-m-Y',strtotime($row['end_date'])); ?>"
                                                        data-timestart="<?php echo $row['start_time']; ?>"
                                                        data-timeend="<?php echo $row['end_time']; ?>"
                                                        data-vip="<?php echo $row['vip']; ?>"
                                                        data-pax="<?php echo $row['pax']; ?>"
                                                        data-pack="<?php echo $row['package'].' = RM'.number_format($row['package_price'],2); ?>"
                                                        data-tblsetup="<?php echo $row['table_setup']; ?>"
                                                        data-equipment="<?php echo $row['equipment']; ?>"
                                                        data-breakfast="<?php echo $row['breakfast']; ?>"
                                                        data-lunch="<?php echo $row['lunch']; ?>"
                                                        data-othermenu="<?php echo $row['other_menu']; ?>"
                                                        data-hitea="<?php echo $row['hi_tea']; ?>"
                                                        data-special="<?php echo $row['special_request']; ?>"
                                                        data-room="<?php echo $row['room']; ?>"
                                                        data-otherroom="<?php echo $row['other_room']; ?>"
                                                        onclick="open_view_meeting_modal(this)">
                                                        <i class="far fa-eye"></i> </button>

                                                        <?php if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4){ ?>
                                                            <a href="<?php echo base_url('hr/serviceform/meeting_form/'.$row['ID']) ?>" type="button" class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="Edit"><i class="far fa-edit"></i></a>
                                                        <?php } else { ?>
                                                            <?php if($disabled == ''){ ?>
                                                                <a href="<?php echo base_url('hr/serviceform/meeting_form/'.$row['ID']) ?>" type="button" class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="Edit"><i class="far fa-edit"></i></a>
                                                            <?php }else{ ?>
                                                                <button class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="Edit" disabled style="cursor: not-allowed;"><i class="far fa-edit"></i></button>
                                                            <?php } ?>
                                                        <?php } ?>                                                        

                                                        <a type="button" class="btn btn-outline-dark" href="<?php echo base_url('hr/serviceform_report/meeting_room_print/').$row['ID']; ?>" target="_blank" data-trigger="hover" data-tooltip="tooltip" title="Print Detail"><i class="fa fa-print"></i></a>

                                                        <?php if(($_SESSION['user']['id'] == $row['requester_id']) || ($_SESSION['user']['id'] == $row['createdBY'])){ ?>
                                                            <button id="deleteButton" type="button" class="btn btn-outline-dark" onclick="delete_meeting(<?php echo $row['ID']; ?>);" data-trigger="hover" data-tooltip="tooltip" title="Delete" <?php echo ($disabled == '')?'':'disabled style="cursor: not-allowed;"'; ?>><i class="far fa-trash-alt"></i></button>
                                                        <?php } ?>
                                                    </div>
                                                </td>
                                            </tr>
                                        <?php } } ?>
                                    </tbody>
                                </table>
                            </div>                   
                        </div>
                    </div>
                </div>
            </div>
        </div>      
    </div>
</div>

<!-- modal view detail -->

<div class="modal fade d-print-none" id="viewDetails" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLongTitle">Meeting & Training Room Booking</h5>&emsp;
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body">
                <div class="row">
                    <div class="col-6">
                        <label>Name</label>
                        <input type="text" class="form-control" name="modal_view_name" id="modal_view_name" style="background-color: none;" disabled>
                    </div>
                    <div class="col-6">
                        <label>Department</label>
                        <input type="text" class="form-control" name="modal_view_dept" id="modal_view_dept" disabled>
                    </div>
                </div>

                <div class="row">
                    <div class="col-6">
                        <label>Date Request</label>
                        <input type="text" class="form-control" name="modal_view_date_req" id="modal_view_date_req" disabled>
                    </div>
                    <div class="col-6">
                        <label>Event Title</label>
                        <input type="text" class="form-control" name="modal_view_event_title" id="modal_view_event_title" disabled>
                    </div>
                </div>

                <div class="row">
                    <div class="col-6">
                        <label>Client</label>
                        <input type="text" class="form-control" name="modal_view_client" id="modal_view_client" disabled>
                    </div>
                    <div class="col-3">
                        <label>VIP</label>
                        <input type="text" class="form-control" name="modal_view_vip" id="modal_view_vip" disabled>
                    </div>
                    <div class="col-3">
                        <label>No. of Pax</label>
                        <input type="text" class="form-control" name="modal_view_pax" id="modal_view_pax" disabled>
                    </div>
                </div>

                <div class="row">
                    <div class="col-3">
                        <label>Date Start</label>
                        <input type="text" class="form-control" name="modal_view_date_start" id="modal_view_date_start" disabled>
                    </div>
                    <div class="col-3">
                        <label>Time Start</label>
                        <input type="text" class="form-control" name="modal_view_time_start" id="modal_view_time_start" disabled>
                    </div>
                    <div class="col-3">
                        <label>Date End</label>
                        <input type="text" class="form-control" name="modal_view_date_end" id="modal_view_date_end" disabled>
                    </div>
                    <div class="col-3">
                        <label>Time End</label>
                        <input type="text" class="form-control" name="modal_view_time_end" id="modal_view_time_end" disabled>
                    </div>
                </div>

                <div class="row">
                    <div class="col-6">
                        <label>Package</label>
                        <textarea class="form-control" name="modal_view_package" id="modal_view_package" disabled></textarea>
                    </div>
                    <div class="col-6">
                        <label>Table Setup</label>
                        <input type="text" class="form-control" name="modal_view_table_setup" id="modal_view_table_setup" disabled>
                    </div>
                </div>

                <div class="row">
                    <div class="col-6">
                        <label>Equipment</label>
                        <textarea class="form-control" name="modal_view_equipment" id="modal_view_equipment" disabled></textarea>
                    </div>
                    <div class="col-6">
                        <label>Breakfast</label>
                        <input type="text" class="form-control" name="modal_view_breakfast" id="modal_view_breakfast" disabled>
                    </div>
                </div>

                <div class="row">
                    <div class="col-6">
                        <label>Lunch</label>
                        <input type="text" class="form-control" name="modal_view_lunch" id="modal_view_lunch" disabled>
                    </div>
                    <div class="col-6">
                        <label>Hi-Tea</label>
                        <input type="text" class="form-control" name="modal_view_hi_tea" id="modal_view_hi_tea" disabled>
                    </div>
                </div>

                <div class="row">
                    <div class="col-6">
                        <label>Room</label>
                        <input type="text" class="form-control" name="modal_view_room" id="modal_view_room" disabled>
                    </div>
                    <div class="col-6">
                        <label>Special Request</label>
                        <input type="text" class="form-control" name="modal_view_special_request" id="modal_view_special_request" disabled>
                    </div>
                </div>

                <br>

                <div class="float-right">
                </div>
            </div>
        </div>
    </div>
</div>

<!-- modal view detail -->

<style type="text/css">
    .tooltipevent
    {
        width:auto;
        height:auto;
        background:rgba(0,0,0,0.75);
        position:absolute;
        color: #fff;
        z-index:10001;
        padding:10px 10px 10px 10px ;  
        line-height: 200%;
    }
</style>

<script>
    function delete_meeting(ID) {
        validateForm("#deleteButton", "Delete this maintenance list?", function() {
            $.ajax({
                url:'<?php echo base_url('hr/serviceform/deleteMeetingList') ?>',
                data: {
                    meetingsID : ID,
                },
                type: 'post',
                dataType: 'json',
                success: (data) => {
                    if(data.status == "Success") {

                        localStorage.setItem("status", data.status);
                        localStorage.setItem("msg", data.msg);

                        location.reload();
                    }
                }
            });
        });
    }

    $(document).ready(function(){

        $('#table_types').DataTable().destroy();

        var fc_event= '';
        var resource = <?php echo $resource;?>;
        
        var fullcalendar = $('#calendar').fullCalendar({ 
            themeSystem: 'bootstrap4',
            header: 
            {
                left: 'prev,next today',
                center: 'title',
                right: 'month,listMonth'
            },
            buttonText: {
                today: 'Today',
                month: 'Calendar',
                listMonth: 'List'
            },

            navLinks: true, // can click day/week names to navigate views
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: <?php echo $fc_event; ?>,

            eventMouseover: function (data, event, param, resource = <?php echo $resource;?>) {
                var js_res = JSON.parse(JSON.stringify(resource));
                var hover_item = js_res[data.id];
                var title = JSON.stringify(data.title);
                var start_date = moment(hover_item.start_date).format('DD-MM-YYYY');
                var end_date = moment(hover_item.end_date).format('DD-MM-YYYY');


                if(hover_item.room_id == 7)
                {
                    var room = hover_item.other_room;
                } else {
                    var room = hover_item.room;
                }

                tooltip = '<div class="tooltipevent"> Requester : '+hover_item.name+'['+hover_item.staff_id+']'+'<br/> Email : '+hover_item.email+'<br/> Room : '+room+'<br/> Start Date : '+start_date+'<br/> End Date : '+end_date+'<br/>Start Time : '+hover_item.start_time+'<br/>End Time : '+hover_item.end_time+'<br/>Department : '+hover_item.dept_name+'/'+hover_item.branchName+'</div>';

                $("body").append(tooltip);
                $(this).mouseover(function (e) {
                    $(this).css('z-index', 10000);
                    $('.tooltipevent').fadeIn('500');
                    $('.tooltipevent').fadeTo('10', 1.9);
                }).mousemove(function (e) {
                    $('.tooltipevent').css('top', e.pageY + 10);
                    $('.tooltipevent').css('left', e.pageX + 20);
                });
            },

            eventMouseout: function(data, event) {
                $(this).css('z-index', 8);
                $('.tooltipevent').remove();
            },
        });

        fullcalendar.fullCalendar();

        $('#searchBtn').click(function(){
            getData();
        });

        <?php $this->session->unset_userdata('sv_room_booking_filter_dept'); ?>
        <?php $this->session->unset_userdata('sv_room_booking_filter_room'); ?>
        <?php $this->session->unset_userdata('sv_room_booking_filter_year'); ?>
        <?php $this->session->unset_userdata('sv_room_booking_filter_month'); ?>
        <?php $this->session->unset_userdata('sv_room_booking_filter_status'); ?>
        <?php $this->session->unset_userdata('sv__booking__room'); ?>
    });

    function open_view_meeting_modal(elem) 
    {
        // console.log(elem);

        let name                 = $(elem).data('name');
        let dept                 = $(elem).data('dept');
        let datereq              = $(elem).data('datereq');
        let title                = $(elem).data('eventtitle');
        let client               = $(elem).data('client');
        let date_start           = $(elem).data('datestart');
        let date_end             = $(elem).data('dateend');
        let time_start           = $(elem).data('timestart');
        let time_end             = $(elem).data('timeend');
        let vip                  = $(elem).data('vip');
        let pax                  = $(elem).data('pax');
        let tblsetup             = $(elem).data('tblsetup');
        let equipment            = $(elem).data('equipment');
        let special_request      = $(elem).data('special');
        let room                 = $(elem).data('room');
        let other_room           = $(elem).data('otherroom');
        // let breakfast            = $(elem).data('breakfast');
        // let lunch                = $(elem).data('lunch');
        // let other_menu           = $(elem).data('othermenu');
        // let hi_tea               = $(elem).data('hitea');
        // let package              = $(elem).data('pack');

        if($(elem).data('pack') == '' || $(elem).data('pack') == '-- Please Select --')
        {
            var package              = 'Not Select';
        }else{
            var package              = $(elem).data('pack');
        }

        if($(elem).data('breakfast') == '' || $(elem).data('breakfast') == '-- Please Select --'){
            var breakfast            = 'Not Request';
        }else{
            var breakfast            = $(elem).data('breakfast');
        }

        if($(elem).data('lunch') == '' || $(elem).data('lunch') == '-- Please Select --'){
            var lunch            = 'Not Request';
        }else{
            var lunch            = $(elem).data('lunch');
        }

        if($(elem).data('othermenu') == '' || $(elem).data('othermenu') == '-- Please Select --'){
            var other_menu            = 'Not Request';
        }else{
            var other_menu            = $(elem).data('othermenu');
        }

        if($(elem).data('hitea') == '' || $(elem).data('hitea') == '-- Please Select --'){
            var hi_tea            = 'Not Request';
        }else{
            var hi_tea            = $(elem).data('hitea');
        }

        /* view modal */
        $('#modal_view_name').val(name);
        $('#modal_view_dept').val(dept);
        $('#modal_view_date_req').val(datereq);
        $('#modal_view_event_title').val(title);
        $('#modal_view_client').val(client);
        $('#modal_view_date_start').val(date_start);
        $('#modal_view_date_end').val(date_end);
        $('#modal_view_time_start').val(time_start);
        $('#modal_view_time_end').val(time_end);
        
        if(vip == 0)
        {
            $('#modal_view_vip').val('No');
        } else {
            $('#modal_view_vip').val('Yes');
        }
        
        $('#modal_view_pax').val(pax);
        $('#modal_view_package').val(package);
        $('#modal_view_table_setup').val(tblsetup);
        $('#modal_view_equipment').val(equipment);
        $('#modal_view_breakfast').val(breakfast);

        if(lunch != null && lunch != '' && lunch != undefined)
        {
            $('#modal_view_lunch').val(lunch);
        } else {
            $('#modal_view_lunch').val(other_menu);
        }
        
        $('#modal_view_hi_tea').val(hi_tea);
        $('#modal_view_special_request').val(special_request);

        if(room == 'OTHER')
        {
            $('#modal_view_room').val(other_room);
        } else {
            $('#modal_view_room').val(room);
        }
    }

    function getData() {
        var table = $('#filter_table_meeting').DataTable();
        table.clear().draw();
        var frmData = new FormData();

        frmData.append('sv_room_booking_filter_dept',$('#sv_room_booking_filter_dept').val());
        frmData.append('sv_room_booking_filter_room',$('#sv_room_booking_filter_room').val());
        frmData.append('sv_room_booking_filter_status',$('#sv_room_booking_filter_status').val());
        frmData.append('sv_room_booking_filter_year',$('#sv_room_booking_filter_year').val());
        frmData.append('sv_room_booking_filter_month',$('#sv_room_booking_filter_month').val());
        frmData.append('user_id',$('#user_id').val());

        $.ajax({
            url:"<?php echo base_url('/hr/api/serviceform/get_meeting_filter'); ?>",
            type:'post',
            dataType:'json',
            data:frmData,
            processData: false,
            contentType: false,
            success:function(data){

                iziToast.success({
                    position: 'bottomRight',
                    message: 'filtering data',
                });

                let room_booking = data.table;

                if(room_booking != null){
                    $.each(room_booking,function(key,content)
                    {
                        var i = key + 1;

                        if(content.room_id == 7)
                        {
                            var room = content.other_room;
                        }else{
                            var room = content.room;
                        }

                        if(content.pax > 0)
                        {
                            var pax = '<br>('+content.pax+' pax)';
                        }else{
                            var pax = '';
                        }

                        if(content.table_setup != null && content.table_setup != undefined && content.table_setup != '' && content.table_setup != "-- Please Select --")
                        {
                            var table_setup = '<br>['+content.table_setup+']';
                        }else{
                            var table_setup = '';
                        }

                        if(content.start_date != '0000-00-00' && content.start_date != undefined){
                            var start_date = moment(content.start_date).format('DD-MM-YYYY');;
                        }
                        if(content.end_date != '0000-00-00' && content.end_date != undefined){
                            var end_date = moment(content.end_date).format('DD-MM-YYYY');;
                        }

                        if(content.breakfast != '' && content.breakfast != '-- Please Select --')
                        { 
                            var breakfast = '<input type="checkbox" disabled name="breakfast" id="breakfast value="1" checked> Breakfast <br>';
                        } else {
                            var breakfast = '<input type="checkbox" disabled name="breakfast" id="breakfast value="1"> Breakfast <br>';
                        }

                        if((content.lunch || content.other_menu) != '' && content.lunch != '-- Please Select --')
                        {
                            var lunch = '<input type="checkbox" disabled name="lunch" id="lunch value="1" checked> Lunch <br>';
                        } else {
                            var lunch = '<input type="checkbox" disabled name="lunch" id="lunch value="1"> Lunch <br>';
                        }

                        if(content.hi_tea != '' && content.hi_tea != '-- Please Select --')
                        { 
                            var hi_tea = '<input type="checkbox" disabled name="hi_tea" id="hi_tea value="1" checked> Hi-Tea <br>';
                        } else {
                            var hi_tea = '<input type="checkbox" disabled name="hi_tea" id="hi_tea value="1"> Hi-Tea <br>';
                        }

                        if(content.special_request != '')
                        {
                            var special_request = '<input type="checkbox" disabled name="special_request" id="special_request value="1" checked> Special Request <br>';
                        } else {
                            var special_request = '<input type="checkbox" disabled name="special_request" id="special_request value="1"> Special Request <br>';
                        }

                        if((content.package != '' || content.package != null || content.package != undefined || content.package != '-- Please Select --') && content.package_id > 0)
                        {
                            var price = parseFloat(content.package_price).toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
                            var package = content.package+' = RM'+price+' per pax';
                        }else{
                            var package = '';
                        }

                        var btn_view = '<button type="button" class="btn btn-outline-dark" data-toggle="modal" data-target="#viewDetails" data-trigger="hover" data-tooltip="tooltip" title="View Detail" data-name="'+content.name+'" data-dept="'+content.dept_name+'/'+content.branchName+'" data-datereq="'+moment(content.createdTS).format('DD-MM-YYYY')+'" data-eventtitle="'+content.event_title+'" data-client="'+content.client+'" data-datestart="'+start_date+'" data-dateend="'+end_date+'" data-timestart="'+content.start_time+'" data-timeend="'+content.end_time+'" data-vip="'+content.vip+'" data-pax="'+content.pax+'" data-pack="'+package+'" data-tblsetup="'+content.table_setup+'" data-equipment="'+content.equipment+'" data-breakfast="'+content.breakfast+'" data-lunch="'+content.lunch+'" data-othermenu="'+content.other_menu+'" data-hitea="'+content.hi_tea+'" data-special="'+content.special_request+'" data-room="'+content.room+'" data-otherroom="'+content.other_room+'" onclick="open_view_meeting_modal(this)"> <i class="far fa-eye"></i> </button>';

                        var btn_print = '<a type="button" class="btn btn-outline-dark" href="<?php echo base_url();?>hr/serviceform_report/meeting_room_print/'+content.ID+'" target="_blank" data-trigger="hover" data-tooltip="tooltip" title="Print Detail"><i class="fa fa-print"></i></a>';

                        if(content.equipment != '' && content.equipment != null)
                        {
                            var equipment_split = content.equipment.split(",");
                            var eqpt = '';
                            if(equipment_split.length > 0)
                            {
                                $.each(equipment_split,function(equipment_key,equipment_content)
                                {
                                    eqpt += '<li>'+equipment_content+'</li>';
                                });
                            }
                        }else{
                            var eqpt = '';
                        }

                        if(content.status_app == null || content.status_app == 'Pending')
                        {
                            var status      = 'Pending <i class="fa fa-exclamation-circle" style="color: #FFC107;"></i>';
                            var disabled    = '';
                        }
                        if(content.status_app == 'In_progress')
                        {
                            var status      = ((content.status_app).replace('_',' '))+' <i class="fa fa-hourglass-start" style="color: grey;"></i>';
                            var disabled    = 'disabled style="cursor: not-allowed;"';
                        }
                        if(content.status_app == 'Verified')
                        {
                            var status      = content.status_app+' <i class="fa fa-check-circle" style="color: green;"></i><p style="font-style: italic; font-size: 13px;">'+content.status_reason+'</p>';
                            var disabled    = '';
                        }
                        if(content.status_app == 'Completed')
                        {
                            var status      = content.status_app+' <i class="fa fa-check-circle" style="color: green;"></i>';
                            var disabled    = 'disabled style="cursor: not-allowed;"';
                        }
                        if(content.status_app == 'Rejected')
                        {
                            var status      = content.status_app+' <i class="fa fa-times-circle" style="color: red;"></i>';
                            var disabled    = 'disabled style="cursor: not-allowed;"';
                        }
                        if(content.status_app == 'Cancel')
                        {
                            var status      = content.status_app+' <i class="fa fa-times-circle" style="color: red;"></i>';
                            var disabled    = 'disabled style="cursor: not-allowed;"';
                        }

                        if("<?php echo $_SESSION['all_modules_access'][0]['access_lvl']; ?>" == 'admin' || "<?php echo $_SESSION['user']['division_id']; ?>" == 4){
                            var btn_edit = '<a type="button" class="btn btn-outline-dark" href="<?php echo base_url();?>hr/serviceform/meeting_form/'+content.ID+'" data-trigger="hover" data-tooltip="tooltip" title="Edit"><i class="far fa-edit"></i></a>';
                        } else {
                            if(disabled == '')
                            {
                                var btn_edit = '<a type="button" class="btn btn-outline-dark" href="<?php echo base_url();?>hr/serviceform/meeting_form/'+content.ID+'" data-trigger="hover" data-tooltip="tooltip" title="Edit"><i class="far fa-edit"></i></a>';
                            }else{
                                var btn_edit = '<button class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="Edit" '+disabled+'><i class="far fa-edit"></i></button>';
                            }
                        }

                        var btn_delete = '<button type="button" class="btn btn-outline-dark" onclick="delete_meeting('+content.ID+')" data-trigger="hover" data-tooltip="tooltip" title="Delete" '+disabled+'><i class="far fa-trash-alt"></i></button>';

                        if(('<?php echo $_SESSION['user']['id']; ?>' == content.requester_id) || ('<?php echo $_SESSION['user']['id']; ?>' == content.createdBY))
                        {
                            var btn = btn_view+btn_edit+btn_print+btn_delete;
                        }else{
                            var btn = btn_view+btn_edit+btn_print;
                        }

                        table.row.add({
                            0   : '<div class="text-center">'+i+'</div>',
                            1   : package,
                            2   : room+pax+table_setup,
                            // 3   : '<li>'+content.equipment+'</li>',
                            3   : eqpt,
                            4   : 'Title : '+content.event_title+'<br>Host : '+content.dept_name+'/'+content.branchName+'<br>Client : '+content.client,
                            5   : breakfast+lunch+hi_tea+special_request,
                            6   : '<div class="text-center">'+start_date+' / '+content.start_time+'</div>',
                            7   : '<div class="text-center">'+end_date+' / '+content.end_time+'</div>',
                            8   : '<div class="text-center">'+status+'</div>',
                            9   : '<div class="text-center"><div class="btn-group btn-group-sm" role="group">'+btn+'</div></div>',
                        }).draw();
                        // console.log(data);
                    });                        
                }
            },
            error:function(){
                iziToast.warning({
                    position: 'bottomRight',
                    message: '500 Internal Server Error.'
                });
            }
        });
    }

</script>