



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

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

<link href="<?php echo asset('css/dataTables.bootstrap4.min.css'); ?>" media="all" rel="stylesheet" type="text/css"/>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('dynamic_css'); ?>
<style>
    
    ul.task_navbra li{
        min-width: 200px;
        text-align: center;
    }
    .f-600 {
        font-weight: 600;
    }

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

    .v-errors {
        background-color: #eee;
        list-style: disc;
        border: 2px solid red;
        padding: 5px 20px;
        color: darkred;
    }

    /* The switch - the box around the slider */
    .switch {
        position: relative;
        display: inline-block;
        width: 50px;
        height: 24px;
        /* margin-top: 6px;*/
    }

    /* Hide default HTML checkbox */
    .switch input {
        opacity: 0;
        width: 0;
        height: 0;
    }

    /* The slider */
    .slider {
        position: absolute;
        cursor: pointer;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: #ccc;
        -webkit-transition: .4s;
        transition: .4s;
    }

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    -webkit-transition: .4s;
    transition: .4s;
}

    input:checked + .slider {
        background-color: #2196F3;
    }

    input:focus + .slider {
        box-shadow: 0 0 1px #2196F3;
    }

    input:checked + .slider:before {
        -webkit-transform: translateX(26px);
        -ms-transform: translateX(26px);
        transform: translateX(26px);
    }

    /* Rounded sliders */
    .slider.round {
        border-radius: 34px;
    }

    .slider.round:before {
        border-radius: 50%;
    }
    
    @media (max-width: 768px)
    {   
        ul.task_navbra li{
            min-width: 200px;
            text-align: left;
       }    
    }
    .f-33{
        font-size: 25px;
    }
    .hide_div{
        display:none;
    }
    .show_div{
        display: block;
    }
</style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<div class="container">
    <div class="row container_layout justify-content-center">
