
<table class="table table-striped">
  <tr>
    <!-- <th><%= t("views.right_panel.header.menu_category") %></th> -->
    <th><%= t("views.right_panel.detail.product") %></th>
    <th><%= t("views.right_panel.detail.min_order") %></th>
    <th><%= t("views.right_panel.detail.max_stock") %></th>
    <th><%= t("views.right_panel.detail.balance") %></th>
    <th><%= t("views.right_panel.detail.status") %></th>
    <th><%= t("views.right_panel.detail.action") %></th>
    <!-- <th><%= t("views.right_panel.detail.created_by") %></th>
    <th><%= t("views.right_panel.detail.created_time") %></th> -->
  </tr>
  <% cate_arr = Array.new %>
  <%
    count = 0
    @inventory_definitions.each do |item|
    count += 1
  %>

    <tr>

      <!-- <% if !cate_arr.include?(item.menu_category_id) %> -->
      <!-- <td><%= item.menu_category_name %></td> -->
      <!-- <% cate_arr.push(item.menu_category_id) %> -->
      <!-- <% else %> -->
      <!-- <td>&nbsp;</td> -->
      <!-- <% end %> -->
      <td><%= item.item_name rescue '-' %> - <%= item.instance_name%></td>
      <td><%= item.min_order_level %></td>
      <td><%= item.max_stock_level %></td>
      <td>
        <% if item.balance.nil? %>
        0
        <% else %>
        <%= item.balance rescue 0 %>
        <% end %>
      </td>
      <% if !item.balance.nil? %>
        <% if item.balance >= 0 %>
          <td>
              <div class="badge badge-success">OK</div>
          </td>
        <% else %>
          <td>
            <div class="badge badge-danger">OUT OF STOCK</div>
          </td>
        <% end %>
      <% else %>
        <td><div class="badge badge-success">OK</div></td>
      <% end %>
      <td>
        <button type="button" data-value="<%= item.id %>" class="btn bg-blue waves-effect btn-link show_track"> <%= t("views.right_panel.detail.stock_ledger") %></button>
        <button type="button" class="delete btn btn-danger btn-sm waves-effect" data-ref="<%= inventory_inventory_definition_path(item) %>" data-method="delete">
          <%= t("views.btn.delete") %>
        </button>
        <span class="hidden" id="delete_text">
            <h6>Are you sure you want to delete this row ?</h6>
            <h6>This action can't be undo. </h6>
        </span>
      </td>

    </tr>
   <!--  <tr>
      <td><%= count %></td>
      <td>
        <% menu_item = MenuItemInstance.find_by_item_instance_code(item.item_code)%>
        <% if menu_item.nil? %>
        <%= Product.find_by_item_code(item.item_code).name rescue "-" %>
        <% else %>
        <%= menu_item.menu_item.name rescue "-" %>
        - <%= menu_item.item_instance_name rescue "-" %>
        <% end %>
      </td>
      <td><%= item.min_order_level %></td>
      <td><%= item.max_stock_level %></td>
      <td>
        <% if item.balance.nil? %>
          0
        <% else %>
          <%= item.balance rescue 0 %>
        <% end %>
      </td>
      <td>
        <button type="button" data-value="<%= item.id %>" class="btn bg-blue waves-effect btn-link show_track"><%= t("views.btn.show") %> <%= t("views.right_panel.detail.stock_check") %></button>
      </td>
    </tr> -->
    <% end %>
  </table>

  <script>
    $('.show_track').on('click', function () {
      var ID = $(this).attr("data-value");
      window.location.href = '/inventory/'+ID+'/show';
    });

  </script>
