Commit 7e168abf authored by Chanelle Lunod's avatar Chanelle Lunod

Initial commit

parent 6e675488
......@@ -6,21 +6,21 @@ class OrdersController < ApplicationController
def new
@product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new
@order = @product.transactions.new
end
def create
@product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new(supply_params)
@order = @product.transactions.new(order_params)
@order.mode = "Order"
@order.user_id = current_user.id
@order.quantity = @order.quantity * -1
@order.quantity = @order.quantity
if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully placed a new order"
else
render 'new'
end
if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully placed a new order"
else
render 'new'
end
end
private
......
class ProductsController < ApplicationController
before_action :authenticate_admin_user!
def index
@products = Product.all
@products = Product.where(["name LIKE ?","%#{params[:search]}%"])
......
class SuppliesController < ApplicationController
def index
@products = Product.all
@products = Product.all
end
def new
@product = Product.find_by(id: params[:product_id])
@supply = @product.transactions.new
@supply = @product.transactions.new
end
def create
@product = Product.find_by(id: params[:product_id])
@supply = @product.transactions.new(supply_params)
@supply = @product.transactions.new(supply_params)
@supply.mode = "Supply"
@supply.user_id = current_user.id
@supply.quantity =@supply.quantity
@supply.quantity = @supply.quantity
if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully added a new supply."
else
render 'new'
end
if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully added a new supply."
else
render 'new'
end
end
private
......@@ -28,3 +28,4 @@ class SuppliesController < ApplicationController
params.require(:transaction).permit!
end
end
......@@ -55,7 +55,7 @@
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', includedLanguages: 'af,ar,da,de,en,es,fi,fr,hi,id,is,ja,ko,mi,ms,my,nl,no,pt,sw,tl,zh-CN', layout: google.translate.TranslateElement.InlineLayout.HORIZONTAL}, 'google_translate_element');
}
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>>
</script><script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<div class="container" id="container">
<% if notice %>
......
<h1>New Order</h1>
<%= simple_form_for @post do |f| %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Supply", class: "btn btn-info" %>
<%= link_to "Back", transaction_path, class: "btn btn-default" %>
<%= simple_form_for([@product, @order], url: product_orders_path) do |f| %>
<%= f.input :quantity %>
<%= f.button :submit, "Add Order", class: "btn btn-primary" %>
<%= link_to "Back", authenticated_user_root_path, class: "btn-btn-default" %>
<% end %>
\ No newline at end of file
......@@ -3,7 +3,6 @@
<%= simple_form_for @product do |f| %>
<%= f.input :name %>
<%= 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" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
......@@ -12,7 +12,7 @@
</small>
<% else %>
<table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #333">
<thead style="background-color: #F08080">
<th>Name</th>
<th>Description</th>
<th>Status</th>
......@@ -36,7 +36,7 @@
</td>
<td>
<% @supplies = 0 %>
<% product.transactions.each do |transaction| %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
......@@ -49,10 +49,10 @@
</td>
<td>
<% @orders = 0 %>
<% product.transactions.each do |transaction| %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "ORDER" %>
<% if trans.quantity == nil %>
<% if trans.quantity == nil %>
<% transaction.quantity == 0 %>
<% end %>
......@@ -63,8 +63,8 @@
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |transaction| %>
<% if trans.quantity == nil %>
<% product.transactions.each do |trans| %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @total += trans.quantity %>
......@@ -94,9 +94,9 @@
<% end%>
</tbody>
</table>
<% end %>
<% end %>
<% else %>
<% elsif user_signed_in? %>
<h1>Transactions</h1>
<br>
......@@ -106,7 +106,7 @@
</small>
<% else %>
<table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #333">
<thead style="background-color: #76D7C4">
<th>Name</th>
<th>Description</th>
<th>Status</th>
......@@ -135,7 +135,6 @@
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @supplies += trans.quantity %>
<% end %>
<% end %>
......@@ -144,22 +143,21 @@
<td>
<% @orders = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "ORDER" %>
<% if trans.mode == "Order" %>
<% if trans.quantity == nil %>
<% transaction.quantity == 0 %>
<% trans.quantity == 0 %>
<% end %>
<% @orders += trans.quantity %>
<% end %>
<% end %>
<%= "(#{@orders.abs})" %>
</td>
<%= @orders %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.quantity == nil %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% end %>
<% @total += trans.quantity %>
<% end %>
<%= @total %>
......@@ -171,7 +169,7 @@
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% end %>
<% end%>
</tbody>
</table>
<% end %>
......
......@@ -3,7 +3,6 @@
<%= simple_form_for @product do |f| %>
<%= f.input :name %>
<%= 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" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
......@@ -14,7 +14,7 @@
<%= simple_form_for :user, url: session_path(:user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.button :submit, "Log In" %>
<%= f.button :submit, "Log In", as: :authenticated_user %>
<%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %>
<% end %>
</div>
......
<h1>New Supply</h1>
<%= simple_form_for @post do |f| %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Supply", class: "btn btn-info" %>
<%= link_to "Back", transaction_path, class: "btn btn-default" %>
<%= 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" %>
<% end %>
Rails.application.routes.draw do
get 'orders/new'
get 'supplies/new'
devise_for :admin_users
devise_scope :admin_user do
authenticated :admin_user do
......
......@@ -6,9 +6,4 @@ class OrdersControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
test "should get create" do
get orders_create_url
assert_response :success
end
end
require 'test_helper'
class SuppliesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get supplies_index_url
assert_response :success
end
test "should get new" do
get supplies_new_url
assert_response :success
end
test "should get create" do
get supplies_create_url
assert_response :success
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