<script>
$("#table_filter_work").select2({
  placeholder: "Select Work",
  templateResult: format_project_dropdown
})
$("#table_filter_work_type").select2({
  placeholder: "Select Work Type"
})
$("#table_filter_payment_status").select2({
  placeholder: "Select Payment Status"
})
$("#table_filter_vehicle").select2({
  placeholder: "Select Vehicle"
})
$("#table_filter_driver").select2({
  placeholder: "Select Vehicle"
})
$('body').on('click', '#btn_print_work_slip', function() {
  var id = $(this).data('slip-id');
  window.open('<?php echo base_url() . 'vehicle_work_slips/print/' ?>' + id, 'newwindow', 'width=1200,height=700');
  return false
});
$("#vehicle_work_date_add,#vehicle_paid_date_add,#vehicle_reference_date_add,#vehicle_work_date_edit").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', '#vehicle_work_slip_debit_payment_mode', function() {
    var payment_mode=$('#vehicle_work_slip_debit_payment_mode :selected').val();
    if(payment_mode=='POST DATED CHEQUE'){
      $('#vehicle_paid_date_add').datepicker('destroy');
      $("#vehicle_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{
      $('#vehicle_paid_date_add').datepicker('destroy');
      $("#vehicle_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 } ?>
        })
    }
  })
  $("#vehicle_work_slip_debit_acc_add").select2({
    placeholder: "Select Debit Account",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })
  $("#vehicle_add").select2({
    placeholder: "Select vehicle",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })
  $("#vehicle_category_add").select2({
    placeholder: "Select Category",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })
  $("#vehicle_type_add").select2({
    placeholder: "Select Type",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })
  $("#work_slip_work_add").select2({
    placeholder: "Select Work",
    dropdownParent: $("#form_vehicle_work_slip_add"),
    templateResult: format_project_dropdown
  })
  $("#work_duration_type2_add").select2({
    placeholder: "Duration Type",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })
  $("#driver_add").select2({
    placeholder: "Select Driver",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })
  $("#vehicle_work_slip_load_qty_type_add").select2({
    placeholder: "Select Type",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })
  $("#vehicle_work_slip_debit_payment_mode").select2({
    placeholder: "Select Payment Mode",
    dropdownParent: $("#form_vehicle_work_slip_add")
  })

  $("#vehicle_edit").select2({
    placeholder: "Select vehicle",
    dropdownParent: $("#form_vehicle_work_slip_edit")
  })
  $("#vehicle_category_edit").select2({
    placeholder: "Select Category",
    dropdownParent: $("#form_vehicle_work_slip_edit")
  })
  $("#work_slip_work_edit").select2({
    placeholder: "Select Work",
    dropdownParent: $("#form_vehicle_work_slip_edit"),
    templateResult: format_project_dropdown
  })
  $("#work_duration_type2_edit").select2({
    placeholder: "Duration Type",
    dropdownParent: $("#form_vehicle_work_slip_edit")
  })
  $("#driver_edit").select2({
    placeholder: "Select Driver",
    dropdownParent: $("#form_vehicle_work_slip_edit")
  })
  $("#vehicle_work_slip_load_qty_type_edit").select2({
    placeholder: "Select Type",
    dropdownParent: $("#form_vehicle_work_slip_edit")
  })

  $("#start_time_add,#start_time_edit").timepicker({
    defaultTime: "<?php echo date("h:i A",strtotime($this->config->item('HR_duty_start_time')))?>",
    minuteStep: 1,
  })
  $("#end_time_add,#end_time_edit").timepicker({
    defaultTime: "<?php echo date("h:i A",strtotime($this->config->item('HR_duty_end_time')))?>",
    minuteStep: 1,
  })

  function select_vehicles(select_id,selected_value='',category='',vehicle_type=''){
    $('#'+select_id).html('');
    $('#'+select_id).append("<option disabled selected >Select Vehicle</option>");

    $.post("<?php echo base_url() ?>vehicles/select_vehicles_list",{category:category,vehicle_type:vehicle_type},function(data) {
      var obj = $.parseJSON(data);
      var i=0;
      if(obj.count>0) {
        while (i < obj.data.length) {
          $('#'+select_id).append("<option  value=" + obj.data[i]['id'] + ">" + obj.data[i]['vehicle_name'] + " : "+obj.data[i]['vehicle_no']+" [" + obj.data[i]['consignee_name'] + "]</option>");
          i++;
        }
        if(selected_value!=''){
          $("#"+select_id).val(selected_value).trigger("change");
        }
      }
    })
  }
  select_vehicles("vehicle_add");
  $('#vehicle_category_add,#vehicle_type_add').on("change", function(e) {
    var category = $('#vehicle_category_add :selected').val();
    var vehicle_type = $('#vehicle_type_add :selected').val();
    select_vehicles("vehicle_add",'',category,vehicle_type);
  });
  $('#vehicle_category_edit').on("change", function(e) {
    var category = $('#vehicle_category_edit :selected').val();
    select_vehicles("vehicle_edit",'',category);
  });

  function calculate_pay_add(){
    var sl_no = $("#vehicle_add").val();

    var worked_duration = parseFloat($("#worked_duration_add").val());
    var basic_charge = parseFloat($("#basic_charge_add").val());
    var overtime_duration = parseFloat($("#overtime_duration_vehicle_add").val());
    var overtime_rate = parseFloat($("#overtime_rate_vehicle_add").val());
    var overtime_amount = overtime_duration*overtime_rate;
    var commission = parseFloat($("#commission_add").val());
    var labour_charge = parseFloat($("#labour_charge_add").val());
    var other_expenses = parseFloat($("#other_expenses_add").val());
    var total_paid = parseFloat($("#vehicle_work_slip_paid_amount_add").val());
    var driver_bata = 0;
    if($("#driver_bata_include_add").is(":checked")){
      driver_bata = parseFloat($("#driver_bata_add").val());
    }
    var loading_amount = parseFloat($("#loading_amount_add").val());
    <?php if($this->config->item('app_module_vehicle_management')==1){ ?>
      var total_basic_wage =  parseFloat($("#total_basic_charge_add").val());
      <?php }else{ ?>
    var total_basic_wage = (worked_duration*basic_charge);
    <?php } ?>
    var total_payable =  total_basic_wage + commission+labour_charge+other_expenses+overtime_amount+driver_bata+loading_amount;
    <?php if($this->config->item('app_module_vehicle_management')==1){ ?>
      var expense_amount = parseFloat($("#work_slip_expense_total_amount_add").val());
      total_payable+=expense_amount;
      <?php } ?>
      var total_balance = total_payable - total_paid;
      $("#overtime_amount_add").val(overtime_amount.toFixed(2));
      $("#total_payable_amount_add").val(total_payable);
      $("#total_balance_add").val(total_balance);
      $("#vehicle_work_slip_paid_amount_add").val(total_paid);
      if(total_paid>0){
        $(".vehicle_work_slip_paid_amount_req_fields").attr('required',true);
      }else{
        $(".vehicle_work_slip_paid_amount_req_fields").removeAttr('required',true);
      }
    }
    function calculate_pay_edit(){
      var sl_no = $("#vehicle_edit").val();

      var worked_duration = parseFloat($("#worked_duration_edit").val());
      var basic_charge = parseFloat($("#basic_charge_edit").val());
      var overtime_duration = parseFloat($("#overtime_duration_vehicle_edit").val());
      var overtime_rate = parseFloat($("#overtime_rate_vehicle_edit").val());
      var overtime_amount = overtime_duration*overtime_rate;
      var commission = parseFloat($("#vehicle_work_slip_commission_edit").val());
      var labour_charge = parseFloat($("#vehicle_work_slip_labour_charge_edit").val());
      var other_expenses = parseFloat($("#vehicle_work_slip_other_expenses_edit").val());
      var driver_bata = parseFloat($("#vehicle_work_slip_driver_bata_edit").val());
      var loading_amount = parseFloat($("#vehicle_work_slip_loading_amount_edit").val());
      var total_payable = (worked_duration*basic_charge) + commission+labour_charge+other_expenses+overtime_amount+driver_bata+loading_amount;
      <?php if($this->config->item('app_module_vehicle_management')==1){ ?>
        var fuel_amount = parseFloat($("#fuel_amount_edit").val());
        total_payable+=fuel_amount;
        <?php } ?>
        var total_balance = total_payable - total_paid;
        $("#vehicle_work_slip_overtime_amount_edit").val(overtime_amount.toFixed(2));
        var total_paid = parseFloat($("#vehicle_work_slip_total_paid_edit").val());
        var total_balance = total_payable - total_paid;
        $("#vehicle_work_slip_total_payable_amount_edit").val(total_payable);
        $("#vehicle_work_slip_total_balance_edit").val(total_balance);
      }


      $('body').on('change keyup', '.total_amount_calculate_fields_add', function() {
        if($(this).val()==''){
          $(this).val(0);
        }
        calculate_pay_add();
      })
      $('body').on('change keyup', '.total_amount_calculate_fields_edit', function() {
        if($(this).val()==''){
          $(this).val(0);
        }
        calculate_pay_edit();
      })
      $('body').on('change keyup', '#load_qty_add,#vehicle_work_slip_load_qty_type_add,#worked_duration_add,#work_duration_type2_add', function() {
        var load_qty = parseFloat($("#load_qty_add").val());
        var load_nos = parseFloat($("#worked_duration_add").val());
        if (isNaN(load_qty)) {
          load_qty=0;
        }
        if (isNaN(load_nos)) {
          load_nos=0;
        }
        var total_load = load_qty*load_nos;
        $("#total_load_qty_add").val(total_load);
        $("#total_load_qty_type_add").html($('#vehicle_work_slip_load_qty_type_add :selected').val())
      })
      $('body').on('change keyup', '#load_qty_edit,#vehicle_work_slip_load_qty_type_edit,#worked_duration_edit,#work_duration_type2_edit', function() {
        var load_qty = parseFloat($("#load_qty_edit").val());
        var load_nos = parseFloat($("#worked_duration_edit").val());
        if (isNaN(load_qty)) {
          load_qty=0;
        }
        if (isNaN(load_nos)) {
          load_nos=0;
        }
        var total_load = load_qty*load_nos;
        $("#total_load_qty_edit").val(total_load);
        $("#total_load_qty_type_edit").html($('#vehicle_work_slip_load_qty_type_edit :selected').val())
      })
      $('body').on('change keyup', '.final_balance_calculate_fields', function() {
        var balance = $('#consignee_name_add_payment').val();
        var paid = $('#paid_amount_edit_bill_payment').val();
        var final_balance =  balance - paid;
        $('#balance_amount_add_bill_payment').val(final_balance);
        var balance_edit = $('#bill_balance_amount_edit_bill_payment').val();
        var paid_edit =  $('#paid_amount_edit_bill_payment').val();
        var final_balance_edit =  balance_edit - paid_edit;
        $('#balance_amount_edit_bill_payment').val(final_balance_edit);
      })
      $('body').on('change keyup', '#start_km_add,#end_km_add', function() {
        var start_km = parseFloat($('#start_km_add').val());
        var end_km = parseFloat($('#end_km_add').val());
        if (isNaN(end_km)) {
          end_km=0;
        }
        if (isNaN(start_km)) {
          start_km=0;
        }
        var total_km =  end_km - start_km;
        $('#total_km_add').val(total_km);
      })

      $('body').on('change keyup', '#start_km_edit,#end_km_edit', function() {
        var start_km = parseFloat($('#start_km_edit').val());
        var end_km = parseFloat($('#end_km_edit').val());
        if (isNaN(end_km)) {
          end_km=0;
        }
        if (isNaN(start_km)) {
          start_km=0;
        }
        var total_km =  end_km - start_km;
        $('#total_km_edit').val(total_km);
      })

      function GetSearchWork(){
        return $('#table_filter_work').val();
      }
      function GetSearchPaymentStatus(){
        return $('#table_filter_payment_status').val();
      }
      function GetSearchVehicle(){
        return $('#table_filter_vehicle').val();
      }
      function GetSearchDriver(){
        return $('#table_filter_driver').val();
      }
      function GetSearchDate(){
        return $('#table_filter_date').val();
      }
      <?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 vehicle_work_slip_view_table = $('#vehicle_work_slip_view_table').DataTable({
          "ajax":{
            url :"<?php echo base_url().'vehicle_work_slips/select_vehicle_work_slip/'.$page_type ?>", // json datasource
            type: "post", // type of method  , by default would be get
            data: function(d){
              <?php if($page_name=='work_profile'  || $page_name=='work_summary') { ?>
                d.work = <?= $work_data->work_id ?>;
                <?php }elseif($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                    d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                    <?php }else { ?>
                  d.work = GetSearchWork();
                  <?php } ?>
                  <?php if($page_name=='data_entry_approval'){?>
                    d.start_date = GetStartDate();
                    d.end_date = GetEndDate();
                    d.work = GetSearchWork();
                    d.approval_status = GetSearchApprovalStatus();
                    d.user_id = GetSearchUser();
                    <?php } ?>
                    <?php if($page_name=='vehicle_profile') { ?>
                      d.vehicle_id = <?= $vehicle_data->id ?>;
                      <?php } else { ?>
                        d.vehicle_id = GetSearchVehicle();
                        <?php } ?>
                        <?php if($page_name=='user_profile') { ?>
                          d.user_id = <?= $user_data->user_id ?>;
                          <?php } ?>
                          <?php if($page_name=='consignee_profile') { ?>
                            d.consignee = <?= $consignee_data->consignee_id ?>;
                            <?php } ?>
                            <?php if($page_name=='vehicle_work_slips_view') { ?>
                            d.date = GetSearchDate();
                            d.driver = GetSearchDriver();
                            d.payment_status = GetSearchPaymentStatus();
                            <?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: 'Vehicle Work Slips' },
                          { 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": [ 0,23,24,39,40,41,42,43,44,45,46, <?php if($this->config->item('Vehicle_payment_based_on')=='vehicle'){ echo ",33,34,37";}?><?php if($this->config->item('app_module_vehicle_management')!=1){ echo ",13,14,15,16,17,18,19,20,21,22"; } ?><?php if($page_name=='vehicle_profile') { echo ""; } ?><?php if($this->session->userdata('user_role') == 'auditor'){ echo ",38"; }?><?php if($page_name=='user_profile'){ echo ",38"; }?><?php if($page_name=='work_summary'){ echo ",1,35,36,37,38"; }?> ],
                            className: "hidden"
                          }
                        ],
                        "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                          if(aData[44]=='0'){
                            $('td', nRow).css('background-color', '#ffcccc');
                          }else if(aData[44]=='2'){
                            $('td', nRow).css('background-color', '#ffcccc');
                          }
                        }
                      });

                      var vehicle_work_slip_transaction_view_table = $('#vehicle_work_slip_transaction_view_table').DataTable({
                        "ajax":{
                          url :"<?php echo base_url().'accounts/select_account_transactions/vehicle_work_slip/'.$page_type ?>", // json datasource
                          type: "post", // type of method  , by default would be get
                          data: function(d){
                            <?php if($page_name=='work_profile'  || $page_name=='work_summary') { ?>
                              d.work = <?= $work_data->work_id ?>;
                              <?php }elseif($page_name=='work_profile_master' || $page_name=='work_summary_master'){?>
                                  d.work_ids = "<?php echo implode(',',$sub_project_ids)?>";
                                  <?php }else { ?>
                                d.work = GetSearchWork();
                                <?php } ?>
                                <?php if($page_name=='vehicle_profile') { ?>
                                  d.vehicle_id = <?= $vehicle_data->id ?>;
                                  <?php } else { ?>
                                    d.vehicle_id = GetSearchVehicle();
                                    <?php } ?>
                                    <?php if($page_name=='data_entry_approval'){?>
                                      d.start_date = GetStartDate();
                                      d.end_date = GetEndDate();
                                      d.work = GetSearchWork();
                                      d.approval_status = GetSearchApprovalStatus();
                                      d.user_id = GetSearchUser();
                                      d.acc_head_id = GetSearchAccount();
                                      <?php } ?>
                                      <?php if($page_name=='vehicle_work_slips_view') { ?>
                                      d.date = GetSearchDate();
                                      <?php } ?>
                                      <?php if($page_name=='user_profile') { ?>
                                        d.acc_user_id = <?= $user_data->user_id ?>;
                                        <?php } ?>
                                        <?php if($page_name=='consignee_profile') { ?>
                                          d.consignee = <?= $consignee_data->consignee_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: 'Vehicle Work 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
                                      ],
                                      // set the initial value
                                      "pageLength": 25,
                                      <?php } ?>
                                      "columnDefs": [
                                        {
                                          "targets": [ <?php if($page_name=='vehicle_profile'){ echo "4,5,"; }?>6,7,9,19<?php if($page_name=='reports_activity'){ echo ",18"; }?><?php if($this->session->userdata('user_role') == 'auditor'){ echo ",18"; }?><?php if($page_name=='user_profile'){ echo ",16"; }?><?php if($page_name=='work_summary'){ echo ",1,13,14,15,16,18"; }?>],
                                          className: "hidden"
                                        }
                                      ],
                                      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                        if(aData[23]=='0'){
                                          $('td', nRow).css('background-color', '#ffcccc');
                                        }else if(aData[23]=='2'){
                                          $('td', nRow).css('background-color', '#ffcccc');
                                        }
                                      },
                                      'ordering': false
                                    });
                                    var vehicle_op_balance_transaction_view_table = $('#vehicle_op_balance_transaction_view_table').DataTable({
                                      "ajax":{
                                        url :"<?php echo base_url().'accounts/select_account_transactions/vehicle_payment/'.$page_type ?>", // json datasource
                                        type: "post", // type of method  , by default would be get
                                        data: function(d){
                                          <?php if($page_name=='work_profile'  || $page_name=='work_summary') { ?>
                                            d.work = <?= $work_data->work_id ?>;
                                            <?php } else { ?>
                                              d.work = GetSearchWork();
                                              <?php } ?>
                                              <?php if($page_name=='vehicle_profile') { ?>
                                                d.vehicle_id = <?= $vehicle_data->id ?>;
                                                <?php } else { ?>
                                                  d.vehicle_id = GetSearchVehicle();
                                                  <?php } ?>
                                                  <?php if($page_name=='data_entry_approval'){?>
                                                    d.start_date = GetStartDate();
                                                    d.end_date = GetEndDate();
                                                    d.work = GetSearchWork();
                                                    d.approval_status = GetSearchApprovalStatus();
                                                    d.user_id = GetSearchUser();
                                                    <?php } ?>
                                                    <?php if($page_name=='vehicle_work_slips_view') { ?>
                                                    d.date = GetSearchDate();
                                                    <?php } ?>
                                                    <?php if($page_name=='user_profile') { ?>
                                                      d.acc_user_id = <?= $user_data->user_id ?>;
                                                      <?php } ?>
                                                      <?php if($page_name=='consignee_profile') { ?>
                                                        d.consignee = <?= $consignee_data->consignee_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: 'Vehicle Opening Balance 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
                                                    ],
                                                    // set the initial value
                                                    "pageLength": 25,
                                                    <?php } ?>
                                                    "columnDefs": [
                                                      {
                                                        "targets": [ <?php if($page_name=='vehicle_profile'){ echo "4,5,"; }?>6,7,9,19<?php if($page_name=='reports_activity'){ echo ",18"; }?><?php if($this->session->userdata('user_role') == 'auditor'){ echo ",18"; }?><?php if($page_name=='user_profile'){ echo ",16"; }?><?php if($page_name=='work_summary'){ echo ",1,13,14,15,16,18"; }?>],
                                                        className: "hidden"
                                                      }
                                                    ],
                                                    "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                                      if(aData[23]=='0'){
                                                        $('td', nRow).css('background-color', '#ffcccc');
                                                      }else if(aData[23]=='2'){
                                                        $('td', nRow).css('background-color', '#ffcccc');
                                                      }
                                                    },
                                                    'ordering': false
                                                  });
                                    $(".table_filter").on("change", function() {
                                      vehicle_work_slip_view_table.ajax.reload();
                                      vehicle_work_slip_transaction_view_table.ajax.reload();
                                      vehicle_op_balance_transaction_view_table.ajax.reload();
                                    });
                                    $(".hide_column").hide();


                                    // Date Range Picker
                                    var start = moment();
                                    var end = moment();

                                    function cb(start, end) {
                                      $('#table_filter_date').val(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
                                      vehicle_work_slip_view_table.ajax.reload();
                                      vehicle_work_slip_transaction_view_table.ajax.reload();
                                      vehicle_op_balance_transaction_view_table.ajax.reload();
                                    }

                                    $('#table_filter_date').daterangepicker({
                                      buttonClasses: "m-btn btn",
                                      applyClass: "btn-primary",
                                      cancelClass: "btn-secondary",
                                      startDate: start,
                                      endDate: end,
                                      locale: {
                                        format: 'MMMM D, YYYY'
                                      },
                                      ranges: {
                                        'Today': [moment(), moment()],
                                        'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
                                        'Last 7 Days': [moment().subtract(6, 'days'), moment()],
                                        'Last 30 Days': [moment().subtract(29, 'days'), moment()],
                                        'This Month': [moment().startOf('month'), moment().endOf('month')],
                                        'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')],
                                        'All time': [moment('1970-01-01'), moment().add(9999, 'days')],
                                      }
                                    }, cb);

                                    cb(start, end);

                                    <?php if($page_name!='vehicle_profile' && $page_name!='work_profile' && $page_name!='consignee_profile' && $page_name!='data_entry_approval') { ?>
                                      $(".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: {
                                            worked_duration: {
                                              number: !0,
                                              min: 1
                                            },
                                            basic_charge: {
                                              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);
                                              vehicle_work_slip_view_table.ajax.reload();
                                              vehicle_work_slip_transaction_view_table.ajax.reload();
                                              vehicle_op_balance_transaction_view_table.ajax.reload();
                                              select_vehicles("vehicle_add");
                                              select_vehicles("vehicle_edit");
                                              $('#vehicle_work_slip_work_date_edit,#labour_wage_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 } ?>

                                    function addVehicleModalShow() {
                                      $('#labour_wage_view_table').modal('hide');
                                      $('#vehicle_add_modal').modal('show');
                                    }
                                    $('input[type=radio][name=work_slip_type]').change(function() {
                                      if (this.value == 'inside_work') {
                                        $("#work_slip_work_add_div").show();
                                        $("#work_slip_work_add").attr('required',true);
                                      }else{
                                        $("#work_slip_work_add_div").hide();
                                        $("#work_slip_work_add").removeAttr('required',true);
                                      }
                                    });
                                    $('input[type=radio][name=work_slip_type_edit]').change(function() {
                                      if (this.value == 'inside_work') {
                                        $("#work_slip_work_edit_div").show();
                                        $("#work_slip_work_edit").attr('required',true);
                                      }else{
                                        $("#work_slip_work_edit_div").hide();
                                        $("#work_slip_work_edit").removeAttr('required',true);
                                      }
                                    });
                                    $("#vehicle_add").change(function() {

                                      $("#basic_charge_add").val($('#basic_charge_'+this.value+'_add').val());
                                      var type = $('#work_duration_type_'+this.value+"_add").val();
                                      $('#work_duration_type2_add').val(type);
                                      $('#work_duration_type2_add').select2().trigger('change');
                                      calculate_pay_add();
                                      <?php if($this->config->item('app_module_vehicle_management')==1){ ?>
                                        var vehicle_id = $('#vehicle_add').val();
                                        $.post("<?php echo base_url() ?>vehicles/select_details",{vehicle_id:vehicle_id},function(data) {
                                          var obj = $.parseJSON(data);
                                          var i=0;
                                          if(obj.count==1) {
                                            $('#driver_add').html('');
                                            $("#driver_add").append("<option selected disabled >Select Driver</option>");
                                            if(obj.data['vehicle_type']=='own'){
                                              $("#work_slip_type_div_add").show();
                                              $(".owned_vehicle_fields_add").show();
                                              $(".owned_vehicle_required_fields_add").attr('required',true);
                                              var assigned_drivers = obj.data['assigned_drivers'];
                                              if(assigned_drivers!=''){
                                                var i=0;
                                                while (i < assigned_drivers.length) {
                                                  $("#driver_add").append("<option value=" + assigned_drivers[i]['employee_id'] + ">" + assigned_drivers[i]['employee_name'] + "</option>");
                                                  i++;
                                                }
                                              }
                                            }else{
                                              $("#work_slip_type_div_add").hide();
                                              $(".owned_vehicle_fields_add").hide();
                                              $(".owned_vehicle_required_fields_add").removeAttr('required',true);
                                            }
                                          }
                                        })
                                        <?php } ?>

                                      });
                                      </script>
                                      <script type="text/javascript">
                                      $('body').on('click', '#vehicle_work_slip_edit_btn', function() {
                                        var no = $(this).closest('tr').children('td');

                                        $('#work_slip_id_edit').val(no.eq(2).text());
                                        select_vehicles("vehicle_edit",no.eq(0).text());
                                        $.post("<?php echo base_url() ?>vehicles/select_details",{vehicle_id:no.eq(0).text()},function(data) {
                                          var obj = $.parseJSON(data);
                                          var i=0;
                                          if(obj.count==1) {
                                            $('#driver_edit').html('');
                                            $("#driver_edit").append("<option selected disabled >Select Driver</option>");
                                            if(obj.data['vehicle_type']=='own'){
                                              var assigned_drivers = obj.data['assigned_drivers'];
                                              if(assigned_drivers!=''){
                                                var i=0;
                                                while (i < assigned_drivers.length) {
                                                  $("#driver_edit").append("<option value=" + assigned_drivers[i]['employee_id'] + ">" + assigned_drivers[i]['employee_name'] + "</option>");
                                                  i++;
                                                }
                                                $('#driver_edit').val(no.eq(45).text()).trigger('change');
                                              }
                                            }
                                          }
                                        })
                                        var vehicle_type = no.eq(46).text();
                                        if(vehicle_type=='own'){
                                          $("#work_slip_type_div_edit").show();
                                          $(".owned_vehicle_fields_edit").show();
                                          $(".owned_vehicle_required_fields_edit").attr('required',true);
                                        }else{
                                          $("#work_slip_type_div_edit").hide();
                                          $(".owned_vehicle_fields_edit").hide();
                                          $(".owned_vehicle_required_fields_edit").removeAttr('required',true);
                                        }
                                        $('#vehicle_work_date_edit').datepicker("setDate", no.eq(7).text());
                                        $('#work_slip_work_edit').val(no.eq(39).text()).trigger('change');
                                        var work_slip_type=no.eq(42).text();
                                        $('input[type=radio][name=work_slip_type_edit][value='+work_slip_type+']').prop('checked',true);
                                        $('#work_duration_type2_edit').val(no.eq(40).text()).trigger('change');
                                        $('#worked_duration_edit').val(no.eq(41).text());
                                        $('#basic_charge_edit').val(no.eq(9).text());
                                        $("#overtime_duration_vehicle_edit").val(no.eq(10).text());
                                        $("#overtime_rate_vehicle_edit").val(no.eq(11).text());

                                        $("#start_time_edit").val(no.eq(14).text());
                                        $("#end_time_edit").val(no.eq(15).text());
                                        $("#start_km_edit").val(no.eq(16).text());
                                        $("#end_km_edit").val(no.eq(17).text());
                                        $("#load_type_edit").val(no.eq(18).text());
                                        $("#load_qty_edit").val(no.eq(19).text());
                                        $("#vehicle_work_slip_load_qty_type_edit").val(no.eq(21).text()).trigger('change');
                                        $("#total_load_qty_type_edit").html(no.eq(21).text());
                                        $("#total_load_qty_edit").val(no.eq(20).text());
                                        $("#vehicle_work_slip_location_edit").val(no.eq(22).text());
                                        $("#fuel_pump_edit").val(no.eq(23).text());
                                        $("#fuel_qty_edit").val(no.eq(24).text());
                                        $("#fuel_amount_edit").val(no.eq(25).text());
                                        $("#fuel_km_reading_edit").val(no.eq(26).text());
                                        $('#vehicle_work_slip_commission_edit').val(no.eq(29).text());
                                        $('#vehicle_work_slip_labour_charge_edit').val(no.eq(30).text());
                                        $('#vehicle_work_slip_other_expenses_edit').val(no.eq(31).text());
                                        $('#vehicle_work_slip_driver_bata_edit').val(no.eq(23).text());
                                        $('#vehicle_work_slip_loading_amount_edit').val(no.eq(28).text());
                                        $('#vehicle_work_slip_overtime_amount_edit').val(no.eq(12).text());
                                        $('#vehicle_work_slip_other_expenses_edit').val(no.eq(31).text());
                                        $('#vehicle_work_slip_total_payable_amount_edit').val(no.eq(32).text());
                                        $('#vehicle_work_slip_total_paid_edit').val(no.eq(33).text());
                                        $('#vehicle_work_slip_total_balance_edit').val(no.eq(34).text());
                                        $('#vehicle_work_slip_remarks_edit').val(no.eq(35).text());

                                      })
                                      $('body').on('click', '#vehicles_work_slip_delete_btn', function() {
                                        var no = $(this).closest('tr').children('td');
                                        $('#work_slip_id_delete').val(no.eq(2).text());
                                      })

                                      function select_vehicle_suppliers(select_id,selected_value){
                                        $('#'+select_id).html('');
                                        $('#'+select_id).append("<option disabled selected >Select Supplier</option>");

                                        $.post("<?php echo base_url() ?>supplier/select",{supplier_type:'vehicle'},function(data) {
                                          var obj = $.parseJSON(data);
                                          var i=0;
                                          if(obj.count>0) {
                                            while (i < obj.id.length) {
                                              $('#'+select_id).append("<option value=" + obj.supplier_mode[i] + "_" + obj.id[i] + ">" + obj.name[i] + "</option>");
                                              i++;
                                            }
                                            if(selected_value!=''){
                                              $("#"+select_id).val(selected_value).trigger("change");
                                            }
                                            $('#'+select_id).selectpicker('refresh');
                                          }
                                        })
                                      }
                                      $("#addrow_work_slip_expense_add").on("click", function () {
                                        var i = parseInt($('#current_row_count_work_slip_expense_add').val());
                                        var new_row = '<tr class="row_'+i+'">';
                                        new_row += '<td class="veh_exp_type_div"><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><div class="m-radio-inline" style="padding-top: 10px;">'+
                                        '<label class="m-radio m-radio--solid m-radio--state-danger">'+
                                        '<input required type="radio" class="form_fields_radio"  data-row-sl-no="'+i+'" name="work_slip_expense[expense_type]['+i+']" value="Fuel"> Fuel'+
                                        '<span></span>'+
                                        '</label>'+
                                        '<label class="m-radio m-radio--solid m-radio--state-warning">'+
                                        '<input type="radio" class="form_fields_radio"  data-row-sl-no="'+i+'" name="work_slip_expense[expense_type]['+i+']"  value="Workshop"> Workshop'+
                                        '<span></span>'+
                                        '</label>'+
                                        '</div></div></td>';
                                        new_row += '<td><div class="form-group m-form__group " style="padding: 0px !important;margin: 0px !important;"><select required data-row-sl-no="'+i+'" name="work_slip_expense[supplier]['+i+']" id="work_slip_expense_supplier_'+(i+1)+'" class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker work_slip_expense_supplier_add" data-live-search="true"></select><span class="m-form__help"></span></div>'+
                                        '<div class="form-group m-form__group" id="work_slip_expense_fuel_type_'+(i+1)+'" style="display:none;padding: 0px !important;margin: 0px !important;"><div class="m-radio-inline" style="padding-top: 10px;">'+
                                        '<label class="m-radio m-radio--solid m-radio--state-info">'+
                                        '<input type="radio" class="form_fields_radio"  data-row-sl-no="'+i+'" name="work_slip_expense[fuel_type]['+i+']" value="Petrol"> Petrol'+
                                        '<span></span>'+
                                        '</label>'+
                                        '<label class="m-radio m-radio--solid m-radio--state-success">'+
                                        '<input type="radio" class="form_fields_radio"  data-row-sl-no="'+i+'" name="work_slip_expense[fuel_type]['+i+']"  value="Diesel"> Diesel'+
                                        '<span></span>'+
                                        '</label>'+
                                        '</div><span class="m-form__help"></span></div></td>';
                                        new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><input type="text" required  data-row-sl-no="'+i+'" name="work_slip_expense[qty]['+i+']" id="work_slip_expense_qty_'+(i+1)+'" class="work_slip_expense_qty form-control m-input m-input--pill m-input--air"></td>';
                                        new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><input type="text" required data-row-sl-no="'+i+'" name="work_slip_expense[price]['+i+']" id="work_slip_expense_price_'+(i+1)+'" class="work_slip_expense_price form-control m-input m-input--pill m-input--air"></td>';
                                          new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><input type="text" value="0" required data-row-sl-no="'+i+'" name="work_slip_expense[total]['+i+']" id="work_slip_expense_total_'+(i+1)+'" readonly class="work_slip_expense_total form-control m-input m-input--pill m-input--air"></td>';
                                        new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><input type="text"  data-row-sl-no="'+i+'" name="work_slip_expense[remarks]['+i+']" id="work_slip_expense_remarks_'+(i+1)+'" class="form-control m-input m-input--pill m-input--air"></td>';
                                        new_row += '<td><div class="m-form__group form-group">';
                                        new_row += '<div class="m-checkbox-list"><label class="m-checkbox m-checkbox--bold m-checkbox--state-brand">';
                                        new_row += '<input type="checkbox" class="work_slip_expense_includable" data-row-sl-no="'+i+'" name="work_slip_expense[includable]['+i+']" value="1" id="work_slip_expense_includable_'+(i+1)+'"  checked>';
                                        new_row += '<span></span></label>	</div>';
                                        new_row += '<td class="veh_exp_type_action"><a href="javascript:" data-row-sl-no="'+i+'" class="ibtnDel_work_slip_expense_add btn btn-danger  m-btn m-btn--icon btn-sm m-btn--icon-only m-btn--pill" ><i class="fa fa-trash"></i></td></tr>';

                                        $('#table_body_work_slip_expense_add').append(new_row);
                                        $('#current_row_count_work_slip_expense_add').val(i+1);

                                        select_vehicle_suppliers('work_slip_expense_supplier_'+(i+1));
                                        $('#work_slip_expense_supplier_'+(i+1)).selectpicker();
                                        $('input[type=radio][name="work_slip_expense[expense_type]['+i+']"]').change(function() {
                                          var slno = $(this).data('row-sl-no');
                                          if(this.value=='Fuel'){
                                            $("#work_slip_expense_fuel_type_"+(slno+1)).show();
                                            $('input[type=radio][name="work_slip_expense[fuel_type]['+slno+']"]').attr('required',true);
                                          }else{
                                            $("#work_slip_expense_fuel_type_"+(slno+1)).hide();
                                            $('input[type=radio][name="work_slip_expense[fuel_type]['+slno+']"]').removeAttr('required',true);
                                          }
                                        });

                                        i++;
                                      });

                                      $("#table_body_work_slip_expense_add").on("click", ".ibtnDel_work_slip_expense_add", function (event) {
                                        var sl_no = $(this).attr("data-sl-no");

                                        var counter = parseInt($("#current_row_count_work_slip_expense_add").val());
                                        $(this).closest("tr").remove();
                                        counter -= 1;
                                        $("#current_row_count_work_slip_expense_add").val(counter);
                                        calculate_expense_add();

                                      });
                                      function calculate_expense_add(){
                                        var total_expense_amount = 0;
                                        $(".work_slip_expense_total").each(function() {
                                          var slno = $(this).data('row-sl-no');
                                          if($('#work_slip_expense_includable_'+(slno+1)).is(":checked")){
                                            var qty = parseFloat($('#work_slip_expense_qty_'+(slno+1)).val());
                                            var price = parseFloat($('#work_slip_expense_price_'+(slno+1)).val());
                                            if (isNaN(qty)) {
                                              qty=0;
                                            }
                                            if (isNaN(price)) {
                                              price=0;
                                            }
                                            var total = qty*price;
                                            $('#work_slip_expense_total_'+(slno+1)).val(total);
                                            total_expense_amount += total;
                                          }
                                        });
                                        $("#work_slip_expense_total_amount_add").val(total_expense_amount);
                                        calculate_pay_add();
                                      }
                                      $('body').on('change keyup', '.work_slip_expense_qty,.work_slip_expense_price,.work_slip_expense_includable', function() {
                                        calculate_expense_add();
                                      })

                                      <?php if($this->config->item('app_module_vehicle_management')==1){ ?>
                                      // Basic Wage
                                      $('#work_slip_basic_wage_duration_type_1').selectpicker();
                                      $("#addrow_work_slip_basic_wage_add").on("click", function () {
                                        var i = parseInt($('#current_row_count_work_slip_basic_wage_add').val());
                                        var new_row = '<tr class="row_'+i+'">';
                                        new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><input type="text" required  data-row-sl-no="'+i+'" value="0" name="work_slip_basic_wage[duration]['+i+']" id="work_slip_basic_wage_duration_'+(i+1)+'" class="work_slip_basic_wage_duration form-control m-input m-input--pill m-input--air"></td>';
                                        new_row += '<td><div class="form-group m-form__group " style="padding: 0px !important;margin: 0px !important;"><select required data-row-sl-no="'+i+'" name="work_slip_basic_wage[duration_type]['+i+']" id="work_slip_basic_wage_duration_type_'+(i+1)+'" class="form-control m-bootstrap-select m-bootstrap-select--air m-bootstrap-select--pill m_selectpicker work_slip_basic_wage_supplier_add" >';
                                        new_row += '<option disabled="" selected="">Duration type</option>';
                                        new_row += '<option value="Hour">Hour</option>';
                                        new_row += '<option value="Trip">Trip</option>';
                                        new_row += '<option value="Kilometer">Kilometer</option>';
                                        new_row += '<option value="Day">Day</option>';
                                        new_row += '<option value="Month">Month</option>';
                                        new_row += '</select><span class="m-form__help"></span></div></td>';
                                        new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><input type="text" required data-row-sl-no="'+i+'" value="0" name="work_slip_basic_wage[unit_price]['+i+']" id="work_slip_basic_wage_unit_price_'+(i+1)+'" class="work_slip_basic_unit_price form-control m-input m-input--pill m-input--air"></td>';
                                        new_row += '<td><div class="form-group m-form__group" style="padding: 0px !important;margin: 0px !important;"><input type="text" style="border-color: #bfc0c3 !important;" value="0" readonly data-row-sl-no="'+i+'" name="work_slip_basic_wage[total]['+i+']" id="work_slip_basic_wage_total_'+(i+1)+'" class="work_slip_basic_wage_total_add form-control m-input m-input--pill m-input--air"></td>';
                                        new_row += '<td><a href="javascript:" data-row-sl-no="'+i+'" class="ibtnDel_work_slip_basic_wage_add btn btn-danger  m-btn m-btn--icon btn-sm m-btn--icon-only m-btn--pill" ><i class="fa fa-trash"></i></td></tr>';


                                        $('#table_body_work_slip_basic_wage_add').append(new_row);
                                        $('#current_row_count_work_slip_basic_wage_add').val(i+1);

                                        $('#work_slip_basic_wage_duration_type_'+(i+1)).selectpicker();
                                        if(i>=2){
                                          $("#addrow_work_slip_basic_wage_add").hide();
                                        }else{
                                          $("#addrow_work_slip_basic_wage_add").show();
                                        }
                                        i++;
                                      });
                                      $("#table_body_work_slip_basic_wage_add").on("click", ".ibtnDel_work_slip_basic_wage_add", function (event) {
                                        var sl_no = $(this).attr("data-sl-no");

                                        var counter = parseInt($("#current_row_count_work_slip_basic_wage_add").val());
                                        $(this).closest("tr").remove();
                                        counter -= 1;
                                        $("#current_row_count_work_slip_basic_wage_add").val(counter);
                                        calculate_basic_wage_add();
                                        if(counter>=3){
                                          $("#addrow_work_slip_basic_wage_add").hide();
                                        }else{
                                          $("#addrow_work_slip_basic_wage_add").show();
                                        }
                                      });
                                      $('body').on('change keyup', '.work_slip_basic_wage_duration,.work_slip_basic_unit_price,.work_slip_basic_overtime_duration,.work_slip_basic_overtime_rate', function() {
                                        calculate_basic_wage_add();
                                      })
                                      function calculate_basic_wage_add(){
                                        var total_basic_wage_amount = 0;
                                        $(".work_slip_basic_wage_total_add").each(function() {
                                          var slno = $(this).data('row-sl-no');
                                          var basic_wage_duration = parseFloat($('#work_slip_basic_wage_duration_'+(slno+1)).val());
                                          var basic_wage = parseFloat($('#work_slip_basic_wage_unit_price_'+(slno+1)).val());
                                          if (isNaN(basic_wage_duration)) {
                                            basic_wage_duration=0;
                                          }
                                          if (isNaN(basic_wage)) {
                                            basic_wage=0;
                                          }
                                          var total_amount = (basic_wage_duration*basic_wage);
                                          $('#work_slip_basic_wage_total_'+(slno+1)).val(total_amount);
                                          total_basic_wage_amount += total_amount;
                                        });
                                        $("#total_basic_charge_add").val(total_basic_wage_amount);
                                        calculate_pay_add();
                                      }
                                      <?php } ?>
                                      </script>
