<script>
<?php if($page_name=='labour_wages_view'){?>
  $("#table_filter_work").select2({
    placeholder: "Select Work",
    templateResult: format_project_dropdown
  })
  $("#table_filter_work_type").select2({
    placeholder: "Select Work Type"
  })
  $("#table_filter_labour").select2({
    placeholder: "Select Labour"
  })
  $("#table_filter_labour_group_head").select2({
    placeholder: "Select Team Head"
  })
  <?php } ?>
  $("#labour_wage_work_date_add,#labour_wage_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 } ?>
    })
    $("#labour_wage_paid_date_add,#labour_wage_paid_date_edit,#labour_wage_reference_date_add,#labour_wage_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', '#labour_wage_payment_mode_add', function() {
        var payment_mode=$('#labour_wage_payment_mode_add :selected').val();
        if(payment_mode=='POST DATED CHEQUE'){
          $('#labour_wage_paid_date_add').datepicker('destroy');
          $("#labour_wage_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{
          $('#labour_wage_paid_date_add').datepicker('destroy');
          $("#labour_wage_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 } ?>
            })
        }
      })
      $("#labour_wage_payment_mode_add").select2({
        placeholder: "Select Debit Account",
        dropdownParent: $("#form_labour_wage_add")
      })
      $("#labour_wage_debit_acc_add").select2({
        placeholder: "Select Debit Account",
        dropdownParent: $("#form_labour_wage_add")
      })
      $("#labour_wage_work_add").select2({
        placeholder: "Select Work",
        dropdownParent: $("#form_labour_wage_add"),
        templateResult: format_project_dropdown
      })
      $("#labour_wage_labour_add").select2({
        placeholder: "Select Labour",
        dropdownParent: $("#form_labour_wage_add")
      })

      $("#labour_wage_work_edit").select2({
        placeholder: "Select Work",
        dropdownParent: $("#form_labour_wage_edit"),
        templateResult: format_project_dropdown
      })
      $("#labour_wage_labour_edit").select2({
        placeholder: "Select Labour",
        dropdownParent: $("#form_labour_wage_edit")
      })

      $("#labour_wage_labour_add_2").select2({
        placeholder: "Select Labour",
        dropdownParent: $("#form_labour_payment_add")
      })

      $("#labour_wage_labour_edit_2").select2({
        placeholder: "Select Labour",
        dropdownParent: $("#form_labour_payment_edit")
      })

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

        function calculate_wage_add(field_id=''){
          var overtime_calculation_type = "<?php echo $this->config->item('Labour_wage_overtime_calculation'); ?>";
          var total_duty_hours = parseFloat("<?php echo $this->config->item('Labour_total_duty_hours'); ?>");
          var wage_per_day = parseFloat($("#wage_per_day_add").val());
          var ta_per_day = parseFloat($("#ta_amount_day_add").val());
          var no_of_days = parseFloat($("#no_of_days_add").val());
          var no_of_labours = parseFloat($("#no_of_labours_add").val());
          var overtime_wage = 0;
          if(field_id!='ta_wage_add'){
            $("#ta_wage_add").val((no_of_days*ta_per_day).toFixed(2));
          }

          if(overtime_calculation_type=='hour'){
            $("#overtime_wage_add").attr('readonly',true);
            if(field_id=='wage_per_day_add' || field_id=='labour_wage_labour_add'){
              // var overtime_wage_per_hour = (wage_per_day/total_duty_hours).toFixed(2);
              // $("#overtime_rate_add").val(overtime_wage_per_hour);
              var overtime_wage_per_hour = parseFloat($("#overtime_rate_add").val());
            }else{
              var overtime_wage_per_hour = parseFloat($("#overtime_rate_add").val());
            }
            var overtime_duration = parseFloat($("#overtime_duration_add").val());
            overtime_wage = parseFloat((overtime_wage_per_hour*overtime_duration).toFixed(2));
            $("#overtime_wage_add").val(overtime_wage);
          }else{
            overtime_wage = parseFloat($("#overtime_wage_add").val());
          }
          var extra_wage = parseFloat($("#extra_wage_add").val());
          var ta_wage = parseFloat($("#ta_wage_add").val());
          var food_allowance = parseFloat($("#food_allowance_add").val());
          var previous_balance = parseFloat($("#previous_balance_add").val());
          var total_wage = (no_of_labours*no_of_days*wage_per_day) + overtime_wage+extra_wage+ta_wage+food_allowance;
          var total_balance = previous_balance + total_wage;
          $("#total_wage_add").val(total_wage);
          $("#total_balance_add_wage_slip").val(total_balance);
        }
        function calculate_wage_edit(){
          var overtime_calculation_type = "<?php echo $this->config->item('Labour_wage_overtime_calculation'); ?>";
          var total_duty_hours = parseFloat("<?php echo $this->config->item('Labour_total_duty_hours'); ?>");
          var wage_per_day = parseFloat($("#wage_per_day_edit").val());
          var no_of_days = parseFloat($("#no_of_days_edit").val());
          var no_of_labours = parseFloat($("#no_of_labours_edit").val());
          var overtime_wage = 0;
          if(overtime_calculation_type=='hour'){
            $("#overtime_wage_edit").attr('readonly',true);
            var overtime_wage_per_hour = (wage_per_day/total_duty_hours).toFixed(2);
            $("#overtime_rate_edit").val(overtime_wage_per_hour);
            var overtime_duration = parseFloat($("#overtime_duration_edit").val());
            overtime_wage = parseFloat((overtime_wage_per_hour*overtime_duration).toFixed(2));
            $("#overtime_wage_edit").val(overtime_wage);
          }else{
            overtime_wage = parseFloat($("#overtime_wage_edit").val());
          }
          var extra_wage = parseFloat($("#extra_wage_edit").val());
          var ta_wage = parseFloat($("#ta_wage_edit").val());
          var food_allowance = parseFloat($("#food_allowance_edit").val());
          var previous_balance = parseFloat($("#previous_balance_edit").val());

          var total_wage = (no_of_labours*no_of_days*wage_per_day) + overtime_wage+extra_wage+ta_wage+food_allowance;
          var total_balance = previous_balance + total_wage;
          $("#total_wage_edit").val(total_wage);
          // $("#total_balance_edit").val(total_balance);
        }

        $('body').on('change', '#labour_wage_labour_add', function() {
          var labour_id=$('#labour_wage_labour_add :selected').val();
          $.post("<?php echo base_url() ?>labours/select_details",{labour_id:labour_id},function(data) {
            var obj = $.parseJSON(data);
            var i=0;
            if(obj.count==1) {
              if(obj.fixed_wage==1){
                $("#wage_per_day_add").attr('readonly',true);
              }else{
                $("#wage_per_day_add").removeAttr('readonly',true);
              }
              var Labour_wage_slip_no_of_labours_field_show = <?php echo $this->config->item('Labour_wage_slip_no_of_labours_field_show')?>;
              if(obj.labour_type==1 && obj.group_position==1){
                $("#no_of_labours_add").val(1);
                $("#labour_wage_no_of_labours_div_add").show();
              }else{
                $("#no_of_labours_add").val(1);
                if(Labour_wage_slip_no_of_labours_field_show==0){
                  $("#labour_wage_no_of_labours_div_add").hide();
                }
              }
              $("#wage_per_day_add").val(obj.daily_wage);
              $("#overtime_rate_add").val(obj.overtime_rate_per_hr);
              $("#ta_amount_day_add").val(obj.ta_amount);
              $("#ta_wage_add").val(obj.ta_amount);
              $("#previous_balance_add").val(obj.current_balance);
              calculate_wage_add('wage_per_day_add');
            }
          })
        })

        $('body').on('change keyup', '.wage_add_calculate_fields', function() {
          if($(this).val()==''){
            $(this).val(0);
          }
          var field_id = $(this).attr('id');
          calculate_wage_add(field_id);
        })
        $('body').on('change keyup', '.wage_edit_calculate_fields', function() {
          if($(this).val()==''){
            $(this).val(0);
          }
          calculate_wage_edit();
        })

        $('body').on('click', '#labour_wage_edit_btn', function() {
          var no = $(this).closest('tr').children('td');
          $('#labour_wage_id_edit').val(no.eq(1).text());
          $('#labour_wage_labour_edit').val(no.eq(22).text()).trigger('change');
          $('#labour_id_edit').val(no.eq(22).text());

          // $.post("<?php echo base_url() ?>labours/select_details",{labour_id:no.eq(20).text()},function(data) {
          //   var obj = $.parseJSON(data);
          //   var i=0;
          //   if(obj.count==1) {
          //     if(obj.labour_type==1 && obj.group_position==1){
          //       $("#labour_wage_no_of_labours_div_edit").show();
          //     }else{
          //       $("#labour_wage_no_of_labours_div_edit").hide();
          //     }
          //   }
          // })
          var Labour_wage_slip_no_of_labours_field_show = <?php echo $this->config->item('Labour_wage_slip_no_of_labours_field_show')?>;
          if(Labour_wage_slip_no_of_labours_field_show==0){
            $("#labour_wage_no_of_labours_div_edit").hide();
          }else{
            $("#labour_wage_no_of_labours_div_edit").show();
          }
          $('#labour_wage_work_edit').val(no.eq(23).text()).trigger('change');
          $('#labour_wage_work_date_edit').datepicker("setDate", no.eq(4).text());
          $('#no_of_labours_edit').val(no.eq(9).text());
          $('#wage_per_day_edit').val(no.eq(10).text());
          $('#overtime_rate_edit').val(no.eq(24).text());
          $('#overtime_duration_edit').val(no.eq(12).text());
          $('#no_of_days_edit').val(no.eq(8).text());
          $('#overtime_wage_edit').val(no.eq(13).text());
          $('#extra_wage_edit').val(no.eq(14).text());
          $('#ta_wage_edit').val(no.eq(15).text());
          $('#food_allowance_edit').val(no.eq(16).text());
          $('#total_wage_edit').val(no.eq(17).text());
          $('#remarks_edit').val(no.eq(18).text());
        })
        $('body').on('click', '#labour_wage_delete_btn', function() {
          var no = $(this).closest('tr').children('td');
          $('#labour_wage_id_delete').val(no.eq(1).text());
        })

        <?php if($page_name=='labour_wages_view'){?>
          function GetSearchWork(){
            return $('#table_filter_work').val();
          }
          function GetSearchWorkType(){
            return $('#table_filter_work_type').val();
          }
          function GetSearchLabour(){
            return $('#table_filter_labour').val();
          }
          function GetSearchLabourGroupHead(){
            return $('#table_filter_labour_group_head').val();
          }
          function GetSearchDate(){
            return $('#table_filter_date').val();
          }
          <?php } ?>
          <?php if($page_name=='labour_profile'){?>
            function GetWageSlipsStartDate(){
              return $('#wage_slips_table_filter_start_date').val();
            }
            function GetWageSlipsEndDate(){
              return $('#wage_slips_table_filter_end_date').val();
            }
            function GetWageSlipsWork(){
              return $('#wage_slips_table_filter_work').val();
            }

            <?php } ?>
            <?php if($page_name=='user_profile'){?>
              function GetStartDate(){
                return $('#table_filter_start_date').val();
              }
              function GetEndDate(){
                return $('#table_filter_end_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();
                }
                <?php } ?>
                <?php
                $page_type='l';
                if($page_name=='data_entry_approval'){
                  $page_type='approval_entries';
                }
                ?>
                var labour_wage_view_table = $('#labour_wage_view_table').DataTable({
                  "ajax":{
                    url :"<?php echo base_url().'labour_wages/select_labour_wages/'.$page_type ?><?php if($page_name=='labour_profile'){ echo "/nospace";} ?>", // json datasource
                    type: "post", // type of method  , by default would be get
                    data: function(d){
                      <?php if($page_name=='labour_wages_view'){?>
                        d.work = GetSearchWork();
                        d.work_type = GetSearchWorkType();
                        d.labour = GetSearchLabour();
                        d.labour_group_head = GetSearchLabourGroupHead();
                        d.date = GetSearchDate();
                        <?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();
                              d.work = GetSearchWork();
                              <?php } ?>
                              <?php if($page_name=='labour_profile'){?>
                                d.labour = "<?php echo $labour_data->labour_id?>";
                                d.start_date = GetWageSlipsStartDate();
                                d.end_date = GetWageSlipsEndDate();
                                d.work = GetWageSlipsWork();
                                <?php } ?>
                                <?php if($page_name=='user_profile'){?>
                                  d.user_id = "<?php echo $user_data->user_id?>";
                                  d.start_date = GetStartDate();
                                  d.end_date = GetEndDate();
                                  <?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=='data_entry_approval'){?>
                                      d.start_date = GetStartDate();
                                      d.end_date = GetEndDate();
                                      d.work = GetSearchWork();
                                      d.approval_status = GetSearchApprovalStatus();
                                      d.user_id = GetSearchUser();
                                      <?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: '<?php if($page_name=="labour_profile"){ echo "Labour Wages - ".$labour_data->labour_name;}else{ echo "Labour Wages";}?>' },
                                        { 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": [ 1,6,22,23,24,25  <?php if($this->config->item('Labour_wage_overtime_calculation')=='amount'){ echo ",11,22";?><?php } ?><?php if($page_name=='work_profile'){ echo ",7"; }?><?php if($page_name=='work_summary'){ echo ",5,7,18,19,20,21"; }?><?php if($page_name=='reports_activity'){ echo ",21"; }?><?php if($page_name=='labour_profile'){ echo ",2,3,20"; }?> ],
                                          className: "hidden"
                                        }
                                      ],
                                      "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                        if ( aData[7] == "" )
                                        {
                                          $('td', nRow).css('background-color', '#868686');
                                        }
                                        if(aData[25]=='0'){
                                          $('td', nRow).css('background-color', '#ffcccc');
                                        }else if(aData[25]=='2'){
                                          $('td', nRow).css('background-color', '#ffcccc');
                                        }
                                      }
                                    });
                                    <?php if($page_name=='labour_profile' && $labour_data->labour_type==1 && $labour_data->group_position==1){?>
                                      var labour_wage_team_view_table = $('#labour_wage_team_view_table').DataTable({
                                        "ajax":{
                                          url :"<?php echo base_url().'labour_wages/select_labour_wages/nospace' ?>", // json datasource
                                          type: "post", // type of method  , by default would be get
                                          data: function(d){
                                            d.labour_group_head = "<?php echo $labour_data->labour_id?>";
                                            d.start_date = GetWageSlipsStartDate();
                                            d.end_date = GetWageSlipsEndDate();
                                            d.work = GetWageSlipsWork();
                                          }
                                        },
                                        "bProcessing": true,
                                        "deferRender": true,
                                        "bDeferRender": true,
                                        "scrollX" : true,
                                        buttons: [
                                          { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'}, title: 'Team Wage Slips Of : <?php echo $labour_data->labour_name ?>', },
                                          { 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>>",
                                        "lengthMenu": [
                                          [25, 50, 100, -1],
                                          [25, 50, 100, "All"] // change per page values here
                                        ],
                                        "columnDefs": [
                                          {
                                            "targets": [ 1,6,20,22,23,24,25 ],
                                            className: "hidden"
                                          }
                                        ],
                                        'order': false,
                                        "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                          if(aData[25]=='0'){
                                            $('td', nRow).css('background-color', '#ffcccc');
                                          }else if(aData[25]=='2'){
                                            $('td', nRow).css('background-color', '#ffcccc');
                                          }
                                        }
                                      });
                                      <?php } ?>
                                      var labour_wage_summary_view_table = $('#labour_wage_summary_view_table').DataTable({
                                        "ajax":{
                                          url :"<?php echo base_url().'labour_wages/select_labour_wage_summary' ?>", // json datasource
                                          type: "post", // type of method  , by default would be get
                                          data: function(d){
                                            <?php if($page_name=='labour_wages_view'){?>
                                              d.work = GetSearchWork();
                                              d.work_type = GetSearchWorkType();
                                              d.labour = GetSearchLabour();
                                              d.labour_group_head = GetSearchLabourGroupHead();
                                              d.date = GetSearchDate();
                                              <?php } ?>
                                              <?php if($page_name=='labour_profile'){?>
                                                d.labour = "<?php echo $labour_data->labour_id?>";
                                                <?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=='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 } ?>
                                                    }
                                                  },
                                                  "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',grouped_array_index: [ 1 ]} ,title: 'Labour Wage Summary'},
                                                        { 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 } ?>
                                                      "rowCallback": function (nRow, aData, iDisplayIndex) {
                                                        var oSettings = this.fnSettings ();
                                                        $("td:first", nRow).html(oSettings._iDisplayStart+iDisplayIndex +1);
                                                        return nRow;
                                                      },
                                                      "columnDefs": [
                                                        {
                                                          "targets": [1 ],
                                                          className: "hidden"
                                                        }
                                                      ],
                                                      <?php if($page_name!='labour_profile'){?>
                                                        rowGroup: {
                                                          dataSrc: 1
                                                        },
                                                        <?php } ?>
                                                        "order" : [[1,'asc']]
                                                      });
                                                      $(".table_filter").on("change", function() {
                                                        labour_wage_view_table.ajax.reload();
                                                        labour_wage_summary_view_table.ajax.reload();
                                                      });
                                                      <?php if($page_name=='labour_profile' && $labour_data->labour_type==1 && $labour_data->group_position==1){?>
                                                        var labour_wage_summary_team_view_table = $('#labour_wage_summary_team_view_table').DataTable({
                                                          "ajax":{
                                                            url :"<?php echo base_url().'labour_wages/select_labour_wage_summary' ?>", // json datasource
                                                            type: "post", // type of method  , by default would be get
                                                            data: function(d){
                                                              <?php if($page_name=='labour_profile'){?>
                                                                d.labour_group_head = "<?php echo $labour_data->labour_id?>";
                                                                <?php } ?>
                                                              }
                                                            },
                                                            "bProcessing": true,
                                                            "deferRender": true,
                                                            "bDeferRender": true,
                                                            "scrollX" : true,
                                                            buttons: [
                                                              { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible',grouped_array_index: [ 1 ]},title: 'Labour Wage Summary - Team' },
                                                              { 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
                                                            ],
                                                            "rowCallback": function (nRow, aData, iDisplayIndex) {
                                                              var oSettings = this.fnSettings ();
                                                              $("td:first", nRow).html(oSettings._iDisplayStart+iDisplayIndex +1);
                                                              return nRow;
                                                            },
                                                            "columnDefs": [
                                                              {
                                                                "targets": [1 ],
                                                                className: "hidden"
                                                              }
                                                            ],rowGroup: {
                                                              dataSrc: 1
                                                            },
                                                            "order" : [[1,'asc']]
                                                          });
                                                          <?php } ?>
                                                          <?php if($page_name=='labour_wages_view' || $page_name=='reports_activity' || $page_name=='user_profile' || $page_name=='labour_profile' || $page_name=='data_entry_approval'){?>
                                                            <?php if($page_name=='labour_profile'){?>
                                                              function GetWagePaymentsStartDate(){
                                                                return $('#wage_payments_table_filter_start_date').val();
                                                              }
                                                              function GetWagePaymentsEndDate(){
                                                                return $('#wage_payments_table_filter_end_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 labour_wage_transaction_view_table = $('#labour_wage_transaction_view_table').DataTable({
                                                                  "ajax":{
                                                                    url :"<?php echo base_url().'accounts/select_account_transactions/labour/'.$page_type ?>", // json datasource
                                                                    type: "post", // type of method  , by default would be get
                                                                    data: function(d){
                                                                      <?php if($page_name=='labour_wages_view'){?>
                                                                        d.work_type = GetSearchWorkType();
                                                                        d.labour = GetSearchLabour();
                                                                        d.labour_group_head = GetSearchLabourGroupHead();
                                                                        d.date = GetSearchDate();
                                                                        <?php } ?>
                                                                        <?php if($page_name=='labour_profile'){?>
                                                                          d.labour = "<?php echo $labour_data->labour_id?>";
                                                                          d.start_date = GetWagePaymentsStartDate();
                                                                          d.end_date = GetWagePaymentsEndDate();
                                                                          <?php } ?>
                                                                          <?php if($page_name=='reports_activity'){?>
                                                                            d.date = GetSearchDate();
                                                                            <?php } ?>
                                                                            <?php if($page_name=='user_profile'){?>
                                                                              d.acc_user_id = "<?php echo $user_data->user_id?>";
                                                                              d.start_date = GetStartDate();
                                                                              d.end_date = GetEndDate();
                                                                              <?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,
                                                                            "scrollX" : true,
                                                                            buttons: [
                                                                              { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Labour Wage 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,
                                                                            "columnDefs": [
                                                                              {
                                                                                "targets": [ 3,6,7,8,9,19,20,21,22,23<?php if($page_name=='reports_activity'){ echo ",18"; }?><?php if($page_name=='user_profile'){ echo ",16"; }?>],
                                                                                className: "hidden"
                                                                              }
                                                                            ],
                                                                            'ordering': false,
                                                                            "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                                                                              if ( aData[10] == "" )
                                                                              {
                                                                                $('td', nRow).css('background-color', '#868686');
                                                                              }
                                                                              if(aData[23]=='0'){
                                                                                $('td', nRow).css('background-color', '#ffcccc');
                                                                              }else if(aData[23]=='2'){
                                                                                $('td', nRow).css('background-color', '#ffcccc');
                                                                              }
                                                                            }
                                                                          });
                                                                          <?php if($page_name=='labour_profile' && $labour_data->labour_type==1 && $labour_data->group_position==1){?>
                                                                            var labour_wage_transaction_team_view_table = $('#labour_wage_transaction_team_view_table').DataTable({
                                                                              "ajax":{
                                                                                url :"<?php echo base_url().'accounts/select_account_transactions/labour' ?>", // json datasource
                                                                                type: "post", // type of method  , by default would be get
                                                                                data: function(d){
                                                                                  d.labour_group_head = "<?php echo $labour_data->labour_id?>";
                                                                                }
                                                                              },
                                                                              "bProcessing": true,
                                                                              "deferRender": true,
                                                                              "bDeferRender": true,
                                                                              "scrollX" : true,
                                                                              buttons: [
                                                                                { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'}, title: 'Team Labour Wage Payment Towards : <?php echo $labour_data->labour_name ?>', },
                                                                                { 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>>",
                                                                              "lengthMenu": [
                                                                                [25, 50, 100, -1],
                                                                                [25, 50, 100, "All"] // change per page values here
                                                                              ],
                                                                              "columnDefs": [
                                                                                {
                                                                                  "targets": [ 3,6,7,8,9,19,20,21,22,23],
                                                                                  className: "hidden"
                                                                                }
                                                                              ],
                                                                              'order': false,
                                                                              "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');
                                                                                }
                                                                              }
                                                                            });
                                                                            <?php } ?>
                                                                            $(".table_filter").on("change", function() {
                                                                              labour_wage_transaction_view_table.ajax.reload();
                                                                            });
                                                                            $(".hide_column").hide();

                                                                            <?php }
                                                                            if($page_name=='labour_wages_view'){ ?>

                                                                              // 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'));
                                                                                labour_wage_view_table.ajax.reload();
                                                                                labour_wage_summary_view_table.ajax.reload();
                                                                                labour_wage_transaction_view_table.ajax.reload();
                                                                                $("#labour_wage_summary_view_table_caption").text("Labour Wage Report - "+$('#table_filter_date').val())
                                                                              }

                                                                              $('#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);


                                                                              $(".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
                                                                                    },
                                                                                    ta_wage: {
                                                                                      number: !0
                                                                                    },
                                                                                    no_of_labours: {
                                                                                      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);
                                                                                      labour_wage_view_table.ajax.reload();
                                                                                      labour_wage_transaction_view_table.ajax.reload();
                                                                                      <?php if($page_name=='labour_profile' && $labour_data->labour_type==1 && $labour_data->group_position==1){?>
                                                                                        labour_wage_team_view_table.ajax.reload();
                                                                                        <?php } ?>
                                                                                        labour_wage_summary_view_table.ajax.reload();
                                                                                        <?php if($page_name=='labour_profile' && $labour_data->labour_type==1 && $labour_data->group_position==1){?>
                                                                                          labour_wage_summary_team_view_table.ajax.reload();
                                                                                          <?php } ?>
                                                                                          <?php if($page_name=='labour_profile' && $labour_data->labour_type==1 && $labour_data->group_position==1){?>
                                                                                            labour_wage_transaction_team_view_table.ajax.reload();
                                                                                            <?php } ?>
                                                                                            $('#labour_wage_work_date_add,#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 } ?>
                                                                                  </script>
