<?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">
          BOQ Details
        </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().'work' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                <!-- List Of <?php if($this->session->userdata('user_role')=='supervisor'){ echo "Assigned";}?> Works -->
                BOQ Details
              </span>
            </a>
          </li>
        </ul>
      </div>
      <div>
        <?php if ($this->session->flashdata('flashdata_msg') != "")
        {?>
          <div class="alert alert-<?php echo $this->session->flashdata('alert_type')?> alert-dismissible fade show   m-alert m-alert--air m-alert--outline m-alert--outline-2x" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
            <strong>
              <?php echo $this->session->flashdata('flashdata_title')?>
            </strong>
            <?php echo $this->session->flashdata('flashdata_msg')?>
          </div>
        <?php } ?>
      </div>
    </div>
  </div>
  <!-- END: Subheader -->
  <div class="m-content">
    <div class="m-portlet m-portlet--mobile m-portlet--info m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <?php if($boq_data->created_by == $this->session->userdata('user_id')){ ?>
            <div class="m-portlet__head-title">
              <h3 class="m-portlet__head-text">
                <div id="toolbar" class="btn-group">
                  <button type="button" href="#add_work_cat_modal" data-toggle="modal" class="btn btn-light btn-elevate-hover btn-pill"><i class="la la-plus"></i> Add Work Type</button>
                </div>
              </h3>
            </div>
            <div class="m-portlet__head-title">
              <h3 class="m-portlet__head-text">
                <div id="toolbar" class="btn-group">
                  <button type="button" style="margin-left: 6%" href="#boq_task_add_modal" data-toggle="modal" class="btn btn-brand btn-elevate btn-pill"><i class="la la-tasks"></i> Add Task</button>
                </div>
              </h3>
            </div>
            <div class="m-portlet__head-title">
              <h3 class="m-portlet__head-text">
                <div id="toolbar" class="btn-group">
                  <a href="<?php echo base_url()?>boq/details_edit/<?php echo $boq_data->boq_id ?>" style="margin-left: 6%"   class="btn btn-focus btn-elevate btn-pill">
                    <span>
                      <i class="la la-edit"></i>
                      <span>
                        Add/Edit BOQ Details
                      </span>
                    </span>
                  </a>
                </div>
              </h3>
            </div>
          <?php } ?>
        </div>
        <div class="m-portlet__head-tools">
          <?php if($this->config->item('BOQ_dpr_template')==1){?>
            <a href="<?php echo base_url()?>boq/daily_progress/<?php echo $boq_data->boq_id ?>" style="margin-left: 5px;margin-right: 5px"   class="btn btn-success m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="la la-print"></i>
                <span>
                  Add Daily Progress
                </span>
              </span>
            </a>
          <?php } ?>

          <a href="#" style="margin-left: 5px;margin-right: 5px" data-print-type="boq"  class="btn_print_boq btn btn-warning m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
            <span>
              <i class="la la-print"></i>
              <span>
                Print BOQ
              </span>
            </span>
          </a>
          <a href="#" style="margin-left: 5px;margin-right: 5px" data-print-type="boq_details"  class="btn_print_boq btn btn-warning m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
            <span>
              <i class="la la-print"></i>
              <span>
                Print BOQ With Details
              </span>
            </span>
          </a>
        </div>
      </div>
      <div class="m-portlet__body">
        <!--begin: Datatable -->
        <table class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="table_boq_list">
          <thead>
            <tr class="">
              <th style="display: none">Task ID</th>
              <th style="display: none" >#</th>
              <th>ITEM</th>
              <th>DESCRIPTION</th>
              <th>QTY</th>
              <th>UNIT</th>
              <th>UNIT PRICE<br/>(Expense)</th>
              <th>TOTAL PRICE<br/>(Expense)</th>
              <th style="display: none" >Task Type</th>
              <th style="display: none" >Task Type</th>
              <th>UNIT PRICE<br/>(Client)</th>
              <th><?php echo $this->config->item('Tax_tax_name')?> %<br/>(Client)</th>
              <th><?php echo $this->config->item('Tax_tax_name')?> AMOUNT<br/>(Client)</th>
              <th>TOTAL PRICE<br/>(Client)</th>
              <th>Acheived Qty</th>
              <th>Acheived Price<br/>(Expense)</th>
              <th>Remaining Qty</th>
              <th class="delete_column">Actions</th>
              <th></th>
              <th></th>
              <th></th>
              <th></th>
            </tr>
          </thead>
          <tbody id="table-body">
          </tbody>
        </table>
      </div>
    </div>

    <div class="m-portlet m-portlet--mobile m-portlet--focus m-portlet--head-solid-bg m-portlet--bordered m-portlet--rounded">
      <div class="m-portlet__head">
        <div class="m-portlet__head-caption">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
              BOQ Daily Progress Report
            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools">
          <?php if($this->config->item('BOQ_dpr_template')==2){?>
            <a href="javascript:;" data-boq-id="<?php echo $boq_data->boq_id ?>" id="btn_print_dpr_summary" style="margin-left: 5px;margin-right: 5px"   class="btn btn-warning m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="la la-print"></i>
                <span>
                  Print Total DPR Summary
                </span>
              </span>
            </a>
            <a href="#dpr_add_modal" data-toggle="modal" style="margin-left: 5px;margin-right: 5px"   class="btn btn-success m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="la la-plus-circle"></i>
                <span>
                  Add DPR
                </span>
              </span>
            </a>
          <?php } ?>
        </div>
      </div>
      <div class="m-portlet__body">
        <!--begin: Datatable -->
        <div class="m-form m-form--label-align-right m--margin-bottom-10">
          <div class="row">
            <div class="col-xl-12 order-2 order-xl-1">
              <div class="row ">
                <div class="col-md-4">
                  <div class="form-group m-form__group row ">
                    <div class="col-md-4">
                      <label class="m-label m-label--single" style="margin-top: 10px;float: right;">
                        Start Date:
                      </label>
                    </div>
                    <div class="col-md-8">
                      <div class="m-form__control">
                        <input value="<?php echo date('d-m-Y');?>" data-date-format="dd-mm-yyyy" id="table_filter_start_date" type="text"  class="form-control m-input table_filter  m-input--pill m-input--air" placeholder="Start Date" >
                      </div>
                    </div>
                  </div>
                </div>
                <div class="col-md-4">
                  <div class="form-group m-form__group row ">
                    <div class="col-md-4">
                      <label class="m-label m-label--single" style="margin-top: 10px;float: right;">
                        End Date:
                      </label>
                    </div>
                    <div class="col-md-8">
                      <div class="m-form__control">
                        <input value="<?php echo date('d-m-Y');?>" data-date-format="dd-mm-yyyy" id="table_filter_end_date" type="text"  class="form-control m-input table_filter  m-input--pill m-input--air" placeholder="End Date" >
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <?php if($this->config->item('BOQ_dpr_template')==1){?>
          <table class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="table_boq_daily_progress">
            <thead>
              <tr class="">
                <th style="display: none">Task ID</th>
                <th style="display: none" >#</th>
                <th >ITEM</th>
                <th style="width: 100%">DESCRIPTION</th>
                <th style="display: none">QTY</th>
                <th>UNIT</th>
                <th>UNIT PRICE</th>
                <th style="display: none">TOTAL PRICE</th>
                <th style="display: none" >Task Type</th>
                <th style="display: none" >Task Type</th>
                <th>Acheived/Consumed <br/>Qty(Client)</th>
                <th>Acheived/Consumed <br/>Amount(Client)</th>
                <th>Acheived/Consumed <br/>Qty(Expense)</th>
                <th>Acheived/Consumed <br/>Amount(Expense)</th>
                <th>Cosnumption Type</th>
                <th>Profit</th>
                <th class="delete_column">Actions</th>
                <th></th>
                <th></th>
              </tr>
            </thead>
            <tbody id="table_boq_daily_progress_body">
            </tbody>
          </table>
        <?php } ?>
        <?php if($this->config->item('BOQ_dpr_template')==2){?>
          <table class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="table_boq_daily_progress">
            <thead>
              <tr class="">
                <th style="display: none">Task ID</th>
                <th style="display: none" >#</th>
                <th >ITEM</th>
                <?php if($project_data->project_section=='Road Marking'){?>
                  <th>Details</th>
                <?php }elseif($project_data->project_section=='Sign Boards'){?>
                  <th>Location</th>
                  <th>Board</th>
                <?php }else{?>
                  <th>From</th>
                  <th>To</th>
                <?php } ?>
                <th>Side</th>
                <?php if($project_data->project_section=='Road Marking' || $project_data->project_section=='Sign Boards'){?>
                  <th>No</th>
                <?php } ?>
                <?php if($project_data->project_section=='Road Studs'){?>
                  <th>Spacing</th>
                <?php }elseif($project_data->project_section=='Crash Barriers' || $project_data->project_section=='Road Marking'){?>
                  <th>Length (Mtr)</th>
                <?php } ?>
                <?php if($project_data->project_section=='Road Marking'){?>
                  <th>Width (Mtr)</th>
                <?php } ?>
                <?php if($project_data->project_section=='Road Marking'){?>
                  <th>Total (SQMtr)</th>
                <?php } ?>
                <?php if(sizeof($stock_materials)>0 && $project_data->project_section!='Road Marking'){ ?>
                  <?php foreach ($stock_materials as $key => $value) {?>
                    <th><?php echo $value->material_name?></th>
                  <?php } ?>
                <?php } ?>
                <?php if($project_data->project_section=='Sign Boards'){?>
                  <th>Ref No</th>
                <?php } ?>
                <th>Remarks</th>
                <th class="delete_column">Actions</th>
                <th></th>
                <th></th>
              </tr>
            </thead>
            <tbody id="table_boq_daily_progress_body">
            </tbody>
          </table>
        <?php } ?>
      </div>
    </div>
  </div>

  <div class="modal fade" tabindex="-1" id="dpr_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog " role="document" style="max-width: 500px">
      <div class="modal-content">
        <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
          <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
            Add DPR
          </h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">
              &times;
            </span>
          </button>
        </div>
        <form data-form-type='boq' class="m-form m-form--fit m-form--state m-form--label-align-right "  data-modal-id="dpr_add_modal" autocomplete="off" id="form_dpr_add" method="post" action="<?php echo base_url().'boq/dpr_add'?>" enctype="multipart/form-data" class="m-form m-form--fit m-form--state m-form--label-align-right " >
          <div class="modal-body">
            <div class="m-form__content">
              <div class="m-alert m-alert--icon alert alert-warning m--hide" role="alert" id="form_dpr_add_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 class="row">
              <div class="col-lg-12">
                <div class="form-group m-form__group">
                  <label for="user_name">
                    DPR Date
                  </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-calendar"></i>
                      </span>
                    </div>
                    <input required data-date-format="dd-mm-yyyy" type="text" name="date" id="dpr_date"  class="form-control m-input form_dpr_add_fields" aria-describedby="basic-addon1">
                  </div>
                  <span class="m-form__help"></span>
                </div>
              </div>
              <input type="hidden"  name="boq_id" value="<?php echo $boq_data->boq_id?>">
              <input type="hidden" name="redirect_url" value="<?php echo base_url(uri_string())?>" >
            </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary " data-dismiss="modal">
              Close
            </button>
            <button type="submit" class="btn btn-primary">
              Add
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>

  <?php $this->view("modules/boq/boq_modals");?>
  <?php $this->view("modules/include_modals/modal_work_type_add");?>
