Permalink
Browse files

Fix salary payslip for employees with no employment.

  • Loading branch information...
1 parent 35c462b commit da7259deb2407ac5a292dd4f673ebc912c358097 @huerlisi committed Sep 4, 2012
Showing with 41 additions and 13 deletions.
  1. +6 −11 app/controllers/salaries_controller.rb
  2. +30 −0 app/models/salary.rb
  3. +5 −2 app/views/salaries/payslip.pdf.prawn
@@ -55,21 +55,16 @@ def new
def payslip
@salary = Salary.find(params[:id])
- @include_hours_table = !@salary.employment.hourly_paid
- @include_leave_days_table = !@salary.employment.hourly_paid && @salary.used_leave_days && @salary.leave_days_balance
+ @include_hours_table = @salary.track_hours?
+ @include_leave_days_table = @salary.track_leave_days?
if @include_hours_table
@hours_carry = @salary.hours_carry
- work_days = @salary.work_days
- if work_days.present?
- @hours_due = @salary.work_days.sum(:hours_due)
- @hours_worked = @salary.work_days.sum(:hours_worked)
- @hours_saldo = @salary.work_days.last.overall_overtime
- else
- # Don't show hours table if no work days are recorded
- @include_hours_table = false
- end
+ work_days = @salary.work_days
+ @hours_due = work_days.sum(:hours_due)
+ @hours_worked = work_days.sum(:hours_worked)
+ @hours_saldo = work_days.last.overall_overtime
end
show! do |format|
View
@@ -19,10 +19,40 @@ def employee_id
company_id
end
+ # Emplyoment helpers
def employment
employee.employments.valid_at(value_date).last
end
+ def hourly_paid?
+ employment.try(:hourly_paid?)
+ end
+
+ 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
+
+ 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
+
# States
# ======
STATES = ['booked', 'canceled', 'paid']
@@ -10,9 +10,12 @@ prawn_document(:filename => "#{resource.to_s}.pdf", :renderer => PayslipDocument
pdf.move_down 20
rows = [
- [t_attr(:social_security_nr, Employee), employee.social_security_nr],
- [t_attr(:payment_to, Employment), resource.employment.payment_to]
+ [t_attr(:social_security_nr, Employee), employee.social_security_nr]
]
+ rows << [
+ [t_attr(:payment_to, Employment), resource.employment.payment_to]
+ ] if resource.employment
+
pdf.table rows, :width => pdf.bounds.width do
cells.valign = :top
cells.borders = []

0 comments on commit da7259d

Please sign in to comment.