<style>
.pointer{
    cursor:pointer;
}
</style>
<section class="container-fluid" style="padding-bottom: 1rem;">
	<div class="row">
		<div class="col-6">
            <div class="card bg-light-transparent">
                <div class="card-header bg-white">
                    <div class="float-left">
                        <h4 class="card-title">Calendar</h4>
                    </div>
                </div>
                <div class="card-body">
                    <div class="card bg-white no-shadow" style="padding-bottom: 4.9rem;">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-2" style="padding-top: 2rem;">
                                    <?php if(!empty($booking_name)) foreach ($booking_name as $booking) { ?>
                                            <br>
                                            <div data-trigger="hover" data-tooltip="tooltip" title="<?php echo $booking['title']; ?>" class="text-center mt-2 text-white" style="background-color: <?php echo '#'.$booking['color_code']; ?>;-webkit-border-radius:8px; -moz-border-radius:8px; border-radius:8px; border:1px solid #ccc; height:28px;">
                                                <?php echo $booking['short_name']; ?>
                                            </div>
                                    <?php } ?>
                                </div>
                                <div class="col-10">
                                    <div id="calendar"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
		</div>
        <div class="col-6">
            <div class="tab-pane fade show active" id="forms" role="tabpanel" aria-labelledby="forms-tab">
                <div class="card bg-light-transparent" style="margin-bottom: 2rem;">
                    <div class="card-header bg-light">
                        <h3>Service Form</h3>
                    </div>
                    
                    <div class="tab-content">

                        <div class="tab-pane fade show active" id="formTableView" role="tabpanel" aria-labelledby="nav-table-tab">
                            <div class="card-body">
                                <?php foreach($categories as $index => $cat): ?>
                                    <div class="card no-shadow bg-dark-transparent mb-3">
                                        <div class="card-header bg-dark text-white pointer" data-toggle="collapse" data-target="#form_collapse_list_<?php echo $index; ?>">
                                            <h5 class="card-title"><?php echo $cat['category']; ?> <span class="forms_<?php echo $index; ?> badge badge-danger float-right"></span></h5>
                                        </div>

                                        <div class="card-body bg-dark-transparent collapse" id="form_collapse_list_<?php echo $index; ?>">
                                            <div class="table-responsive bg-white p-3">
                                                <table id="table_forms" class="table table-bordered table-hover">
                                                    <thead>
                                                        <th class="text-center">Code</th>
                                                        <th>Title</th>
                                                        <!-- <?php //if($this->session->userdata('module_data')['role'] == 'admin'){ ?>    
                                                            <th>Status</th>
                                                        <?php //}else{ ?>
                                                            <th></th>
                                                        <?php //} ?>-->
                                                        <th></th>
                                                        <th></th>
                                                    </thead>
                                                    <tbody>
                                                    <?php if(isset($forms)): ?>
                                                        <?php $document_no = 0; ?>
                                                        <?php foreach($forms as $form): ?>

                                                            <?php if($form['category'] == $cat['category']): $document_no++; ?>
                                                                <?php if($form['id'] == 34){ ?>
                                                                    <?php if($_SESSION['user']['department_id'] == 1){ ?>
                                                                        <tr>
                                                                            <td class="text-center"><?php echo $form['short_name']; ?></td>
                                                                            <td><a target="_blank" href="<?php echo base_url('hr/serviceform/onlineForm/').$form['file_listing']; ?>"><?php echo $form['title']; ?></a></td>
                                                                            <td class="text-center">    
                                                                                <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total In-Progress" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_progess'].'</span>'; ?>
                                                                                <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Approved" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Verified" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_verified'].'</span>'; ?>
                                                                                <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Cancel" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_cancel'].'</span>'; ?>
                                                                                <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                            </td>
                                                                            <td class="text-center">
                                                                            <div class="btn-group btn-group-sm" role="group">
                                                                                <div class="btn-group btn-group-sm" role="group">
                                                                                    <a href="<?php echo base_url('hr/serviceform/onlineForm/').$form['file_listing']; ?>" class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="Listing" target="_blank"><i class="fas fa-align-justify"></i></a>
                                                                                    <a href="<?php echo base_url('hr/serviceform/').(($form['id'] == 20)?$form['file_name']:$form['file_name'].'_form'); ?>" class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="New Form" target="_blank"><i class="far fa-file"></i></a>
                                                                                </div>
                                                                            </div>
                                                                        </tr>
                                                                    <?php }else{ $document_no--; } ?>
                                                                <?php }else{ ?>
                                                                    <tr>
                                                                        <td class="text-center"><?php echo $form['short_name']; ?></td>
                                                                        <td><a target="_blank" href="<?php echo base_url('hr/serviceform/onlineForm/').$form['file_listing']; ?>"><?php echo $form['title']; ?></a></td>

                                                                        <?php if($form['category_id'] == 8){ ?>
                                                                            <?php if($this->session->userdata('all_modules_access')[1]['access_lvl'] == 'admin'){ ?>
                                                                                <?php if($form['id'] == 43 || $form['id'] == 44 || $form['id'] == 45){ ?>
                                                                                    <td class="text-center">
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total In-Progress" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_progess'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Verified" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_verified'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Approved" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Cancel" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_cancel'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                                    </td>
                                                                                <?php } else { ?>    
                                                                                    <?php if($count_complaint){ ?>
                                                                                        <td class="text-center">
                                                                                            <?php echo '<span class="badge badge-pill badge-danger" data-trigger="hover" data-tooltip="tooltip" title="Total New!" style="font-size: 90%; display: inline;">'.$count_complaint[0]->count_comp_new.'</span>'; ?>
                                                                                            <?php echo '<span class="badge badge-pill badge-warning" data-trigger="hover" data-tooltip="tooltip" title="Total In Progress" style="font-size: 90%; display: inline;">'.$count_complaint[0]->count_comp_in_progress.'</span>'; ?>
                                                                                            <?php echo '<span class="badge badge-pill badge-info" data-trigger="hover" data-tooltip="tooltip" title="Total Action Taken" style="font-size: 90%; display: inline;">'.$count_complaint[0]->count_comp_solved.'</span>'; ?>
                                                                                            <?php echo '<span class="badge badge-pill badge-success" data-trigger="hover" data-tooltip="tooltip" title="Total Verified" style="font-size: 90%; display: inline;">'.$count_complaint[0]->count_comp_approved.'</span>'; ?>
                                                                                            <?php echo '<span class="badge badge-pill badge-dark" data-trigger="hover" data-tooltip="tooltip" title="Total Approved" style="font-size: 90%; display: inline;">'.$count_complaint[0]->count_comp_verified.'</span>'; ?>
                                                                                        </td>
                                                                                    <?php } else { echo '<td></td>'; } ?>
                                                                                <?php } ?>    
                                                                            <?php } else if($get_hod[0]->hod_id == $this->session->userdata('user')['id']) { ?>
                                                                                <?php if($count_complaint_hod){ ?>
                                                                                    <td class="text-center">
                                                                                        <?php echo '<span class="badge badge-pill badge-danger" data-trigger="hover" data-tooltip="tooltip" title="Total New!" style="font-size: 90%; display: inline;">'.$count_complaint_hod[0]->count_comp_new.'</span>'; ?>
                                                                                        <?php echo '<span class="badge badge-pill badge-warning" data-trigger="hover" data-tooltip="tooltip" title="Total In Progress" style="font-size: 90%; display: inline;">'.$count_complaint_hod[0]->count_comp_in_progress.'</span>'; ?>
                                                                                        <?php echo '<span class="badge badge-pill badge-info" data-trigger="hover" data-tooltip="tooltip" title="Total Action Taken" style="font-size: 90%; display: inline;">'.$count_complaint_hod[0]->count_comp_solved.'</span>'; ?>
                                                                                        <?php echo '<span class="badge badge-pill badge-success" data-trigger="hover" data-tooltip="tooltip" title="Total Verified" style="font-size: 90%; display: inline;">'.$count_complaint_hod[0]->count_comp_approved.'</span>'; ?>
                                                                                        <?php echo '<span class="badge badge-pill badge-dark" data-trigger="hover" data-tooltip="tooltip" title="Total Approved" style="font-size: 90%; display: inline;">'.$count_complaint_hod[0]->count_comp_verified.'</span>'; ?>
                                                                                    </td>
                                                                                <?php } else { echo '<td></td>'; } ?>
                                                                            <?php } else { echo '<td></td>'; } ?>
                                                                        <?php } elseif($form['category_id'] == 9) { ?>
                                                                            <?php if($_SESSION['user']['division_id'] == 8 || $_SESSION['user']['division_id'] == 10){ ?>
                                                                                <td class="text-center">
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Approved" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Completed" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_completed'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Duplicate" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_duplicate'].'</span>'; ?>
                                                                                </td>
                                                                            <?php } else { echo '<td></td>'; } ?>
                                                                        <?php } elseif($form['category_id'] == 7) { ?>
                                                                            <?php if($_SESSION['all_modules_access'][0]['access_lvl'] == 'admin' || $_SESSION['user']['division_id'] == 4){ ?>
                                                                                <td class="text-center">
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total In-Progress" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_progess'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Approved" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Verified" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_verified'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Cancel" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_cancel'].'</span>'; ?>
                                                                                    <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                                </td>
                                                                            <?php } else { echo '<td></td>'; } ?>
                                                                        <?php } elseif($form['category_id'] == 1) { ?>
                                                                            <?php if($this->session->userdata('module_data')['role'] == 'admin' && $form['id'] != 30){ ?>
                                                                                <?php if($form['id'] != 42){ ?>
                                                                                    <td class="text-center">
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total In-Progress" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_progess'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Approved" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Verified" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_verified'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Cancel" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_cancel'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                                    </td>
                                                                                <?php } else { ?>
                                                                                    <td class="text-center">
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Processed" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_progess'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Completed" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Verified" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_verified'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                                    </td>
                                                                                <?php } ?>
                                                                            <?php } else { echo '<td></td>'; } ?>
                                                                        <?php } elseif($form['category_id'] == 3) { ?>
                                                                            <?php if($this->session->userdata('user')['division_id'] == 19 || $_SESSION['user']['division_id'] == 10){ ?>
                                                                                <?php if($form['id'] != 33){ ?>    
                                                                                    <td class="text-center">
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total In-Progress" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_progess'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Approved" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Verified" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_verified'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Cancel" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_cancel'].'</span>'; ?>
                                                                                        <?php echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                                    </td>
                                                                                <?php } else { echo '<td></td>'; } ?>
                                                                            <?php } else { echo '<td></td>'; } ?>
                                                                        <?php } else { echo '<td></td>'; } ?>
                                                                        <?php //} else { ?>
                                                                            <?php //if($this->session->userdata('module_data')['role'] == 'admin' && $form['id'] != 30 && $form['id'] != 33){ ?>
                                                                                <!-- <td class="text-center">
                                                                                    <?php //echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Pending" class="badge badge-pill badge-warning" style="font-size: 90%; display: inline;">'.$form['total_pending'].'</span>'; ?>
                                                                                    <?php //echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total In-Progress" class="badge badge-pill badge-secondary" style="font-size: 90%; display: inline;">'.$form['total_progess'].'</span>'; ?>
                                                                                    <?php //echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Approved" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_approved'].'</span>'; ?>
                                                                                    <?php //echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Verified" class="badge badge-pill badge-success" style="font-size: 90%; display: inline;">'.$form['total_verified'].'</span>'; ?>
                                                                                    <?php //echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Cancel" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_cancel'].'</span>'; ?>
                                                                                    <?php //echo '<span data-trigger="hover" data-tooltip="tooltip" title="Total Rejected" class="badge badge-pill badge-danger" style="font-size: 90%; display: inline;">'.$form['total_rejected'].'</span>'; ?>
                                                                                </td> -->
                                                                            <?php //} else { echo '<td></td>'; } ?>
                                                                        <?php //} ?>

                                                                        <td class="text-center">
                                                                            <div class="btn-group btn-group-sm" role="group">
                                                                                <div class="btn-group btn-group-sm" role="group">
                                                                                    <a href="<?php echo base_url('hr/serviceform/onlineForm/').$form['file_listing']; ?>" class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="Listing" target="_blank"><i class="fas fa-align-justify"></i></a>
                                                                                </div>
                                                                                <div class="btn-group btn-group-sm" role="group">
                                                                                <?php if ($form['id'] == 35) { //crm
                                                                                    ?>  
                                                                                    <!-- <a href="#" data-target="#modal_detail_new" data-toggle="modal"><?php //echo $form['title']; ?></a></td> -->
                                                                                    <!-- <a href="#" data-target="#modal_detail_new" class="btn btn-outline-dark" data-toggle="modal"><i class="far fa-file"></i></a> -->
                                                                                    <a href="<?php echo base_url('hr/serviceform/complaint_form'); ?>" class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="New Form" target="_blank"><i class="far fa-file"></i></a>
                                                                                <?php } elseif($form['id'] == 37) { ?>
                                                                                    <a href="#" data-target="#modal_invoice_entity" class="btn btn-outline-dark" data-toggle="modal" data-trigger="hover" data-tooltip="tooltip" title="New Form"><i class="far fa-file"></i></a>
                                                                                <?php } elseif($form['id'] == 38) { ?>
                                                                                    <a href="#" data-target="#modal_credit_note_entity" class="btn btn-outline-dark" data-toggle="modal" data-trigger="hover" data-tooltip="tooltip" title="New Form"><i class="far fa-file"></i></a>
                                                                                <?php } elseif($form['id'] == 44) { ?> 
                                                                                    <a href="#" data-target="#modal_client_new_resignation" class="btn btn-outline-dark" data-toggle="modal" data-trigger="hover" data-tooltip="tooltip" title="New Form"><i class="far fa-file"></i></a>
                                                                                <?php } else {?>
                                                                                    <a href="<?php echo base_url('hr/serviceform/').(($form['id'] == 20)?$form['file_name']:$form['file_name'].'_form'); ?>" class="btn btn-outline-dark" data-trigger="hover" data-tooltip="tooltip" title="New Form" target="_blank"><i class="far fa-file"></i></a>
                                                                                </div>
                                                                                <?php } ?>
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                <?php } ?>
                                                            <?php endif; ?>
                                                            
                                                        <?php endforeach; ?>
                                                    <?php endif; ?>
                                                    </tbody>
                                                </table>
                                                <input 
                                                    type="hidden" 
                                                    value="<?php echo $document_no; ?>" 
                                                    class="collapse_setter_doc_no"
                                                    data-collapsetarget=".forms_<?php echo $index;?>"
                                                >
                                            </div>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
	</div>
