<?php $__env->startSection('content'); ?>
<?php $__env->startPush('css'); ?>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
<link href="https://cdn.jsdelivr.net/npm/summernote@0.8.18/dist/summernote-bs4.min.css" rel="stylesheet">

<!-- Start Developed By: Abu Taher -->

    <script src="<?php echo e(asset('backend/app-assets/vendors/js/vendors.min.js')); ?>"></script>
    <link rel="stylesheet" href="<?php echo e(asset('backend/app-assets/fullcallendar/css/fullcalendar.css')); ?>" />

    <link rel="stylesheet" href="<?php echo e(asset('resources/assets/fullcallendar/css/fullcalendar.css')); ?>" />
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.js"></script>
<!-- End Developed By: Abu Taher -->
<style type="text/css">
    label{
        font-weight: 600;
    }
    .col-6{
        margin-top: 10px;
    }
    .required{
        font-weight: 800;
        color: red;
    }
    label{
        font-weight: 600;
    }
    .btn-light{
        background-color: #156b53 !important;
    }
</style>
<?php $__env->stopPush(); ?>
<div class="content-wrapper">
    <div class="content-body">
        <div class="card">
            <div class="card-body">
                <form method="GET">
                    <div class="row">
                        <div class="col-md-2">
                            <input type="text" class="form-control" name="daterange" id="daterange" placeholder="Enter Date range" value="<?php echo e(($request->daterange)?: ''); ?>" />
                        </div>
                        <div class="col-md-2">
                            <div class="form-group">
                                <select name="employee" class="form-control select2">
                                    <option value="">Select Employee</option>
                                    <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $emp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($emp->id); ?>" <?php echo e(($request->employee == $emp->id)? 'selected' : ''); ?>><?php echo e($emp->name); ?></option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                            </div>
                        </div>
                       
                        <div class="col-md-2">
                            <div class="form-group">
                                <select class="form-control" name="dp_status">
                                    <option value="">Select DH Status</option>
                                    <option value="1" <?php echo e(($request->dp_status == 1)? 'selected' : ''); ?>>Pending</option>
                                    <option value="2" <?php echo e(($request->dp_status == 2)? 'selected' : ''); ?>>Approved</option>
                                    <option value="3" <?php echo e(($request->dp_status == 3)? 'selected' : ''); ?>>Declined</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2">
                            <div class="form-group">
                                <select class="form-control" name="hr_status">
                                    <option value="">Select HR Status</option>
                                    <option value="1" <?php echo e(($request->hr_status == 1)? 'selected' : ''); ?>>Pending</option>
                                    <option value="2" <?php echo e(($request->hr_status == 2)? 'selected' : ''); ?>>Approved</option>
                                    <option value="3" <?php echo e(($request->hr_status == 3)? 'selected' : ''); ?>>Declined</option>
                                </select>
                            </div>
                        </div>

                        <div class="col-md-2">
                            <div class="form-inline">
                                <button type="submit" class="btn btn-success"><i class="fa fa-search"></i></button>
                                <a href="<?php echo e(url('leave-application')); ?>"><button type="button" style="margin-left: 5px;" class="btn btn-warning"><i class="fa fa-refresh"></i></button></a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!-- Table Hover Animation start -->
        <div class="row" id="table-hover-animation">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h4 class="card-title"><?php echo e($title); ?> List  
                             <button type="button" class="btn btn-primary"> <strong>Left Holidays 
                                <span class="text-danger text-bold">
                                   <?php echo e($left_holiday); ?> 
                                </span>
                            </strong> </button>                           
                        </h4>
                        <button type="button" onclick="return showCallendar()" class="btn btn-warning waves-effect waves-light"> 
                            <strong>Calendar</strong> 
                        </button>  
                        <div class="">
                               
                        </div> 
                        <?php if( $left_holiday > 0 ): ?>
                            <div class="content-header-right text-md-right col-md-3 col-12 d-md-block d-none">
                                <button class="btn btn-info" data-toggle="modal" data-target="#large"><i class="fa fa-plus"></i> Add <?php echo e($title); ?></button>
                            </div>
                        <?php endif; ?>
                        <!-- <div class="content-header-right text-md-right col-md-3 col-12 d-md-block d-none">
                            <button class="btn btn-info" data-toggle="modal" data-target="#large"><i class="fa fa-plus"></i> Add <?php echo e($title); ?></button>
                        </div> -->
                    </div>                     
                    <div class="card-content">
                        <div class="card-body">
                            <div class="table-responsive">
                                <table class="table table-bordered table-striped table-hover-animation">
                                    <thead>
                                        <tr>
                                            <th>ID</th>            
                                            <th>Name</th>
                                            <th>Type</th>
                                            <th>Application Date</th>
                                            <th>Start Date</th>
                                            <th>End Date</th>
                                            <th>Days</th>
                                            <th>Reason</th>
                                            <th>Date Changed</th>
                                            <th>DP Status</th>
                                            <th>HR Status</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    	<?php $__currentLoopData = $leave_application; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <?php
                                            $start_date = \Carbon\Carbon::createFromFormat('Y-m-d', $list->start_date);
                                            $end_date = \Carbon\Carbon::createFromFormat('Y-m-d', $list->end_date);
                                            $diff_in_days = (($start_date->diffInDays($end_date) + 1) > 0)? ($start_date->diffInDays($end_date) + 1) : 1 ;
                                        ?>
                                        <tr>
                                            <th><?php echo e(++$key); ?></th>
                                            <td><?php echo e($list->employee->name); ?>     
                                            </td>       
                                            <td>
                                                <?php if($list->type == 1): ?>
                                                Medical Leave
                                                <?php elseif($list->type == 2): ?>
                                                Personal Leave
                                                <?php elseif($list->type == 3): ?>
                                                Holiday Leave
                                                <?php elseif($list->type == 4): ?>
                                                Emergency Leave
                                                <?php else: ?>
                                                ---
                                                <?php endif; ?>
                                            </td>

                                            <td><?php echo e(date('d M y', strtotime($list->application_date))); ?></td>
                                            <td><?php echo e(date('d M Y', strtotime($list->start_date))); ?></td>
                                            <td><?php echo e(date('d M Y', strtotime($list->end_date))); ?></td>
                                            <td><?php echo e($diff_in_days); ?> Days</td>
                                            <td><?php echo e($list->reason); ?></td>
                                            <td>
                                                <?php
                                                if( $list->application_date_changed_by ){
                                                    $user = App\User::find( $list->application_date_changed_by );
                                                    if( $user ){
                                                       $date_changed_message = "Your Orginal Date <br/>From: ".date('d M Y', strtotime($list->previous_start_date))." To: ".date('d M Y', strtotime($list->previous_end_date)). 
                                                       "<br/> Cahnged By: ". $user->name;
                                                       echo $date_changed_message;
                                                    }
                                                }    
                                                ?>
                                            </td>
                                            <td>
                                                <?php if($list->dp_status == 1): ?>
                                                <button class="btn btn-warning btn-sm">Pending</button>
                                                <?php elseif($list->dp_status == 2): ?>
                                                <button class="btn btn-success btn-sm">Approved</button>
                                                <?php elseif($list->dp_status == 3): ?>
                                                <button class="btn btn-danger btn-sm">Declined</button>
                                                <?php else: ?>
                                                ---
                                                <?php endif; ?>
                                            </td>                                            
                                            <td>
                                                <?php if($list->hr_status == 1): ?>
                                                <button class="btn btn-warning btn-sm">Pending</button>
                                                <?php elseif($list->hr_status == 2): ?>
                                                <button class="btn btn-success btn-sm">Approved</button>
                                                <?php elseif($list->hr_status == 3): ?>
                                                <button class="btn btn-danger btn-sm">Declined</button>
                                                <?php else: ?>
                                                ---
                                                <?php endif; ?>
                                            </td>
                                            
                                            <td>
                                                <?php if($list->dp_status == 1): ?>
                                                <button type="button" onclick="return editData( <?php echo e(json_encode($list)); ?> )" class="btn btn-primary btn-sm"><i class="fa fa-edit"></i></button>
                                            	<button type="button" class="btn btn-sm bg-gradient-danger" onclick="return deleteCertification(<?php echo $list->id; ?>)" title="delete"><i class="fa fa-trash-o"></i></button>
				                                <form id="delete-form-<?php echo e($list->id); ?>" action="<?php echo e(url('leave-application',$list->id)); ?>" method="POST" style="display: none;">
				                                    <?php echo csrf_field(); ?>
				                                    <?php echo method_field('DELETE'); ?>
				                                </form>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </tbody>
                                </table>
                                <div class="paginate" style="float: right;">
                                    <?php echo $leave_application->links(); ?>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Table head options end -->


        <!-- Modal -->
        <div class="modal fade text-left" id="callendar" role="dialog" aria-labelledby="callendar" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="callendar">Holiday Lists</h4>                        
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                    <div id='calendar'></div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Modal -->
        <div class="modal fade text-left" id="large" role="dialog" aria-labelledby="myModalLabel17" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel17">Add <?php echo e($title); ?></h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <form method="POST" action="<?php echo e(url('leave-application')); ?>" enctype="multipart/form-data">
                    	<?php echo csrf_field(); ?>
                        <div class="modal-body">
                            <div class="form-group row">
                                <div class="col-md-6">
                                    <label>From Date <span class="required">*</span></label>
                                    <input type="date" name="start_date" class="form-control" min="<?php echo e(date('Y-m-d')); ?>" required="">
                                </div>
                                <div class="col-md-6">
                                    <label>To Date <span class="required">*</span></label>
                                    <input type="date" name="end_date" class="form-control" min="<?php echo e(date('Y-m-d')); ?>" required="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label>Leave Type <span class="required">*</span></label>
                                <select name="type" class="form-control" required="">
                                    <option value="">Select Leave Type</option>
                                    <option value="1">Medical Leave</option>
                                    <option value="2">Personal Leave</option>
                                    <option value="3">Holiday Leave</option>
                                    <option value="4">Emergency Leave</option>
                                    <option value="5">Paid</option>
                                    <option value="6">Unpaid</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>Reason <span class="required">*</span></label>
                                <textarea class="form-control" name="reason" placeholder="Enter Reason" required=""></textarea>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <!-- Edit Modal -->
        <div class="modal fade text-left" id="editModal" role="dialog" aria-labelledby="myModalLabel17" aria-hidden="true">
            <div class="modal-dialog modal-dialog-centered" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel17">Update <?php echo e($title); ?></h4>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <form method="POST" action="<?php echo e(url('leave-application-update')); ?>" enctype="multipart/form-data">
                    	<?php echo csrf_field(); ?>
                        <div class="modal-body">
                            <div class="form-group row">
                                <div class="col-md-6">
                                    <label>From Date <span class="required">*</span></label>
                                    <input type="date" id="start_date" name="start_date" class="form-control" min="<?php echo e(date('Y-m-d')); ?>" required="">
                                </div>
                                <div class="col-md-6">
                                    <label>To Date <span class="required">*</span></label>
                                    <input type="date" id="end_date" name="end_date" class="form-control" min="<?php echo e(date('Y-m-d')); ?>" required="">
                                </div>
                            </div>
                            <div class="form-group">
                                <label>Leave Type <span class="required">*</span></label>
                                <select name="type" id="type" class="form-control" required="">
                                    <option value="">Select Leave Type</option>
                                    <option value="">Select Leave Type</option>
                                    <option value="1">Medical Leave</option>
                                    <option value="2">Personal Leave</option>
                                    <option value="3">Holiday Leave</option>
                                    <option value="4">Emergency Leave</option>
                                    <option value="5">Paid</option>
                                    <option value="6">Unpaid</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>Reason <span class="required">*</span></label>
                                <textarea class="form-control" id="reason" name="reason" placeholder="Enter Reason" required=""></textarea>
                            </div>
                            <?php if(Auth::user()->role == 1 || Auth::user()->role == 3): ?>
                            <div class="form-group">
                                <label>DP Status</label>
                                <select name="dp_status" id="dp_status" class="form-control">
                                    <option value="1">Pending</option>
                                    <option value="2">Approved</option>
                                    <option value="3">Declined</option>
                                </select>
                            </div>
                            <?php endif; ?>
                            <?php if(Auth::user()->role == 1 || Auth::user()->role == 4): ?>
                            <div class="form-group">
                                <label>HR Status</label>
                                <select name="hr_status" id="hr_status" class="form-control">
                                    <option value="">Select Status</option>
                                    <option value="1">Pending</option>
                                    <option value="2">Approved</option>
                                    <option value="3">Declined</option>
                                </select>
                            </div>
                            <?php endif; ?>
                            
                        </div>
                        <input type="hidden" name="leave_application_id" id="leave_application_id">
                        <div class="modal-footer">
                            <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Submit</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    </div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startPush('js'); ?>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
