diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..fadd49af Binary files /dev/null and b/.DS_Store differ diff --git a/Gemfile b/Gemfile index e87fad5f..8494f595 100644 --- a/Gemfile +++ b/Gemfile @@ -3,8 +3,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 @@ -35,6 +34,8 @@ 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' + # Use sqlite3 as the database for Active Record + gem 'sqlite3' end group :development do @@ -45,3 +46,7 @@ group :development do gem 'spring' end +group :production do + gem 'pg' + gem 'rails_12factor' +end diff --git a/Gemfile.lock b/Gemfile.lock index 6c97c19f..e3e361b4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -76,6 +76,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) rack (1.6.4) rack-test (0.6.3) @@ -99,6 +100,11 @@ GEM rails-deprecated_sanitizer (>= 1.0.1) 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) @@ -151,7 +157,9 @@ DEPENDENCIES coffee-rails (~> 4.1.0) jbuilder (~> 2.0) jquery-rails + pg rails (= 4.2.7) + rails_12factor sass-rails (~> 5.0) sdoc (~> 0.4.0) spring diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 00000000..b1504a01 Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/assets/images/fruits.jpg b/app/assets/images/fruits.jpg new file mode 100644 index 00000000..1e0f7cee Binary files /dev/null and b/app/assets/images/fruits.jpg differ diff --git a/app/assets/images/healthy-organic-food.jpg b/app/assets/images/healthy-organic-food.jpg new file mode 100644 index 00000000..3124bbf2 Binary files /dev/null and b/app/assets/images/healthy-organic-food.jpg differ diff --git a/app/assets/images/lemons.jpg b/app/assets/images/lemons.jpg new file mode 100644 index 00000000..3288390d Binary files /dev/null and b/app/assets/images/lemons.jpg differ diff --git a/app/assets/images/tomatoes.jpg b/app/assets/images/tomatoes.jpg new file mode 100644 index 00000000..83deaf55 Binary files /dev/null and b/app/assets/images/tomatoes.jpg differ diff --git a/app/assets/images/vege.jpeg b/app/assets/images/vege.jpeg new file mode 100644 index 00000000..d34ca264 Binary files /dev/null and b/app/assets/images/vege.jpeg differ diff --git a/app/assets/javascripts/markets.coffee b/app/assets/javascripts/markets.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/markets.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/products.coffee b/app/assets/javascripts/products.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/products.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/sales.coffee b/app/assets/javascripts/sales.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/sales.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/vendors.coffee b/app/assets/javascripts/vendors.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/vendors.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..32b264ef 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -1,3 +1,124 @@ +/*Section A: Overall font, background image, header, footer, body's background container */ + +* { + font-family: 'Lora', serif; +} + +body { + background-image: url("healthy-organic-food.jpg"); + background-size: auto; +} + +.container { + margin: 30px 30px 30px 30px; + padding: 3px 50px 5px 50px; + background-color: #F1F2F2; + opacity: 0.90; + border-radius: 20px; +} + +header { + border-bottom: 5px solid #CC3333; + font-weight: bolder; + text-align: center; + color: #CC3333; +} + +header p { + font-size: 30px; + margin: auto; + padding-top: 30px; + padding-bottom: 5px; +} + +header nav ul li { + font-size: 18px; + list-style-type: none; + display: inline-block; + padding-left: 20px; + padding-right: 20px; +} + +header nav ul li a:link { + text-decoration: none; + color: #CC3333; +} + +footer { + font-size: 15px; + color: #333333; + text-align: center; + margin-top: 100px; + line-height: 0.5; +} + +/*Section B: Content display for body's container*/ +main { + color: #333333; + line-height: 1.5; +} + +main h1 { + text-align: center; + font-size: 25px; +} + +main a:link { + text-decoration: none; + color: #CC3333; +} + +table { + border-collapse: collapse; + width: auto; +} + +th, td { + text-align: left; + padding: 15px; + border: 1px solid #CCCCCC; +} + +th { + font-weight: 600; + font-weight: bold; + color: black; + background-color: #CCCCCC; + border: 1px solid #F1F2F2; +} +/*Section C: This is the Overview page*/ + +.overview { + text-align: center; + margin-top: 50px; +} + +.overview li { + font-size: 25px; + list-style-type: none; + display: inline-block; + margin: 20px; + padding: 15px; + border: 2px solid #CC3333; +} + +.overview li a:link { + text-decoration: none; + color: #333333; +} + +.overview li a:visited { + text-decoration: none; + color: #333333; +} + + +/*MISC*/ + +a:hover { + background: #CCCCCC; +} + /* * 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/markets.scss b/app/assets/stylesheets/markets.scss new file mode 100644 index 00000000..98116b70 --- /dev/null +++ b/app/assets/stylesheets/markets.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Markets 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/products.scss b/app/assets/stylesheets/products.scss new file mode 100644 index 00000000..bff386e5 --- /dev/null +++ b/app/assets/stylesheets/products.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Products 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/sales.scss b/app/assets/stylesheets/sales.scss new file mode 100644 index 00000000..6f3405b9 --- /dev/null +++ b/app/assets/stylesheets/sales.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the sales 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/vendors.scss b/app/assets/stylesheets/vendors.scss new file mode 100644 index 00000000..94dd8d0b --- /dev/null +++ b/app/assets/stylesheets/vendors.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Vendor 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/.DS_Store b/app/controllers/.DS_Store new file mode 100644 index 00000000..4433ed77 Binary files /dev/null and b/app/controllers/.DS_Store differ diff --git a/app/controllers/markets_controller.rb b/app/controllers/markets_controller.rb new file mode 100644 index 00000000..a9a36b4b --- /dev/null +++ b/app/controllers/markets_controller.rb @@ -0,0 +1,77 @@ +class MarketsController < ApplicationController + def overview + end + + def view_markets # show all markets + @markets = Market.all + end + + def view_market # show a market + @market = Market.find(params[:id]) + @vendors = @market.vendors + end + + def index + @markets = Market.all + end + + def show + @market = Market.find(params[:id]) + end + + def new + @market = Market.new + end + + def create + @market = Market.new(market_params) + if @market.save + redirect_to markets_path + else + render :new + end + end + + def edit # + @market = Market.find(params[:id]) + end + + def update # + @market = Market.find(params[:id]) + if @market.update(market_params) + redirect_to markets_path + else + render :edit + end + end + + def market_vendors + @market = Market.find(params[:id]) + @vendors = @market.vendors + end + + def market_new_vendor + @market = Market.find(params[:id]) + @vendor = @market.vendors.build + end + + def market_create_vendor + @market = Market.find(params[:id]) + @vendor = @market.vendors.build(vendor_params) + if @vendor.save + redirect_to market_view_vendors_path + else + render :market_new_vendor + end + end + + private + + def market_params + params.require(:market).permit(:ref_id, :name, :address, :city, :county, :state, :zip) + end + + def vendor_params + params.require(:vendor).permit(:ref_id, :name, :num_employees, :market_id) + end +end diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb new file mode 100644 index 00000000..55125a90 --- /dev/null +++ b/app/controllers/products_controller.rb @@ -0,0 +1,54 @@ +class ProductsController < ApplicationController + + def index + @vendor = Vendor.find(params[:vendor_id]) + @products = @vendor.products + end + + def new + @vendor = Vendor.find(params[:vendor_id]) + @product = @vendor.products.build + end + + def create + @vendor = Vendor.find(params[:vendor_id]) + @product = @vendor.products.new(prod_params) + if @product.save + # SAVED SUCCESSFULLY + redirect_to vendor_products_path + else + # DID NOT SAVE + puts @product.errors.messages + render :new + end + end + + def edit + @vendor = Vendor.find(params[:vendor_id]) + @product = Product.find(params[:id]) + end + + def update + @vendor = Vendor.find(params[:vendor_id]) + @product = Product.find(params[:id]) + if @product.update(prod_params) + # SUCCESS + redirect_to vendor_products_path + else + # NOPE + render :edit + end + end + + def destroy + Product.find(params[:id]).destroy + redirect_to vendor_products_path + end + + private + + def prod_params + params.require(:product).permit(:ref_id, :name, :vendor_id) + end + +end diff --git a/app/controllers/sales_controller.rb b/app/controllers/sales_controller.rb new file mode 100644 index 00000000..feb57abd --- /dev/null +++ b/app/controllers/sales_controller.rb @@ -0,0 +1,32 @@ +class SalesController < ApplicationController + + def index + @vendor = Vendor.find(params[:vendor_id]) + @sales = @vendor.sales + end + + def new + @vendor = Vendor.find(params[:vendor_id]) + @sale = @vendor.sales.build + end + + def create + @vendor = Vendor.find(params[:vendor_id]) + @sale = @vendor.sales.new(sale_params) + if @sale.save + # SAVED SUCCESSFULLY + redirect_to vendor_sales_path + else + # DID NOT SAVE + puts @sale.errors.messages + render :new + end + end + + private + + def sale_params + params.require(:sale).permit(:ref_id, :product_id, :vendor_id, :amount, :purchase_time) + end + +end diff --git a/app/controllers/vendors_controller.rb b/app/controllers/vendors_controller.rb new file mode 100644 index 00000000..2450b332 --- /dev/null +++ b/app/controllers/vendors_controller.rb @@ -0,0 +1,60 @@ +class VendorsController < ApplicationController + + def index + @vendors = Vendor.all + end + + def show + @vendor = Vendor.find(params[:id]) + @products = @vendor.products + end + + def view_products + @vendor = Vendor.find(params[:id]) + @products = @vendor.products + end + + # This is double ^^ revisit routes + + def new + @vendor = Vendor.new + end + + def create + @vendor = Vendor.new(vend_params) + if @vendor.save + # SAVED SUCCESSFULLY + else + # DID NOT SAVE + render :new + end + + redirect_to vendors_path + end + + def edit + @vendor = Vendor.find(params[:id]) + end + + def update + @vendor = Vendor.find(params[:id]) + if @vendor.update(vend_params) + # SUCCESS + redirect_to vendors_path + else + # NOPE + render :edit + end + end + + def destroy + Vendor.find(params[:id]).destroy + redirect_to vendors_path + end + + private + + def vend_params + params.require(:vendor).permit(:ref_id, :name, :num_employees, :market_id) + end +end diff --git a/app/helpers/markets_helper.rb b/app/helpers/markets_helper.rb new file mode 100644 index 00000000..655b79b7 --- /dev/null +++ b/app/helpers/markets_helper.rb @@ -0,0 +1,2 @@ +module MarketsHelper +end diff --git a/app/helpers/products_helper.rb b/app/helpers/products_helper.rb new file mode 100644 index 00000000..ab5c42b3 --- /dev/null +++ b/app/helpers/products_helper.rb @@ -0,0 +1,2 @@ +module ProductsHelper +end diff --git a/app/helpers/sales_helper.rb b/app/helpers/sales_helper.rb new file mode 100644 index 00000000..8611c4a0 --- /dev/null +++ b/app/helpers/sales_helper.rb @@ -0,0 +1,2 @@ +module SalesHelper +end diff --git a/app/helpers/vendors_helper.rb b/app/helpers/vendors_helper.rb new file mode 100644 index 00000000..5429ffa4 --- /dev/null +++ b/app/helpers/vendors_helper.rb @@ -0,0 +1,2 @@ +module VendorsHelper +end diff --git a/app/models/market.rb b/app/models/market.rb new file mode 100644 index 00000000..bc1d0136 --- /dev/null +++ b/app/models/market.rb @@ -0,0 +1,8 @@ +class Market < ActiveRecord::Base + has_many :vendors + + def all_vendors + self.vendors + end + +end diff --git a/app/models/product.rb b/app/models/product.rb new file mode 100644 index 00000000..29761393 --- /dev/null +++ b/app/models/product.rb @@ -0,0 +1,5 @@ +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..11a86503 --- /dev/null +++ b/app/models/sale.rb @@ -0,0 +1,5 @@ +class Sale < ActiveRecord::Base + belongs_to :vendor + belongs_to :product + +end diff --git a/app/models/vendor.rb b/app/models/vendor.rb new file mode 100644 index 00000000..d9054bb8 --- /dev/null +++ b/app/models/vendor.rb @@ -0,0 +1,9 @@ +class Vendor < ActiveRecord::Base + belongs_to :market + has_many :products + has_many :sales + + def self.products + products + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 443f3152..601fc48a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -2,13 +2,38 @@ FarMarRails + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> +
+
+

FARMAR DATABASE

+ +
-<%= yield %> +
+ <%= yield %> +
+ + +
diff --git a/app/views/markets/_form.html.erb b/app/views/markets/_form.html.erb new file mode 100644 index 00000000..890b3444 --- /dev/null +++ b/app/views/markets/_form.html.erb @@ -0,0 +1,41 @@ +<%= form_for @market, method: http_method do |t| %> + +

+ <%= t.label "Reference ID" %> + <%= t.text_field :ref_id %> +

+ +

+ <%= t.label "Name" %> + <%= t.text_field :name %> +

+ + +

+ <%= t.label "Address" %> + <%= t.text_field :address %> +

+ +

+ <%= t.label "City" %> + <%= t.text_field :city %> +

+ +

+ <%= t.label "County" %> + <%= t.text_field :county %> +

+ +

+ <%= t.label "State" %> + <%= t.text_field :state %> +

+ +

+ <%= t.label "Zip" %> + <%= t.text_field :zip %> +

+ + <%= t.submit "Submit" %> + +<% end %> diff --git a/app/views/markets/edit.html.erb b/app/views/markets/edit.html.erb new file mode 100644 index 00000000..37949f50 --- /dev/null +++ b/app/views/markets/edit.html.erb @@ -0,0 +1,7 @@ +

Edit this entry: <%= @market.name %>

+ +

+ <%= link_to "Return to Markets Overview", markets_path %> +

+ +<%= render partial: "form", locals: { http_method: :patch} %> diff --git a/app/views/markets/index.html.erb b/app/views/markets/index.html.erb new file mode 100644 index 00000000..016254e4 --- /dev/null +++ b/app/views/markets/index.html.erb @@ -0,0 +1,23 @@ +

All Markets

+ +

+ <%= link_to "Create a new Market entry", new_market_path %> +

+ + + + + + + + + + <% @markets.each do |market| %> + + + + + + <% end %> +

+
NameDetailsUpdate
<%= market.name %><%= link_to "View", market_path(market) %><%= link_to "Edit", edit_market_path(market) %>
diff --git a/app/views/markets/market_new_vendor.html.erb b/app/views/markets/market_new_vendor.html.erb new file mode 100644 index 00000000..75b6475f --- /dev/null +++ b/app/views/markets/market_new_vendor.html.erb @@ -0,0 +1,39 @@ +

Create a new Vendor entry for <%= @market.name %>

+ +<%= form_for @vendor, url: market_post_vendor_path(@market.id) do |v| %> +

+ + <%# v.label :name %> + <%= v.text_field :name %> +

+ +

+ + <%# v.label "Reference ID" %> + <%= v.text_field :ref_id %> +

+ +

+ + <%# v.label :num_employees %> + <%= v.text_field :num_employees %> +

+ +

+ + <%# v.label "Market ID" %> + <%= v.text_field :market_id %> +

+ +

+ <%= v.submit "Submit" %> +

+<% end %> + +

+ <%= link_to "Return to list of Vendors participating in #{@market.name}", market_view_vendors_path%> +

+ +

+ <%= link_to "Return to #{@market.name}", market_path%> +

diff --git a/app/views/markets/market_vendors.html.erb b/app/views/markets/market_vendors.html.erb new file mode 100644 index 00000000..35cba285 --- /dev/null +++ b/app/views/markets/market_vendors.html.erb @@ -0,0 +1,20 @@ +

Vendors participating in <%= @market.name %>

+ +

+ <%= link_to "Return to #{@market.name}", market_path %> +

+ + + + + + + +<% @vendors.each do |vendor| %> + + + + + +<% end %> +
NameNumber of EmployeesUpdate
<%= vendor.name %><%= vendor.num_employees %><%= link_to "Edit", edit_vendor_path(vendor) %>, <%= link_to "Delete", vendor_path(vendor), method: :delete, data: { confirm: "Are you sure you want to delete the vendor?" } %>
Create a new Market entry + +

+ <%= link_to "Return to Markets Overview", markets_path%> +

+ +<%= render partial: "form", locals: { http_method: :post } %> diff --git a/app/views/markets/overview.html.erb b/app/views/markets/overview.html.erb new file mode 100644 index 00000000..0690960e --- /dev/null +++ b/app/views/markets/overview.html.erb @@ -0,0 +1,5 @@ + diff --git a/app/views/markets/show.html.erb b/app/views/markets/show.html.erb new file mode 100644 index 00000000..7272c54f --- /dev/null +++ b/app/views/markets/show.html.erb @@ -0,0 +1,41 @@ +

<%= @market.name %>

+ +

+ <%= link_to "Edit this Market entry", edit_market_path %> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name<%= @market.name %>
Address<%= @market.address %>
City<%= @market.city %>
County<%= @market.county %>
State<%= @market.state %>
Zip<%= @market.zip %>
+ +

+ <%= link_to "View all Vendors participating in this Market", market_view_vendors_path %> +

+ +

<%= link_to "Create a new Vendor", market_new_vendor_path %>

diff --git a/app/views/markets/view_market.html.erb b/app/views/markets/view_market.html.erb new file mode 100644 index 00000000..2d50e25e --- /dev/null +++ b/app/views/markets/view_market.html.erb @@ -0,0 +1,49 @@ +

<%= @market.name %>

+ +

+ <%= link_to "Return to Markets Overview", view_all_markets_path %> +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name<%= @market.name %>
Address<%= @market.address %>
City<%= @market.city %>
County<%= @market.county %>
State<%= @market.state %>
Zip<%= @market.zip %>
+ +

+ Vendors participating in <%= @market.name %>: +

+ + + + + <% @vendors.each do |vendor| %> + + + +<% end %> +
Vendors
<%= vendor.name %>
diff --git a/app/views/markets/view_markets.html.erb b/app/views/markets/view_markets.html.erb new file mode 100644 index 00000000..eacbae10 --- /dev/null +++ b/app/views/markets/view_markets.html.erb @@ -0,0 +1,12 @@ +

All Markets

+ +

+ Click on a Market to see details +

+ + <% @markets.each do |market| %> + + + + <% end %> +
<%= link_to market.name, view_market_path(market) %>
diff --git a/app/views/products/_form.html.erb b/app/views/products/_form.html.erb new file mode 100644 index 00000000..f5b3d161 --- /dev/null +++ b/app/views/products/_form.html.erb @@ -0,0 +1,8 @@ +<%= form_for [@vendor, @product] do |p| %> +

<%= p.label :name %> + <%= p.text_field :name %>

+ +

+ <%= p.submit "Submit" %> +

+<% end %> diff --git a/app/views/products/edit.html.erb b/app/views/products/edit.html.erb new file mode 100644 index 00000000..103015de --- /dev/null +++ b/app/views/products/edit.html.erb @@ -0,0 +1,5 @@ +

Edit this product:

+ +<%= render partial: "form", locals: { http_method: :patch } %> + +

<%= link_to "Return to Vendor's list of Products", vendor_products_path(@vendor.id) %>

diff --git a/app/views/products/index.html.erb b/app/views/products/index.html.erb new file mode 100644 index 00000000..7b1e84dd --- /dev/null +++ b/app/views/products/index.html.erb @@ -0,0 +1,26 @@ +

Products of <%= @vendor.name %>

+ +

<%= link_to "Create New Product", new_vendor_product_path(@vendor.id) %>

+ + + + + + + + +<% @products.each do |product| %> + + + + + + + +<% end %> + +
NameNew SaleUpdate
<%= product.name %><%= link_to "Create", new_vendor_sale_path(@vendor) %><%= link_to "Edit", edit_vendor_product_path(@vendor, product) %>, <%= link_to "Delete", vendor_product_path(@vendor, product), method: :delete, data: { confirm: "Are you sure you want to delete the product?" } %>
+ +

<%= link_to "See list of vendor's sales", vendor_sales_path(@vendor.id) %>

+ +

<%= link_to "Return to Vendor page", vendor_path(@vendor.id) %>

diff --git a/app/views/products/new.html.erb b/app/views/products/new.html.erb new file mode 100644 index 00000000..d74d1692 --- /dev/null +++ b/app/views/products/new.html.erb @@ -0,0 +1,5 @@ +

Create a new product

+ +<%= render partial: "form", locals: { http_method: :post } %> + + diff --git a/app/views/sales/index.html.erb b/app/views/sales/index.html.erb new file mode 100644 index 00000000..1aaf61c5 --- /dev/null +++ b/app/views/sales/index.html.erb @@ -0,0 +1,53 @@ +

Sales of <%= @vendor.name %>

+ +

+ <%= link_to "Return to Products page", vendor_products_path %> +

+ +

<%= link_to "Return to Vendor page", vendor_path(@vendor.id) %>

+ + + + + + + <% total = 0 %> + <% monthly_sales = [] %> + <% @sales.each do |s| %> + + + + <% total += s.amount %> + + + <% if s.purchase_time >= DateTime.now.at_beginning_of_month - 24.hours && s.purchase_time <= DateTime.now.at_end_of_month - 24.hours %> + <% monthly_sales << s %> + <% end %> + <% end %> +
AmountPurchase Date
<%= "$#{sprintf('%.2f' % (s.amount/100.0))}" %><%= s.purchase_time.strftime("%m/%d/%Y") %>
+ +

<%= "Total sales: $#{ sprintf('%.2f' % (total/100.0)) }" %>

+ +

+

Sales of current month:

+ <% if monthly_sales.count > 0 %> + <% monthly_total = 0 %> + + + + + + <% monthly_sales.each do |ms| %> + + + + <% monthly_total += ms.amount %> + + <% end %> +
AmountPurchase Date
<%= "$#{sprintf('%.2f' % (ms.amount/100.0))}" %><%= ms.purchase_time.strftime("%m/%d/%Y") %>
+ +

<%= "Monthly total: $#{ sprintf('%.2f' % (monthly_total/100.0)) }" %>

+ + <% else %> + <%= "No sales so far this month" %> + <% end %> diff --git a/app/views/sales/new.html.erb b/app/views/sales/new.html.erb new file mode 100644 index 00000000..656593fe --- /dev/null +++ b/app/views/sales/new.html.erb @@ -0,0 +1,17 @@ +

Add a Sale entry for <%= @vendor.name %>

+ +<%= form_for [@vendor, @sale] do |s| %> +

<%= s.label :amount %> + <%= s.text_field :amount %>

+ +

+ <%= s.label "Purchase date" %> + <%= s.date_field :purchase_time %> +

+ +

+ <%= s.submit "Submit" %> +

+<% end %> + +

<%= link_to "Return to Vendor's list of Products", vendor_products_path(@vendor.id) %>

diff --git a/app/views/vendors/_form.html.erb b/app/views/vendors/_form.html.erb new file mode 100644 index 00000000..2c2d235d --- /dev/null +++ b/app/views/vendors/_form.html.erb @@ -0,0 +1,14 @@ +<%= form_for @vendor do |v| %> +

<%= v.label "Name" %> + <%= v.text_field :name %>

+ +

<%= v.label "Number of employees" %> + <%= v.text_field :num_employees %>

+ +

<%= v.label "Market ID" %> + <%= v.text_field :market_id %>

+ +

+ <%= v.submit "Submit" %> +

+<% end %> diff --git a/app/views/vendors/edit.html.erb b/app/views/vendors/edit.html.erb new file mode 100644 index 00000000..dd6b528f --- /dev/null +++ b/app/views/vendors/edit.html.erb @@ -0,0 +1,5 @@ +

Edit existing vendor: <%=@vendor.name %>

+ +<%= render partial: "form" %> + +

<%= link_to "Return to Vendor page", vendor_path(@vendor.id) %>

diff --git a/app/views/vendors/index.html.erb b/app/views/vendors/index.html.erb new file mode 100644 index 00000000..54b2f170 --- /dev/null +++ b/app/views/vendors/index.html.erb @@ -0,0 +1,35 @@ +

Vendors List

+ +

+ <%= link_to "Create a new Vendor entry", new_vendor_path %> +

+ + + + + + + + + + + <% @vendors.each do |v| %> + + + + + + + + + <% end %> + +
+ Name + + Vendor's details + + Products & Sales details + + Update +
<%= "#{ v.name.capitalize } " %><%= link_to "View Vendor", vendor_path(v) %><%= link_to "View Products & Sales", vendor_products_path(v) %><%= link_to "Edit", edit_vendor_path(v) %>, <%= link_to "Delete", vendor_path(v), method: :delete, data: { confirm: "Are you sure you want to delete the vendor?" } %>
diff --git a/app/views/vendors/new.html.erb b/app/views/vendors/new.html.erb new file mode 100644 index 00000000..375bdfde --- /dev/null +++ b/app/views/vendors/new.html.erb @@ -0,0 +1,3 @@ +

Create a new vendor

+ +<%= render partial: "form" %> diff --git a/app/views/vendors/show.html.erb b/app/views/vendors/show.html.erb new file mode 100644 index 00000000..d009468d --- /dev/null +++ b/app/views/vendors/show.html.erb @@ -0,0 +1,17 @@ +

Vendor: <%= @vendor.name %>

+ +

<%= link_to "Edit this Vendor entry", edit_vendor_path(@vendor)%>

+ + + + + + + + + +
Number of employees<%= @vendor.num_employees %>
Market ID<%= @vendor.market_id %>
+ +

<%= link_to "View Products", vendor_view_products_path(@vendor.id) %>

+ +

<%= link_to "View Sales", vendor_sales_path(@vendor.id) %>

diff --git a/app/views/vendors/view_products.html.erb b/app/views/vendors/view_products.html.erb new file mode 100644 index 00000000..1d4ca16b --- /dev/null +++ b/app/views/vendors/view_products.html.erb @@ -0,0 +1,23 @@ + + +

List of <%= @vendor.name %>'s Products

+ +

+ <%= link_to "Return to Vendor", vendor_path %> +

+ +

Products:

+ +<% @products.each do |product| %> + +<% end %> + +<%= link_to "Create a new product", new_vendor_product_path(@vendor.id) %> + +<%= link_to "View list of vendor's sales", vendor_sales_path(@vendor.id) %> diff --git a/config/environments/production.rb b/config/environments/production.rb index 5c1b32e4..323e73cd 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -29,7 +29,7 @@ # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false + config.assets.compile = true # Asset digests allow you to set far-future HTTP expiration dates on all assets, # yet still be able to expire them through the digest params. @@ -76,4 +76,7 @@ # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false + + config.serve_static_assets = true + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' end diff --git a/config/routes.rb b/config/routes.rb index 3f66539d..464234e9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,20 @@ Rails.application.routes.draw do + root 'markets#overview' + get '/markets/view', to: 'markets#view_markets', as: 'view_all_markets' + get '/markets/view/:id', to: 'markets#view_market', as: 'view_market' + + resources :markets, except: [:destroy] + get '/markets/:id/vendors', to: 'markets#market_vendors', as: 'market_view_vendors' + get '/markets/:id/vendors/new', to: 'markets#market_new_vendor', as: 'market_new_vendor' + post '/markets/:id/vendors', to: 'markets#market_create_vendor', as: 'market_post_vendor' + + resources :vendors do + resources :products, except: [:show] + resources :sales, only: [:index, :create, :new] + end + + get '/vendors/:id/products', to: 'vendors#view_products', as: 'vendor_view_products' + # 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/20161004204756_create_markets.rb b/db/migrate/20161004204756_create_markets.rb new file mode 100644 index 00000000..7d76b41b --- /dev/null +++ b/db/migrate/20161004204756_create_markets.rb @@ -0,0 +1,15 @@ +class CreateMarkets < ActiveRecord::Migration + def change + create_table :markets do |t| + t.integer :ref_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/20161004205803_create_vendors.rb b/db/migrate/20161004205803_create_vendors.rb new file mode 100644 index 00000000..c892e1f7 --- /dev/null +++ b/db/migrate/20161004205803_create_vendors.rb @@ -0,0 +1,13 @@ +class CreateVendors < ActiveRecord::Migration + def change + create_table :vendors do |t| + t.belongs_to :market, index: true + t.integer :ref_id + t.string :name + t.integer :num_employees + t.integer :ref_id_market + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004210355_create_products.rb b/db/migrate/20161004210355_create_products.rb new file mode 100644 index 00000000..93f1807a --- /dev/null +++ b/db/migrate/20161004210355_create_products.rb @@ -0,0 +1,12 @@ +class CreateProducts < ActiveRecord::Migration + def change + create_table :products do |t| + t.belongs_to :vendor, index: true + t.integer :ref_id + t.string :name + t.integer :ref_id_vendor + + t.timestamps null: false + end + end +end diff --git a/db/migrate/20161004210435_create_sales.rb b/db/migrate/20161004210435_create_sales.rb new file mode 100644 index 00000000..d8f2dc5a --- /dev/null +++ b/db/migrate/20161004210435_create_sales.rb @@ -0,0 +1,15 @@ +class CreateSales < ActiveRecord::Migration + def change + create_table :sales do |t| + t.belongs_to :vendor, index: true + t.belongs_to :product, index: true + t.integer :ref_id + t.integer :amount + t.datetime :purchase_time + t.integer :ref_id_vendor + t.integer :ref_id_product + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..5c1d100c --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,66 @@ +# 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: 20161004210435) do + + create_table "markets", force: :cascade do |t| + t.integer "ref_id" + 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.integer "ref_id" + t.string "name" + t.integer "ref_id_vendor" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "products", ["vendor_id"], name: "index_products_on_vendor_id" + + create_table "sales", force: :cascade do |t| + t.integer "vendor_id" + t.integer "product_id" + t.integer "ref_id" + t.integer "amount" + t.datetime "purchase_time" + t.integer "ref_id_vendor" + t.integer "ref_id_product" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "sales", ["product_id"], name: "index_sales_on_product_id" + add_index "sales", ["vendor_id"], name: "index_sales_on_vendor_id" + + create_table "vendors", force: :cascade do |t| + t.integer "market_id" + t.integer "ref_id" + t.string "name" + t.integer "num_employees" + t.integer "ref_id_market" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "vendors", ["market_id"], name: "index_vendors_on_market_id" + +end diff --git a/db/seeds.rb b/db/seeds.rb index 4edb1e85..0222e845 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -5,3 +5,25 @@ # # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # Mayor.create(name: 'Emanuel', city: cities.first) + +require 'csv' + +CSV.read('seed_csvs/markets.csv').each do |line| + market_hash = { ref_id: line[0].to_i, name: line[1], address: line[2], city: line[3], county: line[4], state: line[5], zip: line[6]} + Market.create(market_hash) +end + +CSV.read('seed_csvs/vendors.csv').each do |line| + vendor_hash = { ref_id: line[0].to_i, name: line[1], num_employees: line[2].to_i, market_id: line[3].to_i} + Vendor.create(vendor_hash) +end + +CSV.read('seed_csvs/products.csv').each do |line| + product_hash = { ref_id: line[0].to_i, name: line[1], vendor_id: line[2].to_i} + Product.create(product_hash) +end + +CSV.read('seed_csvs/sales.csv').each do |line| + sale_hash = { ref_id: line[0].to_i, amount: line[1].to_i, purchase_time: DateTime.parse(line[2]), vendor_id: line[3].to_i, product_id: line[4].to_i} + Sale.create(sale_hash) +end diff --git a/delete-me.txt b/delete-me.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/test/controllers/markets_controller_test.rb b/test/controllers/markets_controller_test.rb new file mode 100644 index 00000000..f43ed535 --- /dev/null +++ b/test/controllers/markets_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class MarketsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/products_controller_test.rb b/test/controllers/products_controller_test.rb new file mode 100644 index 00000000..c881fa68 --- /dev/null +++ b/test/controllers/products_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class ProductsControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/sales_controller_test.rb b/test/controllers/sales_controller_test.rb new file mode 100644 index 00000000..669ca5cf --- /dev/null +++ b/test/controllers/sales_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SalesControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/vendors_controller_test.rb b/test/controllers/vendors_controller_test.rb new file mode 100644 index 00000000..40e26779 --- /dev/null +++ b/test/controllers/vendors_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..3b9d7c84 --- /dev/null +++ b/test/fixtures/markets.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + ref_id: + name: MyString + address: MyString + city: MyString + county: MyString + state: MyString + zip: MyString + +two: + ref_id: + 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..5a479060 --- /dev/null +++ b/test/fixtures/products.yml @@ -0,0 +1,11 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + ref_id: 1 + name: MyString + ref_id_vendor: 1 + +two: + ref_id: 1 + name: MyString + ref_id_vendor: 1 diff --git a/test/fixtures/sales.yml b/test/fixtures/sales.yml new file mode 100644 index 00000000..d1c32fd9 --- /dev/null +++ b/test/fixtures/sales.yml @@ -0,0 +1,15 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + ref_id: 1 + amount: 1 + purchase_time: 2016-10-04 14:04:35 + ref_id_vendor: 1 + ref_id_product: 1 + +two: + ref_id: 1 + amount: 1 + purchase_time: 2016-10-04 14:04:35 + ref_id_vendor: 1 + ref_id_product: 1 diff --git a/test/fixtures/vendors.yml b/test/fixtures/vendors.yml new file mode 100644 index 00000000..28446a76 --- /dev/null +++ b/test/fixtures/vendors.yml @@ -0,0 +1,13 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + ref_id: 1 + name: MyString + num_employees: 1 + ref_id_market: 1 + +two: + ref_id: 1 + name: MyString + num_employees: 1 + ref_id_market: 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