Class: GenerateQuoteWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Workers::StatusBroadcastable
Defined in:
app/workers/generate_quote_worker.rb

Overview

Sidekiq worker: generate quote.

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/workers/generate_quote_worker.rb', line 10

def perform(options = {})
  options = options.deep_symbolize_keys
  quote = Quote.find(options[:quote_id])
  quote_options = options[:quote_options] || {}
  quote.room_configurations.reject(&:quoted_heating_system_pl_id).each(&:set_quoted_heating_system_product_line)
  quote_upload_category = options[:preview].to_b ? 'preview_organization_quote_pdf' : 'organization_quote_pdf'
  quote_upload_category = 'materials_pdf' if quote_options.dig(:materials_only).to_b

  combined_pdf_result = Quote::CombinedPdfGenerator.new.process(quote, quote_options) do |current_step, total_steps, message|
    total total_steps
    at(current_step, message)
  end

  if options[:preview].to_b
    upload = Upload.uploadify(combined_pdf_result.pdf_file_path,
                              quote_upload_category)
    store upload_id: upload.id
  else
    new_uploads = []
    upload = Upload.uploadify(combined_pdf_result.pdf_file_path,
                              quote_upload_category,
                              quote, combined_pdf_result.file_name)
    quote.uploads << upload
    new_uploads << upload
    if combined_pdf_result.copy_of_plans_pdf_file_path
      plans_upload = Upload.uploadify(combined_pdf_result.copy_of_plans_pdf_file_path,
                                      'copy_of_plans_pdf',
                                      quote, combined_pdf_result.copy_of_plans_file_name)
      quote.uploads << plans_upload
      new_uploads << plans_upload
    end
    combined_pdf_result.additional_attachments.each do |upload_id|
      new_uploads << Upload.find(upload_id)
    end
    store redirect_to: "/quotes/#{quote.id}/build_communication?#{new_uploads.map { |u| "upload_ids[]=#{u.id}" }.join('&')}"
  end
end