</section>

<!-- modal -->

<div class="modal fade" id="modal_detail_new" 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">Company</h5>
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
			</div>

			<div class="modal-body">
				<form class="form" id="crmcompany" method="post" action="<?php echo base_url('hr/serviceform/crm_submit') ?>">
					
					<div class="row p-3">
						<div class="col-12">
							<label>Company</label>
							<select class="form-control" id="compname" name="compname" required>
								<option value="-1"><?php echo "-- Select Company --"; ?></option>
                                <?php if(!empty($customer)): foreach($customer as $row): //debug($row); ?>
                                    <option value="<?php echo $row->customer_id; ?>"><?php echo $row->name; ?></option>
								<?php endforeach; endif;?>
							</select>
						</div>
					</div>

					<div class="float-right">
						<button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
						<button type="submit" class="btn btn-primary" onclick="">Go</button>
					</div> 
				</form>
			</div>
		</div>
	</div>
</div>

<div class="modal fade" id="modal_invoice_entity" 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"></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body">
                <!-- <form class="form" id="crmcompany" method="post" action="<?php //echo base_url('hr/serviceform/invoice_form') ?>"> -->
                    <div class="row p-3">
                        <div class="col-12">
                            <label>Business Entity</label>
                            <select class="form-control" id="entity_id" name="entity_id" required>
                                <option value="-1"><?php echo "-- Select Company --"; ?></option>
                                <?php if(!empty($business_entity)): foreach($business_entity as $row): //debug($row); ?>
                                    <option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
                                <?php endforeach; endif;?>
                            </select>
                        </div>
                    </div>

                    <div class="float-right">
                        <button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary" onclick="to_invoice_form()">Go</button>
                    </div> 
                <!-- </form> -->
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_credit_note_entity" 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"></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body">
                <!-- <form class="form" id="crmcompany" method="post" action="<?php //echo base_url('hr/serviceform/invoice_form') ?>"> -->
                    <div class="row p-3">
                        <div class="col-12">
                            <label>Business Entity</label>
                            <select class="form-control" id="cn_entity_id" name="cn_entity_id" required>
                                <option value="-1"><?php echo "-- Select Company --"; ?></option>
                                <?php if(!empty($business_entity)): foreach($business_entity as $row): //debug($row); ?>
                                    <option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
                                <?php endforeach; endif;?>
                            </select>
                        </div>
                    </div>

                    <div class="float-right">
                        <button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary" onclick="to_credit_note_form()">Go</button>
                    </div> 
                <!-- </form> -->
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="modal_client_new_resignation" 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"></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body">
                <!-- <form class="form" id="crmcompany" method="post" action="<?php //echo base_url('hr/serviceform/invoice_form') ?>"> -->
                    <div class="row p-3">
                        <div class="col-12">
                            <label>Type</label>
                            <select class="form-control" id="type" name="type" required>
                                <option value="1">New Client</option>
                                <option value="2">Client Resignation</option>
                            </select>
                        </div>
                    </div>

                    <div class="float-right">
                        <button type="button" class="btn btn-light" data-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-primary" onclick="to_client_new_resignation_form()">Go</button>
                    </div> 
                <!-- </form> -->
            </div>
        </div>
    </div>