<script type="text/javascript">
	function editData(value){        
		$('#editModal').modal('show');
		$('#leave_application_id').val(value.id)
		$('#start_date').val(value.start_date)
        $('#end_date').val(value.end_date)
        $('#type').val(value.type)
        $('#reason').val(value.reason)
        $('#dp_status').val(value.dp_status)
        $('#hr_status').val(value.hr_status)
	}
    function showCallendar(){        
        $('#callendar').modal('show');        
    }


    $(document).ready(function() {
        $('#daterange').daterangepicker({
            autoUpdateInput: false,
            locale: {
                cancelLabel: 'Clear'
            }
        });
          // page is now ready, initialize the calendar...
        $('#calendar').fullCalendar({
            // put your options and callbacks here
            header: {
              left: 'prev,next',
              center: 'title',
              right: 'year,month,basicWeek,basicDay'

            },
            timezone: 'local',
            height: "auto",
            selectable: false,
            dragabble: false,
            defaultView: 'month',
            yearColumns: 2,
            durationEditable: false,
            bootstrap: true,

            events : [
                <?php $__currentLoopData = $leave_application; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $appointment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                {
                    title : '<?php echo e(strlen($appointment->reason) > 10 ? substr($appointment->reason, 10) :  $appointment->reason); ?>',
                    start : '<?php echo e($appointment->start_date); ?>',
                    end : "<?php echo e($appointment->end_date); ?>",
                    hr_status : "<?php echo e($appointment->hr_status); ?>",
                    allDay: true
                   
                },
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            ],
            eventRender: function(event, element) {
                var today = new Date().toISOString().slice(0,10);               
                var end_date = new Date(event.end).toISOString().slice(0,10);
                if(event.hr_status=='1' || event.hr_status=='3') {
                    element.css('background-color', '#BC375A');
                }
                else{
                    element.css('background-color', '#30C76F');
                }
            },
            eventDataTransform: function(event) {                                                                                                                                
                if(event.allDay) {                                                                                                                                               
                    event.end = moment(event.end).add(1, 'days')                                                                                                                 
                }
                return event;  
            }   
        });
    });
    $('#daterange').on('apply.daterangepicker', function(ev, picker) {
        $(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
    });

    $('#daterange').on('cancel.daterangepicker', function(ev, picker) {
        $(this).val('');
    });

</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/shagmtco/urportals.com/resources/views/pages/hris/leave_application.blade.php ENDPATH**/ ?>