</div>
</div>
<!-- end:: Body -->
<!-- begin::Footer -->
<!-- end::Footer -->
<!-- end:: Page -->
<?php $this->view("includes/Inc_footer");?>
</div>

<?php $this->view("includes/Inc_sidebar");?>
<?php $this->view("includes/Inc_scripts");?>


<!--begin::Page Snippets -->
<script>
$("#table_filter_status").selectpicker();
$("[data-switch=true]").bootstrapSwitch()
</script>
<!--end::Page Snippets -->
<script>

$("#works_menu").addClass('m-menu__item--active m-menu__item--open');
$("#works_menu_2").addClass('m-menu__item--active');

//    Toggle Sidebar
$("#m_aside_left_minimize_toggle").addClass("m-brand__toggler--active");
$("#body").addClass("m-brand--minimize m-aside-left--minimize");

$("#dpr_date").datepicker( {
  todayHighlight:!0, orientation:"bottom left", templates: {
    leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
  }
})
$("#table_filter_start_date,#table_filter_end_date").datepicker( {
  todayHighlight:!0, orientation:"bottom left", templates: {
    leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
  }
})

$('#project_work_type_add').select2({
  dropdownParent: $("#form_work_cat_add")
});

$('#boq_task_work_type_add').select2({
  dropdownParent: $("#form_boq_task_add")
});
$('#boq_task_unit_add').select2({
  dropdownParent: $("#form_boq_task_add")
});

