diff --git a/app/controllers/bikes_controller.rb b/app/controllers/bikes_controller.rb index c55ca4c..7d8d1fb 100644 --- a/app/controllers/bikes_controller.rb +++ b/app/controllers/bikes_controller.rb @@ -38,6 +38,10 @@ class BikesController < ApplicationController end end + def freecyclery_pickup + @bikes_for_pickup = Bike.bikes_ready_for_pickup + end + def update if @bike.update(bike_params) redirect_to @bike, notice: 'Bike was successfully updated.' diff --git a/app/models/bike.rb b/app/models/bike.rb index 454ebe4..a295c73 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -10,4 +10,17 @@ class Bike < ActiveRecord::Base self.brand + ' ' + self.model end + def client + client = Client.find_by bike_id: self.id + end + + def ready_for_pickup? + client = self.client + client && self.completion_date && !client.application_voided + end + + def self.bikes_ready_for_pickup + Bike.all.select{|bike| bike.ready_for_pickup?} + end + end diff --git a/app/models/client.rb b/app/models/client.rb index 8840405..8854e5b 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -9,4 +9,8 @@ class Client < ActiveRecord::Base waiting_list = incomplete_clients.sort_by!{|client| client.application_date} end + def name + self.first_name + ' ' + self.last_name + end + end diff --git a/app/views/bikes/freecyclery_pickup.html.haml b/app/views/bikes/freecyclery_pickup.html.haml new file mode 100644 index 0000000..60cbfa0 --- /dev/null +++ b/app/views/bikes/freecyclery_pickup.html.haml @@ -0,0 +1,17 @@ +.container + %br + + %h1 Freecyclery Bikes for Pickup + %table.table.table-striped.table-bordered.table-hover + %thead + %tr + %th Brand + %th Model + %th Client + %tbody + - @bikes_for_pickup.each do |bike| + %tr + %td= bike.brand + %td= bike.model + %td= bike.client.name + diff --git a/app/views/static_pages/home.html.haml b/app/views/static_pages/home.html.haml index 92ff605..c8f8a33 100644 --- a/app/views/static_pages/home.html.haml +++ b/app/views/static_pages/home.html.haml @@ -8,3 +8,5 @@ = link_to "Print Sale Bike Labels", print_select_bikes_path %br = link_to "Freecyclery Agencies", agencies_path + %br + = link_to "Freecyclery Bikes Ready for Pickup", freecyclery_pickup_bikes_path diff --git a/config/routes.rb b/config/routes.rb index 53c2bae..d8a8d7d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,7 @@ Bikedb::Application.routes.draw do resources :bikes do get 'print_select' => 'bikes#print_select', on: :collection get 'print_labels' => 'bikes#print_labels', on: :collection + get 'freecyclery_pickup' => 'bikes#freecyclery_pickup', on: :collection patch 'mark_as_sold' => 'bikes#mark_as_sold', on: :member end