Class: Salary
- Inherits:
-
Invoice
- Object
- Invoice
- Salary
- Defined in:
- app/models/salary.rb
Class Method Summary collapse
-
.direct_account ⇒ Object
Bookings ========.
Instance Method Summary collapse
- #ahv_amount ⇒ Object
-
#build_booking(params = {}, template_code = nil) ⇒ Object
Build booking.
- #bvg_amount ⇒ Object
-
#duration_from=(value) ⇒ Object
Assignment proxies.
-
#net_amount ⇒ Object
Calculations.
- #social_amount ⇒ Object
-
#to_s(format = :default) ⇒ Object
String.
Class Method Details
.direct_account ⇒ Object
Bookings
52 53 54 |
# File 'app/models/salary.rb', line 52 def self.direct_account Account.find_by_code("5000") end |
Instance Method Details
#ahv_amount ⇒ Object
27 28 29 30 31 32 |
# File 'app/models/salary.rb', line 27 def ahv_amount result = amount result += bookings.where(:title => "Kinderzulage").sum(:amount) result end |
#build_booking(params = {}, template_code = nil) ⇒ Object
Build booking
We need to ensure the order of creation as we depent on current balance.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/salary.rb', line 59 def build_booking(params = {}, template_code = nil) # Build and assign booking super(params, 'salary:employee:ahv_iv_eo').save super(params, 'salary:employer:ahv_iv_eo').save super(params, 'salary:employee:alv').save super(params, 'salary:employer:alv').save super(params, 'salary:employee:nbu').save super(params, 'salary:employer:nbu').save super(params, 'salary:employer:bu').save super(params, 'salary:employer:fak').save super(params, 'salary:employer:vkb').save super(params, 'salary:employee:ktg').save super(params.merge(:person_id => company.id), "salary:bvg").save super(params, 'salary:invoice').save super(params.merge(:person_id => company.id), "salary:kz").save super(params.merge(:person_id => company.id), "salary:social:kz").save end |
#bvg_amount ⇒ Object
15 16 17 |
# File 'app/models/salary.rb', line 15 def bvg_amount bookings.by_text("BVG").sum(:amount) end |
#duration_from=(value) ⇒ Object
Assignment proxies
35 36 37 38 39 40 41 42 43 |
# File 'app/models/salary.rb', line 35 def duration_from=(value) write_attribute(:duration_from, value) value_as_date = self.duration_from # Calculate value and due dates date = Date.new(value_as_date.year, value_as_date.month, 1).in(1.month).ago(1.day) self.value_date ||= date self.due_date ||= date end |
#net_amount ⇒ Object
Calculations
8 9 10 11 12 13 |
# File 'app/models/salary.rb', line 8 def net_amount salary_invoice_booking = bookings.where(:debit_account_id => Account.find_by_code('2050').id).first return 0.0 unless salary_invoice_booking salary_invoice_booking.amount end |
#social_amount ⇒ Object
19 20 21 22 23 24 25 |
# File 'app/models/salary.rb', line 19 def result = bookings.by_text("AHV/IV/EO Arbeitnehmer").sum(:amount) result += bookings.by_text("ALV Arbeitnehmer").sum(:amount) result += bookings.by_text("NBU Arbeitnehmer").sum(:amount) result end |
#to_s(format = :default) ⇒ Object
String
3 4 5 |
# File 'app/models/salary.rb', line 3 def to_s(format = :default) "%s (%s / %s - %s)" % [title, company, duration_from ? I18n::localize(duration_from) : '', duration_to ? I18n::localize(duration_to) : ''] end |