$('#boq_task_work_type_edit').select2({
  dropdownParent: $("#form_boq_task_edit")
});
$('#boq_task_unit_edit').select2({
  dropdownParent: $("#form_boq_task_edit")
});
$("#boq_task_client_tax_percent_add").select2({
  placeholder: "Select Tax",
  dropdownParent: $("#form_boq_task_add")
})
$("#boq_task_client_tax_percent_edit").select2({
  placeholder: "Select Tax",
  dropdownParent: $("#form_boq_task_edit")
})
$('#boq_task_add_modal').on('shown.bs.modal', function() {
  $("#description_add_task").summernote({height:150,width:'100%'});
})
$('#boq_task_edit_modal').on('shown.bs.modal', function() {
  $("#boq_task_description_edit").summernote({height:150,width:'100%'});
})
$('.btn_print_boq').click(function(e){
  var print_type = $(this).data('print-type');
  var project_id="<?php echo $boq_data->project_id ?>";
  var boq_id="<?php echo $boq_data->boq_id ?>";
  window.open('<?php echo base_url().'boq/print/'?>'+boq_id+'/'+print_type,'newwindow','width=1200,height=700');
});
$('body').on('click', '#btn_print_dpr', function() {
  var boq_id = $(this).data('boq-id');
  var date = $(this).data('date');
  window.open('<?php echo base_url().'boq/print_dpr/'?>'+boq_id+'/'+date,'newwindow','width=1200,height=700');
})
$('body').on('click', '#btn_print_dpr_summary', function() {
  var boq_id = $(this).data('boq-id');
  window.open('<?php echo base_url().'boq/print_dpr_summary/'?>'+boq_id,'newwindow','width=1200,height=700');
})
function select_work_type(select_id,selected_option=''){
  $("#"+select_id).html('');
  $("#"+select_id).append("<option disabled selected >Select Work Type</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++;
      }
    }
    if(selected_option!=''){
      $("#"+select_id).val(selected_option).trigger('change');
    }
  })
}
select_work_type('project_work_type_add');
$('input[type=radio][name=boq_items_have_add]').change(function() {
  if (this.value == 1) {
    $("#table_boq_items_add").show();
    $("#boq_task_unit_price_add_div").removeAttr('required',true);
    $("#boq_task_unit_price_add_div").hide();
    $("#boq_task_client_total_price_add").attr('readonly',true);
    $("#boq_task_client_total_price_add").addClass('m-input--solid');
  }else{
    $("#table_boq_items_add").hide();
    $("#boq_task_unit_price_add_div").attr('required',true);
    $("#boq_task_unit_price_add_div").show();
    $("#boq_task_client_total_price_add").removeAttr('readonly',true);
    $("#boq_task_client_total_price_add").removeClass('m-input--solid');
    $("#table_body").html('');
    $("#current_row_count").val(0);
  }
});
$('input[type=radio][name=boq_items_have_edit]').change(function() {
  if (this.value == 1) {
    $("#table_boq_items_edit").show();
    $("#boq_task_unit_price_edit_div").removeAttr('required',true);
    $("#boq_task_unit_price_edit_div").hide();
    $("#boq_task_client_total_price_edit").attr('readonly',true);
    $("#boq_task_client_total_price_edit").addClass('m-input--solid');
  }else{
    $("#table_boq_items_edit").hide();
    $("#boq_task_unit_price_edit_div").attr('required',true);
    $("#boq_task_unit_price_edit_div").show();
    $("#boq_task_client_total_price_edit").removeAttr('readonly',true);
    $("#boq_task_client_total_price_edit").removeClass('m-input--solid');
    $("#table_body_edit").html('');
    $("#current_row_count_edit").val(0);
  }
});
</script>

