diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..b0d73ff8 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 050c9d95..c30acbc1 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,8 @@ /log/* !/log/.keep /tmp + +# .DS B.S. +*.DS_Store +*/.DS_Store +.DS_Store* diff --git a/Gemfile b/Gemfile index f1d0fa33..8129c9c0 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.7' # Use sqlite3 as the database for Active Record -gem 'sqlite3' + # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' # Use Uglifier as compressor for JavaScript assets @@ -23,6 +23,7 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc +gem 'graphviz' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' @@ -35,6 +36,12 @@ gem 'sdoc', '~> 0.4.0', group: :doc group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' + gem 'sqlite3' +end + +group :production do + gem 'pg' + gem 'rails_12factor' end group :development do @@ -46,4 +53,5 @@ group :development do # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' + gem 'rails-erd' end diff --git a/Gemfile.lock b/Gemfile.lock index 6a4ecae9..13c36d9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,6 +45,7 @@ GEM debug_inspector (>= 0.0.1) builder (3.2.2) byebug (9.0.6) + choice (0.2.0) coderay (1.1.1) coffee-rails (4.1.1) coffee-script (>= 2.2.0) @@ -59,6 +60,7 @@ GEM execjs (2.7.0) globalid (0.3.7) activesupport (>= 4.1.0) + graphviz (0.3.0) i18n (0.7.0) jbuilder (2.6.0) activesupport (>= 3.0.0, < 5.1) @@ -82,6 +84,7 @@ GEM nokogiri (1.6.8) mini_portile2 (~> 2.1.0) pkg-config (~> 1.1.7) + pg (0.19.0) pkg-config (1.1.7) pry (0.10.4) coderay (~> 1.1.0) @@ -109,8 +112,18 @@ GEM activesupport (>= 4.2.0.beta, < 5.0) nokogiri (~> 1.6.0) rails-deprecated_sanitizer (>= 1.0.1) + rails-erd (1.5.0) + activerecord (>= 3.2) + activesupport (>= 3.2) + choice (~> 0.2.0) + ruby-graphviz (~> 1.2) rails-html-sanitizer (1.0.3) loofah (~> 2.0) + rails_12factor (0.0.3) + rails_serve_static_assets + rails_stdout_logging + rails_serve_static_assets (0.0.5) + rails_stdout_logging (0.0.5) railties (4.2.7) actionpack (= 4.2.7) activesupport (= 4.2.7) @@ -119,6 +132,7 @@ GEM rake (11.3.0) rdoc (4.2.2) json (~> 1.4) + ruby-graphviz (1.2.2) sass (3.4.22) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -164,10 +178,14 @@ DEPENDENCIES binding_of_caller byebug coffee-rails (~> 4.1.0) + graphviz jbuilder (~> 2.0) jquery-rails + pg pry-rails rails (= 4.2.7) + rails-erd + rails_12factor sass-rails (~> 5.0) sdoc (~> 0.4.0) spring diff --git a/app/assets/javascripts/market.coffee b/app/assets/javascripts/market.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/market.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/product.coffee b/app/assets/javascripts/product.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/product.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/sale.coffee b/app/assets/javascripts/sale.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/sale.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/vendor.coffee b/app/assets/javascripts/vendor.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/vendor.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index f9cd5b34..e3fb0516 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1,3 +1,186 @@ +main { + margin-bottom: 10%; +} + +a:hover { + color: #666699; +} + +a { + color: #F5B19A; + font-family: 'Quicksand'; + text-decoration: none; +} + +.homepage-buttons a{ + color: white; + text-decoration: none; +} + +.homepage-buttons a:hover { + color: white; +} +h6 { + text-align: center; + font-family: 'Quicksand', serif; + color: #F5B19A; +} +h1 { + text-align: center; + font-family: 'Quicksand', serif; + font-size: 4em; + color: #F5B19A; + /*background-color: #efefef;*/ +} + +/*main { + margin-top: 30px; +}*/ + +.add-market { + margin-top: 5%; + text-align: center; +} + +.market-table { + margin-left: 29%; +} + +.market-table tr { + color: grey; +} + +.market-form, .product-form-partial, .sale-form-partial { + margin-left: 20%; +} + +.market-details { + margin-left: 20%; +} + +.table-product-action { +text-align: center; +} + +.table-info td, .table-product td { + padding-right: 3%; + color: #F5B19A; +} + +.table-product { + margin-left: 42%; + column-width: auto; +} + + +.name-title { + text-align: center; + font-family: 'Quicksand', sans-serif; + color: #F5B19A; +} + +nav{ +margin-left: 8%; +margin-bottom: 5%; +} + +nav a { + color: grey; +} + +.top-buttons li { + display: inline; + font-family: 'Julius Sans One', sans-serif; + border-bottom: 2pt solid #F5B19A; + color: #666699; + /*previous color #39324b*/ + margin-right: 8%; + margin-left: 8%; + padding: 5px 25px; + font-size: 9pt; +} + +footer { + font-family: 'Bad Script', sans-serif; + color: #F5B19A; + right: 0; + bottom: 0; + left: 0; + background-color: #efefef; + text-align: center; + margin-top: 5%; + position: fixed; +} + +/*.bottom-buttons li{ + display: inline; + font-family: 'Julius Sans One', sans-serif; + border-right: 2pt solid #39324b; + color: #39324b; + margin-right: 8%; + margin-left: 8%; + padding: 0px 25px; + font-size: 9pt; +}*/ + + +h3 { + text-align: center; + font-family: 'Quicksand', serif; + letter-spacing: 5px; + font-size: 5em; + color: white; + border-radius: 25px; + background-size: 280px 260px; + margin: 0 10%; + background-repeat: repeat; + opacity: 0.7; + background-image: url("http://abwatercolors.com/wp-content/uploads/2012/11/farmersMarket.jpg"); +} + +/*middle pictures in home page*/ +h2 { + text-align: center; + font-family: 'Quicksand', serif; + letter-spacing: 5px; + font-size: 5em; + color: white; + border-radius: 25px; + background-size: 280px 260px; + padding: 3% 3%; + margin: 5% 10%; + background-repeat: repeat; + opacity: 0.7; + background-image: url("http://abwatercolors.com/wp-content/uploads/2012/11/farmersMarket.jpg"); +} + +table { + margin: 0 17%; + font-family: 'Quicksand', sans-serif; + font-size: 14px; + line-height: 25px; +} + +th { + border-bottom: 2pt solid grey; + text-align: left; +} + +main table { + /*margin-top: 6%;*/ + margin-left: 35%; +} + +footer a { + color: #F5B19A; +} +/*.table-top * { + margin: 0 20%; +} + +.table-info * { + margin-right: 10%; +}*/ /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. diff --git a/app/assets/stylesheets/market.scss b/app/assets/stylesheets/market.scss new file mode 100644 index 00000000..d427bd0d --- /dev/null +++ b/app/assets/stylesheets/market.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the market controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/product.scss b/app/assets/stylesheets/product.scss new file mode 100644 index 00000000..3c4e9545 --- /dev/null +++ b/app/assets/stylesheets/product.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the product controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/sale.scss b/app/assets/stylesheets/sale.scss new file mode 100644 index 00000000..ed3b33f7 --- /dev/null +++ b/app/assets/stylesheets/sale.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sale controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d83690e1..4d775767 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,4 +2,8 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + + def index + + end end diff --git a/app/controllers/homepage_controller.rb b/app/controllers/homepage_controller.rb new file mode 100644 index 00000000..e09cc6e5 --- /dev/null +++ b/app/controllers/homepage_controller.rb @@ -0,0 +1,4 @@ +class HomepageController < ApplicationController + def index + end +end diff --git a/app/controllers/market_controller.rb b/app/controllers/market_controller.rb new file mode 100644 index 00000000..c1ae9d33 --- /dev/null +++ b/app/controllers/market_controller.rb @@ -0,0 +1,48 @@ +class MarketController < ApplicationController + def index + @markets = Market.all + end + + def create + @market = Market.create(market_params) + + redirect_to root_path + end + + def new + @market = Market.new + end + + def edit + @market = Market.find(params[:id]) + end + + def show + @market = Market.find(params[:id]) + end + + def update + @market = Market.find(params[:id]) + + if @market.update(market_params) + redirect_to market_path + else + render :edit + end + end + + def destroy + @market = Market.find(params[:id]).destroy + + redirect_to market_index_path + end + +####### STRONG PARAMS ######### + + private + + def market_params + params.require(:market).permit(:name, :address, :city, :county, :state, :zip) + end + +end diff --git a/app/controllers/product_controller.rb b/app/controllers/product_controller.rb new file mode 100644 index 00000000..3c03a11e --- /dev/null +++ b/app/controllers/product_controller.rb @@ -0,0 +1,47 @@ +class ProductController < ApplicationController + def index + vendor = Vendor.find(params[:vendor_id]) + @products = Product.where(:vendor_id => vendor.id) + end + + def create + @product = Product.create!(product_params) + redirect_to vendor_product_index_path + end + + def new + @product = Product.new + end + + def edit + @product = Product.find(params[:id]) + end + + def update + @product = Product.find(params[:id]) + + if @product.update!(product_params) + redirect_to vendor_product_index_path + else + render :edit + end + end + + def show + @product = Product.find(params[:id]) + end + + def destroy + @product = Product.find(params[:id]).destroy + redirect_to vendor_product_index_path + end + +####### STRONG PARAMS ######### + + private + + def product_params + params.require(:product).permit(:name, :vendor_id) + end + +end diff --git a/app/controllers/sale_controller.rb b/app/controllers/sale_controller.rb new file mode 100644 index 00000000..b693e927 --- /dev/null +++ b/app/controllers/sale_controller.rb @@ -0,0 +1,69 @@ +class SaleController < ApplicationController + require 'path_check.rb' + include PathCheck + + def index + if product_sale? + product = Product.find(params[:product_id]) + @sales = Sale.where(:product_id => product.id) + else vendor_sale? + vendor = Vendor.find(params[:vendor_id]) + @sales = Sale.where(:vendor_id => vendor.id) + end + end + + def create + @sale = Sale.create!(sale_params) + if vendor_sale? + redirect_to vendor_sale_index_path(params[:vendor_id]) + elsif product_sale? + redirect_to product_sale_index_path(params[:product_id]) + else + redirect_to root_path + end + end + + def new + @sale = Sale.new + end + + def edit + @sale = Sale.find(params[:id]) + end + + def update + @sale = Sale.find(params[:id]) + + if @sale.update!(sale_params) + redirect_to vendor_sale_index_path + else + render :edit + end + end + + def show + @sale = Sale.find(params[:id]) + end + + def destroy + @sale = Sale.find(params[:id]).destroy + + if vendor_sale? + redirect_to vendor_sale_index_path(params[:vendor_id]) + elsif product_sale? + redirect_to product_sale_index_path(params[:product_id]) + else + redirect_to root_path + end + end + + ####### STRONG PARAMS ######### + + private + + def sale_params + params.require(:sale).permit(:amount, :purchase_time, :vendor_id, :product_id) + end + + +end diff --git a/app/controllers/vendor_controller.rb b/app/controllers/vendor_controller.rb new file mode 100644 index 00000000..c8e16396 --- /dev/null +++ b/app/controllers/vendor_controller.rb @@ -0,0 +1,54 @@ +class VendorController < ApplicationController + + def index + if params[:market_id] != nil + market = Market.find(params[:market_id]) + @vendors = market.vendors + return @vendors + else + @vendors = Vendor.all + end + end + + def create + @vendor = Vendor.create!(vendor_params) + + redirect_to market_vendor_index_path(vendor_params[:market_id]) + end + + def new + @vendor = Vendor.new + end + + def edit + @vendor = Vendor.find(params[:id]) + end + + def show + @vendor = Vendor.find(params[:id]) + end + + def update + @vendor = Vendor.find(params[:id]) + + if @vendor.update!(vendor_params) + redirect_to vendor_path + else + render :edit + end + end + + def destroy + @vendor = Vendor.find(params[:id]).destroy + redirect_to vendor_index_path + end + + +####### STRONG PARAMS ######### + + private + + def vendor_params + params.require(:vendor).permit(:name, :num_employees, :market_id) + end +end diff --git a/app/helpers/market_helper.rb b/app/helpers/market_helper.rb new file mode 100644 index 00000000..c9783721 --- /dev/null +++ b/app/helpers/market_helper.rb @@ -0,0 +1,3 @@ +module MarketHelper + +end diff --git a/app/helpers/product_helper.rb b/app/helpers/product_helper.rb new file mode 100644 index 00000000..d5da5605 --- /dev/null +++ b/app/helpers/product_helper.rb @@ -0,0 +1,2 @@ +module ProductHelper +end diff --git a/app/helpers/sale_helper.rb b/app/helpers/sale_helper.rb new file mode 100644 index 00000000..22dc359f --- /dev/null +++ b/app/helpers/sale_helper.rb @@ -0,0 +1,28 @@ +module SaleHelper + require 'path_check.rb' + include PathCheck + + def total_sales(sales) + total = [] + + sales.each do |sale| + total << sale.amount.to_f.round(2) + end + + total = total.reduce(:+) + + return total / 100.00 + end + + def current_month?(time) + time = time.to_datetime + + if time > (DateTime.now - 30) + return true + else + return false + end + end + + +end diff --git a/app/helpers/vendor_helper.rb b/app/helpers/vendor_helper.rb new file mode 100644 index 00000000..e3f597e0 --- /dev/null +++ b/app/helpers/vendor_helper.rb @@ -0,0 +1,2 @@ +module VendorHelper +end diff --git a/app/models/market.rb b/app/models/market.rb new file mode 100644 index 00000000..6a148291 --- /dev/null +++ b/app/models/market.rb @@ -0,0 +1,3 @@ +class Market < ActiveRecord::Base + has_many :vendors +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 00000000..86f8d94b --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,4 @@ +class Product < ActiveRecord::Base + belongs_to :vendor + has_many :sales +end diff --git a/app/models/sale.rb b/app/models/sale.rb new file mode 100644 index 00000000..d6dc744d --- /dev/null +++ b/app/models/sale.rb @@ -0,0 +1,15 @@ +class Sale < ActiveRecord::Base + belongs_to :product + belongs_to :vendor + + require 'path_check.rb' + include PathCheck + + # accepts_nested_attributes_for :sales#, + # :reject_if => proc {|attributes| + # attributes.all? {|k,v| v.blank?} + # } + + # validates :vendor_id, presence: true + # # validates :product_id, presence: true +end diff --git a/app/models/vendor.rb b/app/models/vendor.rb new file mode 100644 index 00000000..f8f66089 --- /dev/null +++ b/app/models/vendor.rb @@ -0,0 +1,6 @@ +class Vendor < ActiveRecord::Base + belongs_to :market + has_many :products + has_many :sales + +end diff --git a/app/views/homepage/index.html.erb b/app/views/homepage/index.html.erb new file mode 100644 index 00000000..0e4d8cb1 --- /dev/null +++ b/app/views/homepage/index.html.erb @@ -0,0 +1,16 @@ + + + + + + <% @little_title = 'welcome to'%> + <%= @title = '~FARMAR HELL~'%> + + + +
+

<%= link_to "Act As A Market", market_index_path %>

+

<%= link_to "Act As A Vendor", vendor_index_path %>

+
+ + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 443f3152..a585364c 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,14 +1,35 @@ - FarMarRails + FarMar <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> + + +
+
<%= @little_title %>
+

<%= @title %>

+

<%= @page_name %>

+ +
+
+ <%= yield %> +
-<%= yield %> + diff --git a/app/views/market/_market_form.html.erb b/app/views/market/_market_form.html.erb new file mode 100644 index 00000000..97e11425 --- /dev/null +++ b/app/views/market/_market_form.html.erb @@ -0,0 +1,48 @@ + + <%= @page_name = 'Create Market'%> + +<% if @market.errors.any? %> + +<% end %> + +<%= form_for @market, url: path, method: http_method do |f| %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<%= f.label :name %> <%= f.text_field :name, :size => 100 %>
<%= f.label :address %> <%= f.text_field :address, :size => 100 %>
<%= f.label :city %><%= f.text_field :city %>
<%= f.label :county %><%= f.text_field :county, :size => 50 %>
<%= f.label :state %><%= f.text_field :state %>
<%= f.label :zip %><%= f.text_field :zip %>
<%= f.submit "Mark it, Market!" %>
+<% end %> diff --git a/app/views/market/edit.html.erb b/app/views/market/edit.html.erb new file mode 100644 index 00000000..8c9ce0ab --- /dev/null +++ b/app/views/market/edit.html.erb @@ -0,0 +1,3 @@ +

Edit this market

+ +<%= render partial: "market_form", locals: {path: market_path, http_method: :patch} %> diff --git a/app/views/market/index.html.erb b/app/views/market/index.html.erb new file mode 100644 index 00000000..16f03734 --- /dev/null +++ b/app/views/market/index.html.erb @@ -0,0 +1,20 @@ + + <%= @page_name = 'View All Markets'%> + + +

<%= link_to "Add a new market", new_market_path %>

+ + + + + + + <% @markets.each do |market| %> + + + + + <% end %> +
Market NameActions
<%= link_to "#{market.name}", market_path(market) %> + <%= link_to "[Edit]", edit_market_path(market) %> + <%= link_to "[Delete]", market_path(market), method: :delete, data: { confirm: "Really, now?" } %>
diff --git a/app/views/market/new.html.erb b/app/views/market/new.html.erb new file mode 100644 index 00000000..9233fca5 --- /dev/null +++ b/app/views/market/new.html.erb @@ -0,0 +1,2 @@ + +<%= render partial: "market_form", locals: {path: market_index_path, http_method: :post} %> diff --git a/app/views/market/show.html.erb b/app/views/market/show.html.erb new file mode 100644 index 00000000..2d1e0ee8 --- /dev/null +++ b/app/views/market/show.html.erb @@ -0,0 +1,28 @@ + + <%= @page_name = 'Market Info'%> + + + + + + + + + + + + + + + + + + + +
NameAddressCityCountyStateZip
<%= @market.name %><%= @market.address %><%= @market.city %><%= @market.county %><%= @market.state %><%= @market.zip %>
+ +

<%= link_to "Back to all markets", market_index_path %>

+

<%= link_to "View all vendors", market_vendor_index_path(params[:id]) %>

+ +
+<%= button_to "Delete this market", {:action => 'destroy', :id => @market.id }, :method => :delete, data: { confirm: "Really, now?" } %> diff --git a/app/views/product/_product_form.html.erb b/app/views/product/_product_form.html.erb new file mode 100644 index 00000000..345ca7e7 --- /dev/null +++ b/app/views/product/_product_form.html.erb @@ -0,0 +1,26 @@ +<% if @product.errors.any? %> + +<% end %> + + +<%= form_for @product, url: path, method: http_method do |f| %> + + + + + + + + + + + + + + +
<%= f.label :name %> <%= f.text_field :name, :size => 100 %>
<%= f.label :vendor_id %> <%= f.text_field :vendor_id, :value=> params[:vendor_id], :required => true %>
<%= f.submit "Produce Product!" %>
+<% end %> diff --git a/app/views/product/edit.html.erb b/app/views/product/edit.html.erb new file mode 100644 index 00000000..6c99f2f1 --- /dev/null +++ b/app/views/product/edit.html.erb @@ -0,0 +1,7 @@ + + <%= @page_name = Vendor.find(params[:vendor_id]).name + "'s Product'"%> + + + + +<%= render partial: "product_form", locals: {path: vendor_product_path, http_method: :patch} %> diff --git a/app/views/product/index.html.erb b/app/views/product/index.html.erb new file mode 100644 index 00000000..343468ad --- /dev/null +++ b/app/views/product/index.html.erb @@ -0,0 +1,21 @@ + + <% @page_name = Vendor.find(@products[0].vendor_id).name + "'s Products"%> + +

Market: <%= Market.find(@products[0].vendor_id).name %>

+ + + + + + + <% @products.each do |product| %> + + + + + <% end %> +
Product NameActions
<%= product.name %> + <%= link_to "[Edit]", edit_vendor_product_path(product.vendor_id, product.id) %> + <%= link_to "[Delete]", vendor_product_path(product.vendor_id, product.id), method: :delete, data: { confirm: "Really, now?" } %>
+ +

<%= link_to "Add a new product!", new_vendor_product_path %>

diff --git a/app/views/product/new.html.erb b/app/views/product/new.html.erb new file mode 100644 index 00000000..2007a119 --- /dev/null +++ b/app/views/product/new.html.erb @@ -0,0 +1,8 @@ + + <% @page_name = Vendor.find(params[:vendor_id]).name %> + + +

Add new product

+ + +<%= render partial: "product_form", locals: {path: vendor_product_index_path, http_method: :post} %> diff --git a/app/views/product/show.html.erb b/app/views/product/show.html.erb new file mode 100644 index 00000000..994ef3f2 --- /dev/null +++ b/app/views/product/show.html.erb @@ -0,0 +1,20 @@ +

Detailed Product Page

+ + + + + + + + + + +
NameProduct IDVendor ID
<%= @product.name %><%= @product.id %> + <%= @product.vendor_id %> +
+ +

<%= link_to "Back to all products", vendor_product_index_path %>

+

<%= link_to "Add a new sale for this product", new_product_sale_path(@product.id) %>

+ +
+<%= button_to "Delete this product", {:action => 'destroy', :id => @product.id }, :method => :delete, data: { confirm: "Really, now?" } %> diff --git a/app/views/sale/_sale_form.html.erb b/app/views/sale/_sale_form.html.erb new file mode 100644 index 00000000..79af4a44 --- /dev/null +++ b/app/views/sale/_sale_form.html.erb @@ -0,0 +1,43 @@ +<% if @sale.errors.any? %> + +<% end %> + + +<%= form_for @sale, url: path, method: http_method do |f| %> + + + + + + + + + + + + + <% if vendor_sale? %> + + <% else %> + + <% end %> + + + + + <% if product_sale? %> + + <% else %> + + <% end %> + + + + + +
<%= f.label :amount %> <%= f.text_field :amount, :size => 100 %>
<%= f.label :purchase_time %> <%= f.datetime_field :purchase_time, :value => "YYYY-MM-DD", :size => 100 %>
<%= f.label :vendor_id, "Vendor ID*" %> <%= f.text_field :vendor_id, :value => params[:vendor_id], :required => true %> <%= f.text_field :vendor_id, :required => true %>
<%= f.label :product_id, "Product ID*" %> <%= f.text_field :product_id, :value => params[:product_id], :required => true %> <%= f.text_field :product_id, :required => true %>
<%= f.submit "Set Sale!" %>
+<% end %> diff --git a/app/views/sale/edit.html.erb b/app/views/sale/edit.html.erb new file mode 100644 index 00000000..09662caf --- /dev/null +++ b/app/views/sale/edit.html.erb @@ -0,0 +1,13 @@ +<% if product_sale? %> + <% product = Product.find(params[:product_id]) %> +

<%= product.vendor.name %>

+

Edit sale

+ <%= render partial: "sale_form", locals: {path: edit_product_sale_path, http_method: :patch} %> + +<% elsif vendor_sale? %> +

<%= Vendor.find(params[:vendor_id]).name %>

+

Edit sale

+ <%= render partial: "sale_form", locals: {path: edit_vendor_sale_path, http_method: :patch} %> +<% else %> + <%= puts "Error on add new sale page" %> +<% end %> diff --git a/app/views/sale/index.html.erb b/app/views/sale/index.html.erb new file mode 100644 index 00000000..5bdadca4 --- /dev/null +++ b/app/views/sale/index.html.erb @@ -0,0 +1,62 @@ + + <%= @page_name = Vendor.find(@sales[0].vendor_id).name + "'s Products"%> + +

Market: <%= Market.find(@sales[0].vendor_id).name %>

+ +

ALL SALES

+ + + + + + + + <% @sales.each do |sale| %> + + + + + + + <% end %> +
Sale IDPurchase TimeAmountActions
<%= sale.id %><%= sale.purchase_time %>$<%= sale.amount.to_f.round(2) / 100 %> + <%= link_to "[Edit]", edit_vendor_sale_path(sale.vendor_id, sale.id) %> + <%= link_to "[Delete]", vendor_sale_path(sale.vendor_id, sale.id), method: :delete, data: { confirm: "Really, now?" } %> +
+ +

Total sales:

+

$<%= total_sales(@sales) %>

+ +<% month_sales = [] %> +

ALL SALES FOR LAST MONTH

+ + + + + + + + <% @sales.each do |sale| %> + + <% if current_month?(sale.purchase_time) %> + <% month_sales << sale %> + + + + <% end %> + + <% end %> +
Sale IDPurchase TimeAmountActions
<%= sale.id %><%= sale.purchase_time %> + $<%= sale.amount.to_f.round(2) / 100%> + <%= link_to "[Edit]", edit_vendor_sale_path(sale.vendor_id, sale.id) %> + <%= link_to "[Delete]", vendor_sale_path(sale.vendor_id, sale.id), method: :delete, data: { confirm: "Really, now?" } %> +
+ +

Total sales for last month:

+

$<%= total_sales(month_sales) %>

+ +<% if product_sale? %> +

<%= link_to "Add a new sale!", new_product_sale_path %>

+<% else vendor_sale? %> +

<%= link_to "Add a new sale!", new_vendor_sale_path %>

+<% end %> diff --git a/app/views/sale/new.html.erb b/app/views/sale/new.html.erb new file mode 100644 index 00000000..6966a00c --- /dev/null +++ b/app/views/sale/new.html.erb @@ -0,0 +1,15 @@ + +<% if product_sale? %> + <% product = Product.find(params[:product_id]) %> +

<%= product.vendor.name %>

+

Add new sale

+ <%= render partial: "sale_form", locals: {path: product_sale_index_path, http_method: :post} %> + +<% elsif vendor_sale? %> +

<%= Vendor.find(params[:vendor_id]).name %>

+

Add new sale

+ <%= render partial: "sale_form", locals: {path: vendor_sale_index_path, http_method: :post} %> + +<% else %> + <%= puts "Error on add new sale page" %> +<% end %> diff --git a/app/views/sale/show.html.erb b/app/views/sale/show.html.erb new file mode 100644 index 00000000..37cb47b4 --- /dev/null +++ b/app/views/sale/show.html.erb @@ -0,0 +1,23 @@ +

Detailed Sale Page

+ + + + + + + + + + + + + + + + +
Sale IDAmountPurchase TimeVendor IDMarket ID
<%= @sale.id %>$<%= @sale.amount / 100 %><%= @sale.purchase_time %><%= @sale.vendor_id %><%= @sale.market_id %>
+ +

<%= link_to "Back to all sales", vendor_sale_index_path %>

+ +
+<%= button_to "Delete this sale", {:action => 'destroy', :id => @sale.id }, :method => :delete, data: { confirm: "Really, now?" } %> diff --git a/app/views/vendor/_vendor_form.html.erb b/app/views/vendor/_vendor_form.html.erb new file mode 100644 index 00000000..04a2cbe2 --- /dev/null +++ b/app/views/vendor/_vendor_form.html.erb @@ -0,0 +1,33 @@ + + <%= @page_name = 'Vendor Form'%> + +<% if @vendor.errors.any? %> + +<% end %> + +<%= form_for @vendor, :url => vendor_index_path, method: http_method do |f| %> + + + + + + + + + + + + + + + + + + + +
<%= f.label :name,"Name*"%> <%= f.text_field :name, :size => 100 , :required => true%>
<%= f.label :num_employees %> <%= f.text_field :num_employees, :size => 100 %>
<%= f.label :market_id, "Market ID*" %><%= f.text_field :market_id, :value => params[:market_id], :required => true %>
<%= f.submit "Send 'er, Vendor!" %>
+<% end %> diff --git a/app/views/vendor/edit.html.erb b/app/views/vendor/edit.html.erb new file mode 100644 index 00000000..6fb916b8 --- /dev/null +++ b/app/views/vendor/edit.html.erb @@ -0,0 +1,5 @@ + + <%= @page_name = 'Edit this Vendor'%> + + +<%= render partial: "vendor_form", locals: {http_method: :patch} %> diff --git a/app/views/vendor/index.html.erb b/app/views/vendor/index.html.erb new file mode 100644 index 00000000..aeff2c48 --- /dev/null +++ b/app/views/vendor/index.html.erb @@ -0,0 +1,22 @@ + + <%= @page_name = 'View All Vendors'%> + + +<% if params[:market_id] != nil %> +

<%= link_to "Add a new vendor for this market", new_market_vendor_path(@vendors[0].market_id) %>

+<% end %> + + + + + + + <% @vendors.each do |vendor| %> + + + + + <% end %> +
Vendor NameActions
<%= link_to "#{vendor.name}", vendor_path(vendor) %> + <%= link_to "[Edit]", edit_vendor_path(vendor) %> + <%= link_to "[Delete]", vendor_path(vendor), method: :delete, data: { confirm: "Really, now?" } %>
diff --git a/app/views/vendor/new.html.erb b/app/views/vendor/new.html.erb new file mode 100644 index 00000000..77f06ed9 --- /dev/null +++ b/app/views/vendor/new.html.erb @@ -0,0 +1,3 @@ +

Add new vendor!

+ +<%= render partial: "vendor_form", locals: {http_method: :post} %> diff --git a/app/views/vendor/show.html.erb b/app/views/vendor/show.html.erb new file mode 100644 index 00000000..9542fd19 --- /dev/null +++ b/app/views/vendor/show.html.erb @@ -0,0 +1,28 @@ + + <%= @page_name = 'Detailed Vendor Page'%> + + +
+ + + + + + + + + + + + + +
NameID# of EmployeesMarket
<%= @vendor.name %><%= @vendor.id %><%= @vendor.num_employees %><%= Market.find(@vendor.market_id).name %>
+ +

<%= link_to "Back to all vendors", vendor_index_path %>

+

<%= link_to "Add a new sale", new_vendor_sale_path(@vendor.id) %>

+

<%= link_to "View all products", vendor_product_index_path(params[:id]) %>

+

<%= link_to "View all sales", vendor_sale_index_path(params[:id]) %>

+ +
+<%= button_to "Delete this vendor", {:action => 'destroy', :id => @vendor.id }, :method => :delete, data: { confirm: "Really, now?" } %> +
diff --git a/config/routes.rb b/config/routes.rb index 3f66539d..989a102a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,29 @@ Rails.application.routes.draw do + + root 'homepage#index' + # Acting as a market + resources :market do + resources :vendor + end + + + # Acting as a Vendor on product things and sales things through product + resources :vendor do + resources :product do + resources :sale, only: [:index, :new, :create] + end + end + + # Acting as a vendor doing things directly to sales without going through product + resources :vendor do + resources :sale + end + + # Getting to sales through product + resources :product, only: [:index, :new, :create] do + resources :sale + end + # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/db/migrate/20161004190501_create_markets.rb b/db/migrate/20161004190501_create_markets.rb new file mode 100644 index 00000000..53e43ae5 --- /dev/null +++ b/db/migrate/20161004190501_create_markets.rb @@ -0,0 +1,16 @@ +class CreateMarkets < ActiveRecord::Migration + def change + create_table :markets, id: false do |t| + + t.primary_key :id + t.string :name + t.string :address + t.string :city + t.string :county + t.string :state + t.string :zip + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004190547_create_vendors.rb b/db/migrate/20161004190547_create_vendors.rb new file mode 100644 index 00000000..9d5147dd --- /dev/null +++ b/db/migrate/20161004190547_create_vendors.rb @@ -0,0 +1,14 @@ +class CreateVendors < ActiveRecord::Migration + def change + create_table :vendors, id: false do |t| + t.belongs_to :market + + t.primary_key :id + t.string :name + t.integer :num_employees + t.integer :market_id + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004190612_create_products.rb b/db/migrate/20161004190612_create_products.rb new file mode 100644 index 00000000..3ac9d572 --- /dev/null +++ b/db/migrate/20161004190612_create_products.rb @@ -0,0 +1,13 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products, id: false do |t| + t.belongs_to :vendor + + t.primary_key :id + t.string :name + t.integer :vendor_id + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004190718_create_sales.rb b/db/migrate/20161004190718_create_sales.rb new file mode 100644 index 00000000..19aecec2 --- /dev/null +++ b/db/migrate/20161004190718_create_sales.rb @@ -0,0 +1,16 @@ +class CreateSales < ActiveRecord::Migration + def change + create_table :sales, id: false do |t| + t.belongs_to :product + t.belongs_to :vendor + + t.primary_key :id + t.integer :amount + t.datetime :purchase_time + t.integer :vendor_id + t.integer :product_id + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..b5075535 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,51 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20161004190718) do + + create_table "markets", force: :cascade do |t| + t.string "name" + t.string "address" + t.string "city" + t.string "county" + t.string "state" + t.string "zip" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "products", force: :cascade do |t| + t.integer "vendor_id" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "sales", force: :cascade do |t| + t.integer "product_id" + t.integer "vendor_id" + t.integer "amount" + t.datetime "purchase_time" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "vendors", force: :cascade do |t| + t.integer "market_id" + t.string "name" + t.integer "num_employees" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + +end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e85..03600596 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,22 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +require 'csv' + + +CSV.foreach('./seed_csvs/markets.csv', :headers => true) do |market| + Market.create(market.to_hash) +end + +CSV.foreach('./seed_csvs/vendors.csv', :headers => true) do |vendor| + Vendor.create(vendor.to_hash) +end + +CSV.foreach('./seed_csvs/products.csv', :headers => true) do |product| + Product.create(product.to_hash) +end + +CSV.foreach('./seed_csvs/sales.csv', :headers => true) do |sale| + Sale.create(sale.to_hash) +end diff --git a/erd.pdf b/erd.pdf new file mode 100644 index 00000000..b9be1896 Binary files /dev/null and b/erd.pdf differ diff --git a/lib/path_check.rb b/lib/path_check.rb new file mode 100644 index 00000000..bd674783 --- /dev/null +++ b/lib/path_check.rb @@ -0,0 +1,19 @@ +module PathCheck + def product_sale? + if params[:product_id] != nil + return true + end + end + + def vendor_sale? + if params[:vendor_id] != nil + return true + end + end + + def market_sale? + if params[:market_id] != nil + return true + end + end +end diff --git a/seed_csvs/markets.csv b/seed_csvs/markets.csv index 9860f59f..b70dea63 100644 --- a/seed_csvs/markets.csv +++ b/seed_csvs/markets.csv @@ -1,3 +1,4 @@ +id,name,address,city,county,state,zip 1,"People's Co-op Farmers Market","30th and Burnside",Portland,Multnomah,Oregon,97202 2,"Silverdale Farmers Market",98383,Silverdale,Kitsap,Washington,98383 3,"Dolgeville Farmer's Market","(Parking Lot) Between Main St. and Helmer Ave",Dolgeville,Herkimer,"New York",13329 diff --git a/seed_csvs/products.csv b/seed_csvs/products.csv index ac508548..2f686605 100644 --- a/seed_csvs/products.csv +++ b/seed_csvs/products.csv @@ -1,3 +1,4 @@ +id,name,vendor_id 1,"Dry Beets",1 2,"Fierce Greens",2 3,"Heavy Chicken",2 diff --git a/seed_csvs/sales.csv b/seed_csvs/sales.csv index 67cfa4be..82ce2165 100644 --- a/seed_csvs/sales.csv +++ b/seed_csvs/sales.csv @@ -1,3 +1,4 @@ +id,amount,purchase_time,vendor_id,product_id 1,9290,"2013-11-07 12:34:56.000000",1,1 2,2262,"2013-11-10 10:44:56.000000",1,1 3,9588,"2013-11-13 09:49:37.000000",1,1 diff --git a/seed_csvs/vendors.csv b/seed_csvs/vendors.csv index a2bec328..242cd837 100644 --- a/seed_csvs/vendors.csv +++ b/seed_csvs/vendors.csv @@ -1,3 +1,4 @@ +id,name,num_employees,market_id 1,Feil-Farrell,8,1 2,"Hamill, Kilback and Pfeffer",5,1 3,"Breitenberg Inc",5,1 diff --git a/test/controllers/market_controller_test.rb b/test/controllers/market_controller_test.rb new file mode 100644 index 00000000..c7d2332f --- /dev/null +++ b/test/controllers/market_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MarketControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/product_controller_test.rb b/test/controllers/product_controller_test.rb new file mode 100644 index 00000000..cc3f473f --- /dev/null +++ b/test/controllers/product_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/sale_controller_test.rb b/test/controllers/sale_controller_test.rb new file mode 100644 index 00000000..4ba79389 --- /dev/null +++ b/test/controllers/sale_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SaleControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/vendor_controller_test.rb b/test/controllers/vendor_controller_test.rb new file mode 100644 index 00000000..40e26779 --- /dev/null +++ b/test/controllers/vendor_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class VendorControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/markets.yml b/test/fixtures/markets.yml new file mode 100644 index 00000000..13e26ee7 --- /dev/null +++ b/test/fixtures/markets.yml @@ -0,0 +1,17 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + address: MyString + city: MyString + county: MyString + state: MyString + zip: MyString + +two: + name: MyString + address: MyString + city: MyString + county: MyString + state: MyString + zip: MyString diff --git a/test/fixtures/products.yml b/test/fixtures/products.yml new file mode 100644 index 00000000..3e906fd1 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + vendor_id: 1 + +two: + name: MyString + vendor_id: 1 diff --git a/test/fixtures/sales.yml b/test/fixtures/sales.yml new file mode 100644 index 00000000..412e9e21 --- /dev/null +++ b/test/fixtures/sales.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + amount: 1 + purchase_time: 2016-10-04 12:07:18 + vendor_id: 1 + product_id: 1 + +two: + amount: 1 + purchase_time: 2016-10-04 12:07:18 + vendor_id: 1 + product_id: 1 diff --git a/test/fixtures/vendors.yml b/test/fixtures/vendors.yml new file mode 100644 index 00000000..b36e126a --- /dev/null +++ b/test/fixtures/vendors.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + num_employees: 1 + market_id: 1 + +two: + name: MyString + num_employees: 1 + market_id: 1 diff --git a/test/models/market_test.rb b/test/models/market_test.rb new file mode 100644 index 00000000..62e16016 --- /dev/null +++ b/test/models/market_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MarketTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/product_test.rb b/test/models/product_test.rb new file mode 100644 index 00000000..211cdd0b --- /dev/null +++ b/test/models/product_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/sale_test.rb b/test/models/sale_test.rb new file mode 100644 index 00000000..8f0c60c0 --- /dev/null +++ b/test/models/sale_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SaleTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/vendor_test.rb b/test/models/vendor_test.rb new file mode 100644 index 00000000..07dd4193 --- /dev/null +++ b/test/models/vendor_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class VendorTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end