<?php $__env->startSection('maincontent'); ?>
    <?php if(Helper::hasPermit('taskSubmit')): ?>
        <div class="col-md-6 col-lg-7">
            <div class="card">
                <div class="header">
                    <h4 class="title">Attendance &amp; Task</h4>
                </div>
                <div class="content">

                    <div class="row">
                        <div class="col-md-12">
                            <?php
                            $in=$out=null;
                            if($result==null){
                                $out='disabled';
                            }else{
                                $in='disabled';
                            }
                            ?>

                            <?php echo Form::open(['url'=>'in','class'=>'col-xs-6 col-sm-4 col-md-5 col-lg-4']); ?>

                                <button class="btn btn-success btn-fill btn-wd" type="button" id="inBtn" <?php echo e($in); ?>>
                                    IN<img id="in_loader" style="display:none; position: absolute; left:32%;" height="20" src="<?php echo e(secure_url('public/img/small-loader.gif')); ?>">
                                </button>
                            <?php echo Form::close(); ?>


                            <?php echo Form::open(['url'=>'out','class'=>'col-xs-6 col-sm-4 col-md-5 col-lg-4','id'=>'outForm']); ?>

                            <button class="btn btn-danger btn-fill btn-wd" type="button" id="outBtn" <?php echo e($out); ?>>
                                OUT<img id="out_loader" style="display:none; position: absolute; left:35%;" height="20" src="<?php echo e(secure_url('public/img/small-loader.gif')); ?>">
                            </button>
                            <?php echo Form::close(); ?>


                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-12">
                            <?php echo Form::open(['url'=>'taskSubmit']); ?>

                            <div class="form-group"> <br>
                                <h4 class="title">Daily Task Submission</h4> <br>
                                <textarea placeholder="Whole day's task summary" id="task_submission" name="details"><?php echo e(@$task->details); ?></textarea>

                            </div>
                            <div class="form-group">
                                <label>Next Task:</label>
                                <textarea id="next_task" class="form-control" name="next_task" placeholder="Next day task"><?php echo e(@$task->next_task); ?></textarea>

                            </div>
                            <div class="form-group">
                                <label>comments:</label>
                                <textarea class="form-control" name="comment" placeholder="If you have leave early or make late write a short note for the reason or can write any comments"><?php echo e(@$task->comment); ?></textarea>

                            </div>
                            <div class="form-group text-center">
                                <button class="btn btn-primary btn-fill btn-wd" type="submit">SUBMIT</button>
                            </div>
                            <?php echo Form::close(); ?>

                        </div>
                    </div>


                </div>
            </div>
        </div>
    <?php endif; ?>
    <?php if(Helper::hasPermit('taskSubmit')): ?>
        <div class="col-md-5">
            <div class="card">
                <div class="header">
                    <h4 class="title">Today's Task</h4>
                </div>
                <div class="content">

                    <div class="row">
                        <div class="col-md-12">
                            <label>Today's Planning:</label>
                            <div class="form-group">
                                <?php echo @$todayTask->next_task; ?>

                            </div>
                            <label>Last Task:</label>
                            <div class="form-group">
                                <?php echo @$todayTask->details; ?>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php endif; ?>
    <?php if(Helper::hasPermit('in-out-record')): ?>
        <div class="col-md-5">

            <div class="card">
                <div class="header">
                    <h4 class="title">Today's Attendance , Date:  <?php echo e(DT::stringDate(date('Y-m-d'))); ?></h4>
                </div>
                <div class="content">
                    <table class="table table-bordered">
                        <thead>
                        <tr>
                            <th>Name</th>
                            <th>IN</th>
                            <th>OUT</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $presents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $present): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <th colspan="3"><?php echo e($present[0]['group_title']); ?></th>
                            </tr>
                            <?php $__currentLoopData = $present; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e(@$value['user']->first_name." ". @$value['user']->last_name); ?></td>
                                <td><?php if($value['user']->min_time): ?><?php echo e(Helper::onlyTime($value['user']->min_time)); ?> <?php endif; ?></td>
                                <td><?php if($value['user']->max_time): ?><?php echo e(Helper::onlyTime($value['user']->max_time)); ?> <?php endif; ?></td>
                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="3"> Nobody there</td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    <?php endif; ?>
    <?php if(Helper::hasPermit('userWiseEvent')): ?>
        <div class="col-md-5">
            <div class="card">
                <div class="header text-center">
                </div>
                <div class="content" id="loadCalendar">
                    <div id="fullCalendar"></div>
                </div>
            </div>
        </div>
        <?php endif; ?>
        <script src="<?php echo e(asset('public/vendor/unisharp/laravel-ckeditor/ckeditor.js')); ?>"></script>
        <script>
            CKEDITOR.replace( 'task_submission' , {
                height: '120px',
                toolbarGroups : [
                    { name: 'basicstyles', groups: [ 'Bold', 'Italic' ] },
                    { name: 'paragraph',   groups: [ 'list' ] },
                ]
            });
            CKEDITOR.replace( 'next_task',{
                height: '120px',
                toolbarGroups : [
                    { name: 'basicstyles', groups: [ 'Bold', 'Italic' ] },
                    { name: 'paragraph',   groups: [ 'list' ] },
                ]
            });
        </script>


        <script>
            $(document).ready(function () {
                var today = new Date();

                var yearMonth= today.getFullYear()+"-"+((today.getMonth()+1)<10? '0'+(today.getMonth()+1) : (today.getMonth()+1)); //year and month
                getEvent(yearMonth);

                /* Retrieve data based on usergroup and year month when click next/prev button*/
                $('.fc-prev-button').click(function(){
                    var date = $('#fullCalendar').fullCalendar('getDate')._d;
                    yearMonth= date.getFullYear()+"-"+((date.getMonth()+1)<10? '0'+(date.getMonth()+1) : (date.getMonth()+1)); //year and month
                    getEvent(yearMonth);
                });

                $('.fc-next-button').click(function(){
                    var date = $('#fullCalendar').fullCalendar('getDate')._d;
                    yearMonth= date.getFullYear()+"-"+((date.getMonth()+1)<10? '0'+(date.getMonth()+1) : (date.getMonth()+1)); //year and month
                    getEvent(yearMonth);
                });

            });
        function getEvent(yearMonth) {

            var events = [];
                today = new Date();
                y = today.getFullYear();
                m = today.getMonth();
                d = today.getDate();
            $.ajax({
                url: "<?php echo e(URL::to('userWiseEvent')); ?>/"+yearMonth,
                async: false,
                dataType: 'json',
                success: function (data) {
                    events = data;
                }
            });
            $calendar = $('#fullCalendar');
                $calendar.fullCalendar({
                    header: {
                        left: 'title',
                        right: 'prev,next today'
                    },
                    defaultDate: today,
                    selectable: false,
                    selectHelper: false,
                    titleFormat: {
                        month: 'MMMM YYYY', // September 2015
                        week: "MMMM D YYYY", // September 2015
                        day: 'D MMM, YYYY'  // Tuesday, Sep 8, 2015
                    },
                    eventLimit: true, // allow "more" link when too many events
                    // color classes: [ event-blue | event-azure | event-green | event-orange | event-red ]
                    events: events,
                    eventClick: function(event) {
                        var date = new Date(event.start);
                        if(event.details){
                            swal({title:date.toDateString(),
                            html:event.details})
                        }
                    }

                });
            $('#fullCalendar').fullCalendar( 'removeEvents');
            $('#fullCalendar').fullCalendar( 'addEventSource', events);

        }
        $("#inBtn").click(function (e) {
            $.ajax({
                url: "<?php echo e(URL::to('in')); ?>",
                type: 'POST',
                data: {
                    _token: '<?php echo e(csrf_token()); ?>'
                },
                dataType: 'json',
                beforeSend:function(){
                    $("#in_loader").show();
                },
                success:function (data) {
                    $("#in_loader").hide();
                    if(data.success){
                        $.notify({
                            icon: 'pe-7s-bell',
                            message: data.success

                        },{
                            type: 'success',
                            timer: 3000
                        });
                        $("#inBtn").attr('disabled','true');
                        $("#outBtn").removeAttr('disabled');
                    }
                },
                error: function () {
                    window.location='<?php echo e(URL::to('dashboard')); ?>';
                }
            });



        });
        $("#outBtn").click(function (e) {
            swal({
                    title: 'Leave a message',
                    html: '<p><input id="out-msg" maxlength="20" class="form-control" placeholder="Reason of punch out">',
                    showCancelButton: true,
                    closeOnConfirm: true,
                    closeOnCancel: true,
                    allowOutsideClick: false
                },
                function(isConfirm) {
                    if (isConfirm){
                        $.ajax({
                            url: "<?php echo e(URL::to('out')); ?>",
                            type: 'POST',
                            data: {
                                out_comment: "" + $('#out-msg').val() + "",
                                _token: '<?php echo e(csrf_token()); ?>'
                            },
                            dataType: 'json',
                            beforeSend:function(){
                                $("#out_loader").show();
                            },
                            success:function (data) {
                                $("#out_loader").hide();
                                if(data.success){
                                    successNotify(data.success);
                                    $("#outBtn").attr('disabled','true');
                                    $("#inBtn").removeAttr('disabled');
                                }else{
                                    errorNotify(data.error);
                                }
                            },
                            error: function () {
                                window.location='<?php echo e(URL::to('dashboard')); ?>';
                            }
                        });

                    }else {

                    }


                })

        });
        </script>


<?php $__env->stopSection(); ?>
<?php echo $__env->make('backend._partials.app', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>