</div>

<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 type="text/javascript">
	$(document).ready(function(){
        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);
                
                if(hover_item.start_date != '0000-00-00' && hover_item.start_date != null && hover_item.start_date != undefined)
                {
                	if(hover_item.short_name == 'FBF'){
                		var start_date = '<br> Departure Date : '+moment(hover_item.start_date).format('DD-MM-YYYY');
                	}else{
                		var start_date = '<br> Start Date : '+moment(hover_item.start_date).format('DD-MM-YYYY');
                	}
                }else{
                	var start_date = '';
                }


                if(hover_item.end_date != '0000-00-00' && hover_item.end_date != null && hover_item.end_date != undefined)
                {
                	if(hover_item.short_name == 'FBF'){
                		var end_date = '<br> Return Date : '+moment(hover_item.end_date).format('DD-MM-YYYY');
                	}else{
                		var end_date = '<br> End Date : '+moment(hover_item.end_date).format('DD-MM-YYYY');
                	}
                }else{
                	if(hover_item.short_name == 'MRF'){
                		var end_date = '<br>End Date : No Fixed Date';
                	}else{
                		var end_date = '';
                	}
                }


                if(hover_item.start_time != '0000-00-00' && hover_item.start_time != null && hover_item.start_time != undefined)
                {
                	var start_time = ' ['+hover_item.start_time+']';
                }else{
                	var start_time = '';
                }
                if(hover_item.end_time != '0000-00-00' && hover_item.end_time != null && hover_item.end_time != undefined)
                {
                	var end_time = ' ['+hover_item.end_time+']';
                }else{
                	var end_time = '';
                }

                tooltip = '<div class="tooltipevent"> Name : '+hover_item.name+'<br/>Department : '+hover_item.department_name+'<br/> Services : '+hover_item.title+'<br/> Detail : '+hover_item.event_title+start_date+start_time+end_date+end_time+'<br>Status : '+hover_item.status+'</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();
    })

    var hash = window.location.hash;
    
    $(function() {
        $('#tab a[href="' + hash + '"]').tab('show');
        let a = $('.collapse_setter_doc_no');
        $.each(a,function(index,value){
            let document_no = $(value).val();
            let target = $(value).data('collapsetarget');


            $(target).html(document_no);
            // console.log(target);
        });
    });

    function to_invoice_form()
    {
        var entity_id = $('#entity_id').val();

        if(entity_id > 0)
        {
            $.ajax({
                url:'<?php echo base_url('hr/serviceform/create_invoice') ?>',
                data: {
                    entity_id : entity_id,
                },
                type: 'post',
                dataType: 'json',
                success: (data) => {
                    localStorage.setItem("status", data.status);
                    localStorage.setItem("msg", data.msg);

                    window.location.href = data.redirect;
                }
            });
            // window.location.href = '<?php //echo base_url('hr/serviceform/invoice_form/'); ?>'+entity_id;
        }
    }

    function to_credit_note_form()
    {
        var entity_id = $('#cn_entity_id').val();

        if(entity_id > 0)
        {
            url = '<?php echo base_url('hr/serviceform/credit_note_form/'); ?>'+entity_id;

            window.open(url, '_blank');
        }
    }

    function to_client_new_resignation_form()
    {
        var type = $('#type').val();

        if(type > 0)
        {
            url = '<?php echo base_url('hr/serviceform/client_new_resignation_form/'); ?>'+type;

            window.open(url, '_blank');
        }
    }
</script>