<script>
<?php if($page_name=='salary_slips_view'){?>
  $("#table_filter_work").select2({
    placeholder: "Select Work",
    templateResult: format_project_dropdown
  })
  $("#table_filter_employee").select2({
    placeholder: "Select Employee"
  })
  <?php } ?>
  $("#salary_slip_month_add,#salary_slip_month_edit,#table_filter_start_month,#table_filter_end_month").datepicker( {
    todayHighlight:!0, orientation:"bottom left",format: "M yyyy",viewMode: "months", minViewMode: "months", templates: {
      leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
    }
  })
  $("#salary_slip_paid_date_add,#salary_slip_paid_date_edit,#salary_slip_reference_date_add,#salary_slip_date_add").datepicker( {
    todayHighlight:!0, orientation:"bottom left", templates: {
      leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
    },
    endDate: '+0d',
    <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
      startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
      <?php } ?>
    })
    $('body').on('change', '#salary_slip_payment_mode_add', function() {
      var payment_mode=$('#salary_slip_payment_mode_add :selected').val();
      if(payment_mode=='POST DATED CHEQUE'){
        $('#salary_slip_paid_date_add').datepicker('destroy');
        $("#salary_slip_paid_date_add").datepicker( {
          todayHighlight:!0, orientation:"bottom left", templates: {
            leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
          },
          <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
            startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
            <?php } ?>
          })
        }else{
          $('#salary_slip_paid_date_add').datepicker('destroy');
          $("#salary_slip_paid_date_add").datepicker( {
            todayHighlight:!0, orientation:"bottom left", templates: {
              leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
            },
            endDate: '+0d',
            <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
              startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
              <?php } ?>
            })
          }
        })

        $("#salary_slip_payment_mode_add").select2({
          placeholder: "Select Debit Account",
          dropdownParent: $("#form_salary_slip_add")
        })
        $("#salary_slip_debit_acc_add").select2({
          placeholder: "Select Debit Account",
          dropdownParent: $("#form_salary_slip_add")
        })
        $("#salary_slip_work_add").select2({
          placeholder: "Select Work",
          dropdownParent: $("#form_salary_slip_add"),
          templateResult: format_project_dropdown
        })
        $("#salary_slip_employee_add").select2({
          placeholder: "Select Labour",
          dropdownParent: $("#form_salary_slip_add")
        })
        $("#salary_slip_basic_wage_type_add").select2({
          placeholder: "Select Type",
          dropdownParent: $("#form_salary_slip_add")
        })
        $("#salary_slip_overtime_type_add").selectpicker();
        // $("#salary_slip_overtime_type_add").select2({
        //   placeholder: "Select Type",
        //   dropdownParent: $("#form_salary_slip_add")
        // })

        $("#salary_slip_work_edit").select2({
          placeholder: "Select Work",
          dropdownParent: $("#form_salary_slip_edit"),
          templateResult: format_project_dropdown
        })
        $("#salary_slip_employee_edit").select2({
          placeholder: "Select Labour",
          dropdownParent: $("#form_salary_slip_edit")
        })
        $("#salary_slip_basic_wage_type_edit").select2({
          placeholder: "Select Type",
          dropdownParent: $("#form_salary_slip_edit")
        })
        $("#salary_slip_overtime_type_edit").select2({
          placeholder: "Select Type",
          dropdownParent: $("#form_salary_slip_edit")
        })

        $("#salary_slip_employee_add_2").select2({
          placeholder: "Select Labour",
          dropdownParent: $("#form_employee_payment_add")
        })

        $("#salary_slip_employee_edit_2").select2({
          placeholder: "Select Labour",
          dropdownParent: $("#form_employee_payment_edit")
        })

        $('body').on('change keyup', '#salary_slip_paid_amount_add', function() {
          var value = $(this).val();
          if(value=="" || value==null){
            $(this).val(0)
          }
          if($(this).val()>0){
            $(".salary_slip_paid_amount_req_fields").attr('required',true);
          }else{
            $(".salary_slip_paid_amount_req_fields").removeAttr('required',true);
          }
        })
        <?php if($page_name=='work_profile'){?>
          var work_id = "<?php echo $work_data->work_id ?>";
          $("#salary_slip_work_add").val(work_id).trigger('change');
          $("#salary_slip_work_div_add").show();
          $("#salary_slip_work_add").attr('required',true);

          $("#salary_slip_work_edit").val(work_id).trigger('change');
          $("#salary_slip_work_div_edit").show();
          $("#salary_slip_work_edit").attr('required',true);
          <?php } ?>
          $('input[type=radio][name=salary_slip_type]').change(function() {
            if (this.value == 'Project') {
              $("#salary_slip_work_div_add").show();
              $("#salary_slip_work_add").attr('required',true);
            }else{
              $("#salary_slip_work_div_add").hide();
              $("#salary_slip_work_add").removeAttr('required',true);
            }
          });

          <?php if($this->config->item('HR_salary_slip_template_3_fields_editable')==0){ ?>
            $(".salary_slip_template_3_fields").attr('readonly',true);
            <?php }else{ ?>
              $(".salary_slip_template_3_fields").removeAttr('readonly',true);
              <?php } ?>
              $('input[type=radio][name=salary_slip_type_edit]').change(function() {
                if (this.value == 'Project') {
                  $("#salary_slip_work_div_edit").show();
                  $("#salary_slip_work_edit").attr('required',true);
                }else{
                  $("#salary_slip_work_div_edit").hide();
                  $("#salary_slip_work_edit").removeAttr('required',true);
                }
              });

              $('#salary_slip_month_add,#salary_slip_employee_add').change(function() {
                var month = $('#salary_slip_month_add').val();
                var employee_id = $('#salary_slip_employee_add :selected').val();
                if (employee_id != 'Select Employee' && month != '' ) {
                  $.post("<?php echo base_url() ?>salary_slips/get_advance_salary",{employee_id:employee_id,month:month},function(data) {
                    var obj = $.parseJSON(data);
                    advance = obj.advance;
                    $('#salary_slip_advance_amount_add').val(advance);
                    $('#salary_slip_advance_amount_add').attr('max',advance.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                    if(advance==0){
                      $('#salary_slip_advance_amount_add').attr('disabled','disabled');
                    }else{
                      $('#salary_slip_advance_amount_add').removeAttr('disabled');
                    }
                    $("#salary_slip_basic_wage_add").trigger('change');

                    $("#salary_slip_month_days_add").val(obj.month_days);
                    <?php if($this->config->item('HR_salary_slip_template')==4){ ?>
                      var month_days = obj.month_days;
                      var sundays = obj.sundays;
                      var holidays = obj.holidays;
                      var max_payable_days = month_days-holidays;
                      var paid_leaves = obj.total_paid_leaves;
                      var unpaid_leaves = obj.total_unpaid_leaves;
                      var net_payable_days = max_payable_days-unpaid_leaves;
                      var working_days = net_payable_days-sundays;
                      var worked_nos = working_days-unpaid_leaves;
                      $('#salary_slip_paid_holidays_add').val(holidays);
                      $('#salary_slip_max_payable_days_add').val(max_payable_days);
                      $('#salary_slip_net_paid_days_add').val(net_payable_days);
                      $('#salary_slip_paid_leaves_add').val(paid_leaves);
                      $('#salary_slip_weekly_off_days_add').val(sundays);
                      $('#salary_slip_working_days_add').val(working_days);
                      $('#salary_slip_lwp_days_add').val(unpaid_leaves);
                      $('#salary_slip_worked_nos_add').val(worked_nos);
                      <?php } ?>
                      <?php if($this->config->item('HR_salary_slip_template')==5){ ?>
                        var month_days = obj.month_days;
                        var sundays = obj.sundays;
                        var holidays = obj.holidays;
                        var max_payable_days = month_days-holidays;
                        var paid_leaves = obj.total_paid_leaves;
                        var unpaid_leaves = obj.total_unpaid_leaves;
                        var net_payable_days = max_payable_days-unpaid_leaves;
                        var working_days = net_payable_days-sundays;
                        var worked_nos = working_days-unpaid_leaves;
                        $('#salary_slip_paid_holidays_add').val(holidays);
                        $('#salary_slip_max_payable_days_add').val(max_payable_days);
                        $('#salary_slip_net_paid_days_add').val(net_payable_days);
                        $('#salary_slip_paid_leaves_add').val(paid_leaves);
                        $('#salary_slip_weekly_off_days_add').val(sundays);
                        $('#salary_slip_working_days_add').val(working_days);
                        $('#salary_slip_lwp_days_add').val(unpaid_leaves);
                        $('#salary_slip_worked_nos_add').val(worked_nos);
                        <?php } ?>
                      });
                    }

                  });

                  $('#salary_slip_month_edit,#salary_slip_employee_edit').change(function() {
                    var month = $('#salary_slip_month_edit').val();
                    var employee_id = $('#salary_slip_employee_edit :selected').val();
                    if (employee_id != 'Select Employee' && month != '' ) {
                      $.post("<?php echo base_url() ?>salary_slips/get_advance_salary",{employee_id:employee_id,month:month},function(data) {
                        var obj = $.parseJSON(data);
                        advance = obj.advance;
                        // $('#salary_slip_advance_amount_edit').val(advance);
                        // $('#salary_slip_advance_amount_edit').attr('max',advance.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        // if(advance==0){
                        //   $('#salary_slip_advance_amount_edit').attr('disabled','disabled');
                        // }
                        // else{
                        //   $('#salary_slip_advance_amount_edit').removeAttr('disabled');
                        // }
                      });
                    }
                  });


                  <?php if($this->config->item('HR_salary_slip_template')==1){ ?>
                    function calculate_salary_add(field_id=''){
                      var basic_wage = parseFloat($("#salary_slip_basic_wage_add").val());
                      var basic_wage_type = $("#salary_slip_basic_wage_type_add :selected").val();
                      if(basic_wage_type=='Hourly'){
                        $("#worked_type_add_1").text("Worked Hours");
                        $("#worked_type_add_2").text("Hours");
                      }else{
                        $("#worked_type_add_1").text("Worked Days");
                        $("#worked_type_add_2").text("Days");
                      }
                      var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_add").val();
                      if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                        var days = parseFloat($("#salary_slip_month_days_add").val());
                        var daily_working_hours = parseFloat($("#salary_slip_daily_work_hour_add").val());
                        var hourly_rate = (basic_wage/days)/daily_working_hours;
                        var overtime_rate = hourly_rate;
                        $('#salary_slip_hourly_rate_add_2').val(hourly_rate);
                        $('#salary_slip_hourly_rate_add').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        if(field_id=='salary_slip_overtime_rate_add' || field_id=='salary_slip_overtime_add'){
                          overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                        }else{
                          $("#salary_slip_overtime_rate_add").val(overtime_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        }
                        // $('#salary_slip_overtime_rate_add').attr('readonly',true);
                        $('.monthly_fields_salary_add').show();
                        $("#salary_slip_worked_nos_add").attr('readonly',true);
                        var public_holidays = parseFloat($("#salary_slip_public_holidays_add").val());
                        var medical_leave = parseFloat($("#salary_slip_medical_leave_add").val());
                        var absent = parseFloat($("#salary_slip_absent_add").val());
                        var present_days = days-public_holidays-medical_leave-absent;
                        $("#worked_type_add_1").text("Present Days");
                        $("#salary_slip_worked_nos_add").val(present_days);
                      }else{
                        $('.monthly_fields_salary_add').hide();
                        $("#salary_slip_worked_nos_add").removeAttr('readonly',true);
                        $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                        var overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                      }

                      var worked_nos = parseFloat($("#salary_slip_worked_nos_add").val());
                      var overtime_nos = parseFloat($("#salary_slip_overtime_add").val());
                      var overtime_type = $("#salary_slip_overtime_type_add :selected").val();
                      if(overtime_type=='Hours'){
                        $("#overtime_rate_type_show_add").text("/Hour");
                      }else{
                        $("#overtime_rate_type_show_add").text("/Day");
                      }
                      var allowance = parseFloat($("#salary_slip_allowance_add").val());
                      var incentive = parseFloat($("#salary_slip_incentive_add").val());
                      var bonus = parseFloat($("#salary_slip_bonus_add").val());
                      var deductions = parseFloat($("#salary_slip_deductions_add").val());
                      var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                      $("#salary_slip_overtime_amount_add").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      var total_basic_wage = 0;
                      if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                        var regular_hours = daily_working_hours*worked_nos;
                        $('#salary_slip_regular_hours_add').val(regular_hours);
                        total_basic_wage = regular_hours*hourly_rate;
                      }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                        total_basic_wage = basic_wage;
                      }else{
                        total_basic_wage = worked_nos*basic_wage;
                      }
                      var total_salary = parseFloat(total_basic_wage+overtime_amount+allowance+incentive+bonus);
                      var total_wage = parseFloat(total_salary-deductions);
                      $("#salary_slip_total_salary_add").val(total_salary.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      $("#salary_slip_payable_amount_add").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      $("#salary_slip_paid_amount_add").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                      //advance
                      var advance_paid_salary =  $("#salary_slip_advance_amount_add").val();
                      var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                      $("#salary_slip_total_payable_amount_add").val(payable_inc_advance);

                      var paid_amount = parseFloat($("#salary_slip_paid_amount_add").val());
                      var balance_amount = payable_inc_advance - paid_amount;
                      $("#salary_slip_balance_amount_add").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                    }
                    function calculate_salary_edit(field_id=''){
                      var basic_wage = parseFloat($("#salary_slip_basic_wage_edit").val());
                      var basic_wage_type = $("#salary_slip_basic_wage_type_edit :selected").val();
                      if(basic_wage_type=='Hourly'){
                        $("#worked_type_edit_1").text("Worked Hours");
                        $("#worked_type_edit_2").text("Hours");
                      }else{
                        $("#worked_type_edit_1").text("Worked Days");
                        $("#worked_type_edit_2").text("Days");
                      }
                      var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_edit").val();
                      if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                        var getDaysInMonth = function(month,year) {
                          // Here January is 1 based
                          //Day 0 is the last day in the previous month
                          // return new Date(year, month, 0).getDate();
                          // Here January is 0 based
                          return new Date(year, month+1, 0).getDate();
                        };
                        // var month = .split("-");
                        var month = new Date($('#salary_slip_month_edit').val());
                        // var days = getDaysInMonth(month.getMonth(),month.getFullYear());
                        // $("#salary_slip_month_days_edit").val(days);
                        var days = $("#salary_slip_month_days_edit").val();
                        var daily_working_hours = parseFloat($("#salary_slip_daily_work_hour_edit").val());
                        var hourly_rate = (basic_wage/days)/daily_working_hours;
                        var overtime_rate = hourly_rate;
                        $('#salary_slip_hourly_rate_edit_2').val(hourly_rate);
                        $('#salary_slip_hourly_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        if(field_id=='salary_slip_overtime_rate_edit' || field_id=='salary_slip_overtime_edit'){
                          overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                        }else{
                          $('#salary_slip_overtime_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        }

                        // $('#salary_slip_overtime_rate_edit').attr('readonly',true);
                        $('.monthly_fields_salary_edit').show();
                        $("#salary_slip_worked_nos_edit").attr('readonly',true);
                        var public_holidays = parseFloat($("#salary_slip_public_holidays_edit").val());
                        var medical_leave = parseFloat($("#salary_slip_medical_leave_edit").val());
                        var absent = parseFloat($("#salary_slip_absent_edit").val());
                        var present_days = days-public_holidays-medical_leave-absent;
                        $("#worked_type_edit_1").text("Present Days");
                        $("#salary_slip_worked_nos_edit").val(present_days);
                      }else{
                        $('.monthly_fields_salary_edit').hide();
                        $("#salary_slip_worked_nos_edit").removeAttr('readonly',true);
                        $("#salary_slip_overtime_rate_edit").removeAttr('readonly',true);
                        var overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                      }

                      var worked_nos = parseFloat($("#salary_slip_worked_nos_edit").val());
                      var overtime_nos = parseFloat($("#salary_slip_overtime_edit").val());
                      var overtime_type = $("#salary_slip_overtime_type_edit :selected").val();
                      if(overtime_type=='Hours'){
                        $("#overtime_rate_type_show_edit").text("/Hour");
                      }else{
                        $("#overtime_rate_type_show_edit").text("/Day");
                      }
                      var allowance = parseFloat($("#salary_slip_allowance_edit").val());
                      var incentive = parseFloat($("#salary_slip_incentive_edit").val());
                      var bonus = parseFloat($("#salary_slip_bonus_edit").val());
                      var deductions = parseFloat($("#salary_slip_deductions_edit").val());
                      var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                      $("#salary_slip_overtime_amount_edit").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      var total_basic_wage = 0;
                      if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                        var regular_hours = daily_working_hours*worked_nos;
                        $('#salary_slip_regular_hours_edit').val(regular_hours);
                        total_basic_wage = regular_hours*hourly_rate;
                      }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                        total_basic_wage = basic_wage;
                      }else{
                        total_basic_wage = worked_nos*basic_wage;
                      }

                      var total_salary = parseFloat(total_basic_wage+overtime_amount+allowance+incentive+bonus);
                      var total_wage = parseFloat(total_salary-deductions);
                      $("#salary_slip_total_salary_edit").val(total_salary.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      $("#salary_slip_payable_amount_edit").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      $("#salary_slip_paid_amount_edit").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                      //advance
                      var advance_paid_salary =  $("#salary_slip_advance_amount_edit").val();
                      var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                      $("#salary_slip_total_payable_amount_edit").val(payable_inc_advance);

                      var paid_amount = parseFloat($("#salary_slip_paid_amount_edit").val());
                      var balance_amount = payable_inc_advance - paid_amount;
                      $("#salary_slip_balance_amount_edit").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                    }
                    <?php }elseif($this->config->item('HR_salary_slip_template')==2){ ?>
                      $('.monthly_fields_salary_add').hide();
                      function calculate_salary_add(field_id=''){
                        var basic_wage = parseFloat($("#salary_slip_basic_wage_add").val());
                        var basic_wage_type = $("#salary_slip_basic_wage_type_add :selected").val();
                        if(basic_wage_type=='Hourly'){
                          $("#worked_type_add_1").text("Worked Hours");
                          $("#worked_type_add_2").text("Hours");
                        }else{
                          $("#worked_type_add_1").text("Worked Days");
                          $("#worked_type_add_2").text("Days");
                        }
                        var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_add").val();
                        if((basic_wage_type=='Monthly' && basic_wage_fixed==0) || basic_wage_type=='Daily'){
                          var getDaysInMonth = function(month,year) {
                            // Here January is 1 based
                            //Day 0 is the last day in the previous month
                            // return new Date(year, month, 0).getDate();
                            // Here January is 0 based
                            return new Date(year, month+1, 0).getDate();
                          };
                          // var month = .split("-");
                          var month = new Date($('#salary_slip_month_add').val());
                          var days = 30; //30 Days Fixed for All Month
                          $("#salary_slip_worked_nos_add").attr('max',30);
                          $("#salary_slip_month_days_add").val(days);
                          if(basic_wage_type=='Daily'){
                            var daily_rate = basic_wage;
                          }else{
                            var daily_rate = (basic_wage/days);
                          }
                          var hourly_rate = 0;
                          $('#salary_slip_hourly_rate_add_2').val(hourly_rate);
                          $('#salary_slip_hourly_rate_add').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                          $('.monthly_fields_salary_add').show();
                          $("#worked_type_add_1").text("Present Days");
                        }else{
                          $('.monthly_fields_salary_add').hide();
                          $("#salary_slip_worked_nos_add").removeAttr('readonly',true);
                          $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                        }


                        var worked_nos = parseFloat($("#salary_slip_worked_nos_add").val());
                        var overtime_nos = parseFloat($("#salary_slip_overtime_add").val());
                        if(basic_wage_type=='Daily'){
                          var overtime_extra_free = 1.5;
                          overtime_nos = overtime_nos*overtime_extra_free;
                          var daily_working_hours = 8;
                          var hourly_rate = 0;
                          var overtime_rate = overtime_nos/daily_working_hours;
                          if(field_id=='salary_slip_overtime_rate_add'){
                            hourly_rate = overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                          }else{
                            $("#salary_slip_overtime_rate_add").val(overtime_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                          }
                          // $("#salary_slip_overtime_rate_add").attr('readonly',true);
                          $("#overtime_rate_div_add").hide();
                        }else{
                          $("#overtime_rate_div_add").show();
                          $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                          var overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                        }

                        var overtime_type = $("#salary_slip_overtime_type_add :selected").val();
                        if(overtime_type=='Hours'){
                          $("#overtime_rate_type_show_add").text("/Hour");
                        }else{
                          $("#overtime_rate_type_show_add").text("/Day");
                        }
                        var allowance = parseFloat($("#salary_slip_allowance_add").val());
                        var deductions = parseFloat($("#salary_slip_deductions_add").val());
                        if(basic_wage_type=='Daily'){
                          var overtime_amount = parseFloat(basic_wage*overtime_rate);
                        }else{
                          var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                        }
                        $("#salary_slip_overtime_amount_add").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        var total_basic_wage = 0;
                        if((basic_wage_type=='Monthly' && basic_wage_fixed==0) || basic_wage_type=='Daily'){
                          var present_days = parseFloat($("#salary_slip_worked_nos_add").val());
                          total_basic_wage = parseFloat(present_days*daily_rate);
                          $("#salary_slip_basic_wage_payable_amount_add").val(total_basic_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                          total_basic_wage = basic_wage;
                        }else{
                          total_basic_wage = worked_nos*basic_wage;
                        }
                        var total_wage = parseFloat(total_basic_wage+overtime_amount+allowance-deductions);
                        $("#salary_slip_payable_amount_add").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        $("#salary_slip_paid_amount_add").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                        //advance
                        var advance_paid_salary =  $("#salary_slip_advance_amount_add").val();
                        var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                        $("#salary_slip_total_payable_amount_add").val(payable_inc_advance);

                        var paid_amount = parseFloat($("#salary_slip_paid_amount_add").val());
                        var balance_amount = payable_inc_advance - paid_amount;
                        $("#salary_slip_balance_amount_add").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      }
                      function calculate_salary_edit(field_id=''){
                        var basic_wage = parseFloat($("#salary_slip_basic_wage_edit").val());
                        var basic_wage_type = $("#salary_slip_basic_wage_type_edit :selected").val();
                        if(basic_wage_type=='Hourly'){
                          $("#worked_type_edit_1").text("Worked Hours");
                          $("#worked_type_edit_2").text("Hours");
                        }else{
                          $("#worked_type_edit_1").text("Worked Days");
                          $("#worked_type_edit_2").text("Days");
                        }
                        var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_edit").val();
                        if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                          var getDaysInMonth = function(month,year) {
                            // Here January is 1 based
                            //Day 0 is the last day in the previous month
                            // return new Date(year, month, 0).getDate();
                            // Here January is 0 based
                            return new Date(year, month+1, 0).getDate();
                          };
                          // var month = .split("-");
                          var month = new Date($('#salary_slip_month_edit').val());
                          // var days = getDaysInMonth(month.getMonth(),month.getFullYear());
                          // $("#salary_slip_month_days_edit").val(days);
                          var days = $("#salary_slip_month_days_edit").val();
                          var daily_working_hours = parseFloat($("#salary_slip_daily_work_hour_edit").val());
                          var hourly_rate = (basic_wage/days)/daily_working_hours;
                          var overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                          $('#salary_slip_hourly_rate_edit_2').val(hourly_rate);
                          $('#salary_slip_hourly_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                          if(field_id=='salary_slip_overtime_rate_edit'){
                            // overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                          }else{
                            // $('#salary_slip_overtime_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                          }
                          // $('#salary_slip_overtime_rate_edit').attr('readonly',true);
                          $('.monthly_fields_salary_edit').show();
                          // $("#salary_slip_worked_nos_edit").attr('readonly',true);
                          // var public_holidays = parseFloat($("#salary_slip_public_holidays_edit").val());
                          // var medical_leave = parseFloat($("#salary_slip_medical_leave_edit").val());
                          // var absent = parseFloat($("#salary_slip_absent_edit").val());
                          var present_days = parseFloat($("#salary_slip_worked_nos_edit").val());
                          $("#worked_type_edit_1").text("Present Days");
                          // $("#salary_slip_worked_nos_edit").val(present_days);
                        }else{
                          $('.monthly_fields_salary_edit').hide();
                          $("#salary_slip_worked_nos_edit").removeAttr('readonly',true);
                          $("#salary_slip_overtime_rate_edit").removeAttr('readonly',true);
                          var overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                        }

                        var worked_nos = parseFloat($("#salary_slip_worked_nos_edit").val());
                        var overtime_nos = parseFloat($("#salary_slip_overtime_edit").val());
                        var overtime_type = $("#salary_slip_overtime_type_edit :selected").val();
                        if(overtime_type=='Hours'){
                          $("#overtime_rate_type_show_edit").text("/Hour");
                        }else{
                          $("#overtime_rate_type_show_edit").text("/Day");
                        }
                        var allowance = parseFloat($("#salary_slip_allowance_edit").val());
                        var deductions = parseFloat($("#salary_slip_deductions_edit").val());
                        var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                        $("#salary_slip_overtime_amount_edit").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        var total_basic_wage = 0;
                        if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                          var regular_hours = daily_working_hours*worked_nos;
                          $('#salary_slip_regular_hours_edit').val(regular_hours);
                          total_basic_wage = regular_hours*hourly_rate;
                        }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                          total_basic_wage = basic_wage;
                        }else{
                          total_basic_wage = worked_nos*basic_wage;
                        }
                        $("#salary_slip_basic_wage_payable_amount_edit").val(total_basic_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        var total_wage = parseFloat(total_basic_wage+overtime_amount+allowance-deductions);
                        $("#salary_slip_payable_amount_edit").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                        $("#salary_slip_paid_amount_edit").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                        //advance
                        var advance_paid_salary =  $("#salary_slip_advance_amount_edit").val();
                        var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                        $("#salary_slip_total_payable_amount_edit").val(payable_inc_advance);

                        var paid_amount = parseFloat($("#salary_slip_paid_amount_edit").val());
                        var balance_amount = payable_inc_advance - paid_amount;
                        $("#salary_slip_balance_amount_edit").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                      }
                      <?php }elseif($this->config->item('HR_salary_slip_template')==3){ ?>
                        $('.monthly_fields_salary_add').hide();
                        function calculate_salary_add(field_id=''){
                          var basic_wage = parseFloat($("#salary_slip_basic_wage_add").val());
                          var basic_wage_type = $("#salary_slip_basic_wage_type_add :selected").val();
                          if(basic_wage_type=='Hourly'){
                            $("#worked_type_add_1").text("Worked Hours");
                            $("#worked_type_add_2").text("Hours");
                          }else{
                            $("#worked_type_add_1").text("Worked Days");
                            $("#worked_type_add_2").text("Days");
                          }
                          var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_add").val();
                          if((basic_wage_type=='Monthly' && basic_wage_fixed==0) || basic_wage_type=='Daily'){
                            var getDaysInMonth = function(month,year) {
                              // Here January is 1 based
                              //Day 0 is the last day in the previous month
                              // return new Date(year, month, 0).getDate();
                              // Here January is 0 based
                              return new Date(year, month+1, 0).getDate();
                            };
                            // var month = .split("-");
                            var month = new Date($('#salary_slip_month_add').val());
                            var days = 30; //30 Days Fixed for All Month
                            $("#salary_slip_worked_nos_add").attr('max',30);
                            $("#salary_slip_month_days_add").val(days);
                            if(basic_wage_type=='Daily'){
                              var daily_rate = basic_wage;
                            }else{
                              var daily_rate = (basic_wage/days);
                            }
                            var hourly_rate = 0;
                            $('#salary_slip_hourly_rate_add_2').val(hourly_rate);
                            $('#salary_slip_hourly_rate_add').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                            $('.monthly_fields_salary_add').show();
                            $("#worked_type_add_1").text("Present Days");
                          }else{
                            $('.monthly_fields_salary_add').hide();
                            $("#salary_slip_worked_nos_add").removeAttr('readonly',true);
                            $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                          }


                          var worked_nos = parseFloat($("#salary_slip_worked_nos_add").val());
                          var overtime_nos = parseFloat($("#salary_slip_overtime_add").val());
                          if(basic_wage_type=='Daily'){
                            var overtime_extra_free = 1;
                            overtime_nos = overtime_nos*overtime_extra_free;
                            var daily_working_hours = parseFloat("<?php echo $this->config->item('HR_total_duty_hours_employee') ?>");
                            var overtime_rate = overtime_nos/daily_working_hours;
                            var hourly_rate = 0;
                            if(field_id=='salary_slip_overtime_rate_add'){
                              hourly_rate = overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                            }else{
                              $("#salary_slip_overtime_rate_add").val(overtime_rate);
                            }
                            $("#salary_slip_overtime_rate_info_add").html("(<?php echo $this->config->item("Currency_currency_format")?>"+overtime_rate+"/Hr)");
                            // $("#salary_slip_overtime_rate_add").attr('readonly',true);
                            $("#overtime_rate_div_add").hide();
                          }else{
                            $("#overtime_rate_div_add").show();
                            $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                            var overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                          }

                          var overtime_type = $("#salary_slip_overtime_type_add :selected").val();
                          if(overtime_type=='Hours'){
                            $("#overtime_rate_type_show_add").text("/Hour");
                          }else{
                            $("#overtime_rate_type_show_add").text("/Day");
                          }
                          var allowance = parseFloat($("#salary_slip_allowance_add").val());
                          var deductions = parseFloat($("#salary_slip_deductions_add").val());
                          if(basic_wage_type=='Daily'){
                            var overtime_amount = parseFloat(basic_wage*overtime_rate);
                          }else{
                            var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                          }
                          $("#salary_slip_overtime_amount_add").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                          var total_basic_wage = 0;
                          if((basic_wage_type=='Monthly' && basic_wage_fixed==0) || basic_wage_type=='Daily'){
                            var present_days = parseFloat($("#salary_slip_worked_nos_add").val());
                            total_basic_wage = parseFloat(present_days*daily_rate);
                            $("#salary_slip_basic_wage_payable_amount_add").val(total_basic_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                          }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                            total_basic_wage = basic_wage;
                          }else{
                            total_basic_wage = worked_nos*basic_wage;
                          }
                          var tiffin_allowance_per_day = parseFloat("<?php echo $this->config->item('HR_salary_tiffin_allowance_per_day') ?>");
                          var salary_bonus_percent = parseFloat("<?php echo $this->config->item('HR_salary_bonus_percent') ?>");
                          var salary_hra_percent = parseFloat("<?php echo $this->config->item('HR_salary_hra_percent') ?>");
                          var salary_ceb_percent = parseFloat("<?php echo $this->config->item('HR_salary_ceb_percent') ?>");
                          var salary_el_percent = parseFloat("<?php echo $this->config->item('HR_salary_el_percent') ?>");
                          var salary_pf_percent = parseFloat("<?php echo $this->config->item('HR_salary_pf_percent') ?>");
                          var salary_esi_percent = parseFloat("<?php echo $this->config->item('HR_salary_esi_percent') ?>");

                          if(basic_wage_fixed==1){
                            var total_salary = total_basic_wage+overtime_amount;
                            var total_wage = Math.round(parseFloat(total_salary+allowance-deductions));
                          }else{
                            <?php if($this->config->item('HR_salary_slip_template_3_fields_editable')==0){ ?>
                              var tiffin_amount = tiffin_allowance_per_day*worked_nos;
                              var bonus_amount = total_basic_wage*salary_bonus_percent/100;
                              var hra_amount = total_basic_wage*salary_hra_percent/100;
                              var ceb_amount = total_basic_wage*salary_ceb_percent/100;
                              var el_amount = total_basic_wage*salary_el_percent/100;
                              var total_salary = total_basic_wage+overtime_amount+el_amount+ceb_amount+hra_amount+bonus_amount+tiffin_amount;
                              var pf_amount = Math.round(total_basic_wage*salary_pf_percent/100);
                              var esi_amount = total_salary*salary_esi_percent/100;
                              var total_wage = Math.round(parseFloat(total_salary+allowance-deductions-pf_amount-esi_amount));

                              $("#salary_slip_bonus_amount_add").val(bonus_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_tiffin_amount_add").val(tiffin_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_hra_amount_add").val(hra_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_ceb_amount_add").val(ceb_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_el_amount_add").val(el_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_pf_amount_add").val(pf_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_esi_amount_add").val(esi_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              <?php }else{ ?>
                                var tiffin_amount = parseFloat($("#salary_slip_tiffin_amount_add").val());
                                var bonus_amount = parseFloat($("#salary_slip_bonus_amount_add").val());
                                var hra_amount = parseFloat($("#salary_slip_hra_amount_add").val());
                                var ceb_amount = parseFloat($("#salary_slip_ceb_amount_add").val());
                                var el_amount = parseFloat($("#salary_slip_el_amount_add").val());
                                var total_salary = total_basic_wage+overtime_amount+el_amount+ceb_amount+hra_amount+bonus_amount+tiffin_amount;
                                var pf_amount = parseFloat($("#salary_slip_pf_amount_add").val());
                                var esi_amount = parseFloat($("#salary_slip_esi_amount_add").val());
                                var total_wage = Math.round(parseFloat(total_salary+allowance-deductions-pf_amount-esi_amount));
                                <?php } ?>
                              }
                              $("#salary_slip_total_salary_add").val(total_salary.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_total_basic_wage_add").val(total_basic_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_payable_amount_add").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              $("#salary_slip_paid_amount_add").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                              //advance
                              var advance_paid_salary =  $("#salary_slip_advance_amount_add").val();
                              var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                              $("#salary_slip_total_payable_amount_add").val(payable_inc_advance);

                              var paid_amount = parseFloat($("#salary_slip_paid_amount_add").val());
                              var balance_amount = payable_inc_advance - paid_amount;
                              $("#salary_slip_balance_amount_add").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                            }
                            function calculate_salary_edit(field_id=''){
                              var basic_wage = parseFloat($("#salary_slip_basic_wage_edit").val());
                              var basic_wage_type = $("#salary_slip_basic_wage_type_edit :selected").val();
                              if(basic_wage_type=='Hourly'){
                                $("#worked_type_edit_1").text("Worked Hours");
                                $("#worked_type_edit_2").text("Hours");
                              }else{
                                $("#worked_type_edit_1").text("Worked Days");
                                $("#worked_type_edit_2").text("Days");
                              }
                              var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_edit").val();
                              if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                                var getDaysInMonth = function(month,year) {
                                  // Here January is 1 based
                                  //Day 0 is the last day in the previous month
                                  // return new Date(year, month, 0).getDate();
                                  // Here January is 0 based
                                  return new Date(year, month+1, 0).getDate();
                                };
                                // var month = .split("-");
                                var month = new Date($('#salary_slip_month_edit').val());
                                var days = getDaysInMonth(month.getMonth(),month.getFullYear());
                                $("#salary_slip_month_days_edit").val(days);
                                var daily_working_hours = parseFloat($("#salary_slip_daily_work_hour_edit").val());
                                var hourly_rate = (basic_wage/days)/daily_working_hours;
                                var overtime_rate = hourly_rate;
                                $('#salary_slip_hourly_rate_edit_2').val(hourly_rate);
                                $('#salary_slip_hourly_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                if(field_id=='salary_slip_overtime_rate_edit'){
                                  hourly_rate = overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                                }else{
                                  $('#salary_slip_overtime_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                }
                                // $('#salary_slip_overtime_rate_edit').attr('readonly',true);
                                $('.monthly_fields_salary_edit').show();
                                $("#salary_slip_worked_nos_edit").attr('readonly',true);
                                var public_holidays = parseFloat($("#salary_slip_public_holidays_edit").val());
                                var medical_leave = parseFloat($("#salary_slip_medical_leave_edit").val());
                                var absent = parseFloat($("#salary_slip_absent_edit").val());
                                var present_days = days-public_holidays-medical_leave-absent;
                                $("#worked_type_edit_1").text("Present Days");
                                $("#salary_slip_worked_nos_edit").val(present_days);
                              }else{
                                $('.monthly_fields_salary_edit').hide();
                                $("#salary_slip_worked_nos_edit").removeAttr('readonly',true);
                                $("#salary_slip_overtime_rate_edit").removeAttr('readonly',true);
                                var overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                              }

                              var worked_nos = parseFloat($("#salary_slip_worked_nos_edit").val());
                              var overtime_nos = parseFloat($("#salary_slip_overtime_edit").val());
                              var overtime_type = $("#salary_slip_overtime_type_edit :selected").val();
                              if(overtime_type=='Hours'){
                                $("#overtime_rate_type_show_edit").text("/Hour");
                              }else{
                                $("#overtime_rate_type_show_edit").text("/Day");
                              }
                              var allowance = parseFloat($("#salary_slip_allowance_edit").val());
                              var deductions = parseFloat($("#salary_slip_deductions_edit").val());
                              var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                              $("#salary_slip_overtime_amount_edit").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                              var total_basic_wage = 0;
                              if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                                var regular_hours = daily_working_hours*worked_nos;
                                $('#salary_slip_regular_hours_edit').val(regular_hours);
                                total_basic_wage = regular_hours*hourly_rate;
                              }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                                total_basic_wage = basic_wage;
                              }else{
                                total_basic_wage = worked_nos*basic_wage;
                              }

                              var tiffin_allowance_per_day = parseFloat("<?php echo $this->config->item('HR_salary_tiffin_allowance_per_day') ?>");
                              var salary_bonus_percent = parseFloat("<?php echo $this->config->item('HR_salary_bonus_percent') ?>");
                              var salary_hra_percent = parseFloat("<?php echo $this->config->item('HR_salary_hra_percent') ?>");
                              var salary_ceb_percent = parseFloat("<?php echo $this->config->item('HR_salary_ceb_percent') ?>");
                              var salary_el_percent = parseFloat("<?php echo $this->config->item('HR_salary_el_percent') ?>");
                              var salary_pf_percent = parseFloat("<?php echo $this->config->item('HR_salary_pf_percent') ?>");
                              var salary_esi_percent = parseFloat("<?php echo $this->config->item('HR_salary_esi_percent') ?>");

                              if(basic_wage_fixed==1){
                                var total_salary = total_basic_wage+overtime_amount;
                                var total_wage = Math.round(parseFloat(total_salary+allowance-deductions));
                              }else{
                                <?php if($this->config->item('HR_salary_slip_template_3_fields_editable')==0){ ?>
                                  var tiffin_amount = tiffin_allowance_per_day*worked_nos;
                                  var bonus_amount = total_basic_wage*salary_bonus_percent/100;
                                  var hra_amount = total_basic_wage*salary_hra_percent/100;
                                  var ceb_amount = total_basic_wage*salary_ceb_percent/100;
                                  var el_amount = total_basic_wage*salary_el_percent/100;
                                  var total_salary = total_basic_wage+overtime_amount+el_amount+ceb_amount+hra_amount+bonus_amount+tiffin_amount;
                                  var pf_amount = Math.round(total_basic_wage*salary_pf_percent/100);
                                  var esi_amount = total_salary*salary_esi_percent/100;
                                  var total_wage = Math.round(parseFloat(total_salary+allowance-deductions-pf_amount-esi_amount));

                                  $("#salary_slip_bonus_amount_edit").val(bonus_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  $("#salary_slip_tiffin_amount_edit").val(tiffin_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  $("#salary_slip_hra_amount_edit").val(hra_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  $("#salary_slip_ceb_amount_edit").val(ceb_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  $("#salary_slip_el_amount_edit").val(el_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  $("#salary_slip_pf_amount_edit").val(pf_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  $("#salary_slip_esi_amount_edit").val(esi_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  <?php }else{ ?>
                                    var tiffin_amount = parseFloat($("#salary_slip_tiffin_amount_edit").val());
                                    var bonus_amount = parseFloat($("#salary_slip_bonus_amount_edit").val());
                                    var hra_amount = parseFloat($("#salary_slip_hra_amount_edit").val());
                                    var ceb_amount = parseFloat($("#salary_slip_ceb_amount_edit").val());
                                    var el_amount = parseFloat($("#salary_slip_el_amount_edit").val());
                                    var total_salary = total_basic_wage+overtime_amount+el_amount+ceb_amount+hra_amount+bonus_amount+tiffin_amount;
                                    var pf_amount = parseFloat($("#salary_slip_pf_amount_edit").val());
                                    var esi_amount = parseFloat($("#salary_slip_esi_amount_edit").val());
                                    var total_wage = Math.round(parseFloat(total_salary+allowance-deductions-pf_amount-esi_amount));
                                    <?php } ?>
                                  }

                                  $("#salary_slip_payable_amount_edit").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  $("#salary_slip_paid_amount_edit").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                                  //advance
                                  var advance_paid_salary =  $("#salary_slip_advance_amount_edit").val();
                                  var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                                  $("#salary_slip_total_payable_amount_edit").val(payable_inc_advance);

                                  var paid_amount = parseFloat($("#salary_slip_paid_amount_edit").val());
                                  var balance_amount = payable_inc_advance - paid_amount;
                                  $("#salary_slip_balance_amount_edit").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                }
                                <?php }elseif($this->config->item('HR_salary_slip_template')==4){ ?>
                                  $('.monthly_fields_salary_add').hide();
                                  function calculate_salary_add(field_id=''){
                                    var basic_wage = parseFloat($("#salary_slip_basic_wage_add").val());
                                    var basic_wage_type = $("#salary_slip_basic_wage_type_add :selected").val();
                                    if(basic_wage_type=='Hourly'){
                                      $("#worked_type_add_1").text("Worked Hours");
                                      $("#worked_type_add_2").text("Hours");
                                    }else{
                                      $("#worked_type_add_1").text("Worked Days");
                                      $("#worked_type_add_2").text("Days");
                                    }
                                    var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_add").val();
                                    if((basic_wage_type=='Monthly' && basic_wage_fixed==0) || basic_wage_type=='Daily'){
                                      var getDaysInMonth = function(month,year) {
                                        // Here January is 1 based
                                        //Day 0 is the last day in the previous month
                                        // return new Date(year, month, 0).getDate();
                                        // Here January is 0 based
                                        return new Date(year, month+1, 0).getDate();
                                      };
                                      // var month = .split("-");
                                      var month = new Date($('#salary_slip_month_add').val());
                                      // var days = 30; //30 Days Fixed for All Month
                                      $("#salary_slip_worked_nos_add").attr('max',30);
                                      // $("#salary_slip_month_days_add").val(days);
                                      var days = $("#salary_slip_month_days_add").val();
                                      if(basic_wage_type=='Daily'){
                                        var daily_rate = basic_wage;
                                      }else{
                                        var daily_rate = (basic_wage/days);
                                      }
                                      var hourly_rate = 0;
                                      $('#salary_slip_hourly_rate_add_2').val(hourly_rate);
                                      $('#salary_slip_hourly_rate_add').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $('.monthly_fields_salary_add').show();
                                      $("#worked_type_add_1").text("Present Days");
                                    }else{
                                      $('.monthly_fields_salary_add').hide();
                                      $("#salary_slip_worked_nos_add").removeAttr('readonly',true);
                                      $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                                    }


                                    var worked_nos = parseFloat($("#salary_slip_worked_nos_add").val());
                                    var overtime_nos = parseFloat($("#salary_slip_overtime_add").val());
                                    if(basic_wage_type=='Daily'){
                                      var overtime_extra_free = 1;
                                      overtime_nos = overtime_nos*overtime_extra_free;
                                      var daily_working_hours = parseFloat("<?php echo $this->config->item('HR_total_duty_hours_employee') ?>");
                                      var overtime_rate = overtime_nos/daily_working_hours;
                                      var hourly_rate = 0;
                                      if(field_id=='salary_slip_overtime_rate_add'){
                                        hourly_rate = overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                                      }else{
                                        $("#salary_slip_overtime_rate_add").val(overtime_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      }
                                      $("#salary_slip_overtime_rate_info_add").html("(<?php echo $this->config->item("Currency_currency_format")?>"+overtime_rate+"/Hr)");
                                      // $("#salary_slip_overtime_rate_add").attr('readonly',true);
                                      $("#overtime_rate_div_add").hide();
                                    }else{
                                      $("#overtime_rate_div_add").show();
                                      $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                                      var overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                                    }

                                    var overtime_type = $("#salary_slip_overtime_type_add :selected").val();
                                    if(overtime_type=='Hours'){
                                      $("#overtime_rate_type_show_add").text("/Hour");
                                    }else{
                                      $("#overtime_rate_type_show_add").text("/Day");
                                    }
                                    var allowance = parseFloat($("#salary_slip_allowance_add").val());
                                    var deductions = parseFloat($("#salary_slip_deductions_add").val());
                                    if(basic_wage_type=='Daily'){
                                      var overtime_amount = parseFloat(basic_wage*overtime_rate);
                                    }else{
                                      var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                                    }
                                    $("#salary_slip_overtime_amount_add").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    var total_basic_wage = 0;
                                    var salary_hra_percent = parseFloat("<?php echo $this->config->item('HR_salary_hra_percent') ?>");
                                    var salary_conveyance_allowance_percent = parseFloat("<?php echo $this->config->item('HR_salary_conveyance_allowance_percent') ?>");
                                    var salary_special_allowance_percent = parseFloat("<?php echo $this->config->item('HR_salary_special_allowance_percent') ?>");
                                    var salary_city_compensatory_allowance_percent = parseFloat("<?php echo $this->config->item('HR_salary_city_compensatory_allowance_percent') ?>");
                                    var salary_basic_salary_percent = parseFloat("<?php echo $this->config->item('HR_salary_basic_salary_percent') ?>");
                                    var salary_pf_percent = parseFloat("<?php echo $this->config->item('HR_salary_pf_percent') ?>");
                                    var salary_esi_percent = parseFloat("<?php echo $this->config->item('HR_salary_esi_percent') ?>");

                                    if((basic_wage_type=='Monthly' && basic_wage_fixed==0) || basic_wage_type=='Daily'){
                                      var present_days = parseFloat($("#salary_slip_worked_nos_add").val());
                                      total_basic_wage = parseFloat(basic_wage*salary_basic_salary_percent/100);
                                      $("#salary_slip_basic_wage_payable_amount_add").val(total_basic_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                                      total_basic_wage = basic_wage;
                                    }else{
                                      total_basic_wage = worked_nos*basic_wage;
                                    }

                                    if(basic_wage_fixed==1){
                                      var total_salary = total_basic_wage+overtime_amount;
                                      var total_wage = Math.round(parseFloat(total_salary+allowance-deductions));
                                    }else{

                                      var hra_amount = basic_wage*salary_hra_percent/100;
                                      var conveyance_allowance_amount = basic_wage*salary_conveyance_allowance_percent/100;
                                      var special_allowance_amount = basic_wage*salary_special_allowance_percent/100;
                                      var city_compensatory_amount = basic_wage*salary_city_compensatory_allowance_percent/100;
                                      var max_payable_days = parseFloat($("#salary_slip_max_payable_days_add").val());
                                      var lwp_days = parseFloat($("#salary_slip_lwp_days_add").val());
                                      var per_day_salary = Math.round(basic_wage/max_payable_days);
                                      var lwp_amount = per_day_salary*lwp_days;

                                      var total_salary = basic_wage;
                                      var pf_amount = Math.round(total_basic_wage*salary_pf_percent/100);
                                      var esi_amount = total_salary*salary_esi_percent/100;
                                      var total_wage = Math.round(parseFloat(total_salary-lwp_amount+allowance-deductions-pf_amount-esi_amount));

                                      $("#salary_slip_hra_amount_add").val(hra_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_conv_allowance_amt_add").val(conveyance_allowance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_special_allowance_amount_add").val(special_allowance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_city_compensatory_amount_add").val(city_compensatory_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_lwp_amount_add").val(lwp_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_pf_amount_add").val(pf_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_esi_amount_add").val(esi_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    }
                                    $("#salary_slip_total_salary_add").val(total_salary.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    $("#salary_slip_total_basic_wage_add").val(total_basic_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    $("#salary_slip_payable_amount_add").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    $("#salary_slip_paid_amount_add").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                                    //advance
                                    var advance_paid_salary =  $("#salary_slip_advance_amount_add").val();
                                    var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                                    $("#salary_slip_total_payable_amount_add").val(payable_inc_advance);

                                    var paid_amount = parseFloat($("#salary_slip_paid_amount_add").val());
                                    var balance_amount = payable_inc_advance - paid_amount;
                                    $("#salary_slip_balance_amount_add").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  }
                                  function calculate_salary_edit(field_id=''){
                                    var basic_wage = parseFloat($("#salary_slip_basic_wage_edit").val());
                                    var basic_wage_type = $("#salary_slip_basic_wage_type_edit :selected").val();
                                    if(basic_wage_type=='Hourly'){
                                      $("#worked_type_edit_1").text("Worked Hours");
                                      $("#worked_type_edit_2").text("Hours");
                                    }else{
                                      $("#worked_type_edit_1").text("Worked Days");
                                      $("#worked_type_edit_2").text("Days");
                                    }
                                    var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_edit").val();
                                    if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                                      var getDaysInMonth = function(month,year) {
                                        // Here January is 1 based
                                        //Day 0 is the last day in the previous month
                                        // return new Date(year, month, 0).getDate();
                                        // Here January is 0 based
                                        return new Date(year, month+1, 0).getDate();
                                      };
                                      // var month = .split("-");
                                      var month = new Date($('#salary_slip_month_edit').val());
                                      var days = getDaysInMonth(month.getMonth(),month.getFullYear());
                                      $("#salary_slip_month_days_edit").val(days);
                                      var daily_working_hours = parseFloat($("#salary_slip_daily_work_hour_edit").val());
                                      var hourly_rate = (basic_wage/days)/daily_working_hours;
                                      var overtime_rate = hourly_rate;
                                      $('#salary_slip_hourly_rate_edit_2').val(hourly_rate);
                                      $('#salary_slip_hourly_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      if(field_id=='salary_slip_overtime_rate_edit'){
                                        hourly_rate = overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                                      }else{
                                        $('#salary_slip_overtime_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      }
                                      // $('#salary_slip_overtime_rate_edit').attr('readonly',true);
                                      $('.monthly_fields_salary_edit').show();
                                      $("#salary_slip_worked_nos_edit").attr('readonly',true);
                                      var public_holidays = parseFloat($("#salary_slip_public_holidays_edit").val());
                                      var medical_leave = parseFloat($("#salary_slip_medical_leave_edit").val());
                                      var absent = parseFloat($("#salary_slip_absent_edit").val());
                                      var present_days = days-public_holidays-medical_leave-absent;
                                      $("#worked_type_edit_1").text("Present Days");
                                      $("#salary_slip_worked_nos_edit").val(present_days);
                                      console.log("Month"+month);
                                      console.log("days"+days);
                                      console.log("daily_working_hours"+daily_working_hours);
                                      console.log("public_holidays"+public_holidays);
                                      console.log("medical_leave"+medical_leave);
                                      console.log("absent"+absent);
                                      console.log("present_days"+present_days);
                                    }else{
                                      $('.monthly_fields_salary_edit').hide();
                                      $("#salary_slip_worked_nos_edit").removeAttr('readonly',true);
                                      $("#salary_slip_overtime_rate_edit").removeAttr('readonly',true);
                                      var overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                                    }

                                    var worked_nos = parseFloat($("#salary_slip_worked_nos_edit").val());
                                    var overtime_nos = parseFloat($("#salary_slip_overtime_edit").val());
                                    var overtime_type = $("#salary_slip_overtime_type_edit :selected").val();
                                    if(overtime_type=='Hours'){
                                      $("#overtime_rate_type_show_edit").text("/Hour");
                                    }else{
                                      $("#overtime_rate_type_show_edit").text("/Day");
                                    }
                                    var allowance = parseFloat($("#salary_slip_allowance_edit").val());
                                    var deductions = parseFloat($("#salary_slip_deductions_edit").val());
                                    var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                                    $("#salary_slip_overtime_amount_edit").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    var total_basic_wage = 0;
                                    if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                                      var regular_hours = daily_working_hours*worked_nos;
                                      $('#salary_slip_regular_hours_edit').val(regular_hours);
                                      total_basic_wage = regular_hours*hourly_rate;
                                    }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                                      total_basic_wage = basic_wage;
                                    }else{
                                      total_basic_wage = worked_nos*basic_wage;
                                    }

                                    var tiffin_allowance_per_day = parseFloat("<?php echo $this->config->item('HR_salary_tiffin_allowance_per_day') ?>");
                                    var salary_bonus_percent = parseFloat("<?php echo $this->config->item('HR_salary_bonus_percent') ?>");
                                    var salary_hra_percent = parseFloat("<?php echo $this->config->item('HR_salary_hra_percent') ?>");
                                    var salary_ceb_percent = parseFloat("<?php echo $this->config->item('HR_salary_ceb_percent') ?>");
                                    var salary_el_percent = parseFloat("<?php echo $this->config->item('HR_salary_el_percent') ?>");
                                    var salary_pf_percent = parseFloat("<?php echo $this->config->item('HR_salary_pf_percent') ?>");
                                    var salary_esi_percent = parseFloat("<?php echo $this->config->item('HR_salary_esi_percent') ?>");

                                    var tiffin_amount = tiffin_allowance_per_day*worked_nos;
                                    var bonus_amount = total_basic_wage*salary_bonus_percent/100;
                                    var hra_amount = total_basic_wage*salary_hra_percent/100;
                                    var ceb_amount = total_basic_wage*salary_ceb_percent/100;
                                    var el_amount = total_basic_wage*salary_el_percent/100;
                                    var total_salary = total_basic_wage+overtime_amount+el_amount+ceb_amount+hra_amount+bonus_amount+tiffin_amount;

                                    var pf_amount = Math.round(total_basic_wage*salary_pf_percent/100);
                                    var esi_amount = total_salary*salary_esi_percent/100;

                                    var total_wage = Math.round(parseFloat(total_salary+allowance-deductions-pf_amount-esi_amount));

                                    var total_wage = parseFloat(total_basic_wage+overtime_amount+allowance-deductions);
                                    $("#salary_slip_payable_amount_edit").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    $("#salary_slip_paid_amount_edit").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                                    //advance
                                    var advance_paid_salary =  $("#salary_slip_advance_amount_edit").val();
                                    var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                                    $("#salary_slip_total_payable_amount_edit").val(payable_inc_advance);

                                    var paid_amount = parseFloat($("#salary_slip_paid_amount_edit").val());
                                    var balance_amount = payable_inc_advance - paid_amount;
                                    $("#salary_slip_balance_amount_edit").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                  }
                                  <?php }elseif($this->config->item('HR_salary_slip_template')==5){ ?>
                                    $('.monthly_fields_salary_add').hide();
                                    function calculate_salary_add(field_id=''){
                                      var basic_wage = parseFloat($("#salary_slip_basic_wage_add").val());
                                      $("#salary_slip_total_basic_wage_add").val(basic_wage);
                                      var basic_wage_type = $("#salary_slip_basic_wage_type_add :selected").val();
                                      if(basic_wage_type=='Hourly'){
                                        $("#worked_type_add_1").text("Worked Hours");
                                        $("#worked_type_add_2").text("Hours");
                                      }else{
                                        $("#worked_type_add_1").text("Worked Days");
                                        $("#worked_type_add_2").text("Days");
                                      }
                                      var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_add").val();
                                      // if((basic_wage_type=='Monthly' && basic_wage_fixed==0) || basic_wage_type=='Daily'){
                                      var getDaysInMonth = function(month,year) {
                                        // Here January is 1 based
                                        //Day 0 is the last day in the previous month
                                        // return new Date(year, month, 0).getDate();
                                        // Here January is 0 based
                                        return new Date(year, month+1, 0).getDate();
                                      };
                                      // var month = .split("-");
                                      var month = new Date($('#salary_slip_month_add').val());
                                      // var days = 30; //30 Days Fixed for All Month
                                      $("#salary_slip_worked_nos_add").attr('max',30);
                                      // $("#salary_slip_month_days_add").val(days);
                                      var days = $("#salary_slip_month_days_add").val();
                                      if(basic_wage_type=='Daily'){
                                        var daily_rate = basic_wage;
                                      }else{
                                        var daily_rate = (basic_wage/days);
                                      }
                                      var hourly_rate = 0;
                                      $('#salary_slip_hourly_rate_add_2').val(hourly_rate);
                                      $('#salary_slip_hourly_rate_add').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $('.monthly_fields_salary_add').show();
                                      $("#worked_type_add_1").text("Present Days");
                                      // }else{
                                      //   $('.monthly_fields_salary_add').hide();
                                      //   $("#salary_slip_worked_nos_add").removeAttr('readonly',true);
                                      //   $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                                      // }


                                      var worked_nos = parseFloat($("#salary_slip_worked_nos_add").val());
                                      var overtime_nos = parseFloat($("#salary_slip_overtime_add").val());
                                      if(basic_wage_type=='Daily'){
                                        var overtime_extra_free = 1;
                                        overtime_nos = overtime_nos*overtime_extra_free;
                                        var daily_working_hours = parseFloat("<?php echo $this->config->item('HR_total_duty_hours_employee') ?>");
                                        var overtime_rate = overtime_nos/daily_working_hours;
                                        var hourly_rate = 0;
                                        if(field_id=='salary_slip_overtime_rate_add'){
                                          hourly_rate = overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                                        }else{
                                          $("#salary_slip_overtime_rate_add").val(overtime_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                        }
                                        $("#salary_slip_overtime_rate_info_add").html("(<?php echo $this->config->item("Currency_currency_format")?>"+overtime_rate+"/Hr)");
                                        // $("#salary_slip_overtime_rate_add").attr('readonly',true);
                                        $("#overtime_rate_div_add").hide();
                                      }else{
                                        $("#overtime_rate_div_add").show();
                                        $("#salary_slip_overtime_rate_add").removeAttr('readonly',true);
                                        var overtime_rate = parseFloat($("#salary_slip_overtime_rate_add").val());
                                      }

                                      var overtime_type = $("#salary_slip_overtime_type_add :selected").val();
                                      if(overtime_type=='Hours'){
                                        $("#overtime_rate_type_show_add").text("/Hour");
                                      }else{
                                        $("#overtime_rate_type_show_add").text("/Day");
                                      }
                                      var allowance = parseFloat($("#salary_slip_allowance_add").val());
                                      var deductions = parseFloat($("#salary_slip_deductions_add").val());
                                      if(basic_wage_type=='Daily'){
                                        var overtime_amount = parseFloat(basic_wage*overtime_rate);
                                      }else{
                                        var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                                      }
                                      $("#salary_slip_overtime_amount_add").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      var total_basic_wage = 0;

                                      total_basic_wage = basic_wage;

                                      var hra_amount = parseFloat($("#salary_slip_hra_amount_add").val());
                                      var conveyance_allowance_amount = parseFloat($("#salary_slip_conv_allowance_amt_add").val());
                                      var batta_amount = parseFloat($("#salary_slip_batta_amount_add").val());
                                      var holiday_worked_amount = parseFloat($("#salary_slip_holiday_worked_amount_add").val());
                                      var stay_days_amount = parseFloat($("#salary_slip_stay_days_amount_add").val());
                                      var travel_allowance = parseFloat($("#salary_slip_travel_allowance_add").val());
                                      var file_balance_addition = parseFloat($("#salary_slip_file_balance_addition_add").val());
                                      var others_addition = parseFloat($("#salary_slip_others_addition_add").val());

                                      var total_salary = basic_wage+overtime_amount+hra_amount+conveyance_allowance_amount+batta_amount+holiday_worked_amount+stay_days_amount+travel_allowance+file_balance_addition+others_addition;
                                      $("#salary_slip_total_salary_add").val(total_salary.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                                      var salary_advance = parseFloat($("#salary_slip_advance_amount_add").val());
                                      var paid_batta_amount = parseFloat($("#salary_slip_paid_batta_add").val());
                                      var leave_deduction = parseFloat($("#salary_slip_leave_amount_add").val());
                                      var no_work_deduction = parseFloat($("#salary_slip_no_work_days_amount_add").val());
                                      var bonus_amount = parseFloat($("#salary_slip_bonus_amount_add").val());
                                      var deposit_amount = parseFloat($("#salary_slip_deposit_amount_add").val());
                                      var loan_amount = parseFloat($("#salary_slip_loan_amount_add").val());
                                      var esi_amount = parseFloat($("#salary_slip_esi_amount_add").val());
                                      var pf_amount = parseFloat($("#salary_slip_pf_amount_add").val());
                                      var charity_amount = parseFloat($("#salary_slip_charity_amount_add").val());
                                      var file_balance_ded = parseFloat($("#salary_slip_file_balance_ded_add").val());
                                      var other_deductions = parseFloat($("#salary_slip_others_ded_add").val());
                                      var total_deductions = salary_advance+paid_batta_amount+leave_deduction+no_work_deduction+bonus_amount+deposit_amount+loan_amount+esi_amount+pf_amount+charity_amount+file_balance_ded+other_deductions;
                                      $("#salary_slip_total_deductions_add").val(total_deductions.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                                      var balance_salary = Math.round(parseFloat(total_salary-total_deductions));

                                      $("#salary_slip_balance_salary_add").val(balance_salary.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_paid_amount_add").attr('max',balance_salary.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                                    }
                                    function calculate_salary_edit(field_id=''){
                                      var basic_wage = parseFloat($("#salary_slip_basic_wage_edit").val());
                                      var basic_wage_type = $("#salary_slip_basic_wage_type_edit :selected").val();
                                      if(basic_wage_type=='Hourly'){
                                        $("#worked_type_edit_1").text("Worked Hours");
                                        $("#worked_type_edit_2").text("Hours");
                                      }else{
                                        $("#worked_type_edit_1").text("Worked Days");
                                        $("#worked_type_edit_2").text("Days");
                                      }
                                      var basic_wage_fixed = $("#salary_slip_basic_wage_fixed_edit").val();
                                      if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                                        var getDaysInMonth = function(month,year) {
                                          // Here January is 1 based
                                          //Day 0 is the last day in the previous month
                                          // return new Date(year, month, 0).getDate();
                                          // Here January is 0 based
                                          return new Date(year, month+1, 0).getDate();
                                        };
                                        // var month = .split("-");
                                        var month = new Date($('#salary_slip_month_edit').val());
                                        var days = getDaysInMonth(month.getMonth(),month.getFullYear());
                                        $("#salary_slip_month_days_edit").val(days);
                                        var daily_working_hours = parseFloat($("#salary_slip_daily_work_hour_edit").val());
                                        var hourly_rate = (basic_wage/days)/daily_working_hours;
                                        var overtime_rate = hourly_rate;
                                        $('#salary_slip_hourly_rate_edit_2').val(hourly_rate);
                                        $('#salary_slip_hourly_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                        if(field_id=='salary_slip_overtime_rate_edit'){
                                          hourly_rate = overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                                        }else{
                                          $('#salary_slip_overtime_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                        }
                                        // $('#salary_slip_overtime_rate_edit').attr('readonly',true);
                                        $('.monthly_fields_salary_edit').show();
                                        $("#salary_slip_worked_nos_edit").attr('readonly',true);
                                        var public_holidays = parseFloat($("#salary_slip_public_holidays_edit").val());
                                        var medical_leave = parseFloat($("#salary_slip_medical_leave_edit").val());
                                        var absent = parseFloat($("#salary_slip_absent_edit").val());
                                        var present_days = days-public_holidays-medical_leave-absent;
                                        $("#worked_type_edit_1").text("Present Days");
                                        $("#salary_slip_worked_nos_edit").val(present_days);
                                        console.log("Month"+month);
                                        console.log("days"+days);
                                        console.log("daily_working_hours"+daily_working_hours);
                                        console.log("public_holidays"+public_holidays);
                                        console.log("medical_leave"+medical_leave);
                                        console.log("absent"+absent);
                                        console.log("present_days"+present_days);
                                      }else{
                                        $('.monthly_fields_salary_edit').hide();
                                        $("#salary_slip_worked_nos_edit").removeAttr('readonly',true);
                                        $("#salary_slip_overtime_rate_edit").removeAttr('readonly',true);
                                        var overtime_rate = parseFloat($("#salary_slip_overtime_rate_edit").val());
                                      }

                                      var worked_nos = parseFloat($("#salary_slip_worked_nos_edit").val());
                                      var overtime_nos = parseFloat($("#salary_slip_overtime_edit").val());
                                      var overtime_type = $("#salary_slip_overtime_type_edit :selected").val();
                                      if(overtime_type=='Hours'){
                                        $("#overtime_rate_type_show_edit").text("/Hour");
                                      }else{
                                        $("#overtime_rate_type_show_edit").text("/Day");
                                      }
                                      var allowance = parseFloat($("#salary_slip_allowance_edit").val());
                                      var deductions = parseFloat($("#salary_slip_deductions_edit").val());
                                      var overtime_amount = parseFloat(overtime_rate*overtime_nos);
                                      $("#salary_slip_overtime_amount_edit").val(overtime_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      var total_basic_wage = 0;
                                      if(basic_wage_type=='Monthly' && basic_wage_fixed==0){
                                        var regular_hours = daily_working_hours*worked_nos;
                                        $('#salary_slip_regular_hours_edit').val(regular_hours);
                                        total_basic_wage = regular_hours*hourly_rate;
                                      }else if(basic_wage_type=='Monthly' && basic_wage_fixed==1){
                                        total_basic_wage = basic_wage;
                                      }else{
                                        total_basic_wage = worked_nos*basic_wage;
                                      }

                                      var tiffin_allowance_per_day = parseFloat("<?php echo $this->config->item('HR_salary_tiffin_allowance_per_day') ?>");
                                      var salary_bonus_percent = parseFloat("<?php echo $this->config->item('HR_salary_bonus_percent') ?>");
                                      var salary_hra_percent = parseFloat("<?php echo $this->config->item('HR_salary_hra_percent') ?>");
                                      var salary_ceb_percent = parseFloat("<?php echo $this->config->item('HR_salary_ceb_percent') ?>");
                                      var salary_el_percent = parseFloat("<?php echo $this->config->item('HR_salary_el_percent') ?>");
                                      var salary_pf_percent = parseFloat("<?php echo $this->config->item('HR_salary_pf_percent') ?>");
                                      var salary_esi_percent = parseFloat("<?php echo $this->config->item('HR_salary_esi_percent') ?>");

                                      var tiffin_amount = tiffin_allowance_per_day*worked_nos;
                                      var bonus_amount = total_basic_wage*salary_bonus_percent/100;
                                      var hra_amount = total_basic_wage*salary_hra_percent/100;
                                      var ceb_amount = total_basic_wage*salary_ceb_percent/100;
                                      var el_amount = total_basic_wage*salary_el_percent/100;
                                      var total_salary = total_basic_wage+overtime_amount+el_amount+ceb_amount+hra_amount+bonus_amount+tiffin_amount;

                                      var pf_amount = Math.round(total_basic_wage*salary_pf_percent/100);
                                      var esi_amount = total_salary*salary_esi_percent/100;

                                      var total_wage = Math.round(parseFloat(total_salary+allowance-deductions-pf_amount-esi_amount));

                                      var total_wage = parseFloat(total_basic_wage+overtime_amount+allowance-deductions);
                                      $("#salary_slip_payable_amount_edit").val(total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                      $("#salary_slip_paid_amount_edit").attr('max',total_wage.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));

                                      //advance
                                      var advance_paid_salary =  $("#salary_slip_advance_amount_edit").val();
                                      var payable_inc_advance = (total_wage - advance_paid_salary).toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>);
                                      $("#salary_slip_total_payable_amount_edit").val(payable_inc_advance);

                                      var paid_amount = parseFloat($("#salary_slip_paid_amount_edit").val());
                                      var balance_amount = payable_inc_advance - paid_amount;
                                      $("#salary_slip_balance_amount_edit").val(balance_amount.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                    }
                                    <?php } ?>
                                    $('body').on('change', '#salary_slip_employee_add', function() {
                                      var employee_id=$('#salary_slip_employee_add :selected').val();
                                      $.post("<?php echo base_url() ?>employees/select_details",{employee_id:employee_id},function(data) {
                                        var obj = $.parseJSON(data);
                                        var i=0;
                                        if(obj.count==1) {
                                          if(obj.basic_wage_fixed==1){
                                            $("#salary_slip_basic_wage_add").attr('readonly',true);
                                          }else{
                                            $("#salary_slip_basic_wage_add").removeAttr('readonly',true);
                                          }
                                          $("#salary_slip_basic_wage_add").val(obj.basic_wage);
                                          $("#salary_slip_total_basic_wage_add").val(obj.basic_wage);
                                          $("#salary_slip_basic_wage_fixed_add").val(obj.basic_wage_fixed);
                                          $("#salary_slip_basic_wage_type_add").val(obj.basic_wage_type).trigger('change');
                                          calculate_salary_add($(this).attr('id'));
                                        }
                                      })
                                    })
                                    $('body').on('change', '#salary_slip_employee_edit', function() {
                                      var employee_id=$('#salary_slip_employee_edit :selected').val();
                                      $.post("<?php echo base_url() ?>employees/select_details",{employee_id:employee_id},function(data) {
                                        var obj = $.parseJSON(data);
                                        var i=0;
                                        if(obj.count==1) {
                                          if(obj.basic_wage_fixed==1){
                                            $("#salary_slip_basic_wage_edit").attr('readonly',true);
                                          }else{
                                            $("#salary_slip_basic_wage_edit").removeAttr('readonly',true);
                                          }
                                          $("#salary_slip_basic_wage_edit").val(obj.basic_wage);
                                          $("#salary_slip_basic_wage_fixed_edit").val(obj.basic_wage_fixed);
                                          $("#salary_slip_basic_wage_type_edit").val(obj.basic_wage_type).trigger('change');
                                          calculate_salary_edit($(this).attr('id'));
                                        }
                                      })
                                    })

                                    $('body').on('change keyup', '.salary_add_calculate_fields', function() {
                                      if($(this).val()==''){
                                        $(this).val(0);
                                      }
                                      calculate_salary_add($(this).attr('id'));
                                    })
                                    $('body').on('change keyup', '.salary_edit_calculate_fields', function() {
                                      if($(this).val()==''){
                                        $(this).val(0);
                                      }
                                      calculate_salary_edit($(this).attr('id'));
                                    })

                                    $('body').on('click', '#salary_slip_edit_btn', function() {
                                      var no = $(this).closest('tr').children('td');
                                      <?php if($this->config->item('HR_salary_slip_template')!=3){ ?>
                                        $('#salary_slip_id_edit').val(no.eq(25).text());
                                        var slip_type=no.eq(29).text();
                                        var basic_wage_type = no.eq(31).text();
                                        var basic_wage_fixed = parseFloat(no.eq(36).text());
                                        var holidays = parseFloat(no.eq(37).text());
                                        var medical_leave = parseFloat(no.eq(38).text());
                                        var absent = parseFloat(no.eq(39).text());
                                        var month_days = parseFloat(no.eq(40).text());
                                        var hourly_rate = parseFloat(no.eq(41).text());
                                        var regular_hours = parseFloat(no.eq(42).text());
                                        var daily_work_hour = parseFloat(no.eq(43).text());
                                        if(slip_type=="Office"){
                                          $("#salary_slip_work_div_edit").hide();
                                          $("#salary_slip_work_edit").removeAttr('required',true);
                                        }else{
                                          $('#salary_slip_work_edit').val(no.eq(27).text()).trigger('change');
                                          $("#salary_slip_work_div_edit").show();
                                          $("#salary_slip_work_edit").attr('required',true);
                                        }
                                        $("input[name=salary_slip_type_edit][value=" + slip_type + "]").prop('checked', true);
                                        $('#salary_slip_month_edit').datepicker("setDate", no.eq(28).text());
                                        $('#salary_slip_employee_edit').val(no.eq(26).text()).trigger('change');
                                        $('#salary_slip_basic_wage_edit').val(no.eq(30).text());
                                        $('#salary_slip_basic_wage_type_edit').val(no.eq(31).text()).trigger('change');
                                        $('#salary_slip_worked_nos_edit').val(no.eq(35).text());

                                        $('#salary_slip_overtime_edit').val(no.eq(32).text());
                                        $('#salary_slip_overtime_type_edit').val(no.eq(33).text()).trigger('change');
                                        $('#salary_slip_overtime_rate_edit').val(no.eq(34).text());
                                        $('#salary_slip_overtime_amount_edit').val(no.eq(11).text());
                                        $('#salary_slip_basic_amount_edit').val(no.eq(12).text());
                                        $('#salary_slip_allowance_edit').val(no.eq(12).text());

                                        $('#salary_slip_incentive_edit').val(no.eq(13).text());
                                        $('#salary_slip_bonus_edit').val(no.eq(14).text());

                                        $('#salary_slip_deductions_edit').val(no.eq(15).text());

                                        $('#salary_slip_advance_amount_edit').val(no.eq(17).text());
                                        $('#salary_slip_payable_amount_edit').val(no.eq(16).text());

                                        $('#salary_slip_remarks_edit').val(no.eq(22).text());

                                        $('#salary_slip_total_paid_edit').val(no.eq(19).text());
                                        $('#salary_slip_balance_edit').val(no.eq(20).text());

                                        $('#salary_slip_month_days_edit').val(month_days);
                                        $('#salary_slip_public_holidays_edit').val(holidays);
                                        $('#salary_slip_medical_leave_edit').val(medical_leave);
                                        $('#salary_slip_absent_edit').val(absent);
                                        $('#salary_slip_hourly_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                        $('#salary_slip_daily_work_hour_edit').val(daily_work_hour);
                                        $('#salary_slip_basic_wage_fixed_edit').val(basic_wage_fixed);
                                        $('#salary_slip_hourly_rate_edit_2').val(hourly_rate);
                                        $('#salary_slip_regular_hours_edit').val(regular_hours);
                                        $("#salary_slip_hourly_rate_edit_info").text("* "+daily_work_hour+" Hours in a Day");
                                        if(basic_wage_type=='Hourly'){
                                          $("#worked_type_edit_1").text("Worked Hours");
                                          $("#worked_type_edit_2").text("Hours");
                                        }else{
                                          $("#worked_type_edit_1").text("Worked Days");
                                          $("#worked_type_edit_2").text("Days");
                                        }
                                        var overtime_type = no.eq(32).text();
                                        if(overtime_type=='Hours'){
                                          $("#overtime_rate_type_show_edit").text("/Hour");
                                        }else{
                                          $("#overtime_rate_type_show_edit").text("/Day");
                                        }
                                        <?php }else{ ?>
                                          $('#salary_slip_id_edit').val(no.eq(33).text());
                                          var slip_type=no.eq(37).text();
                                          var basic_wage_type = no.eq(39).text();
                                          var basic_wage_fixed = parseFloat(no.eq(44).text());
                                          var holidays = parseFloat(no.eq(45).text());
                                          var medical_leave = parseFloat(no.eq(46).text());
                                          var absent = parseFloat(no.eq(47).text());
                                          var month_days = parseFloat(no.eq(48).text());
                                          var hourly_rate = parseFloat(no.eq(49).text());
                                          var regular_hours = parseFloat(no.eq(50).text());
                                          var daily_work_hour = parseFloat(no.eq(51).text());
                                          if(slip_type=="Office"){
                                            $("#salary_slip_work_div_edit").hide();
                                            $("#salary_slip_work_edit").removeAttr('required',true);
                                          }else{
                                            $('#salary_slip_work_edit').val(no.eq(35).text()).trigger('change');
                                            $("#salary_slip_work_div_edit").show();
                                            $("#salary_slip_work_edit").attr('required',true);
                                          }
                                          $("input[name=salary_slip_type_edit][value=" + slip_type + "]").prop('checked', true);
                                          $('#salary_slip_month_edit').datepicker("setDate", no.eq(36).text());

                                          $('#salary_slip_basic_wage_edit').val(no.eq(38).text());
                                          $('#salary_slip_basic_wage_type_edit').val(no.eq(39).text()).trigger('change');
                                          $('#salary_slip_worked_nos_edit').val(no.eq(43).text());
                                          $('#salary_slip_overtime_edit').val(no.eq(40).text());
                                          $('#salary_slip_overtime_type_edit').val(no.eq(41).text()).trigger('change');
                                          $('#salary_slip_overtime_rate_edit').val(no.eq(42).text());
                                          $('#salary_slip_overtime_amount_edit').val(no.eq(21).text());
                                          $('#salary_slip_basic_amount_edit').val(no.eq(22).text());
                                          $('#salary_slip_allowance_edit').val(no.eq(22).text());
                                          $('#salary_slip_deductions_edit').val(no.eq(23).text());

                                          $('#salary_slip_advance_amount_edit').val(no.eq(25).text());
                                          $('#salary_slip_payable_amount_edit').val(no.eq(24).text());

                                          $('#salary_slip_remarks_edit').val(no.eq(30).text());

                                          $('#salary_slip_total_paid_edit').val(no.eq(26).text());
                                          $('#salary_slip_balance_edit').val(no.eq(27).text());

                                          $('#salary_slip_month_days_edit').val(month_days);
                                          $('#salary_slip_public_holidays_edit').val(holidays);
                                          $('#salary_slip_medical_leave_edit').val(medical_leave);
                                          $('#salary_slip_absent_edit').val(absent);
                                          $('#salary_slip_hourly_rate_edit').val(hourly_rate.toFixed(<?php echo $this->config->item('Currency_amount_decimals_2')?>));
                                          $('#salary_slip_daily_work_hour_edit').val(daily_work_hour);
                                          $('#salary_slip_basic_wage_fixed_edit').val(basic_wage_fixed);
                                          $('#salary_slip_hourly_rate_edit_2').val(hourly_rate);
                                          $('#salary_slip_regular_hours_edit').val(regular_hours);
                                          $("#salary_slip_hourly_rate_edit_info").text("* "+daily_work_hour+" Hours in a Day");
                                          if(basic_wage_type=='Hourly'){
                                            $("#worked_type_edit_1").text("Worked Hours");
                                            $("#worked_type_edit_2").text("Hours");
                                          }else{
                                            $("#worked_type_edit_1").text("Worked Days");
                                            $("#worked_type_edit_2").text("Days");
                                          }
                                          var overtime_type = no.eq(40).text();
                                          if(overtime_type=='Hours'){
                                            $("#overtime_rate_type_show_edit").text("/Hour");
                                          }else{
                                            $("#overtime_rate_type_show_edit").text("/Day");
                                          }
                                          $('#salary_slip_employee_edit').val(no.eq(34).text()).trigger('change');
                                          calculate_salary_edit();
                                          <?php } ?>
                                        })
                                        $('body').on('click', '#salary_slip_delete_btn', function() {
                                          var no = $(this).closest('tr').children('td');
                                          <?php if($this->config->item('HR_salary_slip_template')!=3){ ?>
                                            $('#salary_slip_id_delete').val(no.eq(25).text());
                                            <?php }else{ ?>
                                              $('#salary_slip_id_delete').val(no.eq(33).text());
                                              <?php } ?>
                                            })
                                            <?php if($this->session->userdata('user_role')!='boq_manager'){ ?>
                                              <?php if($page_name=='salary_slips_view'){?>
                                                function GetSearchWork(){
                                                  return $('#table_filter_work').val();
                                                }
                                                function GetSearchEmployee(){
                                                  return $('#table_filter_employee').val();
                                                }
                                                function GetSearchStartMonth(){
                                                  return $('#table_filter_start_month').val();
                                                }
                                                function GetSearchEndMonth(){
                                                  return $('#table_filter_end_month').val();
                                                }
                                                function GetSearchDate(){
                                                  return $('#table_filter_date').val();
                                                }
                                                <?php } ?>
                                                <?php if($page_name=='data_entry_approval'){?>
                                                  function GetStartDate(){
                                                    return $('#table_filter_start_date').val();
                                                  }
                                                  function GetEndDate(){
                                                    return $('#table_filter_end_date').val();
                                                  }
                                                  function GetSearchWork(){
                                                    return $('#table_filter_work').val();
                                                  }
                                                  function GetSearchUser(){
                                                    return $('#table_filter_user').val();
                                                  }
                                                  function GetSearchApprovalStatus(){
                                                    return $('#table_filter_approval_status').val();
                                                  }
                                                  function GetSearchAccount() {
                                                    return $('#table_filter_account').val();
                                                  }
                                                  <?php } ?>
                                                  <?php
                                                  $page_type='';
                                                  if($page_name=='data_entry_approval'){
                                                    $page_type='approval_entries';
                                                  }
                                                  ?>
                                                  var salary_slip_view_table = $('#salary_slip_view_table').DataTable({
                                                    "ajax":{
                                                      url :"<?php echo base_url().'salary_slips/select_salary_slips/'.$page_type ?>", // json datasource
                                                      type: "post", // type of method  , by default would be get
                                                      data: function(d){
                                                        <?php if($page_name=='salary_slips_view'){?>
                                                          d.work = GetSearchWork();
                                                          d.employee = GetSearchEmployee();
                                                          d.start_month = GetSearchStartMonth();
                                                          d.end_month = GetSearchEndMonth();
                                                          <?php } ?>
                                                          <?php if($page_name=='work_profile' || $page_name=='work_summary'){?>
                                                            d.work = "<?php echo $work_data->work_id?>";
                                                            <?php } ?>
                                                            <?php if($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                                                              d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                                                              <?php } ?>
                                                            <?php if($page_name=='stage_profile' || $page_name=='stage_summary'){?>
                                                              d.stage_id = "<?php echo $stage_data->stage_id?>";
                                                              <?php } ?>
                                                              <?php if($page_name=='reports_activity'){?>
                                                                d.date = GetSearchDate();
                                                                d.work = GetSearchWork();
                                                                <?php } ?>
                                                                <?php if($page_name=='user_profile'){?>
                                                                  d.user_id = "<?php echo $user_data->user_id?>";
                                                                  <?php } ?>
                                                                  <?php if($page_name=='data_entry_approval'){ ?>
                                                                    d.start_date = GetStartDate();
                                                                    d.end_date = GetEndDate();
                                                                    d.work = GetSearchWork();
                                                                    d.approval_status = GetSearchApprovalStatus();
                                                                    d.created_by = GetSearchUser();
                                                                    d.acc_head_id = GetSearchAccount();
                                                                    <?php } ?>
                                                                  }
                                                                },
                                                                "bProcessing": true,
                                                                "deferRender": true,
                                                                "bDeferRender": true,
                                                                <?php if($page_name=='work_summary'){?>
                                                                  "scrollX": false,
                                                                  bFilter: false,
                                                                  "bLengthChange": false,
                                                                  "bPaginate": false,
                                                                  "bInfo": false,
                                                                  "dom": "<'row' <'col-md-12'>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable
                                                                  <?php }else{?>
                                                                    "scrollX" : true,
                                                                    buttons: [
                                                                      { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Salary Slips',
                                                                      <?php if($this->config->item('company_letter_head')!=''){ ?>
                                                                        customize: function ( win ) {
                                                                          $(win.document.body).prepend(
                                                                            '<img src="<?php echo base_url().'uploads/company/'.$this->config->item('company_letter_head')?>" style="top:0; left:0;width:100%;" />'
                                                                          );
                                                                        }
                                                                        <?php } ?> },
                                                                        { extend: 'csv', className: 'btn purple btn-outline ' },
                                                                        { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
                                                                      ],
                                                                      dom:"<'row'<'col-sm-6 text-left'B><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
                                                                      "lengthMenu": [
                                                                        [25, 50, 100, -1],
                                                                        [25, 50, 100, "All"] // change per page values here
                                                                      ],
                                                                      <?php } ?>
                                                                      'ordering': false,
                                                                      "columnDefs": [
                                                                        {
                                                                          "targets": [ <?php if($this->config->item('HR_salary_slip_template')!=3){ ?>
                                                                            <?php if($this->session->userdata('user_role')=='auditor'){ echo "24,"; } ?>25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44<?php if ($page_name == 'work_summary') {
                                                                              echo ",5,6,24";
                                                                            } ?> ],
                                                                            <?php }else{ ?>
                                                                              <?php if($this->session->userdata('user_role')=='auditor'){ echo "32,"; } ?>33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52<?php if ($page_name == 'work_summary') {
                                                                                echo ",5,6,32";
                                                                              } ?> ],
                                                                              <?php } ?>
                                                                              className: "hidden"
                                                                            }
                                                                          ],
                                                                          "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                                                            <?php if($this->config->item('HR_salary_slip_template')!=3){ ?>
                                                                              var approval_status = aData[44];
                                                                              <?php }else{ ?>
                                                                                var approval_status = aData[52];
                                                                                <?php } ?>
                                                                                if(approval_status=='0'){
                                                                                  $('td', nRow).css('background-color', '#ffcccc');
                                                                                }else if(approval_status=='2'){
                                                                                  $('td', nRow).css('background-color', '#ffcccc');
                                                                                }
                                                                              }
                                                                            });
                                                                            <?php if($page_name=='salary_slips_view' || $page_name=='work_profile' || $page_name=='work_summary' || $page_name=='reports_activity' || $page_name=='user_profile'){?>
                                                                              var salary_slip_transaction_view_table = $('#salary_slip_transaction_view_table').DataTable({
                                                                                "ajax":{
                                                                                  url :"<?php echo base_url().'accounts/select_account_transactions/salary_slip' ?>", // json datasource
                                                                                  type: "post", // type of method  , by default would be get
                                                                                  data: function(d){
                                                                                    <?php if($page_name=='salary_slips_view'){?>
                                                                                      d.work = GetSearchWork();
                                                                                      d.employee = GetSearchEmployee();
                                                                                      d.start_month = GetSearchStartMonth();
                                                                                      d.end_month = GetSearchEndMonth();
                                                                                      <?php } ?>
                                                                                      <?php if($page_name=='work_profile' || $page_name=='work_summary'){?>
                                                                                        d.work = "<?php echo $work_data->work_id?>";
                                                                                        <?php } ?>
                                                                                        <?php if($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                                                                                          d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                                                                                          <?php } ?>
                                                                                        <?php if($page_name=='work_summary'){?>
                                                                                          d.start_date = GetStartDate();
                                                                                          d.end_date = GetEndDate();
                                                                                          <?php } ?>
                                                                                          <?php if($page_name=='reports_activity'){?>
                                                                                            d.date = GetSearchDate();
                                                                                            <?php } ?>
                                                                                            <?php if($page_name=='user_profile'){?>
                                                                                              d.acc_user_id = '<?= $user_data->user_id ?>';
                                                                                              <?php } ?>
                                                                                            }
                                                                                          },
                                                                                          "bProcessing": true,
                                                                                          "deferRender": true,
                                                                                          "bDeferRender": true,
                                                                                          <?php if($page_name=='work_summary'){?>
                                                                                            "scrollX": false,
                                                                                            bFilter: false,
                                                                                            "bLengthChange": false,
                                                                                            "bPaginate": false,
                                                                                            "bInfo": false,
                                                                                            buttons: [
                                                                                              { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
                                                                                            ],
                                                                                            "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // horizobtal scrollable datatable
                                                                                            <?php }else{?>
                                                                                              "scrollX" : true,
                                                                                              buttons: [
                                                                                                { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Salary Slip Transactions' },
                                                                                                { extend: 'csv', className: 'btn purple btn-outline ' },
                                                                                                { extend: 'colvis', className: 'btn dark btn-outline', text: 'Columns'}
                                                                                              ],
                                                                                              dom:"<'row'<'col-sm-6 text-left'B><'col-sm-6 text-right'f>>\n\t\t\t<'row'<'col-sm-12'tr>>\n\t\t\t<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7 dataTables_pager'lp>>", // horizobtal scrollable datatable
                                                                                              "lengthMenu": [
                                                                                                [25, 50, 100, -1],
                                                                                                [25, 50, 100, "All"] // change per page values here
                                                                                              ],
                                                                                              "pageLength": 25,
                                                                                              <?php } ?>
                                                                                              "columnDefs": [
                                                                                                {
                                                                                                  "targets": [ 7,8,10,20,21,22,23,24<?php if($page_name=='reports_activity'){ echo ",19"; }?><?php if($page_name=='work_profile' || $page_name=='projects_profile' || $page_name=='work_summary'){ echo ",19"; }?>],
                                                                                                  className: "hidden"
                                                                                                }
                                                                                              ],
                                                                                              'ordering': false,
                                                                                              "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                                                                                if(aData[24]=='0'){
                                                                                                  $('td', nRow).css('background-color', '#ffcccc');
                                                                                                }else if(aData[24]=='2'){
                                                                                                  $('td', nRow).css('background-color', '#ffcccc');
                                                                                                }
                                                                                              }
                                                                                            });
                                                                                            $(".table_filter").on("change", function() {
                                                                                              salary_slip_view_table.ajax.reload();
                                                                                              salary_slip_transaction_view_table.ajax.reload();
                                                                                            });
                                                                                            $(".hide_column").hide();

                                                                                            <?php }
                                                                                            if($page_name=='salary_slips_view' || $page_name=='salary_slips_add'){ ?>

                                                                                              $(".form_submit_btn").click(function (e) {
                                                                                                e.preventDefault();
                                                                                                var a = $(this),
                                                                                                l = $(this).closest("form"),
                                                                                                action = l.attr('action');
                                                                                                var form_id = l.attr('id');
                                                                                                l.validate({
                                                                                                  rules: {
                                                                                                    wage_per_day: {
                                                                                                      number: !0
                                                                                                    },
                                                                                                    no_of_days: {
                                                                                                      number: !0
                                                                                                    },
                                                                                                    overtime_wage: {
                                                                                                      number: !0
                                                                                                    },
                                                                                                    extra_wage: {
                                                                                                      number: !0
                                                                                                    },
                                                                                                    no_of_employees: {
                                                                                                      min: 1
                                                                                                    },
                                                                                                    paid_amount: {
                                                                                                      number: !0
                                                                                                    },
                                                                                                    paid_amount_2: {
                                                                                                      number: !0,
                                                                                                      min: 0
                                                                                                    }
                                                                                                  }, invalidHandler: function (e, r) {
                                                                                                    var i = $("#" + form_id + "_msg");
                                                                                                    i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
                                                                                                  }, submitHandler: function (e) {
                                                                                                  }
                                                                                                }), l.valid() && (a.addClass("m-loader m-loader--right m-loader--light").attr("disabled", !0),
                                                                                                l.ajaxSubmit({
                                                                                                  url: action,
                                                                                                  success: function (e, t, r, s) {
                                                                                                    var modal_id = l.attr('data-modal-id');
                                                                                                    var form_type = l.attr('data-form-type');
                                                                                                    $("#" + form_id + "_msg").addClass("m--hide");
                                                                                                    // Block UI
                                                                                                    mApp.blockPage({
                                                                                                      overlayColor: "#000000",
                                                                                                      type: "loader",
                                                                                                      state: "success",
                                                                                                      message: "Please wait..."
                                                                                                    }), setTimeout(function () {
                                                                                                      mApp.unblockPage()
                                                                                                    }, 2e3);
                                                                                                    var obj = $.parseJSON(e);
                                                                                                    if (obj.status == 1) {
                                                                                                      a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                                                      $("#"+modal_id).modal('toggle');
                                                                                                      $("."+form_id+"_fields").val('');
                                                                                                      $("."+form_id+"_fields_1").val(0);
                                                                                                      $("."+form_id+"_fields_2").val(1);
                                                                                                      $("."+form_id+"_select").val('').trigger("change");
                                                                                                      toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                                                                                                      salary_slip_view_table.ajax.reload();
                                                                                                      salary_slip_transaction_view_table.ajax.reload();
                                                                                                      $('#salary_slip_work_date_add,#salary_slip_work_date_edit,#paid_date_add').datepicker("setDate", "<?php echo date('d-m-Y')?>");
                                                                                                    } else {
                                                                                                      a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                                                      toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                                                                                                    }
                                                                                                    if (obj == null) {
                                                                                                      setTimeout(function () {
                                                                                                        a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                                                        toastr["warning"]("Your Attempt is Timed Out. Please Try Again.", "Timed Out");
                                                                                                      }, 2e4)
                                                                                                    }
                                                                                                  },error: function() {
                                                                                                    a.removeClass("m-loader m-loader--right m-loader--light").attr("disabled", !1);
                                                                                                    toastr["error"]("Sorry. There Has Been Some Error Occurred. Please Try Again.", "Error");
                                                                                                  }
                                                                                                })
                                                                                              )
                                                                                            });
                                                                                            <?php } ?>
                                                                                            <?php } ?>
                                                                                            </script>
