class Planik::Lohnausweis::PdfGenerator
Generiert aus den Rohdaten
das PDF
Constants
- WIDTH
- XPOS
Public Class Methods
Public Instance Methods
create_pdf()
click to toggle source
Neues Layout. Aenderung für MEDPHONE März 2015: Nur Arbeitsliste, Arbeitszeit und Zulagen
# File lib/lohnausweis/pdf_generator.rb, line 20 def create_pdf @pdf = Prawn::Document.new(page_size: "A4") #@pdf.stroke_axis # Die Masse auf den Achsen @pdf.font("Helvetica", size: 8) #Default Font and size @pdf.default_leading = 0 next_y = 750 next_y = header(next_y) next_y -= 50 next_y = arbeitszeit_block(next_y) next_y -= 50 next_y = zulagen_block(next_y) next_y -= 50 next_y = arbeitsliste(next_y) footer() @pdf end
Private Instance Methods
arbeitsliste(ypos)
click to toggle source
Neu Aenderung für MEDPHONE März 2015: Nur Arbeitsliste, Arbeitszeit und Zulagen
# File lib/lohnausweis/pdf_generator.rb, line 90 def arbeitsliste(ypos) @pdf.move_down(20) @pdf.text("Arbeitszeit von #{@daten.start_datum} bis #{@daten.end_datum}", style: :bold) arbeitsliste = @daten.arbeitsliste make_table_without_bounding_box(arbeitsliste, true) end
arbeitszeit_block(ypos)
click to toggle source
# File lib/lohnausweis/pdf_generator.rb, line 65 def arbeitszeit_block(ypos) pp = @pdf.bounding_box([XPOS, ypos], width: WIDTH) do ypos = 0 make_table(XPOS, ypos, @daten.arbeitszeit_daten, true) @pdf.stroke_bounds end pp.absolute_bottom end
header(ypos)
click to toggle source
Neu Aenderung für MEDPHONE März 2015: Nur Arbeitsliste, Arbeitszeit und Zulagen
# File lib/lohnausweis/pdf_generator.rb, line 41 def header(ypos) bb = @pdf.bounding_box([XPOS, ypos], width: WIDTH) do @pdf.font("Helvetica", size: 12) do parent = @pdf.bounds xpos = parent.top_left[0] + 350 ypos = parent.height - 70 width = parent.top_right[0] - xpos @pdf.bounding_box([350, ypos], width: width, height: 70) do @pdf.text "#{@daten.adresse.voller_name}" @pdf.text @daten.adresse.strasse_nr @pdf.text "#{@daten.adresse.plz} <u>#{@daten.adresse.ort}</u>", inline_format: true #@pdf.stroke_bounds end @pdf.move_down(40) @pdf.text("Arbeitszeiten #{@daten.monat} #{@daten.jahr}", style: :bold) end #@pdf.stroke_bounds end bb.absolute_bottom end
make_table(xpos, ypos, daten, title = false)
click to toggle source
# File lib/lohnausweis/pdf_generator.rb, line 151 def make_table(xpos, ypos, daten, title = false) @pdf.bounding_box([xpos, ypos], width: WIDTH) do #height dynmaisch p_width = @pdf.bounds.width r1 = Rational(1, 2) r2 = r1 * Rational(1, 3) column_width = [p_width * r1, p_width * r2, p_width * r2, p_width * r2] @pdf.table(daten, column_widths: column_width, cell_style: { borders: [], #keine Ränder padding_top: 3, padding_bottom: 3 } ) do |t| if title t.row(0).style(font_style: :bold) #Titel bold t.row(0).background_color = "D8D8D8" end t.columns(1..3).style(align: :right) t.cells[t.row_length-1, 0].font_style = :bold t.cells[t.row_length-1, 3].borders = [:top] t.cells[t.row_length-1, 3].font_style = :bold end end end
make_table_without_bounding_box(daten, title)
click to toggle source
def make_arbeitsliste_table(xpos, ypos, daten, title = false)
@pdf.bounding_box([xpos, ypos], width: WIDTH+30) do #height dynamisch make_table_without_bounding_box(daten, title) end
end
# File lib/lohnausweis/pdf_generator.rb, line 112 def make_table_without_bounding_box(daten, title) p_width = WIDTH #@pdf.bounds.width eintraege = daten[:eintraege] sum_relative_breite = 0 daten[:spalten].each { |x| sum_relative_breite += x.relative_breite } column_width = daten[:spalten].map { |s| p_width * (s.relative_breite/sum_relative_breite) } @pdf.table(eintraege, column_widths: column_width, cell_style: { borders: [], #keine Ränder padding_top: 3, padding_bottom: 3 } ) do |t| if title t.row(0).style(font_style: :bold) #Titel bold t.row(0).background_color = "D8D8D8" end daten[:spalten].each_with_index do |s, i| t.column(i).style(align: :right) if s.formatter.align_right end #Letzte Zeile (Total) daten[:spalten].each_with_index do |s, i| if s.is_summen_spalte? t.cells[t.row_length-1, i].borders = [:top] t.cells[t.row_length-1, i].font_style = :bold end end t.cells[t.row_length-1, 0].font_style = :bold end end
zulagen_block(ypos)
click to toggle source
Neu Aenderung für MEDPHONE März 2015: Nur Arbeitsliste, Arbeitszeit und Zulagen
# File lib/lohnausweis/pdf_generator.rb, line 77 def zulagen_block(ypos) bb = @pdf.bounding_box([XPOS, ypos], width: WIDTH) do inner_ypos = 0 make_table(XPOS, inner_ypos, @daten.zulagen_daten, true) @pdf.stroke_bounds end bb.absolute_bottom end