class LucaSalary::Monthly
Public Class Methods
new(date = nil)
click to toggle source
# File lib/luca_salary/monthly.rb, line 15 def initialize(date = nil) @date = date.nil? ? Date.today : Date.parse(date) @pjdir = Pathname(LucaSupport::PJDIR) @config = load_config(@pjdir + 'config.yml') @driver = set_driver end
Public Instance Methods
calc()
click to toggle source
call country specific calculation
# File lib/luca_salary/monthly.rb, line 24 def calc country = @driver.new(@pjdir, @config, @date) # TODO: handle retirement LucaSalary::Profile.all do |profile| current_profile = parse_current(profile) if self.class.search(@date.year, @date.month, @date.day, current_profile['id']).count > 0 puts "payment record already exists: #{current_profile['id']}" return nil end h = country.calc_payment(current_profile) h['profile_id'] = current_profile['id'] self.class.create(h, date: @date, codes: Array(current_profile['id'])) end end
report(mode = nil)
click to toggle source
output payslips via mail or console
# File lib/luca_salary/monthly.rb, line 41 def report(mode = nil) data = LucaSalary::Payment.new(@date.to_s).payslip if mode == 'mail' mail = Mail.new do subject '[luca salary] Monthly Payment' end mail.to = @config.dig('mail', 'report_mail') mail.text_part = YAML.dump(LucaSupport::Code.readable(data)) LucaSupport::Mail.new(mail, @pjdir).deliver else puts YAML.dump(LucaSupport::Code.readable(data)) end end
Private Instance Methods
parse_date(date = nil)
click to toggle source
# File lib/luca_salary/monthly.rb, line 57 def parse_date(date = nil) date.nil? ? Date.today : Date.parse(date) end