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

initial commit

parents 9c21722b 6e675488
...@@ -5,6 +5,4 @@ ...@@ -5,6 +5,4 @@
@import "bootstrap"; @import "bootstrap";
#container { padding-top: 5rem; } #container { padding-top: 5rem; }
body { body {background-color: #d9e6f2;}
background-color: #d9e6f2;
}
...@@ -3,6 +3,7 @@ class ProductsController < ApplicationController ...@@ -3,6 +3,7 @@ class ProductsController < ApplicationController
def index def index
@products = Product.all @products = Product.all
@products = Product.where(["name LIKE ?","%#{params[:search]}%"])
end end
def show def show
...@@ -37,6 +38,17 @@ class ProductsController < ApplicationController ...@@ -37,6 +38,17 @@ class ProductsController < ApplicationController
end end
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 def count
@products.count @products.count
end end
......
class Transaction < ApplicationRecord class Transaction < ApplicationRecord
has_many :supplies
has_many :orders
belongs_to :product belongs_to :product
belongs_to :user belongs_to :user
has_many :supplies has_many :supplies
......
...@@ -48,9 +48,18 @@ ...@@ -48,9 +48,18 @@
<input class="form-control mr-sm-2" type="search" placeholder="Search"> <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> <button class="btn btn-outline-info my-2 my-sm-0" type="submit">Search</button>
</form> </form>
<%= form_tag products_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search" %>
<% end %>
</div> </div>
</nav> </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"> <div class="container" id="container">
<% if notice %> <% if notice %>
......
<%= if admin_user_signed_in? %> <% if admin_user_signed_in? %>
<h1>Products</h1>
<h2>Inventory System</h1>
<div> <div>
<%= link_to "Create new product", new_product_path, class: "btn btn-primary" %> <%= link_to "Add 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 added.
</small> </small>
<% else %> <% else %>
<table class="table", cellspacing="0", cellpadding="0"> <table class = "table", cellspacing="0", cellpadding="0">
<thead> <thead style="background-color: #333">
<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</th> <th>Created At</th>
<th colspan="7"></th> <th colspan="6"></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) %> <%= product.name %>
</td> </td>
<td> <td>
<%= product.description %> <%= product.description %>
</td> </td>
<td> <td>
<%= product.status %> <%= product.status%>
</td> </td>
<td> <td>
<%= time_ago_in_words(product.created_at) %> ago <% @supplies = 0 %>
</td> <% product.transactions.each do |transaction| %>
<% if trans.mode == "Supply" %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<td> <% @supplies += trans.quantity %>
<% supplies = 0 %>
<% product.transactions.each do |transaction|
<% if transaction.mode == "Supply" %>
<% supplies = supplies + transaction.quantity %>
<% end %> <% end %>
<% end %> <% end %>
<%= supplies %> <%= @supplies %>
</td> </td>
<td> <td>
<% orders = 0 %> <% @orders = 0 %>
<% product.transactions.each do |transaction| <% product.transactions.each do |transaction| %>
<% if transaction.mode == "Order" %> <% if trans.mode == "ORDER" %>
<% orders = orders + transaction.quantity %>
<% if trans.quantity == nil %>
<% transaction.quantity == 0 %>
<% end %>
<% @orders += trans.quantity %>
<% end %> <% end %>
<% end %> <% end %>
<%= orders %> <%= "(#{@orders.abs})" %>
</td> </td>
<td> <td>
<%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-info" %> <% @total = 0 %>
<% product.transactions.each do |transaction| %>
<% if trans.quantity == nil %>
<% trans.quantity == 0 %>
<% end %>
<% @total += trans.quantity %>
<% end %>
<%= @total %>
</td> </td>
<td> <td>
<%= link_to "Add Order", new_product_order_path(product), class: "btn btn-info" %> <%= time_ago_in_words(product.created_at) %> ago
</td> </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>
<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> </tr>
<% end%>
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
<% end %>
<% else %> <% else %>
<h1>Transactions</h1>
<br>
<% if @products.empty? %> <% if @products.empty? %>
<small> <small>
No products available. No products have been added.
</small> </small>
<% else %> <% else %>
<table class="table", cellspacing="0", cellpadding="0"> <table class = "table", cellspacing="0", cellpadding="0">
<thead> <thead style="background-color: #333">
<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</th> <th>Created At</th>
<th colspan="7"></th> <th colspan="6"></th>
</thead> </thead>
<tbody> <tbody>
<% @products.each do |product| %> <% @products.each do |product| %>
<tr> <tr>
<td> <td>
<%= link_to product.name, product_path(product) %> <%= product.name %>
</td> </td>
<td> <td>
<%= product.description %> <%= product.description %>
</td> </td>
<td> <td>
<%= product.status %> <%= product.status%>
</td> </td>
<td> <td>
<% supplies = 0 %> <% @supplies = 0 %>
<% product.transactions.each do |transaction| <% product.transactions.each do |trans| %>
<% if transaction.mode == "Supply" %> <% if trans.mode == "Supply" %>
<% if transaction.quantity == nil %> <% if trans.quantity == nil %>
<% transaction.quantity == 0 %> <% trans.quantity == 0 %>
<% end %> <% end %>
<% @supplies = @supplies + transaction.quantity %>
<% @supplies += trans.quantity %>
<% end %> <% end %>
<% end %> <% end %>
<%= supplies %> <%= @supplies %>
</td> </td>
<td> <td>
<% orders = 0 %> <% @orders = 0 %>
<% product.transactions.each do |transaction| <% product.transactions.each do |trans| %>
<% if transaction.mode == "Order" %> <% if trans.mode == "ORDER" %>
<% if transaction.quantity == nil %> <% if trans.quantity == nil %>
<% transaction.quantity == 0 %> <% transaction.quantity == 0 %>
<% end %> <% end %>
<% @orders = @orders + transaction.quantity %>
<% @orders += trans.quantity %>
<% end %> <% end %>
<% end %> <% end %>
<%= "(#{@orders.abs}" %> <%= "(#{@orders.abs})" %>
</td> </td>
<td> <td>
<% @total = 0 %> <% @total = 0 %>
<% product.transactions.each do |transaction| %> <% product.transactions.each do |trans| %>
<% if transactions.quantity == nil %> <% if trans.quantity == nil %>
<% transaction.quantity == 0 %> <% trans.quantity == 0 %>
<% end %> <% end %>
<% @total = @total + transaction.quantity %> <% @total += trans.quantity %>
<% end %> <% end %>
<%= @total %> <%= @total %>
</td> </td>
<td> <td>
<%= product.comments.count %> <%= link_to "Add Supply", new_product_supply_path(product), class: "btn btn-primary" %>
</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> <td>
<%= link_to "Add Comment", edit_product_comment_path(product), class: "btn btn-info" %> <%= link_to "Add Order", new_product_order_path(product), class: "btn btn-primary" %>
</td> </td>
</tr> </tr>
<% end %>
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
<% end %> <% end %>
>>>>>>> 6e6754882451c54a2f4e7f2bf5f24cb6d6b1d826
...@@ -5,16 +5,14 @@ Rails.application.routes.draw do ...@@ -5,16 +5,14 @@ Rails.application.routes.draw do
resources :products resources :products
root to: 'products#index', as: :authenticated_admin_user_root root to: 'products#index', as: :authenticated_admin_user_root
end end
end
end
devise_for :users devise_for :users
devise_scope :user do devise_scope :user do
authenticated :user do authenticated :user do
resources :products, only: [] do resources :products, only: [:new, :show] do
resources :orders, only: [:new, :create] resources :orders, only: [:new, :create]
resources :supplies, only: [:new, :create] resources :supplies, only: [:new, :create]
resources :comments, only: [:new, :create]
end end
root to: 'products#index', as: :authenticated_user_root root to: 'products#index', as: :authenticated_user_root
end end
......
if AdminUser.count == 0 if AdminUser.count == 0
AdminUser.create!([ AdminUser.create!([
{
email: 'andrea.dolendo@obf.ateneo.edu',
password: 'Andrea25'
},
{ {
email: 'chanelle.lunod@obf.ateneo.edu', email: 'chanelle.lunod@obf.ateneo.edu',
password: 'December5' password: 'December5'
......
...@@ -4,8 +4,12 @@ ...@@ -4,8 +4,12 @@
# model remove the '{}' from the fixture names and add the columns immediately # model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below # below each fixture, per the syntax in the comments below
# #
one: {} admin_user:
# column: value name: Andrea Dolendo
# email: andrea.dolendo@obf.ateneo.edu
two: {} password: Andrea25
# column: value
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