<?php $this->view("includes/Inc_pagehead");?>
<!-- Page Styles Goes Here-->
<?php $this->view("includes/Inc_navigation");?>
<div class="m-grid__item m-grid__item--fluid m-wrapper">
  <!-- BEGIN: Subheader -->
  <div class="m-subheader ">
    <div class="d-flex align-items-center">
      <div class="mr-auto">
        <h3 class="m-subheader__title m-subheader__title--separator">
          Quick Add Labour Wage Slip
        </h3>
        <ul class="m-subheader__breadcrumbs m-nav m-nav--inline">
          <li class="m-nav__item m-nav__item--home">
            <a href="#" class="m-nav__link m-nav__link--icon">
              <i class="m-nav__link-icon la la-home"></i>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'dashboard'?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Home
              </span>
            </a>
          </li>
          <li class="m-nav__separator">
            -
          </li>
          <li class="m-nav__item">
            <a href="<?php echo base_url().'labour_wages/add_quick' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Quick Add Labour Wage Slip
              </span>
            </a>
          </li>


        </ul>
      </div>
      <div>

      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <!--begin::Portlet-->
    <div class="m-portlet">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
              Quick Add Labour Wage Slip
            </h3>
          </div>
        </div>
      </div>
      <!--begin::Form-->
      <form autocomplete="off" id="form_labour_wage_add" method="post" action="<?php echo base_url().'labour_wages/create_quick'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right ">
        <div class="m-portlet__body" style="padding-top: 0px">
          <div class="m-form__content">
            <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_work_msg">
              <div class="m-alert__icon">
                <i class="la la-warning"></i>
              </div>
              <div class="m-alert__text">
                Oh snap! Change a few things up and try submitting again.
              </div>
              <div class="m-alert__close">
                <button type="button" class="close" data-close="alert" aria-label="Close"></button>
              </div>
            </div>
          </div>
          <div style="background: white;border: 4px solid #f7f7fa;padding: 30px;margin: 20px;padding-bottom: 0px">
            <div class="m-section" style="margin-bottom: 20px">
              <div class="row">
                <div class="col-lg-7">
                  <div class="form-group m-form__group row">
                    <label for="example-text-input" class="col-5 col-form-label"><h3 class="m-section__heading">Select Project</h3></label>
                    <div class="col-7">
                      <div class="m-select2 m-select2--air m-select2--pill">
                        <select required style="width: 100%" class="form-control m-select2  form_labour_wage_add_select" id="work_add" name="work"  >
                          <option selected disabled>Select Work</option>
                          <?php
                          foreach($work_contracts as $row):
                            ?>
                            <option data-work-status="<?php echo $row->work_status?>" value="<?php echo $row->work_id?>"><?php echo $row->work_name?></option>
                            <?php
                          endforeach;
                          ?>
                        </select>
                      </div>
                      <span class="m-form__help"></span>
                    </div>
                  </div>
                </div>
                <div class="col-lg-5">
                  <div class="form-group m-form__group row" >
                    <label for="example-text-input" class="col-6 col-form-label"><h3 class="m-section__heading">Work Date</h3></label>
                    <div class="col-6">
                      <div class="input-group m-input-group--air m-input-group--pill  date">
                        <input required value="<?php echo date('d-m-Y')?>"  data-date-format="dd-mm-yyyy" id="work_date" required type="text" name="work_date" class="form-control  m-input " placeholder="Work Date" >
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="labour_list_div" style="background: white;border: 4px solid #f7f7fa;padding: 30px;margin: 20px;padding-bottom: 0px;">
            <div class="m-section">
              <div class="row">
                <div class="col-lg-6"><h3 class="m-section__heading" style="margin-top: 15px;">List of <?php if($this->config->item('Labour_projet_assigning')==1 ){ echo "Assigned "; } ?>Labours</h3></div>
                <div class="col-lg-3"></div>
                <div class="col-lg-3">
                  <div class="form-group m-form__group row" style="margin-bottom: 15px;">
                    <select style="width: 100%" class="form-control m-select2 " id="work_type"  >

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

              <table style="width: 100%;max-width: 100%"  id="table_labour_quick_wage" class="table order-list table-striped table-bordered table-advance table-hover">
                <thead>
                  <tr>
                    <th style="width:3%">Sl No</th>
                    <th style="width:<?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){ echo '25%'; }else{ echo '15%';}?>">Labour</th>
                    <th style="width:5%">Worked</th>
                    <th style="width:8%">Basic Wage<br/>per <?php echo ucwords($this->config->item('Labour_wage_calculation_type')) ?></th>
                    <th style="width:8%;<?php if($this->config->item('Labour_wage_calculation_type')=='day'){ echo 'display:none'; }?>"><?php echo ucwords($this->config->item('Labour_wage_calculation_type')) ?>s</th>
                      <?php if($this->config->item('Labour_wage_overtime_calculation')=='hour'){ ?>
                        <th style="width:8%">Overtime<br/>Duration</th>
                        <th style="width:8%">Overtime<br/>Rate</th>
                      <?php } ?>
                      <th style="width:8%">Overtime<br/>Amount</th>
                      <th style="width:8%;<?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){ echo 'display:none'; }?>">Extra<br/>Wage</th>
                        <th style="width:8%;<?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){ echo 'display:none'; }?>">Travel<br/>Allowance</th>
                          <th style="width:8%;<?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){ echo 'display:none'; }?>">Food<br/>Allowance</th>
                            <th style="width:8%;">Total Wage</th>
                            <th style="width:8%;display:none">Labour Name</th>
                          </tr>
                        </thead>
                        <tbody id="table_body">

                        </tbody>
                        <tfoot>
                          <tr>
                          </tr>
                        </tfoot>
                      </table>
                      <input type="hidden" value="0" id="current_row_count" name="current_row_count" >
                      <?php if($this->config->item('Labour_projet_assigning')==1 ){ ?>
                        <button type="button" id="btn_show_not_assigned_labours" style="display:none" class="btn btn-focus">
                          Show Not Assigned Labours
                        </button>
                      <?php } ?>
                    </div>
                  </div>
                  <div class="labour_list_div" style="background: white;border: 4px solid #f7f7fa;padding: 30px;margin: 20px;padding-bottom: 0px;">
                    <div class="m-section">
                      <h3 class="m-section__heading">Summary</h3>
                      <div class="row">
                        <div class="col-lg-3">
                          <div class="form-group m-form__group" >
                            <label for="user_name">
                              Total Labours Worked
                            </label>
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                              <div class="input-group-prepend">
                                <span class="input-group-text" id="basic-addon1">
                                  <i class="la la-users"></i>
                                </span>
                              </div>
                              <input value="0" readonly type="text" name="grand_total_labours_worked" id="grand_total_labours_worked"  class="form-control form_labour_add_fields m-input" aria-describedby="basic-addon1">
                            </div>
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                        <div class="col-lg-3">
                          <div class="form-group m-form__group" >
                            <label for="user_name">
                              Total Wage
                            </label>
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                              <div class="input-group-prepend">
                                <span class="input-group-text" id="basic-addon1">
                                  <?php echo $this->config->item('Currency_currency_format'); ?>
                                </span>
                              </div>
                              <input value="0" readonly type="text" name="grand_total_wage" id="grand_total_wage"  class="form_labour_add_fields form-control m-input"  aria-describedby="basic-addon1">
                            </div>
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                        <div class="col-lg-6">
                          <div class="form-group m-form__group" >
                            <label for="user_name">
                              Wage Remarks
                            </label>
                            <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                              <div class="input-group-prepend">
                                <span class="input-group-text" id="basic-addon1">
                                  <i class="la la-edit"></i>
                                </span>
                              </div>
                              <input  type="text" name="remarks" id="remarks"  class="form-control form_labour_add_fields m-input" placeholder="Remarks" aria-describedby="basic-addon1">
                            </div>
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="m-portlet__foot m-portlet__foot--fit">
                  <div class="m-form__actions m-form__actions">
                    <div class="row">
                      <div class="col-lg-9 ml-lg-auto">
                        <button type="submit" class="btn btn-brand">
                          Submit
                        </button>
                        <button type="reset" class="btn btn-secondary">
                          Cancel
                        </button>
                      </div>
                    </div>
                  </div>
                </div>
              </form>
              <!--end::Form-->

            </div>
          </div>


        </div>
      </div>
      <!-- end:: Body -->
      <!-- begin::Footer -->

      <?php $this->view("includes/Inc_footer");?>
      <!-- end::Footer -->
    </div>
    <!-- end:: Page -->

    <?php $this->view("includes/Inc_sidebar");?>
    <?php $this->view("includes/Inc_scripts");?>
    <!--begin::Page Snippets -->

    <script>
    $("#labour_menu").addClass('m-menu__item--active m-menu__item--open');
    $("#labour_menu_2").addClass('m-menu__item--active');
  </script>
  <script>

  $("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
  $("#body").addClass("m-brand--minimize m-aside-left--minimize");
  $("#work_add").select2({
    placeholder: "Select Project",
    dropdownParent: $("#form_labour_wage_add"),
    templateResult: format_project_dropdown
  })
  $("#work_type").select2({
    placeholder: "Select Work Type",
    dropdownParent: $("#form_labour_wage_add")
  })
  function select_work_type(select_id){
    $('#'+select_id).html('');
    $("#"+select_id).append("<option selected value='all' >All Work Types</option>");
    $.post("<?php echo base_url() ?>work_types/select",{},function(data) {
      var obj = $.parseJSON(data);
      var i=0;
      if(obj.count>0) {
        while (i < obj.id.length) {
          $("#"+select_id).append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
          i++;
        }
      }
    })
  }
  select_work_type("work_type");

  $("#work_date").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")
          })
          </script>
          <script>


          //  User Add / Edit Form Validation
          var FormControls=function() {

            add=function() {
              $("#form_labour_wage_add").validate( {
                rules: {
                  email: {
                    email: !0
                  },
                  client_contact: {
                    number: !0,
                    required: !0
                  },
                  budget_amt: {
                    number: !0,
                    required: !0
                  }
                },
                invalidHandler:function(e, r) {
                  var i=$("#form_work_msg");
                  i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
                }
                , submitHandler:function(e) {
                  var total_checked = $('input.work_status:checked').length;
                  if(total_checked!=0){
                    mApp.blockPage({
                      overlayColor: "#000000",
                      type: "loader",
                      state: "primary",
                      message: "Processing...Please Wait"
                    }), setTimeout(function() {}, 3e3);
                    this.submit();
                  }else{
                    toastr["warning"]("Please Select Labours", "No Labours Selected");
                  }

                }
              }
            );
            $('.m-select2,.m-select2-multiple',  $("#form_work")).change(function () {
              $("#form_work").validate().element($(this)); //revalidate the chosen dropdown value and show error or success message for the input
              $(this).select2("close");
            });
          };
          return {
            init:function() {
              add();
            }
          }
        }

        ();
        jQuery(document).ready(function() {
          FormControls.init();

          $(".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: {
                op_balance: {
                  number: !0
                },
                daily_wage: {
                  number: !0
                },
                contact_no: {
                  number: !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+"_select").val('').trigger("change");
                  toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
                  $('input[type=radio]').prop('checked', false);
                } 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");
              }
            })
          )
        });
      });

      </script>

      <script>
      $(document).ready(function () {
        $('body').on('change', '#work_type', function() {
          get_labours();
        })
        <?php if($this->config->item('Labour_projet_assigning')==1 ){ ?>
          $('body').on('change', '#work_add', function() {
            get_labours();
            $("#btn_show_not_assigned_labours").show();
          })
          <?php } ?>
          $('body').on('click', '#btn_show_not_assigned_labours', function() {
            get_labours('not_assigned');
            $("#btn_show_not_assigned_labours").hide();
          })
          var selected_work = '<?php echo $work_id ?>';
          $('#work_add').val(selected_work).trigger('change');

          function get_labours(assign_type=''){
            var work_type=$('#work_type').val();
            var work_id=$('#work_add').val();
            var current_row_count = parseFloat($('#current_row_count').val());
            $.post("<?php echo base_url() ?>labours/select",{work_type:work_type,work_id:work_id,assign_type:assign_type},function(data) {
              // $("#table_body").html("");
              var obj = $.parseJSON(data);
              var i=0;
              var table_body="";
              $('#table_labour_quick_wage').dataTable().fnDestroy();
              if(obj.count>0) {
                while (i < obj.id.length) {
                  var sl_no = current_row_count+i;
                  if(i>1 && obj.labour_group[i]!=obj.labour_group[i-1]){
                    table_body += '<tr style="border-top: 3px solid black">';
                  }else{
                    table_body += '<tr>';
                  }
                  table_body += '<td><div style="width:70px" class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input" name="wage_slip[sl_no]['+(sl_no)+']" value="' + (sl_no+1) + '"/></div></div></td>';
                  table_body += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input style="padding: 10px" readonly type="text" class="form-control m-input" name="wage_slip[labour_name]['+(sl_no)+']" value="' + obj.name[i] + '"/><input type="hidden"  name="wage_slip[labour_id]['+(sl_no)+']" value="' + obj.id[i] + '"/></div></div></td>';
                  table_body += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><span class="m-switch m-switch--outline m-switch--icon m-switch--success"><label><input type="checkbox" class="work_status " data-labour-no="' + (sl_no+1) + '"  name="wage_slip[work_status]['+(sl_no)+']" id="work_status_' + (sl_no+1) + '"><span></span></label></span></div></td>';

                  table_body += '<td><div style="display:none" class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[basic_wage]['+(sl_no)+']" id="basic_wage_' + (sl_no+1) + '" value="' + obj.daily_wage[i] + '"/></div></div></td>';
                  table_body += '<td style="<?php if($this->config->item('Labour_wage_calculation_type')=='day'){ echo 'display:none'; }?>"><div style="display:none" class="form-group m-form__group <?php if($this->config->item('Labour_wage_calculation_type')=='hour'){?> worked_field_'+(sl_no+1)+' <?php } ?> div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[no_of_days]['+(sl_no)+']" id="no_of_days_' + (sl_no+1) + '" value="1"/></div></div></td>';
                  <?php if($this->config->item('Labour_wage_overtime_calculation')=='hour'){ ?>
                    var wage_per_day = obj.daily_wage[i];
                    var total_duty_hours = parseFloat("<?php echo $this->config->item('Labour_total_duty_hours'); ?>");
                    // var overtime_wage_per_hour = (wage_per_day/total_duty_hours).toFixed(2);
                    var overtime_wage_per_hour = obj.overtime_rate_per_hr[i];
                    table_body += '<td><div style="display:none" class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[overtime_duration]['+(sl_no)+']" id="overtime_duration_' + (sl_no+1) + '" value="0"/></div></div></td>';
                    table_body += '<td><div style="display:none" class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[overtime_rate]['+(sl_no)+']" value="' + overtime_wage_per_hour + '" id="overtime_rate_' + (sl_no+1) + '" value="0"/></div></div></td>';
                    <?php } ?>
                    table_body += '<td><div style="display:none" class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[overtime]['+(sl_no)+']" id="overtime_' + (sl_no+1) + '" value="0"/></div></div></td>';
                    table_body += '<td style="<?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){ echo 'display:none'; }?>"><div style="display:none" class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[extra_wage]['+(sl_no)+']" id="extra_wage_' + (sl_no+1) + '" value="0"/></div></div></td>';
                    table_body += '<td style="<?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){ echo 'display:none'; }?>"><div style="display:none" class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[ta]['+(sl_no)+']" id="ta_' + (sl_no+1) + '" value="0"/></div></div></td>';
                    table_body += '<td style="<?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){ echo 'display:none'; }?>"><div style="display:none" class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' wage_calculate_fields numeric_fields" name="wage_slip[food_allowance]['+(sl_no)+']" id="food_allowance_' + (sl_no+1) + '" value="0"/></div></div></td>';
                    table_body += '<td ><div class="form-group m-form__group worked_field_'+(sl_no+1)+' div_labour_'+(sl_no+1)+'" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group  m-input-group--air"><input required style="padding: 10px" data-labour-no="' + (sl_no+1) + '" type="text" class="form-control m-input field_labour_'+(sl_no+1)+' total_wage_field " readonly name="wage_slip[total_wage]['+(sl_no)+']" id="total_wage_' + (sl_no+1) + '" value="0"/></div></div></td>';
                    table_body += '<td style="display:none">' + obj.name[i] + '</td>';
                    table_body += '</tr>';

                    i++;
                  }
                  $("#table_body").append(table_body);
                  $('#current_row_count').val(current_row_count+parseFloat(obj.count));
                  calculate_summary();
                  $(".numeric_fields").each(function () {
                    $(this).rules('add', {
                      number: !0
                    });
                  });
                }else{
                  // $("#table_body").html("");
                  // $('#current_row_count').val(current_row_count+parseFloat(obj.count));
                  // calculate_summary();
                }
                $('#table_labour_quick_wage').dataTable().fnDestroy();
                var table = $('#table_labour_quick_wage').DataTable({
                  "scrollX" : true,
                  dom:"<'row'<'col-sm-6 text-left'><'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
                  "pageLength": false,
                  'ordering': false,
                  "bLengthChange": false,
                  "bPaginate": false,
                  "bInfo": false,
                  "columnDefs": [{
                    render: function (data, type, full, meta) {
                      <?php if($this->config->item('Labour_quick_wage_slip_show_extra_wages')==0){?>
                        return "<div class='text-wrap width-400'>" + data + "</div>";
                        <?php }else{?>
                          return "<div class='text-wrap width-300'>" + data + "</div>";
                          <?php } ?>
                        },
                        targets: [ 1 ],
                      },
                    ],
                  });
                })

              }
              <?php if($this->config->item('Labour_projet_assigning')!=1 ){ ?>
                get_labours();
                <?php } ?>

                $('body').on('change', '.work_status', function() {
                  var id = $(this).attr('id');
                  var labour_no = $(this).attr('data-labour-no');
                  if ($('#'+id).is(':checked')){
                    $(".worked_field_"+labour_no).show();
                    $(".field_labour_"+labour_no).attr('required',true);
                  }else {
                    $(".worked_field_"+labour_no).hide();
                    $(".field_labour_"+labour_no).removeAttr('required',true);
                  }
                  calculate_wage(labour_no);
                })
                function calculate_wage(labour_no){
                  var overtime_calculation_type = "<?php echo $this->config->item('Labour_wage_overtime_calculation'); ?>";
                  var wage_per_day = parseFloat($("#basic_wage_"+labour_no).val());
                  var overtime_wage = 0;
                  if(overtime_calculation_type=='hour'){
                    $("#overtime_"+labour_no).attr('readonly',true);
                    // $("#overtime_rate_"+labour_no).attr('readonly',true);
                    var total_duty_hours = parseFloat("<?php echo $this->config->item('Labour_total_duty_hours'); ?>");
                    // var overtime_wage_per_hour = (wage_per_day/total_duty_hours).toFixed(2);
                    var overtime_wage_per_hour = parseFloat($("#overtime_rate_"+labour_no).val());
                    // $("#overtime_rate_"+labour_no).val(overtime_wage_per_hour);
                    var overtime_duration = parseFloat($("#overtime_duration_"+labour_no).val());
                    overtime_wage = parseFloat((overtime_wage_per_hour*overtime_duration).toFixed(2));
                    $("#overtime_"+labour_no).val(overtime_wage);
                  }else{
                    var overtime_wage = parseFloat($("#overtime_"+labour_no).val());
                  }

                  var extra_wage = parseFloat($("#extra_wage_"+labour_no).val());
                  var ta = parseFloat($("#ta_"+labour_no).val());
                  var food_allowance = parseFloat($("#food_allowance_"+labour_no).val());

                  var no_of_days = parseFloat($("#no_of_days_"+labour_no).val());;
                  var total_wage = (no_of_days*wage_per_day)+overtime_wage+extra_wage+ta+food_allowance;
                  if ($('#work_status_'+labour_no).is(':checked')){
                    var total_balance = total_wage;
                    $("#total_wage_"+labour_no).val(total_wage);
                  }else{
                    $("#total_wage_"+labour_no).val(0);
                  }
                  calculate_summary();
                }
                function calculate_summary(){
                  var total_labours_worked = total_wage = previous_balance = total_to_pay = total_paid = 0;
                  total_labours_worked = $('input.work_status:checked').length;
                  $(".total_wage_field").each(function(){
                    total_wage += +$(this).val();
                  });
                  $("#grand_total_labours_worked").val(total_labours_worked);
                  $("#grand_total_wage").val(total_wage);

                  // $('#table_labour_quick_wage').dataTable().fnDestroy();
                  // var table = $('#table_labour_quick_wage').DataTable({
                  //   "scrollX" : true,
                  //   dom:"<'row'<'col-sm-6 text-left'><'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
                  //   "pageLength": false,
                  //   'ordering': false,
                  //   "bLengthChange": false,
                  //   "bPaginate": false,
                  //   "bInfo": false,
                  // });
                  // var total_labours_worked = 0;
                  // table.rows().every(function (rowIdx, tableLoop, rowLoop) {
                  // var data = this.node();
                  // if($(data).find('input.work_status').is(":checked")){
                  //   var labour_no = $(this).data('labour-no');
                  //   total_labours_worked++;
                  //   total_wage += parseFloat($("#total_wage_"+labour_no).val());
                  // }
                  // $("#grand_total_labours_worked").val(total_labours_worked);
                  // $("#grand_total_wage").val(total_wage);
                  // })

                }
                $('body').on('change keyup', '.wage_calculate_fields', function() {
                  var labour_no = $(this).attr('data-labour-no');
                  if($(this).val()==''){
                    $(this).val(0);
                  }
                  calculate_wage(labour_no);
                })

              })
              </script>
