mirror of
https://github.com/fspc/bike-database.git
synced 2026-09-16 08:31:39 -04:00
lk | update bike & report to use fixed_at instead of entry_date
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user