Commit 9c21722b authored by Chanelle Lunod's avatar Chanelle Lunod

initial commit

parents 30167da0 1b0bc1c6
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
......@@ -4,3 +4,7 @@
*/
@import "bootstrap";
#container { padding-top: 5rem; }
body {
background-color: #d9e6f2;
}
class OrdersController < ApplicationController
def index
@products = Product.all
end
def new
@orders = Order.new
@product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new
end
def create
@orders = Order.new(product_params)
@product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new(supply_params)
@order.mode = "Order"
@order.user_id = current_user.id
@order.quantity = @order.quantity * -1
if @orders.save
redirect_to products_path, notice: "You have successfully placed a new order"
if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully placed a new order"
else
render 'new'
end
end
def show
if params [:status] == 'Active'
@products = Product.Active
else
@products = Product.Inactive
end
end
private
def order_params
params.require(:transaction).permit!
end
end
......@@ -5,25 +5,27 @@ class SuppliesController < ApplicationController
end
def new
@supplies = Supply.new
@product = Product.find_by(id: params[:product_id])
@supply = @product.transactions.new
end
def create
@supplies = Supply.new(product_params)
@product = Product.find_by(id: params[:product_id])
@supply = @product.transactions.new(supply_params)
@supply.mode = "Supply"
@supply.user_id = current_user.id
@supply.quantity =@supply.quantity
if @supplies.save
redirect_to products_path, notice: "You have successfully added a new supply."
if @product.save
redirect_to authenticated_user_root_path, notice: "You have successfully added a new supply."
else
render 'new'
end
end
def show
if params [:status] == 'Active'
@products = Product.Active
else
@products = Product.Inactive
end
end
private
def supply_params
params.require(:transaction).permit!
end
end
class TransactionsController < ApplicationController
before_action :authenticate_user!
def index
@products = Product.all
end
def display
@product = Product.find_by(product_id: params[:product_id])
end
def new
@product.order = Order.new
@products.supply = Supply.new
end
def order
@product.order = Order.new(transaction_params)
if @product.order.save
redirect_to transaction_path, notice: "You have successfuly placed a new order."
else
render 'new'
end
end
def supply
@product.supply = Supply.new(transaction_params)
if @product.supply.save
redirect_to transaction_path, notice: "You have successfully placed a new supply."
else
render 'new'
end
end
private
def product_params
params.require(:product).permit!
end
end
\ No newline at end of file
class Transaction < ApplicationRecord
belongs_to :product
belongs_to :user
has_many :supplies
has_many :orders
end
......@@ -12,24 +12,42 @@
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<%= link_to "Main", root_path, class: "navbar-brand" %>
<style>
background-color: #ccfff2
font-family:'Calibri';
</style>
<nav class="navbar navbar-expand-xl navbar-dark bg-dark">
<%= link_to "HOME", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#">Sign In</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Inventory</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Transactions</a>
</li>
</ul>
<span class="navbar-text">
<% if user_signed_in? %>
Logged in as <strong><%= current_user.email %></strong>.
<br>
<%= link_to 'Edit Profile', edit_user_registration_path, :class => 'navbar-link' %> |
<%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %>
<% elsif admin_user_signed_in? %>
<%= link_to "Logout", destroy_admin_user_session_path, method: :delete, :class => 'navbar-link' %>
<% end %>
</span>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search">
<button class="btn btn-outline-info my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
......
<h1>New Order</h1>
<%= simple_form_for @order do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= simple_form_for @post do |f| %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Order", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
<%= f.button :submit, "Add Supply", class: "btn btn-info" %>
<%= link_to "Back", transaction_path, class: "btn btn-default" %>
<% end %>
\ No newline at end of file
<h1>Inventory System</h1>
<%= if admin_user_signed_in? %>
<div>
<%= link_to "Create new product", new_product_path, class: "btn btn-primary" %>
</div>
<h2>Inventory System</h1>
<div>
<%= link_to "Create new product", new_product_path, class: "btn btn-primary" %>
</div>
<br>
<% if @products.empty? %>
<small>
No products have been created.
</small>
<% else %>
<table class="table", cellspacing="0", cellpadding="0">
<thead>
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Supply</th>
<th>Order</th>
<th>Total</th>
<th>Created</th>
<th colspan="7"></th>
</thead>
<tbody>
<% @products.each do |product| %>
<% if product.status == "Active" %>
<tr>
<td>
<%= link_to product.name, product_path(product) %>
</td>
<td>
<%= product.description %>
</td>
<td>
<%= product.status %>
</td>
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
<br>
<% if @products.empty? %>
<small>
No products have been created.
</small>
<td>
<% supplies = 0 %>
<% product.transactions.each do |transaction|
<% if transaction.mode == "Supply" %>
<% supplies = supplies + transaction.quantity %>
<% end %>
<% end %>
<%= supplies %>
</td>
<td>
<% orders = 0 %>
<% product.transactions.each do |transaction|
<% if transaction.mode == "Order" %>
<% orders = orders + transaction.quantity %>
<% end %>
<% end %>
<%= orders %>
</td>
<td>
<%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-info" %>
</td>
<td>
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-info" %>
</td>
<td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td>
</tr>
</tbody>
</table>
<% end %>
<% end %>
<% else %>
<table class="table">
<thead>
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Time Created</th>
<th colspan="4"></th>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td>
<%= link_to product.name, product_path(product) %>
</td>
<td>
<%= product.description %>
</td>
<td>
<%= product.status %>
</td>
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
<td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% if @products.empty? %>
<small>
No products available.
</small>
<% else %>
<table class="table", cellspacing="0", cellpadding="0">
<thead>
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Supply</th>
<th>Order</th>
<th>Total</th>
<th>Created</th>
<th colspan="7"></th>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td>
<%= link_to product.name, product_path(product) %>
</td>
<td>
<%= product.description %>
</td>
<td>
<%= product.status %>
</td>
<td>
<% supplies = 0 %>
<% product.transactions.each do |transaction|
<% if transaction.mode == "Supply" %>
<% if transaction.quantity == nil %>
<% transaction.quantity == 0 %>
<% end %>
<% @supplies = @supplies + transaction.quantity %>
<% end %>
<% end %>
<%= supplies %>
</td>
<td>
<% orders = 0 %>
<% product.transactions.each do |transaction|
<% if transaction.mode == "Order" %>
<% if transaction.quantity == nil %>
<% transaction.quantity == 0 %>
<% end %>
<% @orders = @orders + transaction.quantity %>
<% end %>
<% end %>
<%= "(#{@orders.abs}" %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |transaction| %>
<% if transactions.quantity == nil %>
<% transaction.quantity == 0 %>
<% end %>
<% @total = @total + transaction.quantity %>
<% end %>
<%= @total %>
</td>
<td>
<%= product.comments.count %>
</td>
<td>
<%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-info" %>
</td>
<td>
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-info" %>
</td>
<td>
<%= link_to "Add Comment", edit_product_comment_path(product), class: "btn btn-info" %>
</td>
</tr>
</tbody>
</table>
<% end %>
<% end %>
......@@ -5,7 +5,7 @@
<%= simple_form_for :admin_user, url: session_path(:admin_user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.button :submit, "Log In" %>
<%= f.submit 'Log In', class: 'btn btn-info' %>
<% end %>
</div>
......@@ -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.submit 'Log In', class: 'btn btn-info' %>
<%= link_to "Sign Up", new_user_registration_path, :class => 'navbar-link' %>
<% end %>
</div>
......
<h1>Supplies</h1>
<div>
<%= link_to "Add New Supply", new_product_supply_path, class: "btn btn-primary" %>
</div>
<br>
<% if @supplies.empty? %>
<small>
No supplies available.
</small>
<% else %>
<table class="table">
<thead>
<th>Name</th>
<th>Description</th>
<th>Date Added</th>
<th>Quantity</th>
<th colspan="4"></th>
</thead>
<tbody>
<% @supplies.each do |supply| %>
<tr>
<td>
<%= link_to supply.name, supply_path(supply) %>
</td>
<td>
<%= supply.description %>
</td>
<td>
<%= time_ago_in_words(supply.created_at) %> ago
</td>
<td>
<%= supply.quantity %>
</td>
<td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<h1>New Supply</h1>
<%= simple_form_for @supply do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", supplies_path, class: "btn btn-default" %>
<%= 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" %>
<% end %>
<h1>Transactions</h1>
<% if @products.empty? %>
<small>
No products have been created.
</small>
<% else%>
<table class="table">
<thead>
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Time Created</th>
<th colspan="4"></th>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td>
<%= link_to product.name, product_path(product) %>
</td>
<td>
<%= product.description %>
</td>
<td>
<%= product.status %>
</td>
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
Rails.application.routes.draw do
get 'orders/new'
get 'orders/create'
get 'supplies/index'
get 'supplies/new'
get 'supplies/create'
get 'comments/new'
devise_for :admin_users
devise_scope :admin_user do
authenticated :admin_user do
......@@ -22,7 +16,7 @@ Rails.application.routes.draw do
resources :supplies, only: [:new, :create]
resources :comments, only: [:new, :create]
end
root to: 'supplies#index', as: :authenticated_user_root
root to: 'products#index', as: :authenticated_user_root
end
end
root to: 'publics#index'
......
if AdminUser.count == 0
AdminUser.add
(
AdminUser.create!([
{
email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25'
......@@ -9,5 +8,5 @@ if AdminUser.count == 0
email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5'
}
)
])
end
\ No newline at end of file
<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" %>
<% end %>
\ No newline at end of file
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