<script>
function select_material(select_id=''){
  $('#'+select_id).html('');
  $('#'+select_id).append("<option disabled selected >Select Material</option>");

  $.post("<?php echo base_url() ?>material/select",{},function(data) {
    var obj = $.parseJSON(data);
    var i=0;
    if(obj.count>0) {
      while (i < obj.id.length) {
        $('#'+select_id).append("<option data-unit=" + obj.unit[i] + " value=" + obj.id[i] + ">" + obj.name[i] + " [" + obj.unit_name[i] + "]</option>");
        i++;
      }
    }
  })
  $('#'+select_id).trigger('change');
}
$(document).ready(function () {
  $("#addrow").on("click", function () {
    var counter = parseInt($("#current_row_count").val());
    var newRow = $("<tr>");
    var cols = "";
    // sl no
    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px; text-align:center;" readonly type="text" class="form-control m-input" name="labour[sl_no]['+(counter)+']" value="' + (counter+1) + '"/></div></div></td>';
    // material and other

    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class=""> <label class="m-radio m-radio--solid m-radio--state-brand"><input data-sl-no="' + (counter+1) + '" required type="radio" name="item[type]['+(counter)+']" id="item_type_' + (counter+1) + '" class=" item_type" checked value="material">Material<span></span></label><label class="m-radio m-radio--solid m-radio--state-success"><input type="radio" name="item[type]['+(counter)+']" id="item_type_' + (counter+1) + '" data-sl-no="' + (counter+1) + '" class=" item_type" value="other">Other<span></span></label></div></div>';
    cols += '<div class="form-group m-form__group text_field_' + (counter+1) + '" style="padding: 0px;margin: 0px;display: none;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input placeholder="Specify" type="text"  class="form-control m-input" name="item[name]['+(counter)+']" id="item_name_spec_' + (counter+1) + '"/></div></div><div class="form-group m-form__group select_field_' + (counter+1) + '" style="padding: 0px;margin: 0px;"><div class="m-select2 m-select2--air m-select2--pill"><select data-sl-no="' + (counter+1) + '" required="" class="form-control material_select" name="item[material]['+(counter)+']" id="item_material_' + (counter+1) + '" aria-required="true" tabindex="-1"   aria-describedby=""><option selected disabled>Select Material</option></select></div></div></td>';

    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="m-select2 m-select2--air m-select2--pill"><select required="" class="form-control measure_unit_select" name="item[unit]['+(counter)+']" id="material_unit_' + (counter+1) + '" aria-required="true" tabindex="-1"   aria-describedby=""><option selected disabled>Select Unit</option><?php foreach($measure_units as $r) { ?><option value="<?php echo $r->unit_id ?>"><?php echo $r->unit_name ?></option><?php }   ?></select></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text"  class="form-control m-input  daily_wage " data-sl-no="' + (counter+1) + '" name="item[grade]['+(counter)+']" id="material_grade_' + (counter+1) + '"/></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text"  class="form-control m-input  daily_wage " data-sl-no="' + (counter+1) + '" name="item[spec]['+(counter)+']" id="material_spec_' + (counter+1) + '"/></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text" required class="form-control m-input  daily_wage unit_quantity" data-sl-no="' + (counter+1) + '" name="item[quantity]['+(counter)+']" id="material_quantity_' + (counter+1) + '"/></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text" required class="form-control m-input daily_wage unit_quantity" data-sl-no="' + (counter+1) + '" name="item[unit_price]['+(counter)+']" id="material_unit_price_' + (counter+1) + '"/></div></div></td>';


    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text" readonly  class="form-control m-input total_item_amount_add" value="0" name="item[total_price]['+(counter)+']" id="material_total_price_' + (counter+1) + '"/></div></div></td>';
    <?php if($this->config->item('BOQ_dpr_template')==2){?>
    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class=""> <label class="m-radio m-radio--solid m-radio--state-focus"><input data-sl-no="' + (counter+1) + '" required type="radio" name="item[consumable_type]['+(counter)+']" id="item_consumable_type_' + (counter+1) + '" class=" consumable_type" checked value="item_wise">Item Wise<span></span></label><label class="m-radio m-radio--solid m-radio--state-warning"><input type="radio" name="item[consumable_type]['+(counter)+']" id="item_consumable_type_' + (counter+1) + '" data-sl-no="' + (counter+1) + '" class=" consumable_type" value="common">Common<span></span></label></div></div></td>';
    <?php } ?>
    cols += '<td><a href="javascript:" class="ibtnDel btn btn-sm btn-danger btn-icon-only" data-sl-no="'+(counter+1)+'" ><i class="fa fa-trash"></i></td>';
    cols += '</tr>';

    select_material('item_material_' + (counter+1));
    newRow.append(cols);
    $("#table_body").append(newRow);
    counter++;
    $("#current_row_count").val(counter);



    $(".material_select").select2({
      placeholder: "Select Work Type",
      dropdownParent: $("#form_boq_task_add")
    })
    $(".measure_unit_select").select2({
      placeholder: "Select Unit",
      dropdownParent: $("#form_boq_task_add")
    })

  });

  $("#table_body").on("click", ".ibtnDel", function (event) {

    var sl_no = $(this).attr("data-sl-no");
    var current_total_price =  $("#total_boq_task_amount_add").val();
    var deleted_item_price = $("#material_total_price_"+sl_no).val();
    var new_total_price = current_total_price - deleted_item_price;
    // alert(new_total_price);
    $("#total_boq_task_amount_add").val((new_total_price).toFixed(3));

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

  });
  $("body").on("change", ".material_select", function (event) {
    var sl_no = $(this).attr("data-sl-no");
    var material_id = $(this).val();
    $.post("<?php echo base_url() ?>material/select",{id:material_id},function(data) {
      var obj = $.parseJSON(data);
      var i=0;
      if(obj.count==1) {
        $("#material_unit_price_"+sl_no).val(obj.unit_price[0]);
        $("#material_unit_"+sl_no).val(obj.unit[0]).trigger('change');
      }
    })

  });
  $("body").on("change keyup", ".client_rate_fields_add", function (event) {
    var have_itmes = $('input[type=radio][name=boq_items_have_add]:checked').val()
    var qty = parseFloat($("#quantity_add_task").val());
    var unit_price = parseFloat($("#boq_task_client_unit_price_add").val());
    var task_unit_price = parseFloat($("#boq_task_unit_price_add").val());
    if(isNaN(qty)) {
      qty = 0;
    }
    if(isNaN(unit_price)) {
      unit_price = 0;
    }
    if(isNaN(task_unit_price)) {
      task_unit_price = 0;
    }
    var total_amount_client = qty*unit_price;
    var tax_percent = parseFloat($('#boq_task_client_tax_percent_add :selected').data('tax-percent'));
    var tax_amount = total_amount_client*tax_percent/100;
    $("#boq_task_client_tax_amount_add").val(tax_amount.toFixed(2));
    total_amount_client = total_amount_client+tax_amount;
    $("#boq_task_client_total_price_add").val(total_amount_client.toFixed(2));
    if(have_itmes==0){
      var total_amount_task = qty*task_unit_price;
      $("#total_boq_task_amount_add").val(total_amount_task.toFixed(2));
    }
  })
  $("body").on("change keyup", ".client_rate_fields_edit", function (event) {
    var have_itmes = $('input[type=radio][name=boq_items_have_edit]:checked').val()
    var qty = parseFloat($("#boq_task_quantity_edit").val());
    var unit_price = parseFloat($("#boq_task_client_unit_price_edit").val());
    var task_unit_price = parseFloat($("#boq_task_unit_price_edit").val());
    if(isNaN(qty)) {
      qty = 0;
    }
    if(isNaN(unit_price)) {
      unit_price = 0;
    }
    if(isNaN(task_unit_price)) {
      task_unit_price = 0;
    }
    var total_amount_client = qty*unit_price;
    var tax_percent = parseFloat($('#boq_task_client_tax_percent_edit :selected').data('tax-percent'));
    var tax_amount = total_amount_client*tax_percent/100;
    $("#boq_task_client_tax_amount_edit").val(tax_amount.toFixed(2));
    total_amount_client = total_amount_client+tax_amount;
    $("#boq_task_client_total_price_edit").val(total_amount_client.toFixed(2));
    if(have_itmes==0){
      var total_amount_task = qty*task_unit_price;
      $("#total_boq_task_amount_edit").val(total_amount_task.toFixed(2));
    }
  })
})
</script>
<script type="text/javascript">
$('body').on('click', '#btn_boq_daily_progress_delete', function() {
  var type = $(this).data('type');
  var id = $(this).data('reference-id');
  if(type=='boq_task_item'){
    $("#boq_daily_progress_delete_info").html("Are You Sure To Delete Daily Progree of Task Item?. All the data associate with this will Lost. ")
  }else{
    $("#boq_daily_progress_delete_info").html("Are You Sure To Delete Daily Progree of Task?. All the data associate (Task & Task Items) with this will Lost. ")
  }
  $('#boq_daily_progress_delete_id').val(id);
  $('#boq_daily_progress_delete_type').val(type);
  $('#boq_id_daily_progress_delete').val($(this).data('boq-id'));
  $('#date_daily_progress_delete').val($(this).data('date'));
})
$('body').on('click', '#btn_boq_task_edit', function() {
  var boq_id = $(this).attr('data-boq-id');
  var item_count = $(this).attr('data-item-count');
  var no = $(this).closest('tr').children('td');
  $('#boq_task_description_edit').summernote('code',no.eq(21).html());
  $('#boq_task_quantity_edit').val(no.eq(4).text());
  $('#total_boq_task_amount_edit').val(no.eq(7).text());
  $('#boq_task_id_edit').val(no.eq(0).text());
  $('#boq_task_work_type_edit').val(no.eq(20).text()).trigger('change');
  $('#boq_task_unit_edit').val(no.eq(19).text()).trigger('change');
  $('#boq_task_client_unit_price_edit').val(no.eq(10).text());
  $('#boq_task_client_tax_percent_edit').val(no.eq(22).text()).trigger('change');
  $('#boq_task_client_total_price_edit').val(no.eq(13).text());
  var have_items = 0;
  if(item_count>0){
    currentRowExpanding(item_count,no.eq(20).text(),boq_id,no.eq(0).text());
    have_items = 1;
  }else{
    $('#boq_task_unit_price_edit').val(no.eq(6).text());
  }
  $("input[name=boq_items_have_edit][value="+have_items+"]").prop("checked",true).trigger("change");

})

