Commit 34538002 authored by Chanelle Lunod's avatar Chanelle Lunod

initial commit

parents 7eb1cfec d1dbca7c
...@@ -5,4 +5,6 @@ ...@@ -5,4 +5,6 @@
@import "bootstrap"; @import "bootstrap";
#container { padding-top: 5rem; } #container { padding-top: 5rem; }
body {background-color: #d9e6f2;} body {
background-color: #000000;
}
...@@ -6,15 +6,15 @@ class OrdersController < ApplicationController ...@@ -6,15 +6,15 @@ class OrdersController < ApplicationController
def new def new
@product = Product.find_by(id: params[:product_id]) @product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new @order = @product.transactions.new
end end
def create def create
@product = Product.find_by(id: params[:product_id]) @product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new(supply_params) @order = @product.transactions.new(order_params)
@order.mode = "Order" @order.mode = "Order"
@order.user_id = current_user.id @order.user_id = current_user.id
@order.quantity = @order.quantity * -1 @order.quantity = @order.quantity
if @product.save if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully placed a new order" redirect_to authenticated_user_root_path, notice: "You have successfully placed a new order"
......
class ProductsController < ApplicationController class ProductsController < ApplicationController
before_action :authenticate_admin_user!
def index def index
@products = Product.all @products = Product.all
@products = Product.where(["name LIKE ?","%#{params[:search]}%"]) @products = Product.where(["name LIKE ?","%#{params[:search]}%"])
......
...@@ -14,7 +14,7 @@ class SuppliesController < ApplicationController ...@@ -14,7 +14,7 @@ class SuppliesController < ApplicationController
@supply = @product.transactions.new(supply_params) @supply = @product.transactions.new(supply_params)
@supply.mode = "Supply" @supply.mode = "Supply"
@supply.user_id = current_user.id @supply.user_id = current_user.id
@supply.quantity =@supply.quantity @supply.quantity = @supply.quantity
if @product.save if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully added a new supply." redirect_to authenticated_user_root_path, notice: "You have successfully added a new supply."
......
This diff is collapsed.
<h1>New Order</h1> <h1>New Order</h1>
<%= simple_form_for @post do |f| %> <%= simple_form_for([@product, @order], url: product_orders_path) do |f| %>
<%= f.input :quantity, as: :integer %> <%= f.input :quantity %>
<%= f.button :submit, "Add Supply", class: "btn btn-info" %> <%= f.button :submit, "Add Order", class: "btn btn-primary" %>
<%= link_to "Back", transaction_path, class: "btn btn-default" %> <%= link_to "Back", authenticated_user_root_path, class: "btn-btn-default" %>
<% end %> <% end %>
\ No newline at end of file
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
<%= simple_form_for @product do |f| %> <%= simple_form_for @product do |f| %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :description, as: :text %> <%= f.input :description, as: :text %>
<%= f.input :status, as: :radio_buttons, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Save", class: "btn btn-primary" %> <%= f.button :submit, "Save", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %> <%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %> <% end %>
...@@ -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: #333"> <thead style="background-color: #F08080">
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Status</th> <th>Status</th>
...@@ -36,12 +36,11 @@ ...@@ -36,12 +36,11 @@
</td> </td>
<td> <td>
<% @supplies = 0 %> <% @supplies = 0 %>
<% product.transactions.each do |transaction| %> <% 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 %>
<% end %> <% end %>
...@@ -49,21 +48,19 @@ ...@@ -49,21 +48,19 @@
</td> </td>
<td> <td>
<% @orders = 0 %> <% @orders = 0 %>
<% product.transactions.each do |transaction| %> <% product.transactions.each do |trans| %>
<% if trans.mode == "ORDER" %> <% if trans.mode == "Order" %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% transaction.quantity == 0 %> <% trans.quantity == 0 %>
<% end %> <% end %>
<% @orders += trans.quantity %> <% @orders += trans.quantity %>
<% end %> <% end %>
<% end %> <% end %>
<%= "(#{@orders.abs})" %> <%= @orders %>
</td> </td>
<td> <td>
<% @total = 0 %> <% @total = 0 %>
<% product.transactions.each do |transaction| %> <% product.transactions.each do |trans| %>
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity == 0 %>
<% end %> <% end %>
...@@ -94,9 +91,9 @@ ...@@ -94,9 +91,9 @@
<% end%> <% end%>
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
<% else %> <% elsif user_signed_in? %>
<h1>Transactions</h1> <h1>Transactions</h1>
<br> <br>
...@@ -106,14 +103,13 @@ ...@@ -106,14 +103,13 @@
</small> </small>
<% else %> <% else %>
<table class = "table", cellspacing="0", cellpadding="0"> <table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #333"> <thead style="background-color: #76D7C4">
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Status</th> <th>Status</th>
<th>Supply</th> <th>Supply</th>
<th>Order</th> <th>Order</th>
<th>Total</th> <th>Total</th>
<th>Created At</th>
<th colspan="6"></th> <th colspan="6"></th>
</thead> </thead>
<tbody> <tbody>
...@@ -135,7 +131,6 @@ ...@@ -135,7 +131,6 @@
<% if trans.quantity == nil %> <% if trans.quantity == nil %>
<% trans.quantity == 0 %> <% trans.quantity == 0 %>
<% end %> <% end %>
<% @supplies += trans.quantity %> <% @supplies += trans.quantity %>
<% end %> <% end %>
<% end %> <% end %>
...@@ -144,15 +139,14 @@ ...@@ -144,15 +139,14 @@
<td> <td>
<% @orders = 0 %> <% @orders = 0 %>
<% 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 %>
<% transaction.quantity == 0 %> <% trans.quantity == 0 %>
<% end %> <% end %>
<% @orders += trans.quantity %> <% @orders += trans.quantity %>
<% end %> <% end %>
<% end %> <% end %>
<%= "(#{@orders.abs})" %> <%= @orders %>
</td> </td>
<td> <td>
<% @total = 0 %> <% @total = 0 %>
...@@ -164,16 +158,21 @@ ...@@ -164,16 +158,21 @@
<% end %> <% end %>
<%= @total %> <%= @total %>
</td> </td>
<td>
<% if product.status == "Active" %>
<td> <td>
<%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-primary" %> <%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-primary" %>
</td> </td>
<td> <td>
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-primary" %> <%= link_to "Add Order", new_product_order_path(product), class: "btn btn-primary" %>
</td> </td>
</tr> <% else %>
<% end %> <% end %>
</td>
</tr>
<% end%>
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
<% end %> <% end %>
>>>>>>> 6e6754882451c54a2f4e7f2bf5f24cb6d6b1d826
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
<%= simple_form_for @product do |f| %> <%= simple_form_for @product do |f| %>
<%= f.input :name %> <%= f.input :name %>
<%= f.input :description, as: :text %> <%= f.input :description, as: :text %>
<%= f.input :status, as: :radio_buttons, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Create Product", class: "btn btn-primary" %> <%= f.button :submit, "Create Product", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %> <%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %> <% end %>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h3>Admin User Log In</h3> <h3>Admin</h3>
<%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %> <%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %>
<%= f.input :email %> <%= f.input :email %>
<%= f.input :password %> <%= f.input :password %>
...@@ -10,16 +10,18 @@ ...@@ -10,16 +10,18 @@
</div> </div>
<div class="col"> <div class="col">
<h3>User Log In</h3> <h3>User</h3>
<%= simple_form_for :user, url: session_path(:user) do |f| %> <%= simple_form_for :user, url: session_path(:user) do |f| %>
<%= f.input :email %> <%= f.input :email %>
<%= f.input :password %> <%= f.input :password %>
<%= f.submit 'Log In', class: 'btn btn-info' %> <%= f.button :submit, "Log In", as: :authenticated_user, class: 'btn btn-info' %>
<%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %> <%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %>
<% end %> <% end %>
</div> </div>
</div>
<!-- <body style = "background-image: url(http://www.sunrisecatalogue.com/uploads/posters/duovsvt_ldlcw_YYSRSRC.jpg); background-size: 100%">
</body> -->
</div>
......
<h1>New Supply</h1> <h1>New Supply</h1>
<%= simple_form_for @post do |f| %> <%= simple_form_for([@product, @supply], url: product_supplies_path) do |f| %>
<%= f.input :quantity, as: :integer %> <%= f.input :quantity %>
<%= f.button :submit, "Add Supply", class: "btn btn-info" %> <%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", transaction_path, class: "btn btn-default" %> <%= link_to "Back", authenticated_user_root_path, class: "btn-btn-default" %>
<% end %> <% end %>
Rails.application.routes.draw do Rails.application.routes.draw do
get 'orders/new'
get 'supplies/new'
devise_for :admin_users devise_for :admin_users
devise_scope :admin_user do devise_scope :admin_user do
authenticated :admin_user do authenticated :admin_user do
......
...@@ -6,9 +6,4 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest ...@@ -6,9 +6,4 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
end end
test "should get create" do
get orders_create_url
assert_response :success
end
end end
require 'test_helper' require 'test_helper'
class SuppliesControllerTest < ActionDispatch::IntegrationTest class SuppliesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get supplies_index_url
assert_response :success
end
test "should get new" do test "should get new" do
get supplies_new_url get supplies_new_url
assert_response :success assert_response :success
end end
test "should get create" do
get supplies_create_url
assert_response :success
end
end end
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