@@ -694,7 +694,6 @@ def build_items
694
694
695
695
options = {
696
696
header : true ,
697
- row_colors : [ nil , 'ededed' ] ,
698
697
width : x ( 540 , 2 ) ,
699
698
cell_style : {
700
699
borders : [ ]
@@ -733,10 +732,13 @@ def determine_items_structure
733
732
734
733
# Include only items params with provided data
735
734
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 |
737
740
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 ]
740
742
line << { content : item . variable , align : :right } if items_params [ :variables ]
741
743
line << { content : item . quantity , align : :right } if items_params [ :quantities ]
742
744
line << { content : item . unit , align : :right } if items_params [ :units ]
@@ -745,29 +747,19 @@ def build_items_data(items_params)
745
747
line << { content : item . tax2 , align : :right } if items_params [ :taxes2 ]
746
748
line << { content : item . tax3 , align : :right } if items_params [ :taxes3 ]
747
749
line << { content : item . amount , align : :right } if items_params [ :amounts ]
748
- line
749
- end
750
- end
751
750
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
759
752
760
- options = {
761
- cell_style : {
762
- borders : [ ]
763
- } ,
764
- position : :left
765
- }
753
+ items << line
766
754
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
770
761
end
762
+ items
771
763
end
772
764
773
765
# Include only relevant headers
0 commit comments