function currentRowExpanding(id,work_type_id,boq_id,task_id)
{
  var counter = id;
  var boq_id = boq_id;
  var work_type_id = work_type_id;
  var task_id = task_id;

  $.post("<?php echo base_url() ?>boq/select_task_items",{boq_id:boq_id,work_type_id:work_type_id,counter:counter,task_id:task_id},function(data) {
    var obj=$.parseJSON(data);
    var counter = obj.data.length;
    if(counter>0){
      var content=obj.data;
      $("#table_body_edit").append(content);
      $("#current_row_count_edit").val(obj.count);
    }
    var mat_length = obj.current_mat.length;
    for (var i = 0; i < mat_length; i++) {
      if (obj.current_mat[i] != 0)
      {
        $('#item_material_'+(i+1)+'_edit').val(obj.current_mat[i]).trigger("change");
      }
      if (obj.current_unit[i] != 0)
      {
        $('#material_unit_'+(i+1)+'_edit').val(obj.current_unit[i]).trigger("change");
      }
    }
    $(".material_edit_select").select2({
      placeholder: "Select Work Type",
      dropdownParent: $("#form_boq_task_edit")
    })
    $(".measure_unit_edit_select").select2({
      placeholder: "Select Unit",
      dropdownParent: $("#form_boq_task_edit")
    })
  });
}
</script>


