Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <% if admin_user_signed_in? %>
- <h1>Products</h1>
- <div>
- <%= link_to "Add new Product", new_product_path, class: "btn btn-primary" %>
- </div>
- <br>
- <% if @products.empty? %>
- <small>
- No products have been added.
- </small>
- <% else %>
- <table class = "table", cellspacing="0", cellpadding="0">
- <thead style="background-color: #333">
- <th>Name</th>
- <th>Description</th>
- <th>Status</th>
- <th>Supply</th>
- <th>Order</th>
- <th>Total</th>
- <th>Created At</th>
- <th colspan="6"></th>
- </thead>
- <tbody>
- <% @products.each do |product| %>
- <tr>
- <td>
- <%= product.name %>
- </td>
- <td>
- <%= product.description %>
- </td>
- <td>
- <%= product.status%>
- </td>
- <td>
- <% @supplies = 0 %>
- <% product.transactions.each do |trans| %>
- <% if trans.mode == "Supply" %>
- <% if trans.quantity == nil %>
- <% trans.quantity == 0 %>
- <% end %>
- <% @supplies += trans.quantity %>
- <% end %>
- <% end %>
- <%= @supplies %>
- </td>
- <td>
- <% @orders = 0 %>
- <% product.transactions.each do |trans| %>
- <% if trans.mode == "ORDER" %>
- <% if trans.quantity == nil %>
- <% transaction.quantity == 0 %>
- <% end %>
- <% @orders += trans.quantity %>
- <% end %>
- <% end %>
- <%= "(#{@orders.abs})" %>
- </td>
- <td>
- <% @total = 0 %>
- <% product.transactions.each do |trans| %>
- <% if trans.quantity == nil %>
- <% trans.quantity == 0 %>
- <% end %>
- <% @total += trans.quantity %>
- <% end %>
- <%= @total %>
- </td>
- <td>
- <%= time_ago_in_words(product.created_at) %> ago
- </td>
- <td>
- <%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
- </td>
- <td>
- <% if product.status == "Active" %>
- <%= link_to "Deactivate", product_path(product), method: :delete, class: "btn btn-danger" %>
- <% else %>
- <%= link_to "Activate", product_path(product), method: :delete, class: "btn btn-success"%>
- <% end %>
- </td>
- <!-- <td>
- <%= link_to "Delete", product_path(product), class: "btn btn-danger", method: :post, data: { confirm: "Are you sure you want to delete?" } %>
- </td> -->
- <td>
- <%= link_to "View", product_path(product), class: "btn btn-primary" %>
- </td>
- </tr>
- <% end%>
- </tbody>
- </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement