<?php $this->view("includes/Inc_pagehead");?>
<!-- Page Styles Goes Here-->
<style>
.m-table, .m-table th,.m-table thead th, .m-table td {
  border: 1px solid #0000004a !important;
}
.centre{
  text-align: center;
}

</style>
<?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">
          Manage Tools & Equipments
        </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().'tools' ?>" class="m-nav__link">
              <span class="m-nav__link-text">
                Tools & Equipments
              </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 Tools & Equipments
            </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="#tools_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 Tool
                </span>
              </span>
            </a>
          <?php } ?>
        </div>
      </div>
      <div class="m-portlet__body">
        <div class="m-form m-form--label-align-right m--margin-bottom-10">
          <div class="">
            <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>
                      Tool Category:
                    </label>
                    <div class="m-select2 m-select2--air m-select2--pill">
                      <select style="width: 100%" class="form-control m-select2 table_filter" id="tools_category_filter"  name="" data-placeholder="Select Tool Category">

                      </select>
                    </div>
                    <span class="m-form__help"></span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!--begin: Datatable -->
        <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="tools_view_table">
          <thead>
            <tr class="">
              <th rowspan="2">Sl No</th>
              <th rowspan="2">Tool ID</th>
              <th rowspan="2">Tool Name</th>
              <th rowspan="2">Category</th>
              <th rowspan="2">Description</th>
              <th colspan="4" class="centre">Owned Quantity</th>
              <th rowspan="2">Price/Day</th>
              <th rowspan="2">Total in <?php echo $this->config->item('Tools_transfer_default_location_name') ?></th>
              <th rowspan="2">Total in Sites (Own)</th>
              <th rowspan="2">Total Rented Qty</th>
              <th rowspan="2">Total Returned</th>
              <th rowspan="2">Total in Sites (Rent)</th>
              <th rowspan="2">Creation</th>
              <th rowspan="2">Actions</th>
              <th rowspan="2">Cat ID</th>
              <th rowspan="2">Type</th>
            </tr>
            <tr>
              <th>Opening</th>
              <th>Purchased</th>
              <th>Damaged Qty</th>
              <th>Total Available</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
        <!--end: Datatable -->
      </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">
              List of Tools Purchases
            </h3>
          </div>
        </div>
        <div class="m-portlet__head-tools">

        </div>
      </div>
      <div class="m-portlet__body">
        <div class="m-form m-form--label-align-right m--margin-bottom-10">
          <div class="">
            <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>
                      Tool Category:
                    </label>
                    <div class="m-select2 m-select2--air m-select2--pill">
                      <select style="width: 100%" class="form-control m-select2 table_filter" id="tools_category_filter_2"  name="" data-placeholder="Select Tool Category">

                      </select>
                    </div>
                    <span class="m-form__help"></span>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!--begin: Datatable -->
        <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="tools_purchase_view_table">
          <thead>
            <tr class="">
              <th>Purchase ID</th>
              <th>Purchase Date</th>
              <th>Tool Name</th>
              <th>Category</th>
              <th>Purchased From</th>
              <th>Purchased Qty</th>
              <th>Total Price</th>
              <th>Unit Price</th>
              <th>Remarks</th>
              <th>Actions</th>
              <th>tool id</th>
              <th>tr id</th>
              <th>debit acc</th>
              <th>tr mode</th>
              <th>ref no</th>
              <th>ref date</th>
              <th>description</th>

            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
        <!--end: Datatable -->
      </div>
    </div>
  </div>

  <div class="modal fade" tabindex="-1" id="tools_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog " role="document" style="max-width: 800px">
      <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 New Tool
          </h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">
              &times;
            </span>
          </button>
        </div>
        <!--                                                    ADD EXPENSE DATA start-->
        <form autocomplete="off" id="form_tools_add" data-modal-id="tools_add_modal" method="post" action="<?php echo base_url().'tools/create'?>" 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_tools_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">
                    Category
                  </label>
                  <div class="input-group m-input-group m-input-group--pill">
                    <div class="input-group-prepend">
                      <a href="#tools_category_add_modal"   data-toggle="modal" data-target="#tools_category_add_modal" class="btn btn-focus btn_add_types">
                        <i class="fa fa-plus-circle"></i>
                      </a>
                    </div>
                    <select required style="width: 88%" class="form-control m-select2 m-select2-general form_tools_add_select" required id="tools_category_add" name="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">
              Tool Type
            </label>
            <div >
            <span class="m-bootstrap-switch m-bootstrap-switch--pill m-bootstrap-switch--air">
            <input name="tool_type" id="tool_type" data-switch="true" type="checkbox" data-on-color="success" data-off-color="danger" data-on-text="Own" data-off-text="Rent" checked="checked">
          </span>
        </div>
      </div>
    </div> -->
    <div class="col-lg-8">
      <div class="form-group m-form__group" >
        <label for="user_name">
          Tool Name
        </label>
        <div class="m-input-icon m-input-icon--right">
          <input required type="text" name="name"  class="form-control m-input m-input--pill m-input--air form_tools_add_fields" placeholder="Name of Tool" aria-describedby="basic-addon1">
          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
        </div>
        <span class="m-form__help"></span>
      </div>
    </div>
    <div class="col-lg-4" id="owned_qty_div">
      <div class="form-group m-form__group" >
        <label for="user_name">
          Total Owned Qty
        </label>
        <div class="m-input-icon m-input-icon--right">
          <input   <?php if($this->config->item('Tools_tool_racks')==1) { echo "readonly"; }?> type="text" id="owned_qty"   name="owned_qty"  class="form-control m-input m-input--pill m-input--air form_tools_add_fields" placeholder="Total Owned Qty" aria-describedby="basic-addon1">
          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
        </div>
        <span class="m-form__help"></span>
      </div>
    </div>
    <?php if($this->config->item('Tools_tool_racks')==1) { ?>
      <!-- <div class="col-lg-12" >
        <table style="width: 100%;max-width: 100%;font-size:16px"   class="table order-list table-striped m-table m-table--head-bg-primary table-bordered table-advance table-hover">
          <thead>
            <tr>
              <th style="width: 20%">Sl No</th>
              <th style="width: 20%">Rack</th>
              <th style="width: 20%">Select</th>
              <th style="width: 20%">Qty</th>
            </tr>
          </thead>
          <tbody id="table_body"> -->
            <?php
            foreach ($tool_racks as $key => $value) { ?>
              <!-- <tr>
                <td><?php // echo $key+1 ?></td>
                <td><?php // echo $value->rack_name ?></td>
                <td>
                  <div class="m-form__group form-group">
                    <div class="m-checkbox-list">
                      <label class="m-checkbox m-checkbox--air m-checkbox--state-brand m-checkbox--bold" style="margin-bottom: 0px !important">
                        <input data-rack-id="<?php // echo $value->rack_id ?>" class="rack_qty_add_select" type="checkbox">
                        <span></span>
                      </label>
                    </div>
                  </div>
                </td>
                <td>
                  <div class="form-group m-form__group" >
                    <input type="text" style="display: none"  name="rack_qty_add_<?php // echo $value->rack_id ?>" id="rack_qty_add_<?php // echo $value->rack_id ?>"  class="form-control m-input m-input--pill m-input--air rack_qty_add form_tools_add_fields" placeholder="Qty" aria-describedby="basic-addon1">
                  </div>
                </td>
              </tr> -->
            <?php } ?>
          <!-- </tbody>
          <tfoot>
            <tr>
            </tr>
          </tfoot>
        </table>
      </div> -->
    <?php } ?>
    <div class="col-lg-8">
      <div class="form-group m-form__group">
        <label for="user_name">
          Description
        </label>
        <div class="m-input-icon m-input-icon--right">
          <textarea name="description"  class="form-control m-input  m-input--pill m-input--air form_tools_add_fields" placeholder="Description" aria-describedby="basic-addon1"></textarea>
          <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
        </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">Price / Day</label>
        <div class="m-input-icon m-input-icon--right">
          <input type="text" id="price"  name="price"  class="form-control m-input m-input--pill m-input--air form_tools_add_fields" placeholder="Price Per Day" aria-describedby="basic-addon1">
          <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format'); ?></span></span>
        </div>
        <span class="m-form__help"></span>
      </div>
    </div>
    <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 form_submit_btn">
    Submit
  </button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" id="tools_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <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 Tool Details
        </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">
            &times;
          </span>
        </button>
      </div>
      <form autocomplete="off" data-modal-id="tools_edit_modal" id="form_tools_edit" method="post" action="<?php echo base_url().'tools/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_tools_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>
          </div>
          <div class="row">
            <div class="col-lg-12">
              <div class="form-group m-form__group" >
                <label for="user_name">
                  Category
                </label>
                <div class="input-group m-input-group m-input-group--pill">
                  <div class="input-group-prepend">
                    <a href="#tools_category_add_modal"   data-toggle="modal" data-target="#tools_category_add_modal" class="btn btn-focus btn_add_types">
                      <i class="fa fa-plus-circle"></i>
                    </a>
                  </div>
                  <select required style="width: 88%" class="form-control m-select2 m-select2-general form_tools_edit_select" required id="tools_category_edit" name="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">
            Tool Type
          </label>
          <div >
          <span class="m-bootstrap-switch m-bootstrap-switch--pill m-bootstrap-switch--air">
          <input name="tool_type" id="tool_type_edit" data-switch="true" type="checkbox" data-on-color="success" data-off-color="danger" data-on-text="Own" data-off-text="Rent" >
        </span>
      </div>
    </div>
  </div> -->
  <div class="col-lg-8">
    <div class="form-group m-form__group" >
      <label for="user_name">
        Tool Name
      </label>
      <div class="m-input-icon m-input-icon--right">
        <input required type="text" name="name" id="name_edit"  class="form-control m-input m-input--pill m-input--air form_tools_edit_fields" placeholder="Name of Tool" aria-describedby="basic-addon1">
        <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
      </div>
      <span class="m-form__help"></span>
    </div>
  </div>
  <div class="col-lg-4">
    <div class="form-group m-form__group" id="owned_qty_div_edit" >
      <label for="user_name">
        Owned Qty
      </label>
      <div class="m-input-icon m-input-icon--right">
        <input type="text" id="owned_qty_edit"  name="owned_qty"  class="form-control m-input m-input--pill m-input--air form_tools_edit_fields" placeholder="Total Owned Qty" aria-describedby="basic-addon1">
        <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
      </div>
      <span class="m-form__help"></span>
    </div>
  </div>
  <div class="col-lg-8">
    <div class="form-group m-form__group">
      <label for="user_name">
        Description
      </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>
        <textarea name="description" id="desc_edit"  class="form-control m-input" placeholder="Description" aria-describedby="basic-addon1"></textarea>
      </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">Price / Day</label>
      <div class="m-input-icon m-input-icon--right">
        <input type="text" id="price_edit"  name="price"  class="form-control m-input m-input--pill m-input--air form_tools_add_fields" placeholder="Price Per Day" aria-describedby="basic-addon1">
        <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format'); ?></span></span>
      </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">
        Damaged Qty
      </label>
      <div class="m-input-icon m-input-icon--right">
        <input type="text" id="damaged_qty_edit"  name="damaged_qty"  class="form-control m-input m-input--pill m-input--air form_tools_edit_fields" placeholder="Total Damaged Qty" aria-describedby="basic-addon1">
        <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
      </div>
      <span class="m-form__help"></span>
    </div>
  </div>
  <input type="hidden"  name="tool_id" id="tool_id_edit">
  <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 form_submit_btn btn-primary">
    Submit
  </button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" id="tools_delete_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" >
    <form autocomplete="off" data-modal-id="tools_delete_modal" id="form_tools_delete" method="post" action="<?php echo base_url().'tools/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 Data ?. All the Associated Data will Lost. </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"  name="tool_id" id="tool_id_delete">
          <input type="hidden" name="redirect_url" value="<?php echo base_url(uri_string())?>" >
        </div>
      </div>
    </form>
  </div>
