Skip to content

Commit 940f677

Browse files
authored
Merge pull request #87 from voxik/colspan-breakdown
Replace breakdown subtable by line spanning the whole table
2 parents d66ee5f + 77e600b commit 940f677

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

examples/breakdown.pdf

37 Bytes
Binary file not shown.

examples/breakdown_a4.pdf

35 Bytes
Binary file not shown.

examples/czech_invoice_long.pdf

401 Bytes
Binary file not shown.

lib/invoice_printer/pdf_document.rb

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,6 @@ def build_items
694694

695695
options = {
696696
header: true,
697-
row_colors: [nil, 'ededed'],
698697
width: x(540, 2),
699698
cell_style: {
700699
borders: []
@@ -733,10 +732,13 @@ def determine_items_structure
733732

734733
# Include only items params with provided data
735734
def build_items_data(items_params)
736-
@document.items.map do |item|
735+
colspan = items_params.select { |k, v| v }.count
736+
color_background = false
737+
738+
items = []
739+
@document.items.each do |item|
737740
line = []
738-
line << { content: name_cell(item), borders: [:bottom] } if items_params[:names]
739-
#line << { content: item.name, borders: [:bottom], align: :left } if items_params[:names]
741+
line << { content: item.name, align: :left } if items_params[:names]
740742
line << { content: item.variable, align: :right } if items_params[:variables]
741743
line << { content: item.quantity, align: :right } if items_params[:quantities]
742744
line << { content: item.unit, align: :right } if items_params[:units]
@@ -745,29 +747,19 @@ def build_items_data(items_params)
745747
line << { content: item.tax2, align: :right } if items_params[:taxes2]
746748
line << { content: item.tax3, align: :right } if items_params[:taxes3]
747749
line << { content: item.amount, align: :right } if items_params[:amounts]
748-
line
749-
end
750-
end
751750

752-
# Display item's name and breakdown if present
753-
def name_cell(item)
754-
data = if used?(item.breakdown)
755-
data = [
756-
[{ content: item.name, padding: [5, 0, 0, 5] }],
757-
[{ content: item.breakdown, size: 8, padding: [2, 0, 5, 5] }]
758-
]
751+
line.each {|c| c[:background_color] = 'ededed'} if color_background
759752

760-
options = {
761-
cell_style: {
762-
borders: []
763-
},
764-
position: :left
765-
}
753+
items << line
766754

767-
@pdf.make_table(data, options)
768-
else
769-
item.name
755+
if used?(item.breakdown)
756+
items << [{ content: item.breakdown, align: :left, size: 8, colspan: colspan, padding: [0, 0, 5, 5] }]
757+
items.last.first[:background_color] = 'ededed' if color_background
758+
end
759+
760+
color_background = !color_background
770761
end
762+
items
771763
end
772764

773765
# Include only relevant headers

0 commit comments

Comments
 (0)