<script>
$(document).ready(function () {
  $("#addrow_edit").on("click", function () {
    var counter = parseInt($("#current_row_count_edit").val());
    var newRow = $("<tr>");
    var cols = "";
    // sl no
    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input style="padding: 10px; text-align:center;" readonly type="text" class="form-control m-input" name="labour[sl_no]['+(counter)+']_edit" value="' + (counter+1) + '"/></div></div></td>';
    // material and other
    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class=""> <label class="m-radio m-radio--solid m-radio--state-brand"><input data-sl-no="' + (counter+1) + '_edit" required type="radio" name="item[type_edit]['+(counter)+']" id="item_type_' + (counter+1) + '_edit" class=" item_type_edit" checked value="material">Material<span></span></label><label class="m-radio m-radio--solid m-radio--state-success"><input type="radio" name="item[type_edit]['+(counter)+']" id="item_type_' + (counter+1) + '_edit" data-sl-no="' + (counter+1) + '_edit" class=" item_type_edit" value="other">Other<span></span></label></div></div>';

    cols += '<div class="form-group m-form__group text_field_' + (counter+1) + '_edit" style="padding: 0px;margin: 0px;display: none;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input placeholder="Specify" type="text"  class="form-control m-input" name="item[name]['+(counter)+']" id="item_name_spec_' + (counter+1) + '_edit"/></div></div><div class="form-group m-form__group select_field_' + (counter+1) + '_edit" style="padding: 0px;margin: 0px;"><div class="m-select2 m-select2--air m-select2--pill"><select style="width: 100%" required="" class="form-control material_edit_select" name="item[material]['+(counter)+']" id="item_material_' + (counter+1) + '_edit" aria-required="true" tabindex="-1"   aria-describedby=""><option selected disabled>Select Material</option></select></div></div></td>';

    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="m-select2 m-select2--air m-select2--pill"><select style="width: 100%" required="" class="form-control measure_unit_edit_select" name="item[unit]['+(counter)+']" id="material_unit_' + (counter+1) + '_edit" aria-required="true" tabindex="-1"   aria-describedby=""><option selected disabled>Select Unit</option><?php foreach($measure_units as $r) { ?><option value="<?php echo $r->unit_id ?>"><?php echo $r->unit_name ?></option><?php }   ?></select></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text"  class="form-control m-input  daily_wage " data-sl-no="' + (counter+1) + '_edit" name="item[grade]['+(counter)+']" id="material_grade_' + (counter+1) + '_edit"/></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text"  class="form-control m-input  daily_wage " data-sl-no="' + (counter+1) + '_edit" name="item[spec]['+(counter)+']" id="material_spec_' + (counter+1) + '_edit"/></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text"  class="form-control m-input  daily_wage unit_quantity_edit" data-sl-no="' + (counter+1) + '" name="item[quantity]['+(counter)+']" id="material_quantity_' + (counter+1) + '_edit"/></div></div></td>';

    cols += '<td><div class="form-group m-form__group " style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text"  class="form-control m-input daily_wage unit_quantity_edit" data-sl-no="' + (counter+1) + '" name="item[unit_price]['+(counter)+']" id="material_unit_price_' + (counter+1) + '_edit"/></div></div></td>';



    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class="input-group m-input-group m-input-group--pill m-input-group--air"><input type="text" readonly  class="form-control m-input total_item_amount_edit" value="0" name="item[total_price]['+(counter)+']" id="material_total_price_' + (counter+1) + '_edit"/></div></div></td>';
<?php if($this->config->item('BOQ_dpr_template')==2){?>
    cols += '<td><div class="form-group m-form__group" style="padding: 0px;margin: 0px;"><div class=""> <label class="m-radio m-radio--solid m-radio--state-focus"><input data-sl-no="' + (counter+1) + '" required type="radio" name="item[consumable_type]['+(counter)+']" id="item_consumable_type_' + (counter+1) + '" class=" consumable_type" checked value="item_wise">Item Wise<span></span></label><label class="m-radio m-radio--solid m-radio--state-warning"><input type="radio" name="item[consumable_type]['+(counter)+']" id="item_consumable_type_' + (counter+1) + '" data-sl-no="' + (counter+1) + '" class=" consumable_type" value="common">Common<span></span></label></div></div></td>';
<?php } ?>
    cols += '<td><a href="javascript:" class="ibtnDel btn btn-danger btn-icon-only" data-sl-no="' + (counter+1) + '" ><i class="fa fa-trash"></i></td>';
    cols += '</tr>';

    select_material('item_material_' + (counter+1)+'_edit');

    newRow.append(cols);
    $("#table_body_edit").append(newRow);
    counter++;
    $("#current_row_count_edit").val(counter);

    $(".material_edit_select").select2({
      placeholder: "Select Work Type",
      dropdownParent: $("#form_boq_task_edit")
    })
    $(".measure_unit_edit_select").select2({
      placeholder: "Select Unit",
      dropdownParent: $("#form_boq_task_edit")
    })
  });
  $("#table_body_edit").on("click", ".ibtnDel", function (event) {

    var sl_no = $(this).attr("data-sl-no");
    var current_total_price =  $("#total_boq_task_amount_edit").val();
    var deleted_item_price = $("#material_total_price_"+sl_no+"_edit").val();
    var new_total_price = current_total_price - deleted_item_price;
    $("#total_boq_task_amount_edit").val((new_total_price).toFixed(3));

    var counter = parseInt($("#current_row_count_edit").val());
    $(this).closest("tr").remove();
    counter -= 1;
    // $("#current_row_count_edit").val(counter);
    var item_id = $(this).attr("data-item-id");
    var item_deleted_id = $('#items_deleted').val();
    item_deleted_id +=","+item_id;
    item_deleted_id = item_deleted_id.replace(/(^,)|(,$)/g, "");
    $('#items_deleted').val(item_deleted_id);

  });
})
</script>

