Class: CreateReceiptsWorker
Instance Attribute Summary
#broadcast_status_updates
Instance Method Summary
collapse
#at, #store, #total
Instance Method Details
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'app/workers/create_receipts_worker.rb', line 6
def perform(options = {})
options = options.with_indifferent_access
options = options.deep_symbolize_keys
excel_file = Upload.find_by(id: options[:upload_id])
report = Receipt.create_receipts_from_xlsx(excel_file) do |current_step, total_steps, message|
total total_steps
at(current_step, message)
end
excel_file.destroy
if report[:errors].any?
message = report[:errors].join('. ')
store redirect_to: '/receipts/create_from_excel'
store error_message: message
else
message = report[:successes].join('. ')
store redirect_to: "/receipts/imported?new_receipt_ids%5B%5D=#{report[:new_receipt_ids].join('&new_receipt_ids%5B%5D=')}"
store message: message
end
end
|