<?php $__env->startSection('head'); ?>
    <!-- BEGIN PAGE LEVEL STYLES -->
    <?php echo HTML::style("assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css"); ?>

    <?php echo HTML::style("assets/global/plugins/bootstrap-datepicker/css/datepicker3.css"); ?>

    <!-- BEGIN THEME STYLES -->
<?php $__env->stopSection(); ?>


<?php $__env->startSection('mainarea'); ?>


			<!-- BEGIN PAGE HEADER-->
			<h3 class="page-title">
			Edit Attendance
			</h3>
			<div class="page-bar">
				<ul class="page-breadcrumb">
					<li>
						<i class="fa fa-home"></i>
						<a href="<?php echo e(route('admin.dashboard.index')); ?>">Home</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="<?php echo e(route('admin.attendances.index')); ?>">Attendace</a>
						<i class="fa fa-angle-right"></i>
					</li>
					<li>
						<a href="">Update attendace</a>
					</li>
				</ul>

			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="row">
				<div class="col-md-12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->

                
                <?php echo $__env->make('admin.common.error', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                

                   <div class="row">
                               <div class="col-md-4 form-group">
                               <?php echo Form::open(['route'=>["admin.attendances.create"],'class'=>'form-horizontal','method'=>'GET']); ?>


                                      <div class="input-group input-medium date date-picker"   data-date-format="dd-mm-yyyy" data-date-viewmode="years">
                                           <input type="text" class="form-control" name="date" readonly placeholder="select another date">
                                           <span class="input-group-btn">
                                           <button class="btn blue" type="submit"><i class="fa fa-calendar"></i> Edit</button>
                                           </span>
                                      </div>

                               <?php echo Form::close(); ?>


                                     </div>

                               <div class="col-md-4 form-group">

                                 <?php if($date!=date('Y-m-d')): ?>
                                     <a href="<?php echo e(route('admin.attendances.create')); ?>" class="btn green">
                                        Mark Todays Attendance <i class="fa fa-plus"></i>
                                     </a>
                                <?php endif; ?>


                                </div>
                                 <div class="col-md-4 form-group text-right">

								<span id="load_notification"></span>
 									 <input  type="checkbox"   onchange="ToggleEmailNotification('attendance_notification');return false;" class="make-switch" name="attendance_notification" <?php if($setting->attendance_notification==1): ?>checked	<?php endif; ?> data-on-color="success" data-on-text="Yes" data-off-text="No" data-off-color="danger">
									<strong>Email Notification</strong><br>


								</div>



                   </div>

                <hr>
					<div class="portlet box blue">
						<div class="portlet-title">
							<div class="caption">
								<i class="fa fa-edit"></i>
								<?php if(isset($todays_holidays->date)): ?>
                                        Holiday , <?php echo e(date('d M Y',strtotime($todays_holidays->date))); ?>

                                 <?php else: ?>
                                        Mark Attendance
                                <?php endif; ?>
							</div>
							<div class="tools">
							</div>
						</div>

						<div class="portlet-body form">

						<?php if(isset($todays_holidays->date)): ?>
							   <div class="note note-info">
											<h4 class="block"><?php echo e(date('D', strtotime($todays_holidays->date))); ?></h4>
											<p>
												 Holiday on the occassion of <?php echo e($todays_holidays->occassion); ?>

											</p>
							   </div>
                   		 <?php elseif(count($employees)==0): ?>
                   		 <hr>
						<div class="note note-warning">
										<h4 class="block">Employees Missing</h4>
										<p>
											Please add some employees to the database
										</p>
						   </div>
						   <hr>
							<?php else: ?>
						<!-- BEGIN FORM-->
						<?php echo Form::open(['route'=>["admin.attendances.update",$date],'class'=>'form-horizontal','method'=>'PATCH']); ?>



                                    <div class="form-body">

                                         <h3 class="form-section">Date  <?php echo e(date('d-M-Y',strtotime($date))); ?></h3>

                                        <div class="form-group">

                                           <label class="col-md-1 control-group">EmployeeID</label>
                                           <label class="col-md-2 control-group">Name</label>
                                           <label class="col-md-2 control-group">Status </label>
                                           <label class="col-md-2 control-group leaveType" id="leaveTypeLabel">Type of leave </label>
                                           <label class="col-md-2 control-group"><span class="halfLeaveType" id="halfDayLabel">half Day leave type</span> </label>

                                           <label class="col-md-3 control-group reason" id="reasonLabel">Reason </label>

                                        </div>

                                        <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $employee): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <div class="form-group">
                                                <label class="col-md-1 control-group"><?php echo e($employee->employeeID); ?> </label>
                                                <label class="col-md-2 control-group"><?php echo e($employee->fullName); ?> </label>
                                                <div class="col-md-2">
                                                    <input type="checkbox"  id="checkbox<?php echo e($employee->employeeID); ?>" onchange="showHide('<?php echo e($employee->employeeID); ?>');return false;" class="make-switch" name="checkbox[<?php echo e($employee->employeeID); ?>]" checked data-on-color="success" data-on-text="P" data-off-text="A" data-off-color="danger">
                                                    <input type="hidden"  name="employees[]" value="<?php echo e($employee->employeeID); ?>">
                                                </div>
                                                <div class="col-md-2">
                                                <?php if(isset($attendanceArray[$employee->employeeID]['leaveType'])): ?>
                                                     <?php echo Form::select('leaveType['.$employee->employeeID.']', $leaveTypes,$attendanceArray[$employee->employeeID]['leaveType'],['class' => 'form-control leaveType','onchange'=>'halfDayToggle('.$employee->employeeID.',this.value)','id'=>'leaveType'.$employee->employeeID.''] ); ?>

                                                <?php else: ?>
                                                     <?php echo Form::select('leaveType['.$employee->employeeID.']', $leaveTypes,null,['class' => 'form-control leaveType','onchange'=>'halfDayToggle('.$employee->employeeID.',this.value)','id'=>'leaveType'.$employee->employeeID.''] ); ?>

                                                <?php endif; ?>
                                                </div>
                                                <div class="col-md-2">
													<?php if(isset($attendanceArray[$employee->employeeID]['leaveType'])): ?>
														 <?php echo Form::select('leaveTypeWithoutHalfDay['.$employee->employeeID.']', $leaveTypeWithoutHalfDay,$attendanceArray[$employee->employeeID]['halfDayType'],['class' => 'form-control halfLeaveType','id'=>'halfLeaveType'.$employee->employeeID.''] ); ?>

													<?php else: ?>
														 <?php echo Form::select('leaveTypeWithoutHalfDay['.$employee->employeeID.']', $leaveTypeWithoutHalfDay,null,['class' => 'form-control halfLeaveType','id'=>'halfLeaveType'.$employee->employeeID.''] ); ?>

													<?php endif; ?>
													</div>
                                                 <div class="col-md-3">
                                                        <input type="text" class="form-control reason" id="reason<?php echo e($employee->employeeID); ?>" name="reason[<?php echo e($employee->employeeID); ?>]" placeholder="Absent Reason" value="<?php echo e($attendanceArray[$employee->employeeID]['reason'] ?? ''); ?>">
                                                 </div>
                                            </div>
                                         <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                        <div class="form-actions">
                                            <div class="row">
                                                <div class="col-md-offset-3 col-md-9">
                                                    <button type="submit"   class="btn green"><i class="fa fa-edit"></i> Submit</button>

                                                </div>
                                            </div>
                                        </div>
                    						<?php echo Form::close(); ?>


                    			<?php endif; ?>
                        							<!-- END FORM-->

						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->

				</div>
			</div>
			<!-- END PAGE CONTENT-->