<!--        <div class="col-md-12 text-right">
            <button type="button" class="btn btn-outline-warning btn-sm waves-effect" id="add_district_task"  >
                <i class="fa fa-plus"></i> Add District Task
            </button>
        </div>-->
        
        
        
        <div class="col-md-12 col-md-push-0 p20 bg-white mt10">
            
            
                <!--Navbar-->
                <nav class="navbar navbar-expand-lg navbar-dark primary-color-dark">
                  <!-- Collapse button -->
                  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#basicExampleNav"
                    aria-controls="basicExampleNav" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                  </button>

                  <!-- Collapsible content -->
                  <div class="collapse navbar-collapse" id="basicExampleNav">

                    <!-- Links -->
                    <ul class="navbar-nav mr-auto task_navbra">
                      <li class="nav-item active">
                        <a class="nav-link panel_click" href="#panel1">District Task
                          <span class="sr-only">(current)</span>
                        </a>
                      </li>
                      <li class="nav-item">
                        <a class="nav-link panel_click" href="#panel2">Block Task</a>
                      </li>
                    </ul>
                            <a class="btn btn-outline-light btn-sm waves-effect" id="add_district_task"  >
                                <i class="fa fa-plus"></i> Add District Task
                            </a>
                    <!-- Links -->
                  </div>
                  <!-- Collapsible content -->

                </nav>
                <!--/.Navbar-->

                <!--Panel 1-->
            <div class="custom_tab_container">
                <div  id="panel11" class="custom_tab show_div">           
                    <table class="table table-bordered table-striped table-responsive" id="district_table_id" style="">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Task title</th>
                                <th>District Name</th>
                                <th>Target</th>
                                <th>Month, Year</th>
                                <th>Created On</th>
                                <th>Status</th>
                                <th>
                                    Task File
                                </th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $i = $district_target->firstItem();
                            $month_name=['month','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
                            $status = [
                            'Incomplete',
                            'Complete'
                            ];
                            ?>
                            <?php $__currentLoopData = $district_target; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($i++); ?></td>
                                <td><?php echo e($value['task_title']); ?></td>
                                <td><?php echo e($value['district_name']); ?></td>
                                <td><?php echo e($value['target']); ?></td>
                                <td data-month="<?php echo e($month_name[$value['month']]); ?>" data-year="<?php echo e($value['year']); ?>">
                                    <?php echo e($month_name[$value['month']]); ?>,<?php echo e($value['year']); ?>

                                </td>
                                <td><?php echo e($value['created_at']); ?></td>
                                <td><?php echo e($status[$value['target_status']]); ?></td>
                                <td>
                                    <?php if($value['target_file'] != NULL): ?>
                                    <a href="<?php echo e($global_data['config']->image_url.$value['target_file']); ?>" target="_blank"><i class="fa fa-download" style="color: green;"></i></a>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div style="display:flex;">
                                        <a href="" class=" district-task-edit-btn" data-toggle="modal" data-target="#addDistrictTask" id="edit_<?php echo e($value['id']); ?>" style="padding-top: 2px;">
                                           <i class="fa fa-pencil-square-o f-33 mr10 grey-text" aria-hidden="true"></i>
                                        </a>
                                        <?php if(!$value['employee_targets_id']): ?>
                                        <a class=" del-district-task-btn " id="del_<?php echo e($value['id']); ?>">
                                           <i class="fa fa-trash-o f-33  mr10 red-text" aria-hidden="true"></i>
                                        </a>
                                        <?php endif; ?>	

                                        <label class="switch mr10">
                                            <input type="checkbox" id="activeDeactive" data-task_id="<?php echo e($value['district_target_id']); ?>" <?php if($value['is_active']==1): ?> <?php echo e('checked'); ?> <?php endif; ?> >
                                                   <span class="slider"></span>
                                        </label>
                                        <a class=" view-district-task-btn" id="view_<?php echo e($value['id']); ?>" data-toggle="modal" data-target="#viewDistrictTask">
                                            <i class="fa fa-eye f-33 mr10 purple-text" aria-hidden="true"></i>
                                        </a>
                                    </div>
                                </td>


                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                    <?php echo e($district_target->links()); ?>

                </div>
                <div  id="panel21" class="custom_tab hide_div">           
                    <table class="table table-bordered table-striped table-responsive" id="block_table_id">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Task title</th>
                                <th>District Name</th>
                                <th>Block Name</th>
                                <th>Target</th>
                                <th>Month, Year</th>
                                <th>Created On</th>
                                <th>Status</th>
                                <th>Task File</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $i = $block_target->firstItem();
                            $status = [
                            'Incomplete',
                            'Complete'
                            ];
                            ?>
                            <?php $__currentLoopData = $block_target; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($i++); ?></td>
                                <td><?php echo e($value['task_title']); ?></td>
                                <td><?php echo e($value['district_name']); ?></td>
                                <td><?php echo e($value['block_name']); ?></td>
                                <td><?php echo e($value['target']); ?></td>
                                <td data-month="<?php echo e($month_name[$value['month']]); ?>" data-year="<?php echo e($value['year']); ?>">
                                    <?php echo e($month_name[$value['month']]); ?>,<?php echo e($value['year']); ?></td>
                                <td><?php echo e($value['created_at']); ?></td>
                                <td><?php echo e($status[$value['target_status']]); ?></td>
                                <td>
                                    <?php if($value['target_file'] != NULL): ?>
                                    <a href="<?php echo e($global_data['config']->image_url.$value['target_file']); ?>" target="_blank"><i class="fa fa-download" style="color: green;"></i></a>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <div style="display:flex;">
                                        <a href="" class="district-task-edit-btn" data-toggle="modal" data-target="#addDistrictTask" id="edit_<?php echo e($value['id']); ?>" style="padding-top: 2px;">
                                            <i class="fa fa-pencil-square-o f-33 mr10 grey-text" aria-hidden="true"></i>
                                        </a>
                                        <?php if(!$value['employee_targets_id']): ?>
                                        <a class=" del-district-task-btn" id="del_<?php echo e($value['id']); ?>">
                                            <i class="fa fa-trash-o f-33 mr10 red-text" aria-hidden="true"></i>
                                        </a>
                                        <?php endif; ?>	

                                        <label class="switch mr10">
                                            <input type="checkbox" id="activeDeactive" data-task_id="<?php echo e($value['district_target_id']); ?>" <?php if($value['is_active']==1): ?> <?php echo e('checked'); ?> <?php endif; ?> >
                                                   <span class="slider"></span>
                                        </label>
                                        <a class="view-district-task-btn" id="view_<?php echo e($value['id']); ?>" data-toggle="modal" data-target="#viewDistrictTask">
                                            <i class="fa fa-eye f-33 mr10 purple-text" aria-hidden="true"></i>
                                        </a>
                                    </div>
                                </td>


                            </tr>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </tbody>
                    </table>
                    <?php echo e($district_target->links()); ?>

                </div>
           </div>
        </div>
    </div>
</div>


<!-- =================================================== ADD MODAL =============================================== -->
<div class="modal fade" id="addDistrictTask" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" style="display: none;" aria-hidden="true">
    <div class="modal-dialog cascading-modal modal-lg modal-notify modal-info" role="document">
        <!--Content-->
        <div class="modal-content" id="modelContent">

            <form id="saveDistrictTargetDetails" action="" method="POST">
                <?php echo e(csrf_field()); ?>

                <!--Header-->
<!--                <div class="modal-header">
                    <p class="heading lead">Add Target Task</p>

                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true" class="white-text">×</span>
                    </button>
                </div>-->
            <div class="modal-header light-blue darken-3 white-text">
                <h4 class="title"><i class="fa fa-plus-square-o" aria-hidden="true"></i> <span id="task_header">Add</span> Target Task</h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
                <!--Body-->

                <div class="modal-body">
                    <div class="row">
                        <div class="col-md-12" id="editData">

                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12" id="saveDistrictTargetDetailsValidation"></div>
                    </div>
                    <div class="row">
                        <div class="col-md-6 form-group">
                            <label class="text-upper text_style">Select Task</label>
                            <select name="select_task" id="select_task" class="form-control form-control-sm" required>
                                <option value="">--Select--</option>
                                <?php $__currentLoopData = $task_masters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $li): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($li->id); ?>"><?php echo e($li->task_title); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-md-3 form-group">
                            <label class="text-upper text_style">Select District</label>
                            <select name="select_district" id="select_district" class="form-control form-control-sm" required>
                                <option value="" selected disabled>--Select--</option>
                                <?php $__currentLoopData = $districts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $li): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($li->district_code); ?>"><?php echo e($li->district_name); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-md-3 form-group">
                            <label class="text-upper text_style">Select Block</label>
                            <select name="select_block" id="select_block" class="form-control form-control-sm">
                                <option value="">--Select--</option>
                            </select>
                        </div>
                        <div class="col-md-6 form-group">
                            <label class="text-upper text_style" id="ex_dip_cer_label">Targets</label>
                            <input type="number" name="district_target" id="district_target" class="form-control form-control-sm"/>
                        </div>
                        <div class="col-md-3 form-group">
                            <label class="text-upper text_style" id="ex_dip_cer_label">Target Month</label>
                            <select name="target_month" id="target_month" class="form-control form-control-sm">
                                <option value="">--Select--</option>
                                <option value="1">January</option>
                                <option value="2">February</option>
                                <option value="3">March</option>
                                <option value="4">April</option>
                                <option value="5">May</option>
                                <option value="6">June</option>
                                <option value="7">July</option>
                                <option value="8">August</option>
                                <option value="9">September</option>
                                <option value="10">October</option>
                                <option value="11">November</option>
                                <option value="12">December</option>
                            </select>
                        </div>
                        <div class="col-md-3 form-group">
                            <label class="text-upper text_style" id="ex_dip_cer_label">Target Year</label>
                            <select name="target_year" id="target_year" class="form-control form-control-sm">
                                <option value="">--Select--</option>
                                <?php $__currentLoopData = $years; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $li): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($li); ?>"><?php echo e($li); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="col-md-6 form-group">
                            <label class="text-upper text_style" id="ex_dip_cer_label">Target Description</label>
                            <textarea name="target_desp" id="target_desp" class="form-control form-control-sm"></textarea>
                        </div>
                        <div class="col-md-6 form-group">
                            <label class="text-upper text_style" id="ex_dip_cer_label">Remarks</label>
                            <textarea name="remarks" id="remarks" class="form-control form-control-sm"></textarea>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-6 form-group">
                            <label class="text-upper text_style">Select Task Document</label>
                            <input type="file" class="form-control" name="task_doc" id="task_doc">
                        </div>
                    </div>

                </div>

                <!--Footer-->
                <div class="modal-footer">
                    <button type="submit" class="btn btn-info btn-sm waves-effect waves-light" id="district-task-btn">Assign
                        <i class="fa fa-diamond ml-1"></i>
                    </button>
                    <button type="submit" class="btn btn-info btn-sm waves-effect waves-light display_none" id="district-edit-task-btn">Update
                        <i class="fa fa-upload ml-1"></i>
                    </button>
                    <input type="hidden" name="edit_district_task_id" id="edit_district_task_id" class="form-control">
   
                    <button type="reset" class="btn btn-warning btn-sm waves-effect waves-light">RESET</button>
                    <a type="button" class="btn btn-outline-info btn-sm waves-effect" data-dismiss="modal">CANCEL</a>
                </div>
            </form>
        </div>
        <!--/.Content-->
    </div>
