class LucaSalary::Base
Attributes
config[R]
dict[R]
pjdir[R]
Public Class Methods
new(date = nil)
click to toggle source
# File lib/luca_salary/base.rb, line 15 def initialize(date = nil) @date = date.nil? ? Date.today : Date.parse(date) @dict = load_dict end
Public Instance Methods
amount_by_code(obj)
click to toggle source
Subtotal each items.
- 1
-
Base
salary or wages. - 2
-
Deduction directly related to work payment, including tax, insurance, pension and so on.
- 3
-
Deduction for miscellaneous reasons.
- 4
-
Addition for miscellaneous reasons.
- 5
-
Net payment amount.
# File lib/luca_salary/base.rb, line 36 def amount_by_code(obj) {}.tap do |h| (1..4).each do |n| code = n.to_s h[code] = sum_code(obj, code) end h['5'] = h['1'] - h['2'] - h['3'] + h['4'] end end
select_code(dat, code)
click to toggle source
# File lib/luca_salary/base.rb, line 20 def select_code(dat, code) dat.filter { |k, _v| /^#{code}[0-9A-Fa-f]{,3}$/.match(k.to_s) } end
sum_code(obj, code, exclude = nil)
click to toggle source
# File lib/luca_salary/base.rb, line 46 def sum_code(obj, code, exclude = nil) target = obj.select { |k, _v| /^#{code}[0-9A-Fa-f]{,3}$/.match(k) } target = target.reject { |k, _v| exclude.include?(k) } if exclude target.values.inject(:+) || 0 end
Private Instance Methods
load_dict()
click to toggle source
# File lib/luca_salary/base.rb, line 54 def load_dict LucaRecord::Dict.load_tsv_dict(Pathname(PJDIR) / 'dict' / 'code.tsv') end
set_driver()
click to toggle source
# File lib/luca_salary/base.rb, line 58 def set_driver code = CONFIG['country'] if code require "luca_salary/#{code.downcase}" Kernel.const_get "LucaSalary::#{code.capitalise}" else nil end end