</div>

<div class="modal fade" tabindex="-1" id="tools_category_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content">
      <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
          Create New Tool Category
        </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_tools_category_add" data-modal-id="tools_category_add_modal" method="post" action="<?php echo base_url().'tools/create_category'?>" enctype="multipart/form-data" class="form 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_tools_head_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">
                  Category 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-tag"></i>
                    </span>
                  </div>
                  <input required type="text" name="name"  class="form-control m-input form_tools_category_add_fields" placeholder="Category Name" aria-describedby="basic-addon1">
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </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 form_submit_btn">
            Submit
          </button>
        </div>
      </form>
    </div>
  </div>
</div>

<div class="modal fade" tabindex="-1" id="tools_purchase_add_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content">
      <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
          Create Tool Purchase
        </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_tools_purchase_add" data-modal-id="tools_purchase_add_modal" method="post" action="<?php echo base_url().'tools/create_purchase'?>" enctype="multipart/form-data" class="form 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_tools_purchase_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-8">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Tool 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-tag"></i>
                    </span>
                  </div>
                  <input readonly type="text" id="tool_name_purchase_add" class="form-control m-input form_tools_purchase_add_fields" aria-describedby="basic-addon1">
                </div>
                <span class="m-form__help"></span>
              </div>
              <input type="hidden" id="tool_id_purchase_add" name="tool_id" />
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Tool Category
                </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-tag"></i>
                    </span>
                  </div>
                  <input readonly type="text" id="tool_category_purchase_add" class="form-control m-input form_tools_purchase_add_fields" aria-describedby="basic-addon1">
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-12">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Description
                </label>
                <textarea disabled id="tool_description_purchase_add"  class="form-control m-input  m-input--pill m-input--air form_tools_purchase_add_fields" placeholder="Description" aria-describedby="basic-addon1"></textarea>
                <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">
                  Purchased Date
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required data-date-format="dd-mm-yyyy" id="purchase_paid_date_add"  type="text" name="paid_date" class="form_tools_purchase_add_fields form-control m-input m-input--pill m-input--air purchase_paid_amount_req_fields " placeholder="Purchased Date" >
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-calendar"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-8">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Purchased From
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input   type="text" name="purchase_from" class="form_tools_purchase_add_fields form-control m-input m-input--pill m-input--air " placeholder="Purchased From" >
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Purchased Qty
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required name="purchase_qty" type="text"  class="form-control m-input m-input--pill m-input--air form_tools_purchase_add_fields" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Total Price
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" name="paid_amount" id="purchase_paid_amount_add" value="" class="form-control m-input m-input--pill m-input--air form_tools_purchase_add_fields" placeholder="Total Price" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format'); ?></span></span>
                </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">
                  Paid From Acc
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required id="purchase_debit_acc_add" name="debit_acc" style="width: 100%" class="form_tools_purchase_add_fields form-control m-input form_tools_purchase_add_select purchase_paid_amount_req_fields"  aria-describedby="basic-addon1">
                    <?php
                    foreach($this->config->item('account_heads') as $row):
                      $selected="";
                      if($row->acc_head_id==1){
                        $selected="selected";
                      }
                      ?>
                      <option <?php echo $selected?> value="<?php echo $row->acc_head_id?>"><?php echo $row->acc_head_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </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">
                  Payment Mode
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required id="purchase_payment_mode_add" name="payment_mode" style="width: 100%" class="form_tools_purchase_add_fields form-control m-input form_tools_purchase_add_select purchase_paid_amount_req_fields"  aria-describedby="basic-addon1">
                    <option selected disabled>Select Payment Mode</option>
                    <?php
                    foreach($this->config->item('payment_modes') as $row):
                      ?>
                      <option value="<?php echo $row?>"><?php echo $row?></option>
                      <?php
                    endforeach;
                    ?>
                  </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">
                  TR Reference No
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input type="text" name="reference_no"  class="form-control m-input m-input--pill m-input--air form_tools_purchase_add_fields" placeholder="Reference No" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  TR Reference Date
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input type="text" data-date-format="dd-mm-yyyy" name="reference_date" id="purchase_reference_date_add"  class="form-control m-input m-input--pill m-input--air form_tools_purchase_add_fields" placeholder="Reference Date" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
                </div>
                <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">
                  Remarks
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input type="text" name="tr_remarks" class="form-control m-input m-input--pill m-input--air form_tools_purchase_add_fields" placeholder=" Remarks" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </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 form_submit_btn">
            Submit
          </button>
        </div>
      </form>
    </div>
  </div>
