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

Initial commit

parent d1dbca7c
class Product < ApplicationRecord class Product < ApplicationRecord
validates :name, presence: true
has_many :transactions has_many :transactions
has_many :comments has_many :comments
end end
This diff is collapsed.
<% if admin_user_signed_in? %> <% if admin_user_signed_in? %>
<h1>Products</h1> <h1>PRODUCTS</h1>
<div> <div>
<%= link_to "Add new Product", new_product_path, class: "btn btn-primary" %> <%= link_to "Add new Product", new_product_path, class: "btn btn-primary" %>
</div> </div>
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</small> </small>
<% else %> <% else %>
<table class = "table", cellspacing="0", cellpadding="0"> <table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #F08080"> <thead>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Status</th> <th>Status</th>
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<% @products.each do |product| %> <% @products.each do |product| %>
<tr> <tr>
<td> <td>
<%= product.name %> <%= link_to product.name, product_path(product) %>
</td> </td>
<td> <td>
<%= product.description %> <%= product.description %>
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
<% product.transactions.each do |trans| %> <% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %> <% if trans.mode == "Supply" %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity = 0 %>
<% end %> <% end %>
<% @supplies += trans.quantity %> <% @supplies += trans.quantity %>
<% end %> <% end %>
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
<% product.transactions.each do |trans| %> <% product.transactions.each do |trans| %>
<% if trans.mode == "Order" %> <% if trans.mode == "Order" %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity = 0 %>
<% end %> <% end %>
<% @orders += trans.quantity %> <% @orders += trans.quantity %>
<% end %> <% end %>
...@@ -61,10 +61,17 @@ ...@@ -61,10 +61,17 @@
<td> <td>
<% @total = 0 %> <% @total = 0 %>
<% product.transactions.each do |trans| %> <% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity = 0 %>
<% end %> <% end %>
<% @total += trans.quantity %> <% @total += trans.quantity %>
<% elsif trans.mode == "Order" %>
<% if trans.quantity == nil %>
<% trans.quantity = 0 %>
<% end %>
<% @total -= trans.quantity %>
<% end %>
<% end %> <% end %>
<%= @total %> <%= @total %>
</td> </td>
...@@ -84,9 +91,6 @@ ...@@ -84,9 +91,6 @@
<!-- <td> <!-- <td>
<%= link_to "Delete", product_path(product), class: "btn btn-danger", method: :post, data: { confirm: "Are you sure you want to delete?" } %> <%= link_to "Delete", product_path(product), class: "btn btn-danger", method: :post, data: { confirm: "Are you sure you want to delete?" } %>
</td> --> </td> -->
<td>
<%= link_to "View", product_path(product), class: "btn btn-primary" %>
</td>
</tr> </tr>
<% end%> <% end%>
</tbody> </tbody>
...@@ -94,7 +98,7 @@ ...@@ -94,7 +98,7 @@
<% end %> <% end %>
<% elsif user_signed_in? %> <% elsif user_signed_in? %>
<h1>Transactions</h1> <h1>TRANSACTIONS</h1>
<br> <br>
<% if @products.empty? %> <% if @products.empty? %>
...@@ -103,7 +107,7 @@ ...@@ -103,7 +107,7 @@
</small> </small>
<% else %> <% else %>
<table class = "table", cellspacing="0", cellpadding="0"> <table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #76D7C4"> <thead>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Status</th> <th>Status</th>
...@@ -129,7 +133,7 @@ ...@@ -129,7 +133,7 @@
<% product.transactions.each do |trans| %> <% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %> <% if trans.mode == "Supply" %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity = 0 %>
<% end %> <% end %>
<% @supplies += trans.quantity %> <% @supplies += trans.quantity %>
<% end %> <% end %>
...@@ -141,7 +145,7 @@ ...@@ -141,7 +145,7 @@
<% product.transactions.each do |trans| %> <% product.transactions.each do |trans| %>
<% if trans.mode == "Order" %> <% if trans.mode == "Order" %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity = 0 %>
<% end %> <% end %>
<% @orders += trans.quantity %> <% @orders += trans.quantity %>
<% end %> <% end %>
...@@ -151,10 +155,17 @@ ...@@ -151,10 +155,17 @@
<td> <td>
<% @total = 0 %> <% @total = 0 %>
<% product.transactions.each do |trans| %> <% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity = 0 %>
<% end %> <% end %>
<% @total += trans.quantity %> <% @total += trans.quantity %>
<% elsif trans.mode == "Order" %>
<% if trans.quantity == nil %>
<% trans.quantity = 0 %>
<% end %>
<% @total -= trans.quantity %>
<% end %>
<% end %> <% end %>
<%= @total %> <%= @total %>
</td> </td>
......
...@@ -4,10 +4,6 @@ ...@@ -4,10 +4,6 @@
<%= @product.description %> <%= @product.description %>
</p> </p>
<p>
Status: <%= @product.status %>
</p>
<p> <p>
<small> <small>
Created At: <%= @product.created_at.to_s :short %> Created At: <%= @product.created_at.to_s :short %>
......
<h1>New Supply</h1> <h1>New Supply</h1>
<%= simple_form_for([@product, @supply], url: product_supplies_path) do |f| %> <%= simple_form_for([@product, @supply], url: product_supplies_path) do |f| %>
<%= f.input :quantity %> <%= f.input :quantity %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %> <%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", authenticated_user_root_path, class: "btn-btn-default" %> <%= 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