Class: Returns::SendFirstReminder

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/returns/send_first_reminder.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SendFirstReminder

Returns a new instance of SendFirstReminder.



9
10
11
# File 'app/services/returns/send_first_reminder.rb', line 9

def initialize(options={})
  @renderer = PdfRenderer.new
end

Instance Attribute Details

#rendererObject (readonly)

Returns the value of attribute renderer.



7
8
9
# File 'app/services/returns/send_first_reminder.rb', line 7

def renderer
  @renderer
end

Instance Method Details

#process(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/returns/send_first_reminder.rb', line 13

def process(options = {})
  processed_rmas = []
  invoices = Invoice.joins(order: [:rma, deliveries: [:payments]]).where("invoices.state = ? and payments.category = ? and invoices.document_date = ? and rmas.state = ?", 'unpaid', Payment::ADV_REPL, 10.days.ago.to_date, 'awaiting_return')

  invoices.each do |i|
    rma = i.order.rma
    next if rma.skip_reminders
    keep_as_draft = rma.transmission_email.empty? and rma.transmission_fax.empty?
    comm = CommunicationBuilder.new(resource: i.order.rma, merge_options: {invoice: i, rma: i.order.rma}, template_system_code: 'RMA_REMINDER_1').create(keep_as_draft: keep_as_draft)
    if keep_as_draft == true
      # couldn't send as no email/fax listed on the RMA
      InternalMailer.unable_to_deliver_rma_reminder(rma, comm).deliver_later
    end
    processed_rmas << i.order.rma.rma_number
  end

  Result.new({rmas: processed_rmas})
end