</div>
<div class="modal fade" tabindex="-1" id="tools_purchase_edit_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content">
      <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
          Edit Tool Purchase
        </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_tools_purchase_edit" data-modal-id="tools_purchase_edit_modal" method="post" action="<?php echo base_url().'tools/update_purchase'?>" enctype="multipart/form-data" class="form 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_tools_purchase_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>
          </div>
          <div class="row">
            <div class="col-lg-8">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Tool 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-tag"></i>
                    </span>
                  </div>
                  <input readonly type="text" id="tool_name_purchase_edit" class="form-control m-input form_tools_purchase_edit_fields" aria-describedby="basic-addon1">
                </div>
                <span class="m-form__help"></span>
              </div>
              <input type="hidden" id="tool_id_purchase_edit" name="tool_id" />
              <input type="hidden" id="purchase_id_purchase_edit" name="purchase_id" />
            </div>
            <div class="col-lg-4">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Tool Category
                </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-tag"></i>
                    </span>
                  </div>
                  <input readonly type="text" id="tool_category_purchase_edit" class="form-control m-input form_tools_purchase_edit_fields" aria-describedby="basic-addon1">
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-12">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Description
                </label>
                <textarea disabled id="tool_description_purchase_edit"  class="form-control m-input  m-input--pill m-input--air form_tools_purchase_edit_fields" placeholder="Description" aria-describedby="basic-addon1"></textarea>
                <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">
                  Purchased Date
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required data-date-format="dd-mm-yyyy" id="purchase_paid_date_edit"  type="text" name="paid_date" class="form_tools_purchase_edit_fields form-control m-input m-input--pill m-input--air purchase_paid_amount_req_fields " placeholder="Purchased Date" >
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-calendar"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
            <div class="col-lg-8">
              <div class="form-group m-form__group">
                <label for="user_name">
                  Purchased From
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input  id="purchase_from_edit" type="text" name="purchase_from" class="form_tools_purchase_edit_fields form-control m-input m-input--pill m-input--air " placeholder="Purchased From" >
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Purchased Qty
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required name="purchase_qty" id="purchase_qty_edit" type="text"  class="form-control m-input m-input--pill m-input--air form_tools_purchase_edit_fields" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  Total Price
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input required type="text" name="paid_amount" id="purchase_paid_amount_edit" value="" class="form-control m-input m-input--pill m-input--air form_tools_purchase_edit_fields" placeholder="Total Price" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><?php echo $this->config->item('Currency_currency_format'); ?></span></span>
                </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">
                  Paid From Acc
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required id="purchase_debit_acc_edit" name="debit_acc" style="width: 100%" class="form_tools_purchase_edit_fields form-control m-input form_tools_purchase_edit_select purchase_paid_amount_req_fields"  aria-describedby="basic-addon1">
                    <?php
                    foreach($this->config->item('account_heads') as $row):
                      $selected="";
                      if($row->acc_head_id==1){
                        $selected="selected";
                      }
                      ?>
                      <option <?php echo $selected?> value="<?php echo $row->acc_head_id?>"><?php echo $row->acc_head_name?></option>
                      <?php
                    endforeach;
                    ?>
                  </select>
                </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">
                  Payment Mode
                </label>
                <div class="m-select2 m-select2--air m-select2--pill">
                  <select required id="purchase_payment_mode_edit" name="payment_mode" style="width: 100%" class="form_tools_purchase_edit_fields form-control m-input form_tools_purchase_edit_select purchase_paid_amount_req_fields"  aria-describedby="basic-addon1">
                    <option selected disabled>Select Payment Mode</option>
                    <?php
                    foreach($this->config->item('payment_modes') as $row):
                      ?>
                      <option value="<?php echo $row?>"><?php echo $row?></option>
                      <?php
                    endforeach;
                    ?>
                  </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">
                  TR Reference No
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input type="text" id="reference_no_purchase_edit" name="reference_no"  class="form-control m-input m-input--pill m-input--air form_tools_purchase_edit_fields" placeholder="Reference No" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </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">
                  TR Reference Date
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input type="text" data-date-format="dd-mm-yyyy" name="reference_date" id="purchase_reference_date_edit"  class="form-control m-input m-input--pill m-input--air form_tools_purchase_edit_fields" placeholder="Reference Date" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-tag"></i></span></span>
                </div>
                <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">
                  Remarks
                </label>
                <div class="m-input-icon m-input-icon--right">
                  <input id="remarks_purchase_edit" type="text" name="tr_remarks" class="form-control m-input m-input--pill m-input--air form_tools_purchase_edit_fields" placeholder=" Remarks" aria-describedby="basic-addon1">
                  <span class="m-input-icon__icon m-input-icon__icon--right"><span><i class="la la-edit"></i></span></span>
                </div>
                <span class="m-form__help"></span>
              </div>
            </div>
          </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 form_submit_btn">
            Submit
          </button>
        </div>
      </form>
    </div>
  </div>
