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

initial commit

parents 9c21722b 6e675488
......@@ -5,6 +5,4 @@
@import "bootstrap";
#container { padding-top: 5rem; }
body {
background-color: #d9e6f2;
}
body {background-color: #d9e6f2;}
......@@ -6,21 +6,21 @@ class OrdersController < ApplicationController
def new
@product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new
@order = @order.transactions.new
end
def create
@product = Product.find_by(id: params[:product_id])
@order = @order.transactions.new(supply_params)
@order = @order.transactions.new(supply_params)
@order.mode = "Order"
@order.user_id = current_user.id
@order.quantity = @order.quantity * -1
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
......
......@@ -3,6 +3,7 @@ class ProductsController < ApplicationController
def index
@products = Product.all
@products = Product.where(["name LIKE ?","%#{params[:search]}%"])
end
def show
......@@ -17,9 +18,9 @@ class ProductsController < ApplicationController
@product = Product.new(product_params)
if @product.save
redirect_to products_path, notice: "You have successfully created a new product!"
redirect_to products_path, notice: "You have successfully created a new product!"
else
render 'new'
render 'new'
end
end
......@@ -37,13 +38,24 @@ class ProductsController < ApplicationController
end
end
def destroy
@product = Product.find_by(id: params[:id])
if @product.status == "Inactive"
@product.status = "Active"
else
@product.status = "Inactive"
end
@product.save
redirect_to products_path, alert: alert
end
def count
@products.count
end
private
def product_params
params.require(:product).permit!
params.require(:product).permit!
end
end
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
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
......
class Transaction < ApplicationRecord
has_many :supplies
has_many :orders
belongs_to :product
belongs_to :user
has_many :supplies
......
......@@ -48,9 +48,18 @@
<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>
<%= form_tag products_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search" %>
<% end %>
</div>
</nav>
<div id="google_translate_element"></div><script type="text/javascript">
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>>
<div class="container" id="container">
<% if notice %>
......
<%= if admin_user_signed_in? %>
<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>
<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>
<% if admin_user_signed_in? %>
<h1>Products</h1>
<div>
<%= link_to "Add new Product", new_product_path, class: "btn btn-primary" %>
</div>
<br>
<% if @products.empty? %>
<small>
No products have been added.
</small>
<% else %>
<table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #333">
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Supply</th>
<th>Order</th>
<th>Total</th>
<th>Created At</th>
<th colspan="6"></th>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td>
<%= product.name %>
</td>
<td>
<%= product.description %>
</td>
<td>
<%= product.status%>
</td>
<td>
<% @supplies = 0 %>
<% product.transactions.each do |transaction| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @supplies += trans.quantity %>
<% end %>
<% end %>
<%= @supplies %>
</td>
<td>
<% @orders = 0 %>
<% product.transactions.each do |transaction| %>
<% if trans.mode == "ORDER" %>
<% if trans.quantity == nil %>
<% transaction.quantity == 0 %>
<% end %>
<% @orders += trans.quantity %>
<% end %>
<% end %>
<%= "(#{@orders.abs})" %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |transaction| %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @total += trans.quantity %>
<% end %>
<%= @total %>
</td>
<td>
<%= time_ago_in_words(product.created_at) %> ago
</td>
<td>
<%= link_to "Edit", edit_product_path(product), class: "btn btn-primary" %>
</td>
<td>
<% if product.status == "Active" %>
<%= link_to "Deactivate", product_path(product), method: :delete, class: "btn btn-danger" %>
<% else %>
<%= link_to "Activate", product_path(product), method: :delete, class: "btn btn-success"%>
<% end %>
</td>
<!-- <td>
<%= link_to "Delete", product_path(product), class: "btn btn-danger", method: :post, data: { confirm: "Are you sure you want to delete?" } %>
</td> -->
<td>
<%= link_to "View", product_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% end%>
</tbody>
</table>
<% end %>
<% end %>
</table>
<% 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 %>
<h1>Transactions</h1>
<br>
<% if @products.empty? %>
<small>
No products have been added.
</small>
<% else %>
<table class = "table", cellspacing="0", cellpadding="0">
<thead style="background-color: #333">
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Supply</th>
<th>Order</th>
<th>Total</th>
<th>Created At</th>
<th colspan="6"></th>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td>
<%= product.name %>
</td>
<td>
<%= product.description %>
</td>
<td>
<%= product.status%>
</td>
<td>
<% @supplies = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @supplies += trans.quantity %>
<% end %>
<% end %>
<%= @supplies %>
</td>
<td>
<% @orders = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.mode == "ORDER" %>
<% if trans.quantity == nil %>
<% transaction.quantity == 0 %>
<% end %>
<% @orders += trans.quantity %>
<% end %>
<% end %>
<%= "(#{@orders.abs})" %>
</td>
<td>
<% @total = 0 %>
<% product.transactions.each do |trans| %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @total += trans.quantity %>
<% end %>
<%= @total %>
</td>
<td>
<%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-primary" %>
</td>
<td>
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% 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>
</table>
<% end %>
<% end %>
>>>>>>> 6e6754882451c54a2f4e7f2bf5f24cb6d6b1d826
......@@ -4,20 +4,18 @@ Rails.application.routes.draw do
authenticated :admin_user do
resources :products
root to: 'products#index', as: :authenticated_admin_user_root
end
end
end
devise_for :users
devise_scope :user do
authenticated :user do
resources :products, only: [] do
resources :products, only: [:new, :show] do
resources :orders, only: [:new, :create]
resources :supplies, only: [:new, :create]
resources :comments, only: [:new, :create]
end
root to: 'products#index', as: :authenticated_user_root
end
end
root to: 'publics#index'
end
end
\ No newline at end of file
if AdminUser.count == 0
AdminUser.create!([
{
email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25'
},
{
email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5'
......
......@@ -4,8 +4,12 @@
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
admin_user:
name: Andrea Dolendo
email: andrea.dolendo@obf.ateneo.edu
password: Andrea25
user:
name: Chanelle Lunod
email: chanelle.lunod@obf.ateneo.edu
password: December5
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