</div>

<div class="modal fade" id="viewDistrictTask" 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">View District Task Details</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">
                <h3 class="text text-info text-center" id="waiting_message">Please wait for a moment....</h3>
                <table class="table table-bordered table-responsive" hidden="" id="task_table">
                    <tr>
                        <th>Task Title</th><td id="title_data"></td>
                    </tr>
                    <tr>
                        <th>Task Description</th><td id="task_description_data"></td>
                    </tr>
                    <tr>
                        <th>District Task Description</th><td id="district_task_description_data"></td>
                    </tr>
                    <tr>
                        <th>District Task Remarks</th><td id="district_task_remarks"></td>
                    </tr>
                    <tr>
                        <th>Remaining Targets</th><td id="remaining_target_data"></td>
                    </tr>
                </table>

            </div>

            <!--Footer-->
            <div class="modal-footer">
                <a type="button" class="btn btn-outline-info waves-effect" data-dismiss="modal">CANCEL</a>
            </div>
        </div>
        <!--/.Content-->
    </div>
</div>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('dynamic_js'); ?>
<script src="<?php echo e(asset('js/lib/jquery.dataTables.min.js')); ?>"></script>
<script src="<?php echo e(asset('js/lib/dataTables.bootstrap4.min.js')); ?>"></script>

<script>
    
    var modalHtml=$('#modelContent').clone();
    
    
    
    /*$(document).on('click', '#district-task-btn', function () {
     Swal({
     title: 'Are you sure?',
     text: "You are going to assign new task target!",
     type: 'warning',
     showCancelButton: true,
     confirmButtonColor: '#3085d6',
     cancelButtonColor: '#d33',
     confirmButtonText: 'Yes, assign it!'
     }).then((result) => {
     $('#saveDistrictTargetDetailsValidation').empty();
     if (result.value) {
     
     $.post("<?php echo e(url('/save_task_target')); ?>", {
     '_token': $('meta[name=csrf-token]').attr('content'),
     'task': $('#select_task').val(),
     'district': $('#select_district').val(),
     'block': $('#select_block').val(),
     'target': $('#district_target').val(),
     'month': $('#target_month').val(),
     'year': $('#target_year').val(),
     'desp': $('#target_desp').val(),
     'remarks': $('#remarks').val(),
     'form_data':new FormData('#saveDistrictTargetDetails')
     }, function (j) {
     if (j['msg'] == "VE") {
     $('#saveDistrictTargetDetailsValidation').append('<ul class="form-group f-600 f-13 v-errors" id="saveDistrictTargetDetailValidationErrors"></ul>');
     
     $.each(j.error, function (index, value) {
     $('#saveDistrictTargetDetailValidationErrors').append('<li>' + value + '</li>');
     });
     } else {
     Swal(j['msg']);
     $('#saveDistrictTargetDetails').trigger("reset");
     location.reload();
     
     }
     })
     .fail(function () {
     Swal("Something went wrong! Please try again.");
     });
     
     }
     });
     });*/
    $('#saveDistrictTargetDetails').on('submit', function (e) {
        e.preventDefault();
        $('#saveDistrictTargetDetailsValidation').empty();
        swal({
            title: "Are you sure?",
            text: "You are about to save other district task!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        })
                .then((willStore) => {
                    if (willStore) {
                        $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            type: "POST",
                            url: "<?php echo e(url('/save_task_target')); ?>",
                            dataType: "json",
                            data: new FormData(this),
                            contentType: false,
                            cache: false,
                            processData: false,
                            statusCode: {
                                422: function (data) {
                                    // Error...
                                    var object = "";
                                    $.each(data, function (key, val) {

                                        if (key === "responseText") {
                                            object = jQuery.parseJSON(val);
                                        }

                                    });
                                    var error = "";
                                    $.each(object.errors, function (key, val) {

                                        $('.' + key).text(val);

                                    });
                                    swal("In valid data has been provided please check!", "", "error");
                                },
                                200: function (j) {


                                },
                                500: function () {
                                    swal("Something went wrong. Please try again.", "", "warning");
                                }
                            },
                            error: function (data) {

                            },
                            success: function (j) {
                                if (j['msg'] == "VE") {
                                    $('#saveDistrictTargetDetailsValidation').append('<ul class="form-group f-600 f-13 v-errors" id="saveDistrictTargetDetailValidationErrors"></ul>');

                                    $.each(j.error, function (index, value) {
                                        $('#saveDistrictTargetDetailValidationErrors').append('<li>' + value + '</li>');
                                    });
                                } else {

                                    $('#saveDistrictTargetDetails').trigger("reset");
                                    Swal({
                                        title: 'Success',
                                        text: j['msg'],
                                        type: 'success',
                                        showCancelButton: false,
                                        confirmButtonColor: '#3085d6',
                                        cancelButtonColor: '#d33',
                                        confirmButtonText: 'Ok'
                                    }).then((result) => {
                                        if (result.value) {
                                            location.reload();
                                        }
                                    });

                                }
                            }
                        });
                    } else {
                        swal("You have canceled your operation!");
                    }
                })



    });
    $(document).on('change', '#target_year', function () {
        if ($('#select_task').val() == "") {
            Swal("Please select a task.");
        } else if ($('#select_district').val() == "") {
            Swal("Please select a district.");
        } else if ($('#target_month').val() == "") {
            Swal("Please select a month.");
        }
        if (($('#select_task').val() != "") && ($('#select_district').val() != "") && ($('#target_month').val() != "")) {
            $.get("<?php echo e(url('/check_monthly_task')); ?>", {
                'task': $('#select_task').val(),
                'district': $('#select_district').val(),
                'month': $('#target_month').val(),
                'year': $('#target_year').val()
            }, function (j) {
                if (j.count > 0) {
                    Swal("Same task cannot be alloted to same district for same month.");
                    $('#saveDistrictTargetDetails').trigger("reset");
                }
            });
        }
    });





    $(document).on('click', '#activeDeactive', function (e) {
        e.preventDefault();
        if ($(this).prop("checked") == true) {
            var msg = "You are going to activate this task!";
            var flag = 1;
        } else {
            var msg = "You are going to de-activate this task!";
            var flag = 0;
        }

        var district_task = $(this).data('task_id');
        Swal({
            title: 'Are you sure?',
            text: msg,
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, do it!'
        }).then((result) => {
            if (result.value) {
                $.post("<?php echo e(url('/active_or_deactive_target_task')); ?>", {
                    '_token': $('meta[name=csrf-token]').attr('content'),
                    'flag': flag,
                    'task_id': district_task
                }, function (j) {
                    if (j['msgType'] == true) {
                        Swal({
                            title: 'Success',
                            text: j['msg'],
                            type: 'success',
                            showCancelButton: false,
                            confirmButtonColor: '#3085d6',
                            cancelButtonColor: '#d33',
                            confirmButtonText: 'Ok'
                        }).then((result) => {
                            if (result.value) {
                                location.reload();
                            }
                        });
                    } else {
                        toastr.success(j['msg']);
                    }
                })
                        .fail(function () {
                            Swal("Something went wrong! Please try again.");
                        })
            }
        });
    });

    $(document).on('click', '.del-district-task-btn', function () {
        var task_id = $(this).attr('id').split("_");
        Swal({
            title: 'Are you sure?',
            text: "You are about to delete a district target!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, delete it!'
        }).then((result) => {
            if (result.value) {

                $.post("<?php echo e(url('/delete_task_target')); ?>", {
                    '_token': $('meta[name=csrf-token]').attr('content'),
                    'task': task_id[1]
                }, function (j) {
                    Swal({
                        title: 'Success',
                        text: j['msg'],
                        type: 'success',
                        showCancelButton: false,
                        confirmButtonColor: '#3085d6',
                        cancelButtonColor: '#d33',
                        confirmButtonText: 'Ok'
                    }).then((result) => {
                        if (result.value) {
                            location.reload();
                        }
                    });
                })
                        .fail(function () {
                            Swal("Something went wrong! Please try again.");
                        });

            }
        });
    });

    $(document).on('click', '.view-district-task-btn', function () {
        var id = $(this).attr('id').split("_");
        $.get("<?php echo e(url('/view_target_task')); ?>", {
            district_task: id[1]
        }, function (j) {
            for (var i = 1; i < j.length; i++) {
                $('#title_data').text(j[i].task_title);
                $('#task_description_data').text(j[i].task_description);
                $('#district_task_description_data').text(j[i].task_district_description);
                $('#district_task_remarks').text(j[i].task_district_remarks);
                $('#remaining_target_data').text(j[i].remaining_target)
            }
            $('#waiting_message').hide();
            $('#task_table').removeAttr("hidden");
        }).fail(function () {
            Swal("Something went wrong! Please try again.");
        });
    });






    $(document).on('change', '#select_district', function () {
        var district_code = $(this).val();

        $('.page-loader-wrapper').fadeIn();
        $('#select_block').empty();
        $('#select_block').append('<option value="">--Select--</option>');

        $.ajax({
            type: "GET",
            url: "<?php echo e(route('get_block_list')); ?>",
            data: {district_code: district_code},
            dataType: "json",
            success: function (data) {
                if (data.msgType == true) {
                    $.each(data.data, function (key, value) {
                        $('#select_block').append('<option value=" ' + value.block_id + ' ">' + value.block_name + '</option>');
                    });
                } else {
                    toastr.error(data.msg)
                }
            },
            error: function (jqXHR, textStatus, errorThrown) {

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









    $(document).on('click', '.district-task-edit-btn', function (e) {
        e.preventDefault();
        var id = $(this).attr('id').split("_");
        $.get("<?php echo e(url('/get_target_task')); ?>", {
            district_task: id[1]
        }, function (j) {
            $('#edit_district_task_id').val(id[1]);
            $('#task_header').empty();
            $('#task_header').append('Edit');
            $('#district-edit-task-btn').show();
            $('#district-task-btn').hide();
            
            $('#select_block').empty();
            $.each(j.block, function (key, value) {
                $('#select_block').append('<option value=" ' + value.block_id + ' ">' + value.block_name + '</option>');
            });
            
            
           $("#select_task > option").each(function() {
                if(j.data.task_master_id==this.value){
                     $(this).prop('selected',true)
                }
           });
            
            $("#select_district > option").each(function() {
                if(j.data.district_code==this.value){
                     $(this).prop('selected',true)
                }
           }); 
            
           $("#select_block > option").each(function() {
                if(j.data.block_id==this.value){
                     $(this).prop('selected',true)
                }
           });
            
           $("#target_month > option").each(function() {
                if(j.data.month==this.value){
                     $(this).prop('selected',true)
                }
           });
            
           $("#target_year > option").each(function() {
                if(j.data.year==this.value){
                     $(this).prop('selected',true)
                }
           });
            
          $('#district_target').val(j.data.target);
        
          $('#target_desp').val(j.data.task_description);
          $('#remarks').val(j.data.remarks);
        }).fail(function () {
            Swal("Something went wrong! Please try again.");
        });
    });
    
    
    
    $('#add_district_task').on('click',function(e){
        $('#edit_district_task_id').val('');
        $('#task_header').empty();
        $('#task_header').append('Add');
        $('#saveDistrictTargetDetails').trigger("reset");
        $('#district-edit-task-btn').hide();
        $('#district-task-btn').show();
        $('#addDistrictTask').modal('show');
    })
    
    
    
    
    
    

    $(document).on('click', '#district-edit-task-btn', function (e) {
        e.preventDefault();
        Swal({
            title: 'Are you sure?',
            text: "You are going to update district target!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes, update it!'
        }).then((result) => {
            $('#saveDistrictTargetDetailsValidation').empty();
                if (result.value) {
                       $.ajax({
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                            type: "POST",
                            url: "<?php echo e(url('/edit_district_target')); ?>",
                            dataType: "json",
                            data: new FormData(document.getElementById('saveDistrictTargetDetails')),
                            contentType: false,
                            cache: false,
                            processData: false,
                            statusCode: {
                                422: function (data) {
                                    // Error...
                                    var object = "";
                                    $.each(data, function (key, val) {

                                        if (key === "responseText") {
                                            object = jQuery.parseJSON(val);
                                        }

                                    });
                                    var error = "";
                                    $.each(object.errors, function (key, val) {

                                        $('.' + key).text(val);

                                    });
                                    swal("Invalid data has been provided please check!", "", "error");
                                },
                                200: function (j) {


                                },
                                500: function () {
                                    swal("Something went wrong. Please try again.", "", "warning");
                                }
                            },
                            error: function (data) {

                            },
                            success: function (j) {
                                if (j['msg'] == "VE") {
                                    $('#saveDistrictTargetDetailsValidation').append('<ul class="form-group f-600 f-13 v-errors" id="saveDistrictTargetDetailValidationErrors"></ul>');

                                    $.each(j.error, function (index, value) {
                                        $('#saveDistrictTargetDetailValidationErrors').append('<li>' + value + '</li>');
                                    });
                                } else {
                                    $('#addDistrictTask').modal('hide');
                                    $('#saveDistrictTargetDetails').trigger("reset");
                                    Swal({
                                        title: 'Success',
                                        text: j['msg'],
                                        type: 'success',
                                        showCancelButton: false,
                                        confirmButtonColor: '#3085d6',
                                        cancelButtonColor: '#d33',
                                        confirmButtonText: 'Ok'
                                    }).then((result) => {
                                        if (result.value) {
                                            location.reload();
                                        }
                                    });

                                }
                            }
                        });

            }
        });
    });
    
    
    
    $('.panel_click').on('click',function(e){
        $('.panel_click').parent('li').removeClass('active');
        $(this).parent('li').addClass('active');
        var div_id=$(this).attr('href');
        $('.custom_tab_container').children('.custom_tab').hide();
        div_id=div_id+'1';
        $(div_id).show();
    })
    
    
    var url = $(location).attr('href');
    var last_index=url.lastIndexOf('#');
    if(last_index>0){
        var div_id = url.substring(last_index + 1);
        $('.custom_tab_container').children('.custom_tab').hide();
        $('.panel_click').parent('li').removeClass('active'); 
        $('a[href*="'+div_id+'"]').parent('li').addClass('active');
        div_id='#'+div_id+'1';
        $(div_id).show();
    }
</script>
<?php $__env->stopSection(); ?>


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