</div>
<div class="modal fade" tabindex="-1" id="tools_purchase_delete_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" >
    <form autocomplete="off" data-modal-id="tools_purchase_delete_modal" id="form_tool_purchase_delete" method="post" action="<?php echo base_url().'tools/delete_purchase'?>" 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 Data ?. All the Associated Data will Lost. </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"  name="purchase_id" id="purchase_id_delete">
          <input type="hidden"  name="tool_id" id="tool_id_purchase_delete">
          <input type="hidden" name="redirect_url" value="<?php echo base_url(uri_string())?>" >
        </div>
      </div>
    </form>
  </div>
</div>

<div class="modal fade" tabindex="-1" id="available_list_modal" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog " role="document" style="max-width: 800px">
    <div class="modal-content" style="width: 850px">
      <div class="modal-header" style="background-color: #36a3f7;border-radius: 4px">
        <h5 class="modal-title" id="exampleModalLabel" style="color: #ffffff" >
          List of Available Locations for : <span><strong id="available_list_tool_name"></strong></span>
        </h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">
            &times;
          </span>
        </button>
      </div>
      <div class="modal-body">
        <table width="100%" class="table m-table nowrap table-header-fixed table-striped table-bordered table-hover table-header-fixed" id="available_list_table">
          <thead>
            <tr class="">
              <th>Sl No</th>
              <th>Tool Name</th>
              <th>Type</th>
              <th>Location</th>
              <th>Available Qty</th>
            </tr>
          </thead>
          <tbody>
          </tbody>
        </table>
      </div>
    </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>
$("#tools_menu").addClass('m-menu__item--active m-menu__item--open');
$("#tools_menu_1").addClass('m-menu__item--active');

$("#tools_category_filter").select2({
  placeholder: "Select  Tool Category"
})
$("#tools_category_filter_2").select2({
  placeholder: "Select  Tool Category"
})
function select_tools_category(select_id,type){
  $('#'+select_id).html('');
  if(type=='filter'){
    $("#"+select_id).append("<option value='all' selected >All Category</option>");
  }else{
    $("#"+select_id).append("<option disabled selected >Select Tool Category</option>");
  }
  $.post("<?php echo base_url() ?>tools/select_category_list",{},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_tools_category("tools_category_filter",'filter');
select_tools_category("tools_category_filter_2",'filter');
select_tools_category("tools_category_add");
select_tools_category("tools_category_edit");

$("#purchase_paid_date_add,#purchase_paid_date_edit,#purchase_reference_date_add,#purchase_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', '#purchase_payment_mode_add', function() {
    var payment_mode=$('#purchase_payment_mode_add :selected').val();
    if(payment_mode=='POST DATED CHEQUE'){
      $('#purchase_paid_date_add').datepicker('destroy');
      $("#purchase_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{
      $('#purchase_paid_date_add').datepicker('destroy');
      $("#purchase_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 } ?>
        })
    }
  })
  $('body').on('change', '#purchase_payment_mode_edit', function() {
    var payment_mode=$('#purchase_payment_mode_edit :selected').val();
    if(payment_mode=='POST DATED CHEQUE'){
      $('#purchase_paid_date_edit').datepicker('destroy');
      $("#purchase_paid_date_edit").datepicker( {
        todayHighlight:!0, orientation:"bottom left", templates: {
          leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
        },
        <?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{
      $('#purchase_paid_date_edit').datepicker('destroy');
      $("#purchase_paid_date_edit").datepicker( {
        todayHighlight:!0, orientation:"bottom left", templates: {
          leftArrow: '<i class="la la-angle-left"></i>', rightArrow: '<i class="la la-angle-right"></i>'
        },
        endDate: '+0d',
        <?php if($this->session->userdata('user_role')!='admin' && $this->config->item('User_calendar_date_restriction_enabled')==1){ ?>
          startDate: '<?php echo $this->config->item('User_calendar_date_restriction_start_days');?>d'
          <?php } ?>
        })
    }
  })
  function select_expense_head(select_id,type=''){
    $('#'+select_id).html('');
    if(type=='filter'){
      $("#"+select_id).append("<option value='all' selected >All Expense Heads</option>");
    }else{
      $("#"+select_id).append("<option disabled selected >Select Expense Head</option>");
    }
    $.post("<?php echo base_url() ?>accounts/select_heads_2",{account_type:11},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++;
        }
      }
    })
  }

  $("#purchase_debit_acc_add").select2({
    placeholder: "Select Debit Account",
    dropdownParent: $("#form_tools_purchase_add")
  })
  $("#purchase_payment_mode_add").select2({
    placeholder: "Select Debit Account",
    dropdownParent: $("#form_tools_purchase_add")
  })

  $("#purchase_debit_acc_edit").select2({
    placeholder: "Select Debit Account",
    dropdownParent: $("#form_tools_purchase_edit")
  })
  $("#purchase_payment_mode_edit").select2({
    placeholder: "Select Payment Mode",
    dropdownParent: $("#form_tools_purchase_edit")
  })


  $("#tools_category_add").select2({
    placeholder: "Select Tool Category",
    dropdownParent: $("#form_tools_add")
  })
  $("#tools_category_edit").select2({
    placeholder: "Select Tool Category",
    dropdownParent: $("#form_tools_edit")
  })
  $("[data-switch=true]").bootstrapSwitch()


  $("#owned_qty_div").show();
  $("#owned_qty").attr("required", true);

  // $('#tool_type').on('switchChange.bootstrapSwitch', function (event, state) {
  //   if($("#tool_type").is(':checked')) {
  //     $("#owned_qty_div").show();
  //     $("#owned_qty").attr("required", true);
  //
  //   } else {
  //     $("#owned_qty_div").hide();
  //     $("#owned_qty").attr("required", false);
  //   }
  // });
  $("#owned_qty_div_edit").show();
  $("#owned_qty_edit").attr("required", true);
  // $('#tool_type_edit').on('switchChange.bootstrapSwitch', function (event, state) {
  //   if($("#tool_type_edit").is(':checked')) {
  //     $("#owned_qty_div_edit").show();
  //     $("#owned_qty_edit").attr("required", true);
  //
  //   } else {
  //     $("#owned_qty_div_edit").hide();
  //     $("#owned_qty_edit").attr("required", false);
  //   }
  // });
  // $('body').on('change', '.rack_qty_add_select', function() {
  //   var rack_id = $(this).data('rack-id');
  //   if ($(this).prop('checked')==true){
  //     $("#rack_qty_add_"+rack_id).attr('required',true);
  //     $("#rack_qty_add_"+rack_id).show();
  //   }else{
  //     $("#rack_qty_add_"+rack_id).removeAttr('required',true);
  //     $("#rack_qty_add_"+rack_id).hide();
  //     $("#rack_qty_add_"+rack_id).val(0);
  //   }
  //   calculate_total_owned_qty();
  // })
  // function calculate_total_owned_qty(){
  //   var total_owned_qty = 0;
  //   $(".rack_qty_add").each(function(){
  //     var qty = parseFloat($(this).val());
  //     if(isNaN(qty)){
  //       qty = 0;
  //     }
  //     total_owned_qty+=qty;
  //   });
  //   $("#owned_qty").val(total_owned_qty);
  // }
  // $('body').on('change keyup', '.rack_qty_add', function() {
  //   calculate_total_owned_qty();
  // })
  $('body').on('click', '#tools_purchase_add_btn', function() {
    var no = $(this).closest('tr').children('td');
    $('#tool_id_purchase_add').val(no.eq(1).text());
    $('#tool_name_purchase_add').val(no.eq(2).text());
    $('#tool_category_purchase_add').val(no.eq(3).text());
    $('#tool_description_purchase_add').val(no.eq(4).text());
  })
  $('body').on('click', '#tools_purchase_edit_btn', function() {
    var no = $(this).closest('tr').children('td');
    $('#purchase_id_purchase_edit').val(no.eq(0).text());
    $('#tool_id_purchase_edit').val(no.eq(10).text());
    $('#tool_name_purchase_edit').val(no.eq(2).text());
    $('#tool_category_purchase_edit').val(no.eq(3).text());
    $('#tool_description_purchase_edit').val(no.eq(16).text());
    $('#purchase_paid_date_edit').datepicker("setDate",no.eq(1).text());
    $('#purchase_from_edit').val(no.eq(4).text());
    $('#purchase_qty_edit').val(no.eq(5).text());
    $('#purchase_paid_amount_edit').val(no.eq(6).text());
    $('#purchase_debit_acc_edit').val(no.eq(12).text()).trigger('change');
    $('#purchase_payment_mode_edit').val(no.eq(13).text()).trigger('change');
    $('#reference_no_purchase_edit').val(no.eq(14).text());
    $('#purchase_reference_date_edit').datepicker("setDate",no.eq(15).text());
    $('#remarks_purchase_edit').val(no.eq(8).text());
  })
  $('body').on('click', '#tools_purchase_delete_btn', function() {
    var no = $(this).closest('tr').children('td');
    $('#purchase_id_delete').val(no.eq(0).text());
    $('#tool_id_purchase_delete').val(no.eq(10).text());
  })
  $('body').on('click', '#tools_edit_btn', function() {
    var no = $(this).closest('tr').children('td');
    $('#tool_id_edit').val(no.eq(1).text());
    $('#name_edit').val(no.eq(2).text());
    var description = no.eq(4).text();
    $('#desc_edit').val(description);
    $('#owned_qty_edit').val(no.eq(5).text());
    $('#price_edit').val(no.eq(9).text());
    $('#damaged_qty_edit').val(no.eq(7).text());
    $('#tools_category_edit').val(no.eq(17).text()).trigger('change');
    // var tool_type=no.eq(11).text();
    // if(tool_type=='own')
    // {
    //   $('#tool_type_edit').bootstrapSwitch('state',true);
    //   $("#owned_qty_div_edit").show();
    //   $("#owned_qty_edit").attr("required", true);
    // }else
    // {
    //   $('#tool_type_edit').bootstrapSwitch('state',false);
    //   $("#owned_qty_div_edit").hide();
    //   $("#owned_qty_edit").attr("required", false);
    // }
  })
  $('body').on('click', '#tools_delete_btn', function() {
    var no = $(this).closest('tr').children('td');
    $('#tool_id_delete').val(no.eq(1).text());
  })
  $('body').on('click', '#btn_get_list', function() {
    var no = $(this).closest('tr').children('td');
    var tool_id = no.eq(1).text();
    $('#available_list_tool_name').text(no.eq(2).text()+" ("+no.eq(3).text()+")");
    $('#available_list_table').dataTable().fnDestroy();
    available_list_table(tool_id);
  })
  var available_list_table=function(tool_id) {
    var table2 = $('#available_list_table').DataTable({
      "ajax": {
        url: "<?php echo base_url().'tools/select_all_available_locations_list' ?>", // json datasource
        type: "post", // type of method  , by default would be get
        data: function (d) {
          d.tool_id = tool_id;
        }
      },
      "bProcessing": true,
      "deferRender": true,
      "bDeferRender": true,
      "scrollX" : true,
      buttons: [
        { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'} ,title: 'Available Tools 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": [
        [25, 50, 100, -1],
        [25, 50, 100, "All"] // change per page values here
      ],
      'order': [[0, 'asc']],
      scrollCollapse: true,
      fixedColumns:   true,
      fixedColumns:   {
        leftColumns: 4
      }
    });
    $(".hidden").hide();
    table2.ajax.reload();
  }
  //  client List Data Table
  var Datatable=function() {
    var t=function() {
      function GetSearchcategory(){
        return $('#tools_category_filter').val();
      }
      function GetSearchcategory2(){
        return $('#tools_category_filter_2').val();
      }
      var table = $('#tools_view_table').DataTable({
        "ajax":{
          url :"<?php echo base_url().'tools/select_tools/' ?>", // json datasource
          type: "post", // type of method  , by default would be get
          data: function(d){
            d.category = GetSearchcategory2();
          }
        },
        "bProcessing": true,
        "deferRender": true,
        "bDeferRender": true,
        "scrollX" : true,
        buttons: [
          { extend: 'print', className: 'btn dark btn-outline',exportOptions: {columns: ':visible'} ,title: 'List of Tools'},
          { 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": [ 1,17,18<?php if($this->session->userdata('user_role')=='auditor'){ echo ","; } ?> ],
            className: "hidden",
            // "visible": false,
          },
        ],
        'order': [[1, 'asc']],
        fixedColumns:   true,
        fixedColumns:   {
          leftColumns: 4
        }
      });
      var table3 = $('#tools_purchase_view_table').DataTable({
        "ajax":{
          url :"<?php echo base_url().'tools/select_tools_purchase/' ?>", // 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: 'Tool Purchases' },
          { 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": [ 10,11,12,13,14,15,16<?php if($this->session->userdata('user_role')=='auditor'){ echo ",9,"; } ?>  ],
            className: "hidden"
          }
        ],
        'order': [[0, 'desc']]
      });
      $(".table_filter").on("change", function() {
        table.ajax.reload();
        table3.ajax.reload();
      });
      $(".hide_column").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: {
            qty: {
              number: !0,
              required: !0
            },
            purchase_qty: {
              number: !0,
              required: !0
            },
            paid_amount: {
              number: !0,
              required: !0
            }
          }, invalidHandler: function (e, r) {
            var i = $("#" + form_id + "_msg");
            i.removeClass("m--hide").show(), mUtil.scrollTo(i, -200)
          }, submitHandler: function (e) {
          }
        }),
        <?php if($this->config->item('Tools_tool_racks')==1) { ?>
          // $(".rack_qty_add").each(function () {
          //   if(form_id=="form_tools_add" || form_id=="form_tools_edit"){
          //     $("#"+$(this).attr("id")).rules('add', {
          //       number: !0
          //     });
          //   }
          // }),
          <?php } ?>
          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");

                select_tools_category("tools_category_filter",'filter');
                select_tools_category("tools_category_add");
                select_tools_category("tools_category_edit");
                table.ajax.reload();
                table3.ajax.reload();
              } 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>
<style>
.hidden{
  display: none;
}
</style>
