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



105
106
107
# File 'app/models/salary.rb', line 105

def self.available_credit_accounts
  Account.all
end

.available_debit_accountsObject



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

def self.available_debit_accounts
  Account.all
end

.default_credit_accountObject



109
110
111
# File 'app/models/salary.rb', line 109

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

.default_debit_accountObject



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

def self.
  self.
end

.direct_accountObject

Accounts



101
102
103
# File 'app/models/salary.rb', line 101

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

Instance Method Details

#ahv_amountObject

Calculations



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

def ahv_amount
  amount_of('AHV')
end

#build_line_itemsObject

Line Items



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/salary.rb', line 79

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?
    line_item.position = salary_item.position if salary_item.position.present?
  end
end

#duration_from=(value) ⇒ Object

Assignment proxies



56
57
58
59
60
61
62
63
64
# File 'app/models/salary.rb', line 56

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.valid_at(value_date).last
end

#gross_amountObject



50
51
52
53
# File 'app/models/salary.rb', line 50

def gross_amount
  # TODO: hardcoded salary_booking_template
  amount_of('5000')
end

#net_amountObject



45
46
47
48
# File 'app/models/salary.rb', line 45

def net_amount
  # TODO: hardcoded salary_booking_template
  amount_of('6500')
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.



73
74
75
76
# File 'app/models/salary.rb', line 73

def salary_template
  template = SalaryTemplate.where(:person_id => employee.id).last
  template ||= SalaryTemplate.where(:person_id => nil).last
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

#work_daysObject

bookyt_projects



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

def work_days
  WorkDay.create_or_update_upto(employee, duration_to)
  employee.work_days.where(:date => duration_from..duration_to)
end