Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <% if admin_user_signed_in? %>
  2. <h1>Products</h1>
  3. <div>
  4. <%= link_to "Add new Product", new_product_path, class: "btn btn-primary" %>
  5. </div>
  6.  
  7. <br>
  8.  
  9. <% if @products.empty? %>
  10. <small>
  11. No products have been added.
  12. </small>
  13. <% else %>
  14. <table class = "table", cellspacing="0", cellpadding="0">
  15. <thead style="background-color: #333">
  16. <th>Name</th>
  17. <th>Description</th>
  18. <th>Status</th>
  19. <th>Supply</th>
  20. <th>Order</th>
  21. <th>Total</th>
  22. <th>Created At</th>
  23. <th colspan="6"></th>
  24. </thead>
  25. <tbody>
  26. <% @products.each do |product| %>
  27. <tr>
  28. <td>
  29. <%= product.name %>
  30. </td>
  31. <td>
  32. <%= product.description %>
  33. </td>
  34. <td>
  35. <%= product.status%>
  36. </td>
  37. <td>
  38. <% @supplies = 0 %>
  39. <% product.transactions.each do |trans| %>
  40. <% if trans.mode == "Supply" %>
  41. <% if trans.quantity == nil %>
  42. <% trans.quantity == 0 %>
  43. <% end %>
  44.  
  45. <% @supplies += trans.quantity %>
  46. <% end %>
  47. <% end %>
  48. <%= @supplies %>
  49. </td>
  50. <td>
  51. <% @orders = 0 %>
  52. <% product.transactions.each do |trans| %>
  53. <% if trans.mode == "ORDER" %>
  54.  
  55. <% if trans.quantity == nil %>
  56. <% transaction.quantity == 0 %>
  57. <% end %>
  58.  
  59. <% @orders += trans.quantity %>
  60. <% end %>
  61. <% end %>
  62. <%= "(#{@orders.abs})" %>
  63. </td>
  64. <td>
  65. <% @total = 0 %>
  66. <% product.transactions.each do |trans| %>
  67. <% if trans.quantity == nil %>
  68. <% trans.quantity == 0 %>
  69. <% end %>
  70. <% @total += trans.quantity %>
  71. <% end %>
  72. <%= @total %>
  73. </td>
  74. <td>
  75. <%= time_ago_in_words(product.created_at) %> ago
  76. </td>
  77. <td>
  78. <%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
  79. </td>
  80. <td>
  81. <% if product.status == "Active" %>
  82. <%= link_to "Deactivate", product_path(product), method: :delete, class: "btn btn-danger" %>
  83. <% else %>
  84. <%= link_to "Activate", product_path(product), method: :delete, class: "btn btn-success"%>
  85. <% end %>
  86. </td>
  87. <!-- <td>
  88. <%= link_to "Delete", product_path(product), class: "btn btn-danger", method: :post, data: { confirm: "Are you sure you want to delete?" } %>
  89. </td> -->
  90. <td>
  91. <%= link_to "View", product_path(product), class: "btn btn-primary" %>
  92. </td>
  93. </tr>
  94. <% end%>
  95. </tbody>
  96. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement