Class: Salary

Inherits:
Invoice
  • Object
show all
Defined in:
app/models/salary.rb

Constant Summary

Constants inherited from Invoice

Invoice::STATES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Invoice

#active, #amount, #open, #overdue?, #state_adverb, #state_noun, #update_code

Methods included from ApplicationHelper

#currency_fmt, #current_tenant, #engine_stylesheet_link_tag, #icon_delete_link_to, #icon_edit_link_to, #list_item_actions_for, #show_new_form

Class Method Details

.direct_accountObject

Bookings



66
67
68
# File 'app/models/salary.rb', line 66

def self.
  Account.find_by_code("5000")
end

Instance Method Details

#ahv_amountObject



41
42
43
44
45
46
# File 'app/models/salary.rb', line 41

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.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/salary.rb', line 73

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 => employee.id), "salary:bvg").save

  super(params, 'salary:invoice').save

  super(params.merge(:person_id => employee.id), "salary:kz").save
  super(params.merge(:person_id => employee.id), "salary:social:kz").save
end

#bvg_amountObject



29
30
31
# File 'app/models/salary.rb', line 29

def bvg_amount
  bookings.by_text("BVG").sum(:amount)
end

#duration_from=(value) ⇒ Object

Assignment proxies



49
50
51
52
53
54
55
56
57
# File 'app/models/salary.rb', line 49

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

#employee_id=(value) ⇒ Object



12
13
14
# File 'app/models/salary.rb', line 12

def employee_id=(value)
  company_id = value
end

#employer_id=(value) ⇒ Object



8
9
10
# File 'app/models/salary.rb', line 8

def employer_id=(value)
  customer_id = value
end

#net_amountObject

Calculations



22
23
24
25
26
27
# File 'app/models/salary.rb', line 22

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_amountObject



33
34
35
36
37
38
39
# File 'app/models/salary.rb', line 33

def social_amount
  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



17
18
19
# File 'app/models/salary.rb', line 17

def to_s(format = :default)
  "%s (%s / %s - %s)" % [title, company, duration_from ? I18n::localize(duration_from) : '', duration_to ? I18n::localize(duration_to) : '']
end