

<?php $__env->startSection('dynamic_css'); ?>
    <style type="text/css">
        .f-600 {
            font-weight: 600;
            color: #333;
        }

        .f-13 {
            font-size: 13px;
        }

        .ve_errors{
            color:red;
            font-weight: 700;
            font-size: 13px;
        }
    </style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div class="container">
        <div class="row justify-content-center">

            <div class="col-md-12 col-md-push-0 p20 bg-white mt10">
                <h4><i class="fa fa-users" aria-hidden="true"></i> Employee List</h4>
                <table class="table table-bordered table-condensed table table-striped table-responsive"
                       id="employee_table">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th>Emp Code</th>
                        <th>Name</th>
                        <th>Designation</th>
                        <th>Program</th>
                        <th>Location</th>
                        <th>Status</th>
                        <th>Task Assigned</th>
                        <th>Assign</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                        $i = 1;
                        $j = 0;
                        $month_name = \Carbon\Carbon::now()->format('F');
                        $year = \Carbon\Carbon::now()->year;
                    ?>
                    <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <tr>
                            <td><?php echo e($i++); ?></td>
                            <td><?php echo e($value->employee_code); ?></td>
                            <td><?php echo e($value->name); ?></td>
                            <td><?php echo e($value->designation_name); ?></td>
                            <td><?php echo e($value->program_name); ?></td>
                            <td>
                                <?php if($value->district_code==999): ?>
                                    <?php echo e($value->district_name); ?>

                                <?php else: ?>
                                    District: <?php echo e($value->district_name); ?>

                                    <?php if($value->block_name): ?>
                                        Block : <?php echo e($value->block_name); ?>

                                    <?php endif; ?>
                                    <?php if($value->gram_panchyat_name): ?>
                                        GP: <?php echo e($value->gram_panchyat_name); ?>

                                    <?php endif; ?>
                                <?php endif; ?>
                            </td>
                            <td>
                                <?php if($value->status_id==1): ?>
                                    <span class="badge badge-success"><?php echo e($value->status_name); ?></span>
                                <?php else: ?>
                                    <span class="badge badge-danger"><?php echo e($value->status_name); ?></span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <form action="<?php echo e(route('performance.employee_wise_tasks')); ?>" method="POST">
                                    <?php echo Form::token(); ?>

                                    <input type="hidden" name="employee_code" value="<?php echo e($value->employee_code); ?>"/>
                                    <button type="submit" class="btn btn-outline-info btn-sm waves-effect">
                                        <i class="fa fa-eye"></i>
                                    </button>
                                </form>
                            </td>
                            <td>
                                <?php if($value->status_id==1): ?>
                                    <button type="button" class="btn btn-outline-warning btn-sm waves-effect btn-assign-emp"
                                            data-emp="<?php echo e($value->employee_code); ?>">
                                        <i class="fa fa-plus"></i>
                                    </button>
                                <?php else: ?>
                                    <span class="badge badge-danger">Can't Assign</span>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <?php $j++; ?>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>


    <!-- =================================================== ADD MODAL =============================================== -->
    <div class="modal fade" id="addEmpTask" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
         style="display: none;" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-notify modal-info" role="document">
            <!--Content-->
            <div class="modal-content">
                <!--Header-->
                <div class="modal-header">
                    <p class="heading lead">Assign Target</p>

                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true" class="white-text">×</span>
                    </button>
                </div>

                <!--Body-->
                <div class="modal-body">
                    <div class="col-md-12 text-right" id="programs_div">
                        
                    </div>
                    <div class="row" style="max-height: 35rem;overflow: auto;" id="tasks_div">
                        
                    </div>
                </div>

                <!--Footer-->
                <div class="modal-footer">
                    <a type="button" class="btn btn-outline-danger btn-sm waves-effect" data-dismiss="modal">No,
                        thanks</a>
                </div>
            </div>
            <!--/.Content-->
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('dynamic_js'); ?>
    <script type="application/javascript">
        $(document).ready(function () {
            $('#employee_table').DataTable();

        });

        $('.btn-assign-emp').on('click', function (e) {
            e.preventDefault();
            var emp_code = $(this).data('emp');
             $('#addEmpTask').modal('show');
            
            $('.page-loader-wrapper').fadeIn();
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                type: "POST",
                url:"<?php echo e(route('performance.get_task_list_by_emp_code')); ?>",
                dataType: "json",
                data: {empCode: emp_code},
                success: function (data) {
                    if (data.msgType == true) {
                        var employee_code = employee_code;

                        $('#addEmpTask').modal('show');

                        /*********** ADDING COLOR CODES OF PROGRAMS ************/
                        var progam_style = '';
                        $('#programs_div').empty();
                        $.each(data.data.programs, function (index, value) {

                            if (value.program_code == "PROGRAM-1") {
                                progam_style = "orange";
                            } else if (value.program_code == "PROGRAM-2") {
                                progam_style = "blue";
                            } else if (value.program_code == "PROGRAM-3") {
                                progam_style = "red";
                            } else if (value.program_code == "PROGRAM-4") {
                                progam_style = "green";
                            } else if (value.program_code == "PROGRAM-5") {
                                progam_style = "brown";
                            }

                            $('#programs_div').append('<span style="font-size:11px;margin-right:3px"><i class="fa fa-circle" style="color:' + progam_style + ';"></i>' + value.program_name + '</span>');
                        });
                        /*********** ADDING COLOR CODES OF PROGRAMS ENDED *********/

                        /*********** ADDING TASKS ************/
                        var progam_style = '';
                        $('#tasks_div').empty();
                        var sub = 1;
                        $.each(data.data.tasks, function (key, item) {

                            $('#tasks_div').append('<div class="col-md-12"><h6 style="margin-top:4px">' + key + ' (Total:' + item.T + 'tasks)' + '</h6></div>' +
                                '<div class="col-md-12"><div class="row" id="tasks_sub' + sub + '"></div></div>');

                            $.each(item.list, function (index1, value1) {

                                if (value1.program_code == "PROGRAM-1") {
                                    progam_style = "orange";
                                } else if (value1.program_code == "PROGRAM-2") {
                                    progam_style = "blue";
                                } else if (value1.program_code == "PROGRAM-3") {
                                    progam_style = "red";
                                } else if (value1.program_code == "PROGRAM-4") {
                                    progam_style = "green";
                                } else if (value1.program_code == "PROGRAM-5") {
                                    progam_style = "brown";
                                }

                                $('#tasks_sub' + sub).append('<div class="col-md-6">' +
                                    '<div class="card" style="border-top:5px solid ' + progam_style + ';margin-top: 5px">' +
                                    '<div class="card-header">' +
                                    '<h6 class="f-13 f-600">' + value1.task_code + '</h6>' +
                                    '</div>' +
                                    '<div class="accordion md-accordion" id="accordionEx' + value1.id + '" role="tablist" aria-multiselectable="true">' +
                                    '<div class="card">' +
                                    '<div class="card-header" role="tab" id="headingOne' + value1.id + '">' +
                                    '<a data-toggle="collapse" data-parent="#accordionEx" href="#collapseOne' + value1.id + '" aria-expanded="true" aria-controls="collapseOne' + value1.id + '">' +
                                    '<h5 class="mb-0">' +
                                    '<span class="f-13">Task Title</span><i class="fa fa-angle-down rotate-icon pull-right"></i>' +
                                    '</h5>' +
                                    '</a>' +
                                    '</div>' +

                                    '<div id="collapseOne' + value1.id + '" class="collapse" role="tabpanel" aria-labelledby="headingOne' + value1.id + '" data-parent="#accordionEx' + value1.id + '">' +
                                    '<div class="card-body">' +
                                    value1.task_title +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '<div class="card">' +
                                    '<div class="card-header" role="tab" id="headingTwo' + value1.id + '">' +
                                    '<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx' + value1.id + '" href="#collapseTwo' + value1.id + '" aria-expanded="false" aria-controls="collapseTwo' + value1.id + '">' +
                                    '<h5 class="mb-0">' +
                                    '<span class="f-13">Task Description</span><i class="fa fa-angle-down rotate-icon pull-right"></i>' +
                                    '</h5>' +
                                    '</a>' +
                                    '</div>' +

                                    '<div id="collapseTwo' + value1.id + '" class="collapse" role="tabpanel" aria-labelledby="headingTwo' + value1.id + '" data-parent="#accordionEx' + value1.id + '">' +
                                    '<div class="card-body">' +
                                    value1.task_description +
                                    '</div>' +
                                    '</div>' +

                                    '</div>' +
                                    '<div class="card">' +
                                    '<div class="card-header" role="tab" id="headingFour' + value1.id + '">' +
                                    '<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx' + value1.id + '" href="#collapseFour' + value1.id + '" aria-expanded="false" aria-controls="collapseFour' + value1.id + '">' +
                                    '<h5 class="mb-0">' +
                                    '<span class="f-13">Target Description</span><i class="fa fa-angle-down rotate-icon pull-right"></i>' +
                                    '</h5>' +
                                    '</a>' +
                                    '</div>' +

                                    '<div id="collapseFour' + value1.id + '" class="collapse" role="tabpanel" aria-labelledby="headingFour' + value1.id + '" data-parent="#accordionEx' + value1.id + '">' +
                                    '<div class="card-body">' +
                                    value1.task_district_description +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +

                                    '<div class="card">' +
                                    '<div class="card-header" role="tab" id="headingFive' + value1.id + '">' +
                                    '<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx' + value1.id + '" href="#collapseFive' + value1.id + '" aria-expanded="false" aria-controls="collapseFive' + value1.id + '">' +
                                    '<h5 class="mb-0">' +
                                    '<span class="f-13">Remarks</span><i class="fa fa-angle-down rotate-icon pull-right"></i>' +
                                    '</h5>' +
                                    '</a>' +
                                    '</div>' +

                                    '<div id="collapseFive' + value1.id + '" class="collapse" role="tabpanel" aria-labelledby="headingFive' + value1.id + '" data-parent="#accordionEx' + value1.id + '">' +
                                    '<div class="card-body">' +
                                    value1.remarks +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +

                                    '<div class="card">' +
                                    '<div class="card-header" role="tab" id="headingThree' + value1.id + '">' +
                                    '<a class="collapsed" data-toggle="collapse" data-parent="#accordionEx" href="#collapseThree' + value1.id + '" aria-expanded="false" aria-controls="collapseThree' + value1.id + '">' +
                                    '<h5 class="mb-0">' +
                                    '<span class="f-13">Set Target (T: ' + value1.district_target + ' | R: <span id="remC_'+ value1.id +'">' + value1.remaining_target + '</span>)</span> <i class="fa fa-angle-down rotate-icon pull-right"></i>' +
                                    '</h5>' +
                                    '</a>' +
                                    '</div>' +
                                    '<div id="collapseThree' + value1.id + '" class="collapse" role="tabpanel" aria-labelledby="headingThree' + value1.id + '" data-parent="#accordionEx' + value1.id + '">' +
                                    '<div class="card-body">' +
                                    '<form action="#" method="POST" id="empTargetAssignForm' + value1.id + '">' +
                                    '<input type="hidden" name="emp_code" id="emp_code' + value1.id + '" value="' + emp_code + '" class="form-control"/>' +
                                    '<input type="hidden" name="task_id" id="task_id' + value1.id + '" value="' + value1.id + '" class="form-control"/>' +
                                    '<div class="form-group">' +
                                    '<label>Target</label>' +
                                    '<input type="number" name="target" id="target' + value1.id + '" class="form-control form-control-sm">' +
                                    '</div>' +
                                    '<div class="form-group">' +
                                    '<label>Employee task description</label>' +
                                    '<textarea type="text" name="emp_desp" id="emp_desp' + value1.id + '" class="form-control form-control-sm"></textarea>' +
                                    '</div>' +
                                    '<div class="form-group">' +
                                    '<label>Remarks</label>' +
                                    '<textarea type="text" name="remarks" id="remarks' + value1.id + '" class="form-control form-control-sm"></textarea>' +
                                    '</div>' +
                                    '<button type="button" data-id="' + value1.id + '" class="btn btn-primary btn-sm assignBtn">Assign</button>' +
                                    '</form>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>' +
                                    '</div>');
                            });

                            sub++;

                        });
                        /*********** ADDING TASKS ENDED *********/

                        /*toastr.success(data.msg);*/
                    } else {
                        toastr.error(data.msg);
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {

                    callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                },
                complete: function (data) {
                    $('.page-loader-wrapper').fadeOut();
                }
            });
        });


        $(document).on('click', '.assignBtn', function (e) {
            e.preventDefault();

            var id = $(this).data('id');
            $('.ve_errors').remove();
            $('.page-loader-wrapper').fadeIn();

            var emp_code = $('#emp_code'+id).val();
            var task_id = $('#task_id'+id).val();
            var target = $('#target'+id).val();
            var emp_desp = $('#emp_desp'+id).val();
            var remarks = $('#remarks'+id).val();

            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                type: "POST",
                url: 'empTargetAssignForm',

                dataType: "json",
                data: {emp_code: emp_code, task_id: task_id, target: target, emp_desp: emp_desp, remarks: remarks},
                cache: false,
                success: function (data) {
                    if (data.msgType == true) {
                        $('#remC_'+id).text('');
                        $('#remC_'+id).text(data.data.R);
                        $('#empTargetAssignForm'+id)[0].reset();
                        toastr.success(data.msg);
                    } else {
                        if (data.msg == "VE") {
                            $.each(data.data, function (index, value) {
                                var custom_index=index+id;
                                $('#'+custom_index).after('<p class="text-danger ve_errors">' + value + '</p>');
                            });
                        } else {
                            toastr.error(data.msg);
                        }
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    callAjaxErrorFunction(jqXHR, textStatus, errorThrown);
                },
                complete: function (data) {
                    $('.page-loader-wrapper').fadeOut();
                }
            });

        });
    </script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app2', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>