forked from Ada-C6/FarMarRails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from BrandiPhillips/sale_and_product_loops
Sale and product loops added with basic functionality
- Loading branch information
Showing
15 changed files
with
8,222 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
class VendorsController < ApplicationController | ||
def index | ||
@vendor = Vendor.find(current_user.id) | ||
end | ||
|
||
def show | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
class Sale < ActiveRecord::Base | ||
belongs_to :vendor | ||
belongs_to :product | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
<h1>Products#edit</h1> | ||
<p>Find me in app/views/products/edit.html.erb</p> | ||
<h1>Edit your product</h1> | ||
|
||
<p>Please edit the name of your new product in the space below. When you are finished, press submit!</p> | ||
|
||
<section> | ||
<%= form_for @product, method: 'put', url: products_update_path do |f| %> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
<%= f.submit %> | ||
<% end %> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
<h1>Products#index</h1> | ||
<h1>My products</h1> | ||
|
||
<p><%= "Hi #{current_user.name}! Here are the products you currently sell: " %></p> | ||
<p><%= "Hello, #{current_user.name}! Here are the products you currently sell: " %></p> | ||
|
||
<p><% current_user.products.each do |product| %> | ||
<p><%= "Name: #{product.name}, ID: #{product.id}" %> | ||
<%= button_to "Edit", products_edit_path(product.id)%> | ||
<%= button_to "Delete", products_destroy_path(product.id)%></p> | ||
<%= button_to "Edit", products_edit_path(product.id), method: :get %> | ||
<%= button_to("Delete", products_destroy_path(product.id), :data => {:confirm => 'Are you sure? Deleting a product also deletes all sales associated with that product.'}, :method => 'delete') %></li> | ||
<%end%></p> | ||
|
||
<p>What would you like to do?</p> | ||
<p><%= link_to "Add", markets_new_path %></p> | ||
<p><%= link_to "See my own market's stats", markets_show_path(current_user.id)%></p> | ||
<p><%= link_to "Add a vendor to my market", vendors_new_path %></p> | ||
<p><%= button_to "Add a product", products_new_path, method: :get %></p> | ||
|
||
<p><%= link_to "Back to vendor home", vendors_index_path %> </p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,11 @@ | ||
<h1>Products#new</h1> | ||
<p>Find me in app/views/products/new.html.erb</p> | ||
<h1>Add a new product!</h1> | ||
<p>Please enter the name of your new product in the space below. When you are finished, press submit!</p> | ||
|
||
<section> | ||
<%= form_for @product, method: 'post', url: products_create_path do |f| %> | ||
<%= f.label :name %> | ||
<%= f.text_field :name %> | ||
<%= f.submit %> | ||
<% end %> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
<h1>Sales#index</h1> | ||
<p>Find me in app/views/sales/index.html.erb</p> | ||
<h1>My sales</h1> | ||
<p>See what you've sold and add new sales!</p> | ||
|
||
|
||
<p><%= link_to "All my sales", sales_show_path(:period => :all), method: :get %></p> | ||
<p><%= link_to "This month's sales", sales_show_path(:period => :this_month), method: :get %></p> | ||
<p><%= link_to "Add a sale", sales_new_path, method: :get %></p> | ||
<p><%= link_to "Return to vendor home", vendors_index_path, method: :get %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
<h1>Sales#new</h1> | ||
<p>Find me in app/views/sales/new.html.erb</p> | ||
<h1>Add a new sale </h1> | ||
|
||
<section> | ||
<%= form_for @sale, method: 'post', url: sales_create_path do |f| %> | ||
<%= f.label :amount %> | ||
<%= f.text_field :amount %> | ||
<%= f.label :product_id %> | ||
<%= f.collection_select :product_id, @vendor.products.all, :id, :name %> | ||
<%= f.submit %> | ||
<% end %> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,20 @@ | ||
<h1>Sales#show</h1> | ||
<p>Find me in app/views/sales/show.html.erb</p> | ||
<% if @time_period == 'this_month' %> | ||
<h1>Sales for <%= DateTime.now.strftime("%B %Y")%></h1> | ||
|
||
<% @vendor.sales.each do |sale| %> | ||
<% if sale.purchase_time.month == DateTime.now.month && sale.purchase_time.year == DateTime.now.year %> | ||
<p><%= "ID: #{sale.id}, Amount: $#{format("%.2f", sale.amount/100.0)}, Product: #{sale.product.name}, Sold at: #{sale.purchase_time}" %></p> | ||
<% end %> | ||
<% end %> | ||
<% else%> | ||
<h1>All my sales</h1> | ||
|
||
<p> Total sales: $<%= @vendor.total_sales/100.0%> </p> | ||
|
||
<% @vendor.sales.each do |sale| %> | ||
<p><%= "ID: #{sale.id}, Amount: $#{format("%.2f", sale.amount/100.0)}, Product: #{sale.product.name}, Sold at: #{sale.purchase_time}" %></p> | ||
<% end %> | ||
<% end %> | ||
|
||
<p><%= link_to "Back to sales home", sales_index_path, method: :get%></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
<h1>Vendors#index</h1> | ||
<h1>Welcome, <%= @vendor.name %>!</h1> | ||
|
||
<p><%= "Hello, vendor #{current_user.name}! What would you like to do today?"%></p> | ||
<p><%= link_to "See my vendor stats", vendors_show_path(current_user.id)%></p> | ||
<p><%= link_to "Add, edit, or delete products", products_index_path %></p> | ||
<p><%= link_to "Add a new sale", sales_index_path %></p> | ||
<h2>According to our records...</h2> | ||
|
||
<ul> | ||
<li>You have <%= @vendor.num_employees %> employees</li> | ||
<li>You sell at <%= @vendor.market.name %> </li> | ||
<li>Your vendor ID is: <%= @vendor.id %> </li> | ||
</ul> | ||
|
||
<p>To update any of this information, please contact the administrator of your market. Contact details for your market can be found at <%= link_to "#{@vendor.market.name}", users_show_path(@vendor.market.id) %>.</p> | ||
|
||
<h2>What would you like to do today?</h2> | ||
<p><%= link_to "Go to my products", products_index_path %></p> | ||
<p><%= link_to "Go to my sales", sales_index_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.