Class: LucaSalary::Monthly
- Defined in:
- lib/luca_salary/monthly.rb
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#calc ⇒ Object
call country specific calculation.
-
#initialize(date = nil) ⇒ Monthly
constructor
A new instance of Monthly.
-
#report(mode = nil) ⇒ Object
output payslips via mail or console.
Methods inherited from Base
#amount_by_code, #select_code, sum_code
Constructor Details
#initialize(date = nil) ⇒ Monthly
Returns a new instance of Monthly.
15 16 17 18 19 20 |
# File 'lib/luca_salary/monthly.rb', line 15 def initialize(date = nil) @date = date.nil? ? Date.today : Date.parse(date) @pjdir = Pathname(LucaRecord::CONST.pjdir) @config = load_config(@pjdir + 'config.yml') @driver = set_driver end |
Instance Method Details
#calc ⇒ Object
call country specific calculation
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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.find_secure(profile['id'])) 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, @date) h['profile_id'] = current_profile['id'] self.class.create(h, date: @date, codes: Array(current_profile['id'])) end end |
#report(mode = nil) ⇒ Object
output payslips via mail or console
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# 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 LucaSupport::Code.readable(data) end end |