<?php $this->view("includes/Inc_pagehead");?>
<style>
.m-form .m-form__group {
  margin-bottom: 0;
  padding-top: 0px;
  padding-bottom: 0px;
}
</style>
<!-- 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">
          Materials
        </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().'material' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Materials
              </span>
            </a>
          </li>


        </ul>
      </div>
      <div>

      </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">
          <div class="m-portlet__head-title">
            <h3 class="m-portlet__head-text">
              List of Materials
            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools">
          <?php if($this->session->userdata('user_role')!='auditor' || $this->session->userdata('user_data_permission')['adding']==1) { ?>
            <a href="#" data-toggle="modal" data-target="#material_add_modal" class="btn btn-focus m-btn m-btn--custom m-btn--icon m-btn--air m-btn--pill">
              <span>
                <i class="la la-plus"></i>
                <span>
                  Add New Material
                </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 align-items-center">
            <div class="col-xl-12 order-2 order-xl-1">
              <div class="form-group m-form__group row ">
                <div class="col-md-8">

                </div>
                <div class="col-md-4">
                  <div class="form-group m-form__group">
                    <label>
                      Category:
                    </label>
                    <div class="m-select2 m-select2--air m-select2--pill">
                      <select style="width: 100%" class="form-control m-select2 table_filter" id="table_filter_material_category"  data-placeholder="Select Category">

                      </select>
                    </div>
                    <span class="m-form__help"></span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="material_view_table">
          <thead>
            <tr class="">
              <th>Material Id</th>
              <th>Material Name</th>
              <th>Type</th>
              <th>Section</th>
              <th>Specification</th>
              <th>Item Code</th>
              <th>Category</th>
              <th>Unit</th>
              <th>Unit Price<br/>[Purchase]</th>
              <th>Sale Price <br/>[<?php echo $this->config->item('Material_sale_price1_name') ?>]</th>
              <th>Sale Price <br/>[<?php echo $this->config->item('Material_sale_price2_name') ?>]</th>
              <th>Sale Price <br/>[<?php echo $this->config->item('Material_sale_price3_name') ?>]</th>
              <th>Sale Price <br/>[<?php echo $this->config->item('Material_sale_price4_name') ?>]</th>
              <th>Sale Price <br/>[<?php echo $this->config->item('Material_sale_price5_name') ?>]</th>
              <th>Sale Price <br/>[<?php echo $this->config->item('Material_sale_price6_name') ?>]</th>
              <th><?php echo $this->config->item('Tax_tax_name') ?> %</th>
              <th>Actions</th>
              <th>Unit ID</th>
              <th>Category</th>
              <th>Type</th>
              <th>Branch</th>
              <th>Tax Percent</th>
              <th>Section</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
        <!--end: Datatable -->
        <?php $this->view("modules/include_modals/modal_material_add");?>

        <div class="modal fade" tabindex="-1" id="material_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog " role="document" style="max-width: 750px">
            <div class="modal-content">
              <div class="modal-header" style="background-color: #00c5dc;border-radius: 4px">
                <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
                  Edit Material Details
                </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">
                    &times;
                  </span>
                </button>
              </div>
              <form autocomplete="off" id="form_material_edit" data-form-type="update" data-modal-id="material_edit_modal" method="post" action="<?php echo base_url().'material/update'?>" 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_material_edit_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>
                    <?php if ($this->config->item('app_module_production') == 1 ){?>
                      <div class="row">
                        <div class="col-lg-6">
                          <div class="form-group m-form__group">
                            <label>
                              Material Section
                            </label>
                            <div class="m-radio-inline" style="padding-top: 10px;">
                              <label class="m-radio m-radio--solid m-radio--state-danger">
                                <input required type="radio" class="form_fields_radio" name="material_section_edit" value="product"> Product
                                <span></span>
                              </label>
                              <label class="m-radio m-radio--solid m-radio--state-warning">
                                <input type="radio" class="form_fields_radio" name="material_section_edit"  value="material"> Raw Material
                                <span></span>
                              </label>
                            </div>
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                      </div>
                    <?php } ?>
                    <?php if($this->config->item('app_module_vehicle_management')==1){ ?>
                      <div class="row">
                        <div class="col-lg-6">
                          <div class="form-group m-form__group">
                            <label>
                              Material Type
                            </label>
                            <div class="m-radio-inline" style="padding-top: 10px;">
                              <label class="m-radio m-radio--solid m-radio--state-danger">
                                <input required type="radio" class="form_fields_radio material_edit_branch_disable_fields" name="material_type_edit" value="construction"> Construction Material
                                <span></span>
                              </label>
                              <label class="m-radio m-radio--solid m-radio--state-warning">
                                <input type="radio" class="form_fields_radio material_edit_branch_disable_fields" name="material_type_edit"  value="vehicle"> Vehicle Spare
                                <span></span>
                              </label>
                            </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">
                              <?php echo $this->config->item('Tax_tax_name') ?> %
                            </label>
                            <div class="m-select2 m-select2--air m-select2--pill ">
                              <select id="material_tax_percent_edit" name="tax_percent" style="width: 100%" class="form-control m-input form_material_edit_select" aria-describedby="basic-addon1" data-placeholder="Select Tax %">
                                <?php
                                $tax_percent = $this->config->item('Tax_tax_percent');
                                foreach ($tax_percent as $row) :
                                  $selected_tax = '';
                                  if ($row->tax_percentage == 0) {
                                    $selected_tax = 'selected';
                                  }
                                  ?>
                                  <option <?php echo $selected_tax ?> data-tax-percent="<?php echo $row->tax_percentage ?>" value="<?php echo $row->tax_id ?>"><?php echo $row->tax_name ?></option>
                                  <?php
                                endforeach;
                                ?>
                              </select>
                            </div>
                            <span class="m-form__help"></span>
                          </div>
                        </div>
                      </div>
                    <?php } ?>
                    <div class="row">
                      <div class="col-lg-8">
                        <div class="form-group m-form__group">
                          <label for="material_name">
                            Material Name
                          </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-user"></i>
                              </span>
                            </div>
                            <input required type="text" name="material_name" id="material_name"  class="form-control m-input form_material_edit_fields material_edit_branch_disable_fields" placeholder="Material Name" aria-describedby="basic-addon1">
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group m-form__group">
                          <label for="user_name">
                            Unit
                          </label>
                          <?php if($this->session->userdata('branch_id')==0){?>
                          <div class="input-group m-input-group m-input-group--pill">
                            <div class="input-group-prepend">
                                <a href="#unit_add_modal"   data-toggle="modal" data-target="#unit_add_modal" class="btn btn-focus">
                                  <i class="fa fa-plus-circle"></i>
                                </a>
                            </div>
                            <select style="width: 70%"  class="form-control m-select2 m-select2-general form_material_edit_select material_edit_branch_disable_fields" required id="unit_edit" name="unit">

                            </select>
                          </div>
                        <?php }else{ ?>
                          <div class="m-select2 m-select2--air m-select2--pill ">
                            <select required id="unit_edit" name="unit" style="width: 100%" class="form-control m-input form_material_edit_select material_edit_branch_disable_fields" aria-describedby="basic-addon1" data-placeholder="Select Category">
                            </select>
                          </div>
                        <?php } ?>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-lg-12">
                        <div class="form-group m-form__group">
                          <label for="user_name">
                            Make / Specification / Brand
                          </label>
                          <div class="input-group m-input-group m-input-group--pill m-input-group--air">
                            <input  type="text" name="specification" id="specification_edit"  class="form-control m-input form_material_edit_fields" placeholder="Make / Specification / Brand" aria-describedby="basic-addon1">
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                    </div>
                    <div class="row">
                      <div class="col-lg-4">
                        <div class="form-group m-form__group">
                          <label for="user_name">
                            Category
                          </label>
                          <div class="m-select2 m-select2--air m-select2--pill ">
                            <select id="category_edit" name="category" style="width: 100%" class="form-control m-input form_material_edit_select material_edit_branch_disable_fields" aria-describedby="basic-addon1" data-placeholder="Select Category">
                            </select>
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group m-form__group">
                          <label for="user_name">
                            Unit Price
                          </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 required type="text" name="price" id="material_price"  class="form-control m-input form_material_add_fields" placeholder="Material Unit Price" aria-describedby="basic-addon1">
                          </div>
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                      <div class="col-lg-4">
                        <div class="form-group m-form__group">
                          <label for="user_name">
                            Item Code
                          </label>
                          <input type="text" name="item_code" id="item_code_edit"  class="form-control m-input  m-input--air m-input--pill form_material_edit_fields material_edit_branch_disable_fields" placeholder="Item Code" aria-describedby="basic-addon1">
                          <span class="m-form__help"></span>
                        </div>
                      </div>
                    </div>
                    <?php if ($this->config->item('app_module_sales_invoice') == 1 && $this->config->item('Material_sale_price_category_enable') == 1){ ?>
                      <div class="row">
                        <?php if($this->config->item('Material_sale_price1_name')!=''){ ?>
                          <div class="col-lg-4">
                            <div class="form-group m-form__group">
                              <label for="user_name" style="text-align: left;">
                                Sale Price  <br/>[<?php echo $this->config->item('Material_sale_price1_name') ?>]
                              </label>
                              <input type="text" name="sale_price1" id="sale_price1_edit"   class="form-control m-input  m-input--air m-input--pill form_material_edit_fields" placeholder="Sale Price [<?php echo $this->config->item('Material_sale_price1_name') ?>]" aria-describedby="basic-addon1">
                              <span class="m-form__help"></span>
                            </div>
                          </div>
                        <?php } ?>
                        <?php if($this->config->item('Material_sale_price2_name')!=''){ ?>
                          <div class="col-lg-4">
                            <div class="form-group m-form__group">
                              <label for="user_name" style="text-align: left;">
                                Sale Price  <br/>[<?php echo $this->config->item('Material_sale_price2_name') ?>]
                              </label>
                              <input type="text" name="sale_price2" id="sale_price2_edit"  class="form-control m-input  m-input--air m-input--pill form_material_edit_fields" placeholder="Sale Price [<?php echo $this->config->item('Material_sale_price2_name') ?>]" aria-describedby="basic-addon1">
                              <span class="m-form__help"></span>
                            </div>
                          </div>
                        <?php } ?>
                        <?php if($this->config->item('Material_sale_price3_name')!=''){ ?>
                          <div class="col-lg-4">
                            <div class="form-group m-form__group">
                              <label for="user_name" style="text-align: left;">
                                Sale Price  <br/>[<?php echo $this->config->item('Material_sale_price3_name') ?>]
                              </label>
                              <input type="text" name="sale_price3" id="sale_price3_edit"  class="form-control m-input  m-input--air m-input--pill form_material_edit_fields" placeholder="Sale Price [<?php echo $this->config->item('Material_sale_price3_name') ?>]" aria-describedby="basic-addon1">
                              <span class="m-form__help"></span>
                            </div>
                          </div>
                        <?php } ?>
                        <?php if($this->config->item('Material_sale_price4_name')!=''){ ?>
                          <div class="col-lg-4">
                            <div class="form-group m-form__group">
                              <label for="user_name" style="text-align: left;">
                                Sale Price  <br/>[<?php echo $this->config->item('Material_sale_price4_name') ?>]
                              </label>
                              <input type="text" name="sale_price4" id="sale_price4_edit"  class="form-control m-input  m-input--air m-input--pill form_material_edit_fields" placeholder="Sale Price [<?php echo $this->config->item('Material_sale_price4_name') ?>]" aria-describedby="basic-addon1">
                              <span class="m-form__help"></span>
                            </div>
                          </div>
                        <?php } ?>
                        <?php if($this->config->item('Material_sale_price5_name')!=''){ ?>
                          <div class="col-lg-4">
                            <div class="form-group m-form__group">
                              <label for="user_name" style="text-align: left;">
                                Sale Price  <br/>[<?php echo $this->config->item('Material_sale_price5_name') ?>]
                              </label>
                              <input type="text" name="sale_price5"  id="sale_price5_edit" class="form-control m-input  m-input--air m-input--pill form_material_edit_fields" placeholder="Sale Price [<?php echo $this->config->item('Material_sale_price5_name') ?>]" aria-describedby="basic-addon1">
                              <span class="m-form__help"></span>
                            </div>
                          </div>
                        <?php } ?>
                        <?php if($this->config->item('Material_sale_price6_name')!=''){ ?>
                          <div class="col-lg-4">
                            <div class="form-group m-form__group">
                              <label for="user_name" style="text-align: left;">
                                Sale Price  <br/>[<?php echo $this->config->item('Material_sale_price6_name') ?>]
                              </label>
                              <input type="text" name="sale_price6"  id="sale_price6_edit" class="form-control m-input  m-input--air m-input--pill form_material_edit_fields" placeholder="Sale Price [<?php echo $this->config->item('Material_sale_price6_name') ?>]" aria-describedby="basic-addon1">
                              <span class="m-form__help"></span>
                            </div>
                          </div>
                        <?php } ?>
                      </div>
                    <?php } ?>
                  </div>

                  <input type="hidden" name="material_id" id="material_id">

                </div>
                <div class="modal-footer">
                  <button type="button" class="btn btn-secondary" data-dismiss="modal">
                    Close
                  </button>
                  <button type="submit" class="form_submit_btn btn btn-primary">
                    Submit
                  </button>
                </div>
              </form>
            </div>
          </div>
        </div>
        <div class="modal fade" tabindex="-1" id="material_delete_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
          <div class="modal-dialog " role="document" >
            <form autocomplete="off" data-modal-id="material_delete_modal" id="form_material_delete" method="post" action="<?php echo base_url().'material/delete'?>" class="form-horizontal">
              <div class="modal-content">
                <div class="alert alert-danger" role="alert" style="margin-bottom: 0px">
                  <button type="button" class="close" data-dismiss="modal"></button>
                  <br/>
                  <h4 class="alert-heading">Warning! Please Confirm Your Action</h4>
                  <br/>
                  <p> Are You Sure to Delete this Document ? This can not be undone ! </p>
                  <p>
                    <button class="btn btn-danger form_submit_btn" type="submit" name="submit">Confirm & Delete</button>
                    <button type="button" class="btn btn-primary modal-dismiss" data-dismiss="modal">Cancel</button>
                  </p>
                  <input type="hidden" value name="material_id" id="material_id_delete">
                </div>
              </div>
            </form>
          </div>
        </div>
        <?php $this->view("modules/include_modals/modal_unit_add");?>
      </div>
    </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>

$("#materials_menu").addClass('m-menu__item--open m-menu__item--active');
$("#materials_menu_1").addClass('m-menu__item--active');

$("#material_unit_add").select2({
  placeholder: "Select Unit",
  dropdownParent: $("#form_material_add")
})
$("#material_category_add").select2({
  placeholder: "Select Category",
  dropdownParent: $("#form_material_add")
})
$("#material_tax_percent_add").select2({
  placeholder: "Select Tax %",
  dropdownParent: $("#form_material_add")
})
$("#unit_edit").select2({
  placeholder: "Select Unit",
  dropdownParent: $("#form_material_edit")
})
$("#category_edit").select2({
  placeholder: "Select Category",
  dropdownParent: $("#form_material_edit")
})
$("#material_tax_percent_edit").select2({
  placeholder: "Select Tax %",
  dropdownParent: $("#form_material_edit")
})
$("#table_filter_material_category").select2({
  placeholder: "Select Category"
})
function select_units(){
  $('#material_unit_add').html('');
  $("#material_unit_add").append("<option disabled selected >Select Unit</option>");

  $('#unit_edit').html('');
  $("#unit_edit").append("<option disabled selected >Select Unit</option>");

  $.post("<?php echo base_url() ?>units/select",{},function(data) {
    var obj = $.parseJSON(data);
    var i=0;
    if(obj.count>0) {
      while (i < obj.id.length) {
        $("#material_unit_add").append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        $("#unit_edit").append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        i++;
      }
    }
  })
}
function select_category(){
  $('#material_category_add').html('');
  $("#material_category_add").append("<option disabled selected >Select Category</option>");

  $('#category_edit').html('');
  $("#category_edit").append("<option disabled selected >Select Category</option>");

  $('#table_filter_material_category').html('');
  $("#table_filter_material_category").append("<option selected value='all' >All Categories</option>");

  $.post("<?php echo base_url() ?>material/select_category",{},function(data) {
    var obj = $.parseJSON(data);
    var i=0;
    if(obj.count>0) {
      while (i < obj.id.length) {
        $("#material_category_add").append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        $("#category_edit").append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        $("#table_filter_material_category").append("<option value=" + obj.id[i] + ">" + obj.name[i] + "</option>");
        i++;
      }
    }
  })
}
select_units();
select_category();
//  Material List Data Table
var Datatable=function() {
  var t=function() {
    function GetSearchCategory(){
      return $('#table_filter_material_category').val();
    }
    var table = $('#material_view_table').DataTable({
      "ajax":{
        url :"<?php echo base_url().'material/select_material' ?>", // json datasource
        type: "post", // type of method  , by default would be get
        data: function(d){
          d.category = GetSearchCategory();
        }
      },
      "bProcessing": true,
      "deferRender": true,
      "bDeferRender": true,
      "scrollX" : true,
      buttons: [
        { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'},title: 'List of Materials' },
        { 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
      ],
      "columnDefs": [
        {
          "targets": [ 17,18,19,20,21,22<?php if ($this->config->item('app_module_vehicle_management') != 1) { echo ",2";}?><?php if($this->session->userdata('user_role')=='auditor'){ echo ",16"; }?><?php if($this->config->item('app_module_sales_invoice')!=1 || $this->config->item('Material_sale_price_category_enable') == 0){ echo ",9,10,11,12,13,14"; }?>
        <?php if($this->config->item('Material_sale_price1_name')==''){ echo ",9"; }?><?php if($this->config->item('Material_sale_price2_name')==''){ echo ",10"; }?><?php if($this->config->item('Material_sale_price3_name')==''){ echo ",11"; }?><?php if($this->config->item('Material_sale_price4_name')==''){ echo ",12"; }?><?php if($this->config->item('Material_sale_price5_name')==''){ echo ",13"; }?><?php if($this->config->item('Material_sale_price6_name')==''){ echo ",14"; }?> ],
          className: "hidden"
        }
      ],
      // set the initial value
      "pageLength": 25,
      'order': [[0, 'desc']]
    });
    $(".table_filter").on("change", function() {
      table.ajax.reload();
    });
    $(".hide_column").hide();
    $(".hidden").hide();

    $(".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: {
          "paid_amount": {
            required: !0,
            min: 0,
            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);
            toastr[obj.flashdata_type](obj.flashdata_msg, obj.flashdata_title);
            table.ajax.reload();
            $("#"+modal_id).modal('toggle');
            select_units();
            $("."+form_id+"_fields").val('');
            $("."+form_id+"_select").val('').trigger('change');
          } 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");
        }
      })
    )
  });
};
return {
  init:function() {
    t()
  }
}
}

();
jQuery(document).ready(function() {
  Datatable.init();
  $(".hidden").hide();
  //            $('#service_view_table').wrap("");
}

);
</script>

<script>
$('body').on('click', '#material_edit_btn', function() {
  var no = $(this).closest('tr').children('td');

  $('#material_id').val(no.eq(0).text());
  $('#material_name').val(no.eq(1).text());
  $('#specification_edit').val(no.eq(4).text());
  $('#item_code_edit').val(no.eq(5).text());
  $('#unit_edit').val(no.eq(17).text()).trigger("change");
  $('#category_edit').val(no.eq(18).text()).trigger("change");
  $('#material_price').val(no.eq(8).text());
  $('#sale_price1_edit').val(no.eq(9).text());
  $('#sale_price2_edit').val(no.eq(10).text());
  $('#sale_price3_edit').val(no.eq(11).text());
  $('#sale_price4_edit').val(no.eq(12).text());
  $('#sale_price5_edit').val(no.eq(13).text());
  $('#sale_price6_edit').val(no.eq(14).text());
  $('#material_tax_percent_edit').val(no.eq(21).text()).trigger("change");
  var material_type = no.eq(19).text();
  $("input[name=material_type_edit][value=" + material_type + "]").prop('checked', true);
  var material_section = no.eq(22).text();
  $("input[name=material_section_edit][value=" + material_section + "]").prop('checked', true);
  var material_branch_id = no.eq(20).text();
  var branch_id = '<?php echo $this->session->userdata('branch_id')?>';
  if(branch_id!=material_branch_id){
    $(".material_edit_branch_disable_fields").attr('disabled',true);
  }else{
    $(".material_edit_branch_disable_fields").removeAttr('disabled',true);
  }
})
$('body').on('click', '#material_delete_btn', function() {
  var no = $(this).closest('tr').children('td');

  $('#material_id_delete').val(no.eq(0).text());

})
</script>
