Class: PayrollRunMailer

Inherits:
ApplicationMailer show all
Includes:
ActionView::Helpers::NumberHelper
Defined in:
app/mailers/payroll_run_mailer.rb

Instance Method Summary collapse

Instance Method Details

#approval_request(reviewer:, step_data:, payroll_transaction_header_id:) ⇒ Object



6
7
8
9
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
# File 'app/mailers/payroll_run_mailer.rb', line 6

def approval_request(reviewer:, step_data:, payroll_transaction_header_id:)
  @reviewer = reviewer
  @payroll_transaction_header_id = payroll_transaction_header_id
  @list_items = step_data.map do |entry|
    formatted_value = if entry[:name] == 'payroll_period'
                        entry[:value].formatted
                      elsif %w[
                        net_salary
                        remit_to_cra
                        remit_to_mrq
                        total_fees
                        total_to_be_debited_from_bank_account
                      ].include?(entry[:name])
                        format_currency(entry[:value])
                      elsif entry[:name] == 'employees_count'
                        format_count(entry[:value])
                      else
                        entry[:value]
                      end
    { label: entry[:label], value: formatted_value }
  end
  payroll_period = step_data.find { |entry| entry[:name] == 'payroll_period' }[:value]

  I18n.with_locale(reviewer.locale) do
    mail(
      to: @reviewer.email,
      subject: "#{I18n.t('emails.approval_request.subject')} #{payroll_period.formatted}",
      from: Rails.application.config.from_email_address
    )
  end
end