<script>
function init_table() {
  $('#table_boq_list').dataTable().fnDestroy();
  var table = $('#table_boq_list').dataTable({
    fixedHeader: true,
    "scrollX" : true,
    scrollX:!0, scrollCollapse:!0,
    buttons: [
      { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'BOQ List' },
      { 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": [
      [100, 250, 500, -1],
      [100, 250, 500, "All"] // change per page values here
    ],
    "columnDefs": [
      {
        "targets": [18,19,20,21 ],
        className: "hidden"
      },
      {
        render: function (data, type, full, meta) {
          return "<div class='text-wrap width-500'>" + data + "</div>";
        },
        targets: [ 3 ],
      },
    ],
    'order': false,
    'ordering':false,
    "pageLength":100
  });
}

function init_daily_progress_table() {

  var table = $('#table_boq_daily_progress').dataTable({
    fixedHeader: true,
    "scrollX" : true,
    scrollX:!0, scrollCollapse:!0,
    buttons: [
      { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'Daily Progress Report' },
      { 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": [
      [100, 250, 500, -1],
      [100, 250, 500, "All"] // change per page values here
    ],
    "columnDefs": [
      {
        "targets": [<?php if($this->config->item('BOQ_dpr_template')==1){ echo "17,18";}?>],
        className: "hidden"
      }
    ],
    'order': false,
    'ordering':false,
    "pageLength":100
  });
}
</script>
<script type="text/javascript">
var project_id="<?php echo $boq_data->project_id ?>";
var boq_id="<?php echo $boq_data->boq_id ?>";
function get_tasks() {
  //          Select Work Categories
  $.post("<?php echo base_url() ?>boq/select_boq_task_list",{project_id:project_id,boq_id:boq_id},function (data) {
    var obj=$.parseJSON(data);
    $("#table-body").html('');
    if(parseInt(obj.work_count)>0){
      var content=obj.content;
      $("#table-body").html(content);
    }
    init_table();
  })
}
function get_daily_progress() {
  //          Select Work Categories
  var start_date = $("#table_filter_start_date").val();
  var end_date = $("#table_filter_end_date").val();
  $('#table_boq_daily_progress').dataTable().fnDestroy();
  $.post("<?php echo base_url() ?>boq/select_boq_daily_progress",{project_id:project_id,boq_id:boq_id,start_date:start_date,end_date:end_date},function (data) {
    var obj=$.parseJSON(data);
    $("#table_boq_daily_progress_body").html('');
    if(parseInt(obj.count)>0){
      var content=obj.content;
      $("#table_boq_daily_progress_body").html(content);
    }
    init_daily_progress_table();
  })
}
$(document).ready(function () {
  get_tasks();
  get_daily_progress();
})
$("body").on("change", ".table_filter", function (event) {
  get_daily_progress();
})
</script>

<script>

$("body").on("change", ".item_type", function (event) {
  var sl_no = $(this).attr("data-sl-no");
  if (this.value == 'material') {
    $(".text_field_"+ sl_no + "").hide();
    $(".select_field_"+ sl_no + "").show();

    $("#item_material_"+ sl_no + "").attr('required',true);
    $("#item_name_spec_"+ sl_no + "").attr('disabled',true);
    $("#item_material_"+ sl_no + "").attr('disabled',false);

  }else{
    $(".text_field_"+ sl_no + "").show();
    $(".select_field_"+ sl_no + "").hide();

    $("#item_name_spec_"+ sl_no + "").attr('required',false);
    $("#item_material_"+ sl_no + "").attr('disabled',true);
    $("#item_name_spec_"+ sl_no + "").attr('disabled',false);
  }
});
</script>

<script type="text/javascript">
$("body").on("keyup", ".unit_quantity", function (event) {
  var have_itmes = $('input[type=radio][name=boq_items_have_add]:checked').val();
  if(have_itmes==1){
    var sl_no = $(this).attr("data-sl-no");
    var total_price=0;
    if($("#material_quantity_" + sl_no +"").val()==''){
      $("#material_total_price_" + sl_no +"").val(0)
      $("#total_price").val('0')
    }
    if($("#material_unit_price_" + sl_no + "").val()==''){
      $("#material_total_price_" + sl_no + "").val(0)
      $("#total_price").val('0')
    }
    var unit_price=parseFloat($("#material_unit_price_" + sl_no +"").val());
    var quantity=parseFloat($("#material_quantity_" + sl_no + "").val());
    $("#material_total_price_" + sl_no + "").val((unit_price*quantity).toFixed(3));
    if($("#material_total_price_" + sl_no + "").val()=='NaN'){
      $("#material_total_price_" + sl_no + "").val('')
      $("#total_price").val('')
    }

    $(".total_item_amount_add").each(function(){
      total_price += +$(this).val();
    });
    $("#total_boq_task_amount_add").val((total_price).toFixed(3));
  }
});
</script>
<script>

$("body").on("change", ".item_type_edit", function (event) {
  var sl_no = $(this).attr("data-sl-no");
  if (this.value == 'material') {
    $(".text_field_"+ sl_no + "_edit").hide();
    $(".select_field_"+ sl_no + "_edit").show();

    $("#item_material_"+ sl_no + "_edit").attr('required',true);
    $("#item_name_spec_"+ sl_no + "_edit").attr('disabled',true);
    $("#item_material_"+ sl_no + "_edit").attr('disabled',false);

  }else{
    $(".text_field_"+ sl_no + "_edit").show();
    $(".select_field_"+ sl_no + "_edit").hide();

    $("#item_name_spec_"+ sl_no + "_edit").attr('required',false);
    $("#item_material_"+ sl_no + "_edit").attr('disabled',true);
    $("#item_name_spec_"+ sl_no + "_edit").attr('disabled',false);

  }
});
</script>

<script type="text/javascript">
$("body").on("keyup", ".unit_quantity_edit", function (event) {
  var have_itmes = $('input[type=radio][name=boq_items_have_edit]:checked').val();
  if(have_itmes==1){
    var sl_no = $(this).attr("data-sl-no");
    var total_price=0;
    if($("#material_quantity_" + sl_no +"_edit").val()==''){
      $("#material_total_price_" + sl_no +"_edit").val(0)
    }
    if($("#material_unit_price_" + sl_no + "_edit").val()==''){
      $("#material_total_price_" + sl_no + "_edit").val(0)
    }
    var unit_price=parseFloat($("#material_unit_price_" + sl_no +"_edit").val());
    var quantity=parseFloat($("#material_quantity_" + sl_no + "_edit").val());
    $("#material_total_price_" + sl_no + "_edit").val((unit_price*quantity).toFixed(3));
    if($("#material_total_price_" + sl_no + "_edit").val()=='NaN'){
      $("#material_total_price_" + sl_no + "_edit").val('')
      $("#total_price_edit").val('')
    }
    $(".total_item_amount_edit").each(function(){
      total_price += +$(this).val();
    });
    $("#total_boq_task_amount_edit").val((total_price).toFixed(3));
  }
});
</script>

<script>
$(function () {
  $('.modals_reset').on('hidden.bs.modal', function () {
    $(this).find('form').trigger('reset');
    $("#table_body_edit").html('');
  })
});
</script>
<script>
$(".form_post").each(function(){
  var form_id = $(this).attr('id');
  $("#"+form_id).validate({
    rules: {
      quantity: {
        required: !0,
        number: !0
      },
      client_unit_price: {
        required: !0,
        number: !0
      },
    },
    invalidHandler: function(e, r) {
      var i = $("#" + form_id + "_msg");
      i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
    },
    submitHandler: function(e) {
      this.submit();
    }
  })
});

$(".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: {
      quantity: {
        required: !0,
        number: !0
      },
      client_unit_price: {
        required: !0,
        number: !0
      },
    },
    messages: {
      end_date: "End Date Should Be Greater than or Equal to Start Date",
    }, 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);
        toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
        $("#"+modal_id).modal('toggle');
        $("."+form_id+"_fields").val('');
        $("."+form_id+"_select").val('').trigger("change");
        get_tasks();
        get_daily_progress();
        select_work_type('project_work_type_add');
      } 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");
    }
  })
)
});
$("#form_dpr_add").validate( {
  rules: {
    date: {
      required: !0
    }
  }
  , invalidHandler:function(e, r) {
    var i=$("#form_dpr_add_msg");
    i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
  }
  , submitHandler:function(e) {
    mApp.blockPage({
      overlayColor: "#000000",
      type: "loader",
      state: "primary",
      message: "Processing...Please Wait"
    }), setTimeout(function() {}, 3e3);
    this.submit();
  }
});

</script>
