Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor leave days and hours tables in payslip.

  • Loading branch information...
commit 18531531ec8adc072a24cc91b06a37a5bf0204f0 1 parent 1a8d2e0
@huerlisi authored
View
20 app/controllers/salaries_controller.rb
@@ -55,10 +55,22 @@ def new
def payslip
@salary = Salary.find(params[:id])
- @hours_carry = @salary.hours_carry
- @hours_due = @salary.work_days.sum(:hours_due)
- @hours_worked = @salary.work_days.sum(:hours_worked)
- @hours_saldo = @salary.work_days.last.overall_overtime
+ @include_hours_table = !@salary.employment.hourly_paid
+ @include_leave_days_table = !@salary.employment.hourly_paid && @salary.used_leave_days && @salary.leave_days_balance
+
+ 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
+ end
show! do |format|
format.html { redirect_to :action => :show }
View
58 app/views/salaries/payslip.pdf.prawn
@@ -23,10 +23,11 @@ prawn_document(:filename => "#{resource.to_s}.pdf", :renderer => PayslipDocument
columns(0).width = 5.cm
end
- unless resource.employment.hourly_paid
+ top_y = pdf.y
+ bottom_y = pdf.y
+ if @include_hours_table
pdf.move_down 20
- top_y = pdf.y
pdf.text "Stundenabrechnung", :style => :bold
month_name = t('date.month_names')[@salary.duration_from.month]
@@ -50,36 +51,39 @@ prawn_document(:filename => "#{resource.to_s}.pdf", :renderer => PayslipDocument
rows(3).font_style = :bold
end
bottom_y = pdf.y
-
pdf.y = top_y
- if resource.used_leave_days and resource.leave_days_balance
- pdf.indent 10.cm do
- pdf.text "Ferienabrechnung", :style => :bold
-
- month_name = t('date.month_names')[@salary.duration_from.month]
- rows = [
- ["#{t_attr(:used_leave_days)} #{month_name}", "%0.1f" % resource.used_leave_days],
- [t_attr(:leave_days_balance), "%0.1f" % resource.leave_days_balance],
- ]
-
- pdf.table rows, :width => 8.cm do
- cells.valign = :top
- cells.borders = []
- cells.padding_bottom = 2
- cells.padding_top = 2
-
- columns(0).padding_left = 0
- columns(0).width = 5.cm
- columns(1).align = :right
-
- rows(3).font_style = :bold
- end
+ end
+
+ if @include_leave_days_table
+ pdf.move_down 20
+
+ pdf.indent 10.cm do
+ pdf.text "Ferienabrechnung", :style => :bold
+
+ month_name = t('date.month_names')[@salary.duration_from.month]
+ rows = [
+ ["#{t_attr(:used_leave_days)} #{month_name}", "%0.1f" % resource.used_leave_days],
+ [t_attr(:leave_days_balance), "%0.1f" % resource.leave_days_balance],
+ ]
+
+ pdf.table rows, :width => 8.cm do
+ cells.valign = :top
+ cells.borders = []
+ cells.padding_bottom = 2
+ cells.padding_top = 2
+
+ columns(0).padding_left = 0
+ columns(0).width = 5.cm
+ columns(1).align = :right
+
+ rows(3).font_style = :bold
end
end
-
- pdf.y = bottom_y
+ bottom_y = pdf.y if pdf.y < bottom_y
end
+ pdf.y = bottom_y
+
# Free text with the socical security number
pdf.free_text(resource.text)
Please sign in to comment.
Something went wrong with that request. Please try again.