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 @@ ...@@ -4,3 +4,7 @@
*/ */
@import "bootstrap"; @import "bootstrap";
#container { padding-top: 5rem; } #container { padding-top: 5rem; }
body {
background-color: #d9e6f2;
}
class OrdersController < ApplicationController class OrdersController < ApplicationController
def index
@products = Product.all
end
def new def new
@orders = Order.new @product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new
end end
def create 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 if @product.save
redirect_to products_path, notice: "You have successfully placed a new order" redirect_to authenticated_user_root_path, notice: "You have successfully placed a new order"
else else
render 'new' render 'new'
end end
end end
def show private
if params [:status] == 'Active' def order_params
@products = Product.Active params.require(:transaction).permit!
else
@products = Product.Inactive
end
end end
end end
...@@ -5,25 +5,27 @@ class SuppliesController < ApplicationController ...@@ -5,25 +5,27 @@ class SuppliesController < ApplicationController
end end
def new def new
@supplies = Supply.new @product = Product.find_by(id: params[:product_id])
@supply = @product.transactions.new
end end
def create 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 if @product.save
redirect_to products_path, notice: "You have successfully added a new supply." redirect_to authenticated_user_root_path, notice: "You have successfully added a new supply."
else else
render 'new' render 'new'
end end
end end
def show private
if params [:status] == 'Active' def supply_params
@products = Product.Active params.require(:transaction).permit!
else
@products = Product.Inactive
end
end end
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 class Transaction < ApplicationRecord
belongs_to :product belongs_to :product
belongs_to :user belongs_to :user
has_many :supplies
has_many :orders
end end
...@@ -12,24 +12,42 @@ ...@@ -12,24 +12,42 @@
</head> </head>
<body> <body>
<nav class="navbar navbar-expand-lg navbar-light bg-light"> <style>
<%= link_to "Main", root_path, class: "navbar-brand" %> 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"> <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> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse" id="navbarSupportedContent"> <div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto"> <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> </ul>
<span class="navbar-text"> <span class="navbar-text">
<% if user_signed_in? %> <% if user_signed_in? %>
Logged in as <strong><%= current_user.email %></strong>. Logged in as <strong><%= current_user.email %></strong>.
<br>
<%= link_to 'Edit Profile', edit_user_registration_path, :class => 'navbar-link' %> | <%= link_to 'Edit Profile', edit_user_registration_path, :class => 'navbar-link' %> |
<%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %> <%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %>
<% elsif admin_user_signed_in? %> <% elsif admin_user_signed_in? %>
<%= link_to "Logout", destroy_admin_user_session_path, method: :delete, :class => 'navbar-link' %> <%= link_to "Logout", destroy_admin_user_session_path, method: :delete, :class => 'navbar-link' %>
<% end %> <% end %>
</span> </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> </div>
</nav> </nav>
......
<h1>New Order</h1> <h1>New Order</h1>
<%= simple_form_for @order do |f| %> <%= simple_form_for @post do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %> <%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Order", class: "btn btn-primary" %> <%= f.button :submit, "Add Supply", class: "btn btn-info" %>
<%= link_to "Back", products_path, class: "btn btn-default" %> <%= link_to "Back", transaction_path, class: "btn btn-default" %>
<% end %> <% end %>
\ No newline at end of file
<h1>Inventory System</h1> <%= if admin_user_signed_in? %>
<div> <h2>Inventory System</h1>
<div>
<%= link_to "Create new product", new_product_path, class: "btn btn-primary" %> <%= link_to "Create new product", new_product_path, class: "btn btn-primary" %>
</div> </div>
<br>
<br> <% if @products.empty? %>
<% if @products.empty? %>
<small> <small>
No products have been created. No products have been created.
</small> </small>
<% else %> <% else %>
<table class="table"> <table class="table", cellspacing="0", cellpadding="0">
<thead> <thead>
<th>Name</th> <th>Name</th>
<th>Description</th> <th>Description</th>
<th>Status</th> <th>Status</th>
<th>Time Created</th> <th>Supply</th>
<th colspan="4"></th> <th>Order</th>
<th>Total</th>
<th>Created</th>
<th colspan="7"></th>
</thead> </thead>
<tbody> <tbody>
<% @products.each do |product| %> <% @products.each do |product| %>
<% if product.status == "Active" %>
<tr> <tr>
<td> <td>
<%= link_to product.name, product_path(product) %> <%= link_to product.name, product_path(product) %>
...@@ -34,11 +37,117 @@ ...@@ -34,11 +37,117 @@
<td> <td>
<%= time_ago_in_words(product.created_at) %> ago <%= time_ago_in_words(product.created_at) %> ago
</td> </td>
<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> <td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %> <%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td> </td>
</tr> </tr>
</tbody>
</table>
<% end %>
<% end %>
<% else %>
<% 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 %> <% 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> </tbody>
</table> </table>
<% end %>
<% end %> <% end %>
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<%= 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 %>
<%= f.button :submit, "Log In" %> <%= f.submit 'Log In', class: 'btn btn-info' %>
<% end %> <% end %>
</div> </div>
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<%= 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.button :submit, "Log In" %> <%= f.submit 'Log In', 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>
......
<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> <h1>New Supply</h1>
<%= simple_form_for @supply do |f| %> <%= simple_form_for @post do |f| %>
<%= f.input :name %>
<%= f.input :description, as: :text %>
<%= f.input :quantity, as: :integer %> <%= f.input :quantity, as: :integer %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %> <%= f.button :submit, "Add Supply", class: "btn btn-info" %>
<%= link_to "Back", supplies_path, class: "btn btn-default" %> <%= link_to "Back", transaction_path, class: "btn btn-default" %>
<% end %> <% 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 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_for :admin_users
devise_scope :admin_user do devise_scope :admin_user do
authenticated :admin_user do authenticated :admin_user do
...@@ -22,7 +16,7 @@ Rails.application.routes.draw do ...@@ -22,7 +16,7 @@ Rails.application.routes.draw do
resources :supplies, only: [:new, :create] resources :supplies, only: [:new, :create]
resources :comments, only: [:new, :create] resources :comments, only: [:new, :create]
end end
root to: 'supplies#index', as: :authenticated_user_root root to: 'products#index', as: :authenticated_user_root
end end
end end
root to: 'publics#index' root to: 'publics#index'
......
if AdminUser.count == 0 if AdminUser.count == 0
AdminUser.add AdminUser.create!([
(
{ {
email: 'andrea.dolendo@obf.ateneo.edu', email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25' password: 'Andrea25'
...@@ -9,5 +8,5 @@ if AdminUser.count == 0 ...@@ -9,5 +8,5 @@ if AdminUser.count == 0
email: 'chanelle.lunod@obf.ateneo.edu', email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5' password: 'December5'
} }
) ])
end 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