mirror of
				https://github.com/fspc/bike-database.git
				synced 2025-10-31 08:45:34 -04:00 
			
		
		
		
	lk | client completion date is merged into client pickup date
This commit is contained in:
		
							parent
							
								
									ad76766402
								
							
						
					
					
						commit
						f694d8c238
					
				| @ -67,13 +67,6 @@ class BikesController < ApplicationController | ||||
|     end | ||||
|   end | ||||
| 
 | ||||
|   def mark_picked_up | ||||
|     @bike = Bike.find(params[:id]) | ||||
|     @bike.mark_picked_up | ||||
|     flash[:notice] = @bike.name + ' was marked as picked up' | ||||
|     redirect_to action: "ready_for_pickup", controller: "freecyclery" | ||||
|   end | ||||
| 
 | ||||
|   private | ||||
|     def set_bike | ||||
|       @bike = Bike.find(params[:id]) | ||||
|  | ||||
| @ -24,7 +24,11 @@ class ClientsController < ApplicationController | ||||
| 
 | ||||
|   def update | ||||
|     if @client.update(client_params) | ||||
|       redirect_to edit_client_url(@client), notice: 'Client was successfully updated.' | ||||
|       notice = 'Client was successfully updated.' | ||||
|       unless @client.bike.update_attribute(:date_sold, @client.pickup_date) | ||||
|         notice = "Unable to update client's bike sale date" | ||||
|       end | ||||
|       redirect_to edit_client_url(@client), notice: notice | ||||
|     else | ||||
|       render action: 'edit' | ||||
|     end | ||||
| @ -46,7 +50,6 @@ class ClientsController < ApplicationController | ||||
|         :weight, | ||||
|         :helmet, | ||||
|         :lock, | ||||
|         :completion_date, | ||||
|         :bike_id, | ||||
|         :will_pay, | ||||
|         :bike_type_requested, | ||||
|  | ||||
| @ -43,11 +43,6 @@ class Bike < ActiveRecord::Base | ||||
|     all_freecyclery_bikes - assigned_bikes | ||||
|   end | ||||
| 
 | ||||
|   def mark_picked_up | ||||
|     current_date = Time.new.strftime("%Y-%m-%d") | ||||
|     self.update_attribute(:date_sold, current_date) | ||||
|   end | ||||
| 
 | ||||
|   def post_to_bike_index | ||||
|     return true if self.bike_index_id.present? | ||||
|     BikeIndexLogger.perform_async(self.id) | ||||
|  | ||||
| @ -7,7 +7,7 @@ class Client < ActiveRecord::Base | ||||
|   def self.waiting_list | ||||
|     clients = Client.all | ||||
|     non_voided_clients = clients.select{|client| !client.application_voided} | ||||
|     waiting_list_with_null_application_dates = non_voided_clients.select{|client| !client.completion_date} | ||||
|     waiting_list_with_null_application_dates = non_voided_clients.select{|client| !client.pickup_date} | ||||
|     clients_with_bikes = Client.all.select{|c| !c.bike_id.nil?} | ||||
|     waiting_list = waiting_list_with_null_application_dates.select{|client| !client.application_date.nil?} - clients_with_bikes | ||||
|     waiting_list.sort_by!{|client| client.application_date} | ||||
| @ -18,7 +18,7 @@ class Client < ActiveRecord::Base | ||||
|   end | ||||
| 
 | ||||
|   def self.closed_applications | ||||
|     Client.all.select{|client| client.application_voided || client.completion_date} | ||||
|     Client.all.select{|client| client.application_voided || client.pickup_date} | ||||
|   end | ||||
| 
 | ||||
|   def bike | ||||
|  | ||||
| @ -60,11 +60,6 @@ | ||||
|     .col-sm-10 | ||||
|       = f.check_box :lock, disabled: disabled | ||||
| 
 | ||||
|   .form-group | ||||
|     = f.label "Completion Date:", class: "col-sm-2 control-label" | ||||
|     .col-sm-10 | ||||
|       = f.text_field :completion_date, class: "form-control datepicker", disabled: disabled | ||||
| 
 | ||||
|   .form-group | ||||
|     = f.label "Bike:", class: "col-sm-2 control-label" | ||||
|     .col-sm-10 | ||||
|  | ||||
| @ -14,6 +14,6 @@ | ||||
|           %tr | ||||
|             %td= client.name | ||||
|             %td= client.application_voided | ||||
|             %td= client.completion_date | ||||
|             %td= client.pickup_date | ||||
|             %td= link_to 'Edit', edit_client_path(client) | ||||
|     %br | ||||
|  | ||||
| @ -7,11 +7,9 @@ | ||||
|       %tr | ||||
|         %th Bike | ||||
|         %th Client | ||||
|         %th | ||||
|     %tbody | ||||
|       - @bikes_for_pickup.each do |bike| | ||||
|         %tr | ||||
|           %td= bike.name | ||||
|           %td= bike.client.name | ||||
|           %td= button_to "Mark as picked up", {controller: "bikes", action: "mark_picked_up", id: bike.id}, method: :patch, class: "btn btn-default" | ||||
| 
 | ||||
|  | ||||
| @ -12,7 +12,6 @@ Bikedb::Application.routes.draw do | ||||
|     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 | ||||
|     patch 'mark_picked_up' => 'bikes#mark_picked_up', on: :member | ||||
|   end | ||||
| 
 | ||||
|   resources :volunteers | ||||
|  | ||||
| @ -0,0 +1,5 @@ | ||||
| class RemoveCompletionDateFromClient < ActiveRecord::Migration | ||||
|   def change | ||||
|     remove_column :clients, :completion_date | ||||
|   end | ||||
| end | ||||
| @ -11,7 +11,7 @@ | ||||
| # | ||||
| # It's strongly recommended that you check this file into your version control system. | ||||
| 
 | ||||
| ActiveRecord::Schema.define(version: 20151013231450) do | ||||
| ActiveRecord::Schema.define(version: 20151205223152) do | ||||
| 
 | ||||
|   # These are extensions that must be enabled in order to support this database | ||||
|   enable_extension "plpgsql" | ||||
|  | ||||
| @ -35,7 +35,6 @@ namespace :db do | ||||
|         weight: rand(100) + 100, | ||||
|         helmet: [true, false].sample, | ||||
|         lock: [true, false].sample, | ||||
|         completion_date: [rand(30.days).ago, nil].sample, | ||||
|         bike_type_requested: ["Cruiser", "Road", "Mountain"].sample, | ||||
|         will_pay: [true, false].sample, | ||||
|         notes: "A great client!", | ||||
|  | ||||
| @ -14,7 +14,7 @@ describe Client do | ||||
| 
 | ||||
|     end | ||||
|     it "does not include completed clients" do | ||||
|       create(:client, completion_date: 1.week.ago) | ||||
|       create(:client, pickup_date: 1.week.ago) | ||||
|       expect(Client.waiting_list).to be_empty | ||||
|     end | ||||
|   end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user