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



140
141
142
# File 'app/models/salary.rb', line 140

def self.available_credit_accounts
  Account.all
end

.available_debit_accountsObject



148
149
150
# File 'app/models/salary.rb', line 148

def self.available_debit_accounts
  Account.all
end

.credit_accountObject



144
145
146
# File 'app/models/salary.rb', line 144

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

.debit_accountObject



152
153
154
# File 'app/models/salary.rb', line 152

def self.
  self.
end

.direct_accountObject

Accounts



136
137
138
# File 'app/models/salary.rb', line 136

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

Instance Method Details

#ahv_amountObject

Calculations



76
77
78
# File 'app/models/salary.rb', line 76

def ahv_amount
  amount_of('AHV')
end

#build_line_itemsObject

Line Items



119
120
121
122
123
124
125
126
# File 'app/models/salary.rb', line 119

def build_line_items
  salary_template.salary_items.each do |salary_item|
    line_item = salary_item.build_line_item

    line_item.date    = self.value_date
    self.line_items << line_item
  end
end

#bvg_amountObject



90
91
92
93
# File 'app/models/salary.rb', line 90

def bvg_amount
  # TODO: hardcoded salary_booking_template
  amount_of('5050')
end

#duration_from=(value) ⇒ Object

Assignment proxies



96
97
98
99
100
101
102
103
104
# File 'app/models/salary.rb', line 96

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

Emplyoment helpers



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

def employment
  employee.employments.valid_at(value_date).last
end

#gross_amountObject



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

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

#hourly_paid?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/salary.rb', line 27

def hourly_paid?
  employment.try(:hourly_paid?)
end

#hours_carryObject

bookyt_projects



157
158
159
160
161
162
163
164
# File 'app/models/salary.rb', line 157

def hours_carry
  WorkDay.create_or_update_upto(employee, duration_to)
  last_day = employee.work_days.where(:date => duration_from.ago(1.day)).last

  return 0 unless last_day

  return last_day.overall_overtime
end

#net_amountObject



80
81
82
83
# File 'app/models/salary.rb', line 80

def net_amount
  # TODO: hardcoded salary_booking_template
  amount_of('6500')
end

#previousObject

Helpers



71
72
73
# File 'app/models/salary.rb', line 71

def previous
  employee.salaries.order("duration_to DESC").where("duration_to < ?", duration_to).first
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.



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

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



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

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

#track_hours?Boolean

Returns:

  • (Boolean)


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

def track_hours?
  # No tracking if we have no information how payment is done
  return false if hourly_paid?.nil?

  # No tracking if paid by hour
  return false if hourly_paid?

  # No tracking if we have no current information
  return false unless work_days.present?
end

#track_leave_days?Boolean

Returns:

  • (Boolean)


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/salary.rb', line 42

def track_leave_days?
  # No tracking if we have no information how payment is done
  return false if hourly_paid?.nil?

  # No tracking if paid by hour
  return false if hourly_paid?

  # No tracking if we have no current information
  return false unless used_leave_days && leave_days_balance

  # Track otherwise
  return true
end

#work_daysObject



166
167
168
169
# File 'app/models/salary.rb', line 166

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