Class: Salary

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

Constant Summary collapse

STATES =

States

['booked', 'canceled', 'paid']

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_credit_accountsObject



116
117
118
# File 'app/models/salary.rb', line 116

def self.available_credit_accounts
  Account.all
end

.available_debit_accountsObject



124
125
126
# File 'app/models/salary.rb', line 124

def self.available_debit_accounts
  Account.all
end

.default_credit_accountObject



120
121
122
# File 'app/models/salary.rb', line 120

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

.default_debit_accountObject



128
129
130
# File 'app/models/salary.rb', line 128

def self.
  self.
end

.direct_accountObject

Accounts



112
113
114
# File 'app/models/salary.rb', line 112

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

Instance Method Details

#ahv_amountObject



60
61
62
63
64
65
# File 'app/models/salary.rb', line 60

def ahv_amount
  result = amount
  result += bookings.where(:title => "Kinderzulage").sum(:amount)

  result
end

#build_line_itemsObject

Line Items



91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/salary.rb', line 91

def build_line_items
  salary_template.salary_items.each do |salary_item|
    line_item = line_items.build(:date => self.value_date)

    # Defaults from booking_template
    line_item.set_booking_template(salary_item.salary_booking_template)

    # Overrides from salary_item
    line_item.times = salary_item.times if salary_item.times.present?
    line_item.price = salary_item.price if salary_item.price.present?
  end
end

#bvg_amountObject



48
49
50
# File 'app/models/salary.rb', line 48

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

#duration_from=(value) ⇒ Object

Assignment proxies



68
69
70
71
72
73
74
75
76
# File 'app/models/salary.rb', line 68

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_idObject



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

def employee_id
  company_id
end

#employee_id=(value) ⇒ Object



15
16
17
# File 'app/models/salary.rb', line 15

def employee_id=(value)
  self.company_id = value
end

#employer_idObject



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

def employer_id
  customer_id
end

#employer_id=(value) ⇒ Object



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

def employer_id=(value)
  self.customer_id = value
end

#employmentObject



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

def employment
  employee.employments.current
end

#net_amountObject

Calculations



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

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

#salary_templateObject

Get salary template

Tries to get a personal salary template, falls back to templates with no assigned persons.

If more than one template matches the criteria, it is unspecified which one will be returned.



85
86
87
88
# File 'app/models/salary.rb', line 85

def salary_template
  template = SalaryTemplate.where(:person_id => employee.id).last
  template ||= SalaryTemplate.where(:person_id => nil).last
end

#social_amountObject



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

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



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

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