Commit e67ef1de authored by Chanelle Lunod's avatar Chanelle Lunod

Initial commit

parent a53e92a3
// Place all the styles related to the Transactions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
...@@ -2,9 +2,43 @@ class TransactionsController < ApplicationController ...@@ -2,9 +2,43 @@ class TransactionsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def index def index
@products = Product.all
end end
def show def display
if @product.status == active
Products.find_by(id: [pramas[:id])
else
#dont display
end 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 end
\ No newline at end of file
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
</nav> </nav>
<div class="container" id="container"> <div class="container" id="container">
<% if notice %> <% if notice %>
<p class="alert alert-success"><%= notice %></p> <p class="alert alert-success"><%= notice %></p>
......
<h1>Transactions#index</h1> <h1>Transactions</h1>
<p>Find me in app/views/transactions/index.html.erb</p>
<% if @products.empty? %>
<small>
No products have been created.
</small>
<% elsif @products.status == active %>
<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 "Add Order", order_transaction_path(product), class: "btn btn-primary" %>
</td>
<td>
<%= link_to "Add Supply", supply_transaction_path(product), class: "btn btn-primary" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
<h1>Add Order</h1>
<%= simple_form_for @product do |f| %>
<%= f.input :product_id, as: :integer %>
<%= f.input :user_id, as: :integer %>
<%= f.input :quantity, as: :integer %>
<%= f.input :mode, as: :string, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Add Order", class: "btn btn-primary" %>
<%= link_to "Back", products_path, class: "btn btn-default" %>
<% end %>
\ No newline at end of file
<h1>Add Supply</h1>
<%= simple_form_for @product do |f| %>
<%= f.input :product_id, as: :integer %>
<%= f.input :user_id, as: :integer %>
<%= f.input :quantity, as: :integer %>
<%= f.input :mode, as: :string, collection: [['Active', 'Active'], ['Inactive', 'Inactive']], value_method: :first, label_method: :second %>
<%= f.button :submit, "Add Supply", class: "btn btn-primary" %>
<%= link_to "Back", products_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