diff --git a/app/controllers/checklists_controller.rb b/app/controllers/checklists_controller.rb index 859909f..19f7278 100644 --- a/app/controllers/checklists_controller.rb +++ b/app/controllers/checklists_controller.rb @@ -15,11 +15,30 @@ def show respond_to do |format| format.html format.pdf do - render pdf: 'Checklist', layout: 'pdf.pdf.erb', - title: "Checklist for #{@checklist.vehicle.car_id} for Event #{@checklist.event.id}" # Excluding ".pdf" extension. + render pdf: 'Checklist', + layout: 'pdf.pdf.erb', + title: "Checklist for #{@checklist.vehicle.car_id} for Event #{@checklist.event.id}" end end end + + def create_work_order + @checklist = Checklist.find(params[:checklist_id]) + @vehicle = Vehicle.find(params[:vehicle_id]) + @repairs = Program.find_by(name: 'Repairs') + @request = Request.create(status: 'New', program_id: @repairs.id, + description: '****** Please fill this in ******', + creator: current_user.name, request_mileage: @vehicle.mileage, + vehicle_id: @vehicle.id, creator: User.find(@checklist.user.id).name, + completion_date: (Time.now + 7.days), request_mileage: @vehicle.mileage, + checklist_id: @checklist.id, completed_date: Date.current) + if @request.save + flash[:notice] = 'Work Order Created! Please select Service, Status and enter dates.' + else + flash[:alert] = 'Could not create Work Order!' + end + redirect_to edit_request_path(id: @request.id) + end def edit @vehicle = @checklist.vehicle @@ -40,7 +59,6 @@ def create format.json { render :show, status: :created, location: @checklist } else format.html { render :new } - format.json { render json: @checklist.errors, status: :unprocessable_entity } end end end @@ -49,10 +67,8 @@ def update respond_to do |format| if @checklist.update(checklist_params) format.html { redirect_to @checklist, notice: 'Checklist was successfully updated.' } - format.json { render :show, status: :ok, location: @event } else format.html { render :edit } - format.json { render json: @checklist.errors, status: :unprocessable_entity } end end end @@ -61,7 +77,6 @@ def destroy @event.destroy respond_to do |format| format.html { redirect_to events_url, notice: 'Checklist was successfully destroyed.' } - format.json { head :no_content } end end diff --git a/app/controllers/defects_controller.rb b/app/controllers/defects_controller.rb index f672d43..9eceeb8 100644 --- a/app/controllers/defects_controller.rb +++ b/app/controllers/defects_controller.rb @@ -1,6 +1,16 @@ # frozen_string_literal: true class DefectsController < ApplicationController + + def by_event + @events = Event.where(checklists_completed: true).page(params[:page]) + end + + def index + @q = Defect.all.ransack(params[:q]) + @defects = @q.result.page(params[:page]) + end + def create @defect = Defect.new(defect_params) respond_to do |format| diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 99d0cf8..f5ce0b8 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -31,12 +31,16 @@ def show def vehicle_rotation_metrics; end def dashboard - @display_events = Event.where('date >= ? AND date <= ?', Time.current - 7.days, Time.current + 14.days) + @display_events = Event.where('date >= ? AND date <= ?', Date.current - 7.days, Date.current + 14.days) + @set_completed_events = Event.where('date <= ?', Date.current) @scheduled_events = Event.where(status: 'Scheduled') @completed_events = Event.where(status: 'Completed') @assigned_events = Event.where(status: 'Vehicles Assigned') @date = params[:date] ? Date.parse(params[:date]) : Date.today @events_by_date = Event.group('events.id').group_by(&:date) + @set_completed_events.all.each do |event| + event.set_checklists_completed + end end def next_month_calendar diff --git a/app/controllers/requests_controller.rb b/app/controllers/requests_controller.rb index c46c098..f0ea844 100644 --- a/app/controllers/requests_controller.rb +++ b/app/controllers/requests_controller.rb @@ -9,8 +9,6 @@ class RequestsController < ApplicationController defects repairs completed_requests in_progress] before_action :check_quant, only: [:show] - # GET /requests - # GET /requests.json def index @requests = Request.all.page(params[:page]) @q = Request.ransack(params[:q]) @@ -117,7 +115,7 @@ def create_work_order @other_service = Program.find_by(name: 'Other Service') @request = Request.create(status: 'New', program_id: @other_service.id, vehicle_id: params[:id], description: '****** Please fill this in ******', completion_date: Date.current, - creator: current_user.name, work_order_mileage: Vehicle.find(params[:id].mileage)) + creator: current_user.name, request_mileage: Vehicle.find(params[:id].mileage)) if @request.save flash[:notice] = 'Work Order Created! Please select Service, Status and enter dates.' else @@ -182,12 +180,10 @@ def check_quant redirect_back(fallback_location: root_path) if @part_quant.ids == Part.ids end - # GET /requests/new def new @request = Request.new end - # GET /requests/1/edit def edit @q = Part.ransack(params[:q]) @parts = @q.result.page(params[:page]) @@ -313,7 +309,6 @@ def destroy private - # Use callbacks to share common setup or constraints between actions. def set_request @request = Request.find(params[:id]) end @@ -331,11 +326,6 @@ def set_services @tour_car_prep = Program.find_by(name: 'Tour Car Prep') end - def set_services - @programs = Program.all - end - # Never trust parameters from the scary internet, only allow the white list through. - def request_params params.require(:request).permit(:number, :description, :special_requets, :completion_date, :completed_date, :poc, :checklist_numb, :creator, :vehicle_id, :status, :image, :creator, :request_mileage, :program_id, part_ids: [], user_ids: []) end diff --git a/app/helpers/checklist_helper.rb b/app/helpers/checklist_helper.rb deleted file mode 100644 index 58d9469..0000000 --- a/app/helpers/checklist_helper.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -module ChecklistHelper -end diff --git a/app/helpers/checklists_helper.rb b/app/helpers/checklists_helper.rb new file mode 100644 index 0000000..c9cd856 --- /dev/null +++ b/app/helpers/checklists_helper.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +module ChecklistsHelper + def status_symbol(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + 'fa-check' + else + "fa-thumbs-down" + end + else + "fa-thumbs-down" + end + end + + def status_word(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + 'Completed' + else + "Not Completed" + end + else + "Not Created" + end + end + + def status_word_color(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + 'text-success' + else + "text-warning" + end + else + "text-danger" + end + end + + def status_date_word(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + vehicle.checklists.find_by(event_id: event.id).date.strftime('%D') + else + "Not Completed" + end + else + "Not Created" + end + end + + def deadline_word(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + if vehicle.checklists.find_by(event_id: event.id).deadline + 'Deadlined' + else + 'Not Deadlined' + end + else + "Not Completed" + end + else + "Not Created" + end + end + + def deadline_badge_color(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + if vehicle.checklists.find_by(event_id: event.id).deadline + 'badge-danger' + else + 'badge-success' + end + else + 'badge-warnining' + end + end + end + + def deadline_symbol(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + if vehicle.checklists.find_by(event_id: event.id).deadline + 'fa-exclamation-triangle' + else + 'fa-check' + end + else + 'fa-thumbs-down' + end + end + end + + def checklist_link(vehicle, event) + unless vehicle.checklists.empty? + if vehicle.checklists.where(event_id: event.id).exists? + link_to "Show Checklist", checklist_path( vehicle.checklists.find_by(event_id: event.id).id), class: "btn btn-danger btn-sm" + else + "Not Completed" + end + else + "Not Created" + end + end +end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 794dea2..62951fb 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -22,12 +22,10 @@ def checklist_button_color(checklists, vehicle) end def calendar_symbol(event) - if event.checklists.exists? - if event.checklists_completed + if event.vehicles.exists? && event.checklists_completed 'fa-check' - else + elsif !event.checklists_completed && event.vehicles.exists? 'fa-exclamation-triangle' - end else 'fa-car' end diff --git a/app/models/event.rb b/app/models/event.rb index 17d89c2..bb79152 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -39,8 +39,12 @@ def set_shares self.shares = 0 if shares.blank? end - def checklists_completed - self.checklists_completed = true if self.checklists.exists? && self.vehicles.count == Checklist.where(event_id: self.id, completed: true).count + def set_checklists_completed + if self.vehicles.count == Checklist.where(event_id: self.id, completed: true).count + self.update(checklists_completed: true) + else + self.update(checklists_completed: false) + end end def is_completed? diff --git a/app/views/checklists/edit.html.erb b/app/views/checklists/edit.html.erb index d9d069b..e483816 100644 --- a/app/views/checklists/edit.html.erb +++ b/app/views/checklists/edit.html.erb @@ -1,5 +1,5 @@
Created On | +Vehicle | +Category | +Description | +Status | +Date Fixed | ++ |
---|---|---|---|---|---|---|
+ + + <%= defect.created_at.strftime('%v') %> + ++ |
+ <%= link_to defect.vehicle.car_id, vehicle_path(defect.vehicle.id), class: "badge badge-danger"%> | +<%= defect.category %> | +<%= defect.description %> | +
+ + + <%= fixed_defect_word defect %> + ++ |
+
+ + + <%= defect_date defect%> + ++ |
+ + <% if defect.checklist %> + <%= link_to 'Checklist', checklist_path(defect.checklist.id), class: "btn btn-danger" %> + <% end %> + | +
Created On | +Vehicle | +Category | +Description | +Status | +Date Fixed | ++ |
---|
diff --git a/app/views/requests/show.html.erb b/app/views/requests/show.html.erb
index 886de72..68076e2 100644
--- a/app/views/requests/show.html.erb
+++ b/app/views/requests/show.html.erb
@@ -231,10 +231,10 @@
<%= render 'custom_form'%>
- <% if @parts.count != @number%>
+ <% if @parts.count != @number %>
<% Part::CATEGORIES.each do |category|%>
- <% if @parts.where(category: category) != []%>
+ <% unless @parts.where(category: category).empty? %>
<%= label_tag category %>