<?php $__env->stopSection(); ?>

<?php $__env->startSection('footerjs'); ?>

        <!-- BEGIN PAGE LEVEL PLUGINS -->
        <?php echo HTML::script("assets/global/plugins/bootstrap-switch/js/bootstrap-switch.min.js"); ?>

        <?php echo HTML::script("assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"); ?>

        <?php echo HTML::script("assets/admin/pages/scripts/components-pickers.js"); ?>


        <!-- END PAGE LEVEL PLUGINS -->

<script>
	jQuery(document).ready(function() {
        ComponentsPickers.init();

	});
	</script>
 <script>

        $('.leaveType').hide();
        $('.reason').hide();
        $('.halfLeaveType').hide();



       <?php $__currentLoopData = $attendanceArray; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $attend): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
       {
        <?php if($attend['status']=='absent'): ?>
            $('#leaveTypeLabel').show(100);
            $('#reasonLabel').show(100);

            <?php if($attend['leaveType']=='half day'): ?>
             		$("#halfLeaveType<?php echo e($attend['employeeID']); ?>").show();
			<?php endif; ?>
				<?php if($attend['halfDayType']	!=null): ?>
					$('#halfDayLabel').show(100);
				<?php endif; ?>

            $("#checkbox<?php echo e($attend['employeeID']); ?>").bootstrapSwitch('state',false);

        <?php else: ?>
             $("#reason<?php echo e($attend['employeeID']); ?>").hide();
             $("#leaveType<?php echo e($attend['employeeID']); ?>").hide();
             $("#halfLeaveType<?php echo e($attend['employeeID']); ?>").hide();
        <?php endif; ?>

       }
       <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
     function showHide(id){
                $('#leaveTypeLabel').show(100);
                $('#reasonLabel').show(100);


            if($('#checkbox'+id+':checked').val() == 'on') {
                    $('#leaveType'+id).hide(1000);
                    $('#reason'+id).hide(1000);

                 } else {
                     $('#leaveType'+id).show(100);

                     $('#reason'+id).show(500);
                 }
     }

     function halfDayToggle(id,value){

		if(value	==	'half day')
		{
			$('#halfDayLabel').show(100);
			$('#halfLeaveType'+id).show(100);
		}else{
			$('#halfLeaveType'+id).hide(100);
		}


     }
 </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.adminlayouts.adminlayout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/jemysunc/hrms.jemysun.co.ke/resources/views/admin/attendances/edit.blade.php ENDPATH**/ ?>