Commit 3262b5df authored by Chanelle Lunod's avatar Chanelle Lunod

Initial commit

parent d1dbca7c
class Product < ApplicationRecord
validates :name, presence: true
has_many :transactions
has_many :comments
end
This diff is collapsed.
<% if admin_user_signed_in? %>
<h1>Products</h1>
<h1>PRODUCTS</h1>
<div>
<%= link_to "Add new Product", new_product_path, class: "btn btn-primary" %>
</div>
......@@ -12,7 +12,7 @@
</small>
<% else %>
<table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #F08080">
<thead>
<th>Name</th>
<th>Description</th>
<th>Status</th>
......@@ -26,7 +26,7 @@
<% @products.each do |product| %>
<tr>
<td>
<%= product.name %>
<%= link_to product.name, product_path(product) %>
</td>
<td>
<%= product.description %>
......@@ -39,35 +39,42 @@
<% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% trans.quantity = 0 %>
<% end %>
<% @supplies += trans.quantity %>
<% @supplies += trans.quantity %>
<% end %>
<% end %>
<% end %>
<%= @supplies %>
</td>
<td>
<td>
<% @orders = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "Order" %>
<% if trans.mode == "Order" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% trans.quantity = 0 %>
<% end %>
<% @orders += trans.quantity %>
<% end %>
<% end %>
<%= @orders %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |trans| %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @total += trans.quantity %>
<% trans.quantity = 0 %>
<% end %>
<% @total += trans.quantity %>
<% elsif trans.mode == "Order" %>
<% if trans.quantity == nil %>
<% trans.quantity = 0 %>
<% end %>
<% @total -= trans.quantity %>
<% end %>
<% end %>
<%= @total %>
</td>
</td>
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
......@@ -84,9 +91,6 @@
<!-- <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>
......@@ -94,7 +98,7 @@
<% end %>
<% elsif user_signed_in? %>
<h1>Transactions</h1>
<h1>TRANSACTIONS</h1>
<br>
<% if @products.empty? %>
......@@ -103,7 +107,7 @@
</small>
<% else %>
<table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #76D7C4">
<thead>
<th>Name</th>
<th>Description</th>
<th>Status</th>
......@@ -129,48 +133,55 @@
<% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% trans.quantity = 0 %>
<% end %>
<% @supplies += trans.quantity %>
<% @supplies += trans.quantity %>
<% end %>
<% end %>
<% end %>
<%= @supplies %>
</td>
<td>
<td>
<% @orders = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "Order" %>
<% if trans.mode == "Order" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% trans.quantity = 0 %>
<% end %>
<% @orders += trans.quantity %>
<% end %>
<% end %>
<%= @orders %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |trans| %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @total += trans.quantity %>
<% trans.quantity = 0 %>
<% end %>
<% @total += trans.quantity %>
<% elsif trans.mode == "Order" %>
<% if trans.quantity == nil %>
<% trans.quantity = 0 %>
<% end %>
<% @total -= trans.quantity %>
<% end %>
<% end %>
<%= @total %>
</td>
<td>
<% if product.status == "Active" %>
<td>
<% if product.status == "Active" %>
<td>
<%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-primary" %>
</td>
<td>
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-primary" %>
</td>
<% else %>
<% end %>
<%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% end%>
<td>
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-primary" %>
</td>
<% else %>
<% end %>
</td>
</tr>
<% end%>
</tbody>
</table>
<% end %>
......
......@@ -4,10 +4,6 @@
<%= @product.description %>
</p>
<p>
Status: <%= @product.status %>
</p>
<p>
<small>
Created At: <%= @product.created_at.to_s :short %>
......
<h1>New Supply</h1>
<%= simple_form_for([@product, @supply], url: product_supplies_path) do |f| %>
<%= f.input :quantity %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", authenticated_user_root_path, class: "btn-btn-default" %>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment