Skip to content

Commit

Permalink
Merge pull request #87 from voxik/colspan-breakdown
Browse files Browse the repository at this point in the history
Replace breakdown subtable by line spanning the whole table
  • Loading branch information
strzibny authored Aug 11, 2024
2 parents d66ee5f + 77e600b commit 940f677
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
Binary file modified examples/breakdown.pdf
Binary file not shown.
Binary file modified examples/breakdown_a4.pdf
Binary file not shown.
Binary file modified examples/czech_invoice_long.pdf
Binary file not shown.
38 changes: 15 additions & 23 deletions lib/invoice_printer/pdf_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ def build_items

options = {
header: true,
row_colors: [nil, 'ededed'],
width: x(540, 2),
cell_style: {
borders: []
Expand Down Expand Up @@ -733,10 +732,13 @@ def determine_items_structure

# Include only items params with provided data
def build_items_data(items_params)
@document.items.map do |item|
colspan = items_params.select { |k, v| v }.count
color_background = false

items = []
@document.items.each do |item|
line = []
line << { content: name_cell(item), borders: [:bottom] } if items_params[:names]
#line << { content: item.name, borders: [:bottom], align: :left } if items_params[:names]
line << { content: item.name, align: :left } if items_params[:names]
line << { content: item.variable, align: :right } if items_params[:variables]
line << { content: item.quantity, align: :right } if items_params[:quantities]
line << { content: item.unit, align: :right } if items_params[:units]
Expand All @@ -745,29 +747,19 @@ def build_items_data(items_params)
line << { content: item.tax2, align: :right } if items_params[:taxes2]
line << { content: item.tax3, align: :right } if items_params[:taxes3]
line << { content: item.amount, align: :right } if items_params[:amounts]
line
end
end

# Display item's name and breakdown if present
def name_cell(item)
data = if used?(item.breakdown)
data = [
[{ content: item.name, padding: [5, 0, 0, 5] }],
[{ content: item.breakdown, size: 8, padding: [2, 0, 5, 5] }]
]
line.each {|c| c[:background_color] = 'ededed'} if color_background

options = {
cell_style: {
borders: []
},
position: :left
}
items << line

@pdf.make_table(data, options)
else
item.name
if used?(item.breakdown)
items << [{ content: item.breakdown, align: :left, size: 8, colspan: colspan, padding: [0, 0, 5, 5] }]
items.last.first[:background_color] = 'ededed' if color_background
end

color_background = !color_background
end
items
end

# Include only relevant headers
Expand Down

0 comments on commit 940f677

Please sign in to comment.