<style type="text/css">
    .min_hrs{background:#ed9421 !important;margin-top:20px;border:1px solid #000;color:#fff}
    .add_hrs{background:lightsteelblue !important;border:1px solid #000}
    .non_hrs{background:#ccc !important;border:1px solid #000;}
    .paid_amount{
        min-width: 104px !important;
    }
</style>
<div class="container-fluid container-fixed-lg bg-white">
    <div class="panel panel-transparent">
        <div class="panel-heading">
            <h5 class="bold"><?php print CommonLanguage::getMessage('multi_payroll'); ?></h5>
            <div id="alertdiv"></div>
        </div>
        <div class="row form-group">
            <div class="col-md-3">
                <label><?php echo CommonLanguage::getMessage('departments') ?></label>
                <input type="hidden" id="department_id" class="full-width department_id" name="department_id" />
            </div>
            <div class="col-md-3 ">
                <label><?php echo CommonLanguage::getMessage('nssf') . ' ?' ?></label>
                <select id="is_nssf" class="full-width" data-init-plugin="select2" name="is_nssf" >
                    <option value=""><?php echo CommonLanguage::getMessage('All') ?></option>
                    <option value="1"><?php echo CommonLanguage::getMessage('yes') ?></option>
                    <option value="0"><?php echo CommonLanguage::getMessage('no') ?></option>
                </select>
            </div>
            <div class="col-md-1 ">
                <label><?php echo CommonLanguage::getMessage('paid?') ?></label>
                <select id="is_paid" class="full-width " name="is_paid" data-init-plugin="select2">
                    <option value="0"><?php echo CommonLanguage::getMessage('All') ?></option>
                    <option value="1"><?php echo CommonLanguage::getMessage('paid') ?></option>
                    <option value="2"><?php echo CommonLanguage::getMessage('unpaid') ?></option>
                </select>
            </div>
            <div class="col-md-2">
                <label><?php echo CommonLanguage::getMessage('still_working') . ' ?' ?></label>
                <select id="is_working" class="full-width" data-init-plugin="select2" name="is_working" >
                    <option value=""><?php echo CommonLanguage::getMessage('All') ?></option>
                    <option value="1" selected><?php echo CommonLanguage::getMessage('yes') ?></option>
                    <option value="0"><?php echo CommonLanguage::getMessage('no') ?></option>
                </select>
            </div>
            <div class="col-md-3">
                <label><?php echo CommonLanguage::getMessage('bank_name') ?></label>
                <input type="hidden"  placeholder="<?php print CommonLanguage::getMessage('bank_name'); ?>" id="bank_id" name="bank_id" class="full-width " >
            </div>
        </div >
        <div class="row form-group">
            <div class="col-md-2 ">
                <label><?php echo CommonLanguage::getMessage('type') ?></label>
                <select id="shift_type" class="full-width " name="" data-init-plugin="select2">
                    <option value="0"><?php echo CommonLanguage::getMessage('fixed_shift') ?></option>
                    <option value="1"><?php echo CommonLanguage::getMessage('dynamic_week') ?></option>
                    <option value="2"><?php echo CommonLanguage::getMessage('dynamic_month') ?></option>
                </select>
            </div>
            <div class="col-md-3 date-div month-div hidden">
                <label><?php echo CommonLanguage::getMessage('month') ?></label>
                <input class="month_year form-control" type="text" data-date-format="yyyy-mm" value=""  />
            </div>
            <div class=" week-div date-div  hidden">
                <div class=" col-md-3">
                    <label><?php echo CommonLanguage::getMessage('start') ?></label>
                    <input class="from_date form-control" type="text"  />
                </div>
                <div class=" col-md-3">
                    <label><?php echo CommonLanguage::getMessage('end') ?></label>
                    <input class="to_date form-control" type="text"  readonly/>
                </div>
            </div>
            <div class="col-md-3 range-div date-div ">
                <label><?php echo CommonLanguage::getMessage('Date') ?></label>
                <input type="text" id="EmployeeDate" class="form-control EmployeeDate" name="EmployeeDate" />
            </div>
            <div class="col-md-2">
                <label><?php echo CommonLanguage::getMessage('employee_type') ?></label>
                <select id="employee_type_filter" class="full-width" data-init-plugin="select2">
                    <option value=""><?php print CommonLanguage::getMessage('select'); ?></option>
                    <option value="1"><?php print CommonLanguage::getMessage('IS_Employee'); ?></option>
                    <option value="0"><?php print CommonLanguage::getMessage('not_IS_Employee'); ?></option>
                    <option value="2"><?php print CommonLanguage::getMessage('sign_emp'); ?></option>
                    <option value="3"><?php print CommonLanguage::getMessage('temp_emp'); ?></option>
                    <option value="5"><?php print CommonLanguage::getMessage('daily_emp'); ?></option>
                    <option value="4"><?php print CommonLanguage::getMessage('retired_emp'); ?></option>
                </select>
            </div>
            <div class="col-md-2">
                <label><?php echo CommonLanguage::getMessage('early_payroll') . '?' ?></label>
                <select id="early_payroll_filter" class="full-width" data-init-plugin="select2">
                    <option value=""><?php print CommonLanguage::getMessage('All'); ?></option>
                    <option value="1"><?php print CommonLanguage::getMessage('yes'); ?></option>
                    <option value="0"><?php print CommonLanguage::getMessage('no'); ?></option>
                </select>
            </div>
            <?php if ($is_actual) { ?>
                <div class="col-md-1">
                    <label><?php print CommonLanguage::getMessage('actual_only'); ?></label>
                    <input type="checkbox"  id="actual_only" name="actual_only"/>
                </div>
            <?php } ?>
            <div class='col-md-2 m-t-25'>
                <button class='btn btn-success' id='search_attendance'><?php echo CommonLanguage::getMessage('search') ?></button>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12 table-responsive">
                <table class="table table-bordered hrm" id="tableWithSearch">
                    <thead>
                        <tr>
                            <th class="text-center no-print" ><input type="checkbox" class="select_all"/></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('employee_name') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('second_lang_name') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('start_date') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('basic_salary') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('transportation') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('overtime') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('bonus') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('deduction') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('loan') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('allowance') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('ssnf') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('tax') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('advance_payment') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('lunch') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('phone_recharge') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('other_charges') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('emp_charge1') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('emp_charge2') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('emp_charge3') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('emp_charge4') ?></th>
                            <!--<th class="text-center"><?php // echo CommonLanguage::getMessage('already_paid')            ?></th>-->
                            <?php if (smc_session()['default_setting']['view_net_overall_balance_multipayroll'] == 1) { ?>
                                <th class="text-center"><?php echo CommonLanguage::getMessage('payroll_amount') ?></th>
                                <th class="text-center"><?php echo CommonLanguage::getMessage('previous_balance') ?></th>
                            <?php } ?>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('net_total') ?></th>
                            <th class="text-center"><?php echo CommonLanguage::getMessage('paid_amount') ?><br/><span class="fa fa-2x fa-trash cursor" id="empty_all"></span> &nbsp;&nbsp;&nbsp;&nbsp;<span class="fa fa-pencil fa-2x cursor" id="fill_all"></span></th>
                        </tr>
                    </thead>
                    <tfoot>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th><div class="text-center"><span id="basic_salary_total"></span></div></th>
                    <th><div class="text-center"><span id="transportation_total"></span></div></th>
                    <th><div class="text-center"><span id="overtime_total"></span></div></th>
                    <th><div class="text-center"><span id="bonus_total"></span></div></th>
                    <th><div class="text-center"><span id="deduction_total"></span></div></th>
                    <th><div class="text-center"><span id="loan_total"></span></div></th>
                    <th><div class="text-center"><span id="allownance_total"></span></div></th>
                    <th><div class="text-center"><span id="ssnf_total"></span></div></th>
                    <th><div class="text-center"><span id="tax_total"></span></div></th>
                    <th><div class="text-center"><span id="advance_payment_total"></span></div></th>
                    <th><div class="text-center"><span id="launch_total"></span></div></th>
                    <th><div class="text-center"><span id="phone_recharge_total"></span></div></th>
                    <th><div class="text-center"><span id="other_charges_total"></span></div></th>
                    <th><div class="text-center"><span id="emp_charge1_total"></span></div></th>
                    <th><div class="text-center"><span id="emp_charge2_total"></span></div></th>
                    <th><div class="text-center"><span id="emp_charge3_total"></span></div></th>
                    <th><div class="text-center"><span id="emp_charge4_total"></span></div></th>
                    <?php if (smc_session()['default_setting']['view_net_overall_balance_multipayroll'] == 1) { ?>
                        <th></th>
                        <th></th>
                    <?php } ?>
                    <th><div class="text-center"><span id="net_total"></span></div></th>
                    <th><div class="text-center"><span id="paid_total"></span></div></th>
                    </tfoot>
                </table>
            </div>
        </div>    
        <div class="row">
            <div class="col-md-6 pull-right">
                <div class='col-md-4 m-t-25 pull-right'>
                    <button class='btn btn-success full-width' id='submit_payroll'><?php echo CommonLanguage::getMessage('submit') ?></button>
                </div>
                <div class="col-md-6 pull-right">
                    <label><?php echo CommonLanguage::getMessage('payment_account') ?></label>
                    <select id="paymentType" class="full-width AccountCode" name="paymentType" data-init-plugin="select2">
                        <?php foreach ($payment_type as $type): ?>
                            <option value="<?php echo $type['Account_ID']; ?>" ><?php echo $type['Account_Code'] . ' - ' . $type['Account_Name']; ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
            </div> 
        </div>
    </div>
</div>
<script>
    var emp_id, from_date, to_date, dep_id, actual_only, total = 0.0, total_wrk = 0.0, must_work = 0.0, real_work = 0.0,
            Submitted_Successfully = <?php echo json_encode(CommonLanguage::getMessage('Submitted_Successfully')); ?>,
            Required_Fields = <?php echo json_encode(CommonLanguage::getMessage('Required_Fields')); ?>,
            info_lang = <?php echo json_encode(CommonLanguage::getMessage('info')); ?>,
            Failed_Submit = <?php echo json_encode(CommonLanguage::getMessage('Failed_Submit')); ?>,
            titel = <?php echo json_encode(CommonLanguage::getMessage('multi_payroll_report')); ?>,
            choose_date = <?php echo json_encode(CommonLanguage::getMessage('choose_date')); ?>,
            auto_ded_lang = <?php echo json_encode(CommonLanguage::getMessage('auto_ded_lang')); ?>,
            startDate =<?php echo json_encode($today); ?>, endDate =<?php echo json_encode($today); ?>,
            error = <?php echo json_encode(CommonLanguage::getMessage('err_msg')); ?>,
            is_actual = <?php echo json_encode($is_actual); ?>,
            multi_payroll_msg =<?php echo json_encode(smc_session()['datatable_header_temp']['multi_payroll']) ?>,
            view_net_overall =<?php echo json_encode(smc_session()['default_setting']['view_net_overall_balance_multipayroll']) ?>,
            emp_data = [];
    $(function () {
        build_select2($('.department_id'), 'HRMAjax/searchDepartment');
        build_select2($("#bank_id"), "HRMAjax/searchBanks?add_no_bank=1")
        $("#tableWithSearch").on("click", "input.select_all", function (e) {
            var is_checked = $(this).is(":checked");
            var row = $("#tableWithSearch").dataTable().fnGetNodes();
            for (var i = 0; i < row.length; i++) {
                $(row[i]).find("input.employee_payroll_check").prop("checked", is_checked);
            }
        });
        new Switchery($("#actual_only").get(0), {color: $.Pages.getColor("success")});
        $('#EmployeeDate').daterangepicker({locale: {
                format: 'YYYY-MM-DD'
            }, ranges: {
                'Today': [moment(), moment()],
                'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                'This Month': [moment().startOf('month'), moment().endOf('month')],
                'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
            }
        }, function (start, end, label) {
            window.startDate = start.format("YYYY-MM-DD"),
                    window.endDate = end.format("YYYY-MM-DD");
        });
        $(".month_year").datepicker({autoclose: true,
            viewMode: "months",
            minViewMode: "months"});
        //        build_select2($('.Payment_Method'), 'xhr/accSearch?type=Payroll')
        $(".month_year").on("changeDate", function () {
            var date = new Date($(this).val() + '-01T12:00:00');
            var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
            window.startDate = $(this).val() + '-01';
            window.endDate = $(this).val() + '-' + lastDay;
            //            to_date: endDate,
            //            console.log(startDate + '==' + endDate)
        });
        $(".from_date,.to_date").datepicker({autoclose: true})
        $(".from_date").on("changeDate", function () {
            var date2 = $(this).datepicker('getDate', '+6d');
            date2.setDate(date2.getDate() + 6);
            $('.to_date').datepicker('setDate', date2);
            window.startDate = $(this).val()
            window.endDate = $('.to_date').val()
        })
        $("#shift_type").on("change", function () {
            $(".date-div").addClass("hidden")
            if ($(this).val() == 0) {
                $("#EmployeeDate").val(window.startDate + ' - ' + window.endDate)
                $(".range-div").removeClass("hidden")
            } else
            if ($(this).val() == 1) {
                $(".week-div").removeClass("hidden")
            } else
            if ($(this).val() == 2) {
                $(".month-div").removeClass("hidden")
            }
        })
        $('#search_attendance').on('click', function () {
            $('#alertdiv').addClass("hidden")
            $('#tableWithSearch tbody').empty();
            //            $('#tableWithSearch').DataTable().destroy();
            if (($("#shift_type").val() == 0 && (window.startDate == undefined || window.startDate == undefined))
                    || ($("#shift_type").val() == 1 && ($(".from_date").val() == '' || $(".to_date").val() == ''))
                    || ($("#shift_type").val() == 2 && $(".month_year").val() == '')) {
                $('#alertdiv').attr('class', ' alert alert-danger').empty().html(choose_date)
                return;
            }
            from_date = (window.startDate ? window.startDate : today);
            to_date = (window.endDate ? window.endDate : today);
            dep_id = $('#department_id').val();
            actual_only = $('#actual_only').is(":checked") ? 1 : 0;
            $.ajax({
                url: 'HRMAjax/payroll_report?from_date=' + from_date + '&to_date=' + to_date + '&dep_id=' + dep_id + '&shift_type=' + $("#shift_type").val() + '&is_nssf=' + $("#is_nssf").val() + '&is_paid=' + $('#is_paid').val() + '&bank_filter=' + $('#bank_id').val() + '&is_working=' + $("#is_working").val() + '&emp_type=' + $("#employee_type_filter").val() + '&is_actual=' + is_actual + '&actual_only=' + actual_only + '&early_payroll=' + $("#early_payroll_filter").val(),
                dataType: "JSON",
                complete: function (v1, v2) {
                    if (v2 == 'success' && v1.responseJSON != 'error') {
                        //                        console.log(v1.responseJSON)
                        var row = '';
                        var data = v1.responseJSON[0][0], total = v1.responseJSON[0][1];
                        if (data != undefined || data.length == 0) {
                            for (var i in data) {
                                emp_data[data[i]['main']['Employee_ID']] = data[i];
                                //                                alert()
                                row += '<tr data-paid="' + data[i]['is_paid'] + '">' +
                                        '<td><input type="checkbox" data-id="' + data[i]['main']['Employee_ID'] + '" class="employee_payroll_check"/></td>' +
                                        '<td>' + data[i]['details']['Name'] + '</td>' +
                                        '<td>' + data[i]['details']['second_lang_name'] + '</td>' +
                                        '<td>' + data[i]['main']['start_date'] + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['basic_salary']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['transportation']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['overtime']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['bonus']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['deduction']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['loan_payment']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['allowance']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['ssnf']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['tax']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['advance_payment']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['Lunch']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['Phone']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['other_charges']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['emp_charge1']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['emp_charge2']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['emp_charge3']) + '</td>' +
                                        '<td>' + FixNumber(data[i]['details']['emp_charge4']) + '</td>';
                                        //                                        '<td>' + FixNumber(data[i]['Amount_Paid']) + '</td>' +
     if(view_net_overall==1){
        row+= '<td>' + FixNumber((data[i]['main']['Net_Pay'])) + '</td>' +
                                        '<td>' + FixNumber(data[i]['emp_balance']) + '</td>';
     }                                   
    row+='<td class="bold cursor net_pay">' + FixNumber(data[i]['net_balance']) + '</td>' +
                                        '<td>' + (data[i]['is_paid'] == 1 && data[i]['Amount_Paid'] > 0 ? FixNumber(data[i]['Amount_Paid']) : '<input type="number" data-id="' + data[i]['main']['Employee_ID'] + '" step="any" min="0" class="form-control paid_amount" data-net="' + (data[i]['net_balance'] > 0 ? data[i]['net_balance'] : 0) + '" value="' + (data[i]['net_balance'] >0 ? data[i]['net_balance']:0) + '"/>') + '</td>' +
                                        '</tr>';
                            }
                            $('#paid_total').html("paid_total" in total ? FixNumber(total['paid_total']) : '')
                            $('#net_total').html("net_total" in total ? FixNumber(total['net_total']) : '')
                            $('#other_charges_total').html("other_charges_total" in total ? FixNumber(total['other_charges_total']) : '')
                            $('#emp_charge1_total').html("emp_charge1_total" in total ? FixNumber(total['emp_charge1_total']) : '')
                            $('#emp_charge2_total').html("emp_charge2_total" in total ? FixNumber(total['emp_charge2_total']) : '')
                            $('#emp_charge3_total').html("emp_charge3_total" in total ? FixNumber(total['emp_charge3_total']) : '')
                            $('#emp_charge4_total').html("emp_charge4_total" in total ? FixNumber(total['emp_charge4_total']) : '')
                            $('#phone_recharge_total').html("phone_recharge_total" in total ? FixNumber(total['phone_recharge_total']) : '')
                            $('#launch_total').html("launch_total" in total ? FixNumber(total['launch_total']) : '')
                            $('#advance_payment_total').html("advance_payment_total" in total ? FixNumber(total['advance_payment_total']) : '')
                            $('#tax_total').html("tax_total" in total ? FixNumber(total['tax_total']) : '')
                            $('#ssnf_total').html("ssnf_total" in total ? FixNumber(total['ssnf_total']) : '')
                            $('#allownance_total').html("allownance_total" in total ? FixNumber(total['allownance_total']) : '')
                            $('#loan_total').html("loan_total" in total ? FixNumber(total['loan_total']) : '')
                            $('#deduction_total').html("deduction_total" in total ? FixNumber(total['deduction_total']) : '')
                            $('#bonus_total').html("bonus_total" in total ? FixNumber(total['bonus_total']) : '')
                            $('#overtime_total').html("overtime_total" in total ? FixNumber(total['overtime_total']) : '')
                            $('#transportation_total').html("transportation_total" in total ? FixNumber(total['transportation_total']) : '')
                            $('#basic_salary_total').html("basic_salary_total" in total ? FixNumber(total['basic_salary_total']) : '')
                            $('#tableWithSearch').DataTable().destroy();
                            $('#tableWithSearch tbody').html($(row));
                            var next_date = new Date(to_date);
                            next_date.setDate(next_date.getDate() + +($("#early_payroll_filter").val() == 1 ? 1 : 0));
                            console.log(next_date)
                            var next_date = moment(next_date);
                            //var next_date = moment((new Date()).setDate(new Date(to_date).getDate() + ($("#early_payroll_filter").val() == 1 ? 1 : 0)));
                            var print_month = next_date.format('MM-YYYY')
                            var print_date = next_date.format('YYYY-MM-DD');
                            //console.log(next_date)
                            var msg = multi_payroll_msg.replace("[[date]]", print_date);
                            msg = msg.replace("[[month]]", print_month);
                            var optns = {
                                msg: msg,
                                cb_ft: function (dt_optns) {
                                    // stop sorting for column since on click on header checkbox the sorting is triggered
                                    dt_optns.columnDefs.push({targets: [0, 18], "orderable": false});
                                },
                            };
                            RebuildDataTable(titel, [0, 1, 2, 3, 4], false, false, '#tableWithSearch', [], optns);
                            $('#submit_payroll').removeAttr('disabled')
                        }
                    } else {
                        $('#alertdiv').attr('class', ' alert alert-danger').empty().html(error)
                    }
                    //                    $('#tableWithSearch').DataTable().destroy();
                    //                    RebuildDataTable(titel, [0, 1, 2, 3, 4], false, false, '#tableWithSearch');
                }
            });
        });
        $("#frameModal button").on("click", function () {
            $('#search_attendance').trigger('click')
        });
        $("#empty_all").on("click", function () {
            var row = $("#tableWithSearch").dataTable().fnGetNodes();
            for (var i = 0; i < row.length; i++) {
                $(row[i]).find('input.paid_amount').val(0)
            }
        })
        $("#fill_all").on("click", function () {
            var row = $("#tableWithSearch").dataTable().fnGetNodes();
            for (var i = 0; i < row.length; i++) {
                $(row[i]).find('input.paid_amount').val($(row[i]).find('input.paid_amount').attr('data-net'))
            }
        })
        $("#tableWithSearch").on("click", ".net_pay", function () {
            var input = $(this).parents('tr').find("input.paid_amount");
            input.val(input.attr("data-net"));
        })
        $("#submit_payroll").on("click", function () {
            var row = $("#tableWithSearch").dataTable().fnGetNodes();
            if ($('input.employee_payroll_check:checked').length == 0) {
                toastr.error('<?php echo CommonLanguage::getMessage('choose_entry'); ?>')
                return;
            }
            var mydata = [];
            for (var i = 0; i < row.length; i++) {
                //                if ($(row[i]).attr("data-paid") == 0 && $(row[i]).find("input.employee_payroll_check").is(":checked")) {
                if ($(row[i]).find("input.employee_payroll_check").is(":checked")) {
                    var emp_id = $(row[i]).find("input.paid_amount").attr("data-id");
                    mydata[emp_id] = emp_data[emp_id];
                    mydata[emp_id]['main']['paid_amount'] = $(row[i]).find("input.paid_amount").val();
                    mydata[emp_id]['main']['Payment_Method'] = $("#paymentType").val();
                    mydata[emp_id]['main']['from_date'] = window.startDate;
                    mydata[emp_id]['main']['to_date'] = window.endDate;
                    mydata[emp_id]['main']['Actual'] = is_actual;
                }

            }
            if (mydata.length == 0) {
                return
            }
            //            return
            $.ajax({
                url: "HRMAjax/submit_multi_payroll",
                data: {data: mydata},
                method: "POST",
                complete: function (v1, v2) {
                    if (v2 == "success" && v1.responseText == 'OK') {
                        $("#alertdiv").attr("class", "alert alert-success").html(Submitted_Successfully)
                        $('#submit_payroll').attr('disabled', 'disabled')
                        setTimeout(function () {
                            $("#alertdiv").attr("class", "hidden")
                        }, 5000)
                    } else {
                        $("#alertdiv").attr("class", "alert alert-danger").html(v1.responseText)
                    }
                    $(document.body).animate({scrollTop: 0}, 800)
                }
            });
            //            console.log(mydata)
        })
    });
</script>