lk | update bike & report to use fixed_at instead of entry_date

This commit is contained in:
Louis Knapp
2016-07-17 12:35:13 -05:00
parent 898337a07e
commit 8a46a95678
4 changed files with 37 additions and 35 deletions
+3 -1
View File
@@ -45,6 +45,7 @@ class BikesController < ApplicationController
end
def update
if @bike.update(bike_params)
redirect_to @bike, notice: 'Bike was successfully updated.'
else
@@ -73,8 +74,9 @@ class BikesController < ApplicationController
end
def bike_params
params[:bike][:fixed_at] = DateTime.strptime(params[:bike][:fixed_at], "%m/%d/%Y") if params[:bike][:fixed_at]
params.require(:bike).permit(
:entry_date,
:fixed_at,
:brand,
:model,
:bike_type,
+3 -3
View File
@@ -4,8 +4,8 @@ class Report
def self.bikes_fixed_per_week
beginning_of_year = Time.now.beginning_of_year
bikes = Bike.where("entry_date > ?", beginning_of_year)
weekly_data = bikes.group_by{|b| DateTime.strptime(b.entry_date, "%m/%d/%y").beginning_of_week}
bikes = Bike.where("fixed_at > ? AND purpose = ?", beginning_of_year, Bike::SALE)
weekly_data = bikes.group_by{|b| b.fixed_at.beginning_of_week}
weekly_data.to_a.sort!{|a, b| a.first <=> b.first}.to_h
end
@@ -26,7 +26,7 @@ class Report
average_price = float_prices.inject{ |sum, el| el + sum } / float_prices.size
{k => average_price}
}
average_prices = average_price_array.reduce({}, :merge)
average_price_array.reduce({}, :merge)
end
def self.yearly_data
+2 -2
View File
@@ -52,9 +52,9 @@
= f.text_field :serial_number, class: "form-control", disabled: disabled
.form-group
= f.label "Date Finished:", class: "col-sm-4 control-label"
= f.label "Date Fixed:", class: "col-sm-4 control-label"
.col-sm-6
= f.text_field :entry_date, class: "form-control datepicker", disabled: disabled
= f.text_field :fixed_at, class: "form-control datepicker", :value => @bike.fixed_at ? @bike.fixed_at.strftime("%m/%d/%Y") : "", disabled: disabled
.row
.col-sm-6