Class: Salary
- Inherits:
-
Invoice
- Object
- Invoice
- Salary
- Defined in:
- app/models/salary.rb
Constant Summary collapse
- STATES =
States
['booked', 'canceled', 'paid']
Class Method Summary collapse
- .available_credit_accounts ⇒ Object
- .available_debit_accounts ⇒ Object
- .default_credit_account ⇒ Object
- .default_debit_account ⇒ Object
-
.direct_account ⇒ Object
Accounts ========.
Instance Method Summary collapse
- #ahv_amount ⇒ Object
-
#build_line_items ⇒ Object
Line Items.
- #bvg_amount ⇒ Object
-
#duration_from=(value) ⇒ Object
Assignment proxies.
- #employee_id ⇒ Object
- #employee_id=(value) ⇒ Object
- #employer_id ⇒ Object
- #employer_id=(value) ⇒ Object
- #employment ⇒ Object
-
#net_amount ⇒ Object
Calculations.
-
#salary_template ⇒ Object
Get salary template.
- #social_amount ⇒ Object
-
#to_s(format = :default) ⇒ Object
String.
Class Method Details
.available_credit_accounts ⇒ Object
116 117 118 |
# File 'app/models/salary.rb', line 116 def self.available_credit_accounts Account.all end |
.available_debit_accounts ⇒ Object
124 125 126 |
# File 'app/models/salary.rb', line 124 def self.available_debit_accounts Account.all end |
.default_credit_account ⇒ Object
120 121 122 |
# File 'app/models/salary.rb', line 120 def self.default_credit_account Account.find_by_code('5000') end |
.default_debit_account ⇒ Object
128 129 130 |
# File 'app/models/salary.rb', line 128 def self.default_debit_account self.direct_account end |
.direct_account ⇒ Object
Accounts
112 113 114 |
# File 'app/models/salary.rb', line 112 def self.direct_account Account.find_by_code("2050") end |
Instance Method Details
#ahv_amount ⇒ Object
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_items ⇒ Object
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_amount ⇒ Object
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_id ⇒ Object
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_id ⇒ Object
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 |
#employment ⇒ Object
22 23 24 |
# File 'app/models/salary.rb', line 22 def employment employee.employments.current end |
#net_amount ⇒ Object
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_template ⇒ Object
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_amount ⇒ Object
52 53 54 55 56 57 58 |
# File 'app/models/salary.rb', line 52 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
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 |