Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MIS21_Final_Project
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chanelle Lunod
MIS21_Final_Project
Commits
6e675488
Commit
6e675488
authored
Jul 18, 2018
by
Chanelle Lunod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parent
1b0bc1c6
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
298 additions
and
124 deletions
+298
-124
application.css.scss
app/assets/stylesheets/application.css.scss
+2
-0
orders_controller.rb
app/controllers/orders_controller.rb
+30
-0
products_controller.rb
app/controllers/products_controller.rb
+15
-3
supplies_controller.rb
app/controllers/supplies_controller.rb
+18
-16
transaction.rb
app/models/transaction.rb
+2
-0
user.rb
app/models/user.rb
+0
-1
application.html.erb
app/views/layouts/application.html.erb
+22
-3
create.html.erb
app/views/orders/create.html.erb
+0
-2
new.html.erb
app/views/orders/new.html.erb
+7
-0
index.html.erb
app/views/products/index.html.erb
+175
-41
create.html.erb
app/views/supplies/create.html.erb
+0
-2
index.html.erb
app/views/supplies/index.html.erb
+0
-37
new.html.erb
app/views/supplies/new.html.erb
+7
-0
routes.rb
config/routes.rb
+5
-8
seeds.rb
db/seeds.rb
+6
-6
admin_users.yml
test/fixtures/admin_users.yml
+9
-5
No files found.
app/assets/stylesheets/application.css.scss
View file @
6e675488
...
@@ -4,3 +4,5 @@
...
@@ -4,3 +4,5 @@
*/
*/
@import
"bootstrap"
;
@import
"bootstrap"
;
#container
{
padding-top
:
5rem
;
}
#container
{
padding-top
:
5rem
;
}
body
{
background-color
:
#d9e6f2
;}
app/controllers/orders_controller.rb
View file @
6e675488
class
OrdersController
<
ApplicationController
def
index
@products
=
Product
.
all
end
def
new
@product
=
Product
.
find_by
(
id:
params
[
:product_id
])
@order
=
@order
.
transactions
.
new
end
def
create
@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
@product
.
save
redirect_to
authenticated_user_root_path
,
notice:
"You have successfully placed a new order"
else
render
'new'
end
end
private
def
order_params
params
.
require
(
:transaction
).
permit!
end
end
app/controllers/products_controller.rb
View file @
6e675488
...
@@ -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
...
...
app/controllers/supplies_controller.rb
View file @
6e675488
...
@@ -5,24 +5,26 @@ class SuppliesController < ApplicationController
...
@@ -5,24 +5,26 @@ 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
app/models/transaction.rb
View file @
6e675488
class
Transaction
<
ApplicationRecord
class
Transaction
<
ApplicationRecord
has_many
:supplies
has_many
:orders
belongs_to
:product
belongs_to
:product
belongs_to
:user
belongs_to
:user
...
...
app/models/user.rb
View file @
6e675488
...
@@ -14,5 +14,4 @@ class User < ApplicationRecord
...
@@ -14,5 +14,4 @@ class User < ApplicationRecord
email
email
end
end
end
end
end
end
app/views/layouts/application.html.erb
View file @
6e675488
...
@@ -16,27 +16,46 @@
...
@@ -16,27 +16,46 @@
background-color
:
#ccfff2
background-color
:
#ccfff2
font-family
:
'Calibri'
;
font-family
:
'Calibri'
;
</style>
</style>
<nav
class=
"navbar navbar-expand-
lg navbar-light bg-light
"
>
<nav
class=
"navbar navbar-expand-
xl navbar-dark bg-dark
"
>
<%=
link_to
"
Main
"
,
root_path
,
class:
"navbar-brand"
%>
<%=
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_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
%>
...
...
app/views/orders/create.html.erb
deleted
100644 → 0
View file @
1b0bc1c6
<h1>
Orders#create
</h1>
<p>
Find me in app/views/orders/create.html.erb
</p>
app/views/orders/new.html.erb
View file @
6e675488
<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
app/views/products/index.html.erb
View file @
6e675488
<h1>
Inventory System
</h1>
<%
if
admin_user_signed_in?
%>
<h1>
Products
</h1>
<div>
<%=
link_to
"Add new Product"
,
new_product_path
,
class:
"btn btn-primary"
%>
</div>
<div>
<br>
<%=
link_to
"Create new product"
,
new_product_path
,
class:
"btn btn-primary"
%>
</div>
<br>
<%
if
@products
.
empty?
%>
<%
if
@products
.
empty?
%>
<small>
<small>
No products have been creat
ed.
No products have been add
ed.
</small>
</small>
<%
else
%>
<%
else
%>
<table
class
=
"table
"
>
<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>
Time Created
</th>
<th>
Supply
</th>
<th
colspan=
"4"
></th>
<th>
Order
</th>
<th>
Total
</th>
<th>
Created At
</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>
<%
@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>
<td>
<td>
<%=
time_ago_in_words
(
product
.
created_at
)
%>
ago
<%=
time_ago_in_words
(
product
.
created_at
)
%>
ago
...
@@ -37,8 +77,102 @@
...
@@ -37,8 +77,102 @@
<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>
<%
end
%>
</tbody>
</table>
<%
end
%>
<%
else
%>
<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>
</tr>
<%
end
%>
<%
end
%>
</tbody>
</tbody>
</table>
</table>
<%
end
%>
<%
end
%>
<%
end
%>
\ No newline at end of file
app/views/supplies/create.html.erb
deleted
100644 → 0
View file @
1b0bc1c6
<h1>
Supplies#create
</h1>
<p>
Find me in app/views/supplies/create.html.erb
</p>
app/views/supplies/index.html.erb
deleted
100644 → 0
View file @
1b0bc1c6
<h1>
Transactions
</h1>
<br>
<%
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
%>
\ No newline at end of file
app/views/supplies/new.html.erb
View file @
6e675488
<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"
%>
<%
end
%>
config/routes.rb
View file @
6e675488
...
@@ -5,20 +5,17 @@ Rails.application.routes.draw do
...
@@ -5,20 +5,17 @@ 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:
'
supplie
s#index'
,
as: :authenticated_user_root
root
to:
'
product
s#index'
,
as: :authenticated_user_root
end
end
end
end
root
to:
'publics#index'
root
to:
'publics#index'
end
end
\ No newline at end of file
db/seeds.rb
View file @
6e675488
if
AdminUser
.
count
==
0
if
AdminUser
.
count
==
0
AdminUser
.
create!
(
AdminUser
.
create!
(
[
{
{
email:
'andrea.dolendo@obf.ateneo.edu'
,
email:
'andrea.dolendo@obf.ateneo.edu'
,
password:
'Andrea25'
password:
'Andrea25'
},
},
#
{
{
#
email: 'chanelle.lunod@obf.ateneo.edu',
email:
'chanelle.lunod@obf.ateneo.edu'
,
#
password: 'December5'
password:
'December5'
#
}
}
)
]
)
end
end
\ No newline at end of file
test/fixtures/admin_users.yml
View file @
6e675488
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment