@@ -46,12 +46,12 @@ def generate_tailor_details(pdf)
46
46
def generate_products_table ( pdf )
47
47
pdf . text "Peças Entregues" , size : 14 , style : :bold
48
48
pdf . move_down 10
49
-
50
- data = [ [ "Produto" , "Quantidade" , "Preço Un." , "Sujo" , "Erro" , "Descarte" , "Devolvido" , "Desconto" , "Total" ] ]
51
-
49
+
50
+ data = [ [ "Produto" , "Quantidade" , "Peças Entregues" , " Preço Un.", "Sujo" , "Erro" , "Descarte" , "Devolvido" , "Desconto" , "Total" ] ]
51
+
52
52
total_all_rows = 0
53
53
total_discount = 0
54
-
54
+
55
55
@production . production_products . each do |pp |
56
56
unit_price = pp . unit_price || 0
57
57
total_price = pp . total_price || 0
@@ -60,12 +60,13 @@ def generate_products_table(pdf)
60
60
returned_discount = pp . returned ? total_price : 0
61
61
total_discount_row = discount + returned_discount
62
62
adjusted_price = unit_price * adjusted_quantity - total_discount_row
63
-
63
+
64
64
total_all_rows += total_price
65
65
total_discount += total_discount_row
66
-
66
+
67
67
data << [
68
68
pp . product . name ,
69
+ pp . quantity ,
69
70
pp . pieces_delivered ,
70
71
number_to_currency ( unit_price ) ,
71
72
pp . dirty ,
@@ -76,10 +77,11 @@ def generate_products_table(pdf)
76
77
number_to_currency ( adjusted_price )
77
78
]
78
79
end
79
-
80
+
80
81
# Add a row for totals
81
82
data << [
82
83
"Total" ,
84
+ @production . production_products . sum ( :quantity ) ,
83
85
@production . production_products . sum ( :pieces_delivered ) ,
84
86
"" ,
85
87
@production . production_products . sum ( :dirty ) ,
@@ -89,19 +91,19 @@ def generate_products_table(pdf)
89
91
number_to_currency ( total_discount ) ,
90
92
number_to_currency ( total_all_rows - total_discount )
91
93
]
92
-
93
- column_widths = [ 120 , 60 , 60 , 40 , 40 , 40 , 60 , 60 , 80 ]
94
-
94
+
95
+ column_widths = [ 100 , 50 , 50 , 50 , 40 , 40 , 40 , 50 , 60 , 70 ]
96
+
95
97
# Calculate row heights
96
98
row_heights = data . map do |row |
97
99
row . map . with_index do |cell , i |
98
- pdf . height_of ( cell . to_s , width : column_widths [ i ] , size : 10 ) + 10 # Add some padding
100
+ pdf . height_of ( cell . to_s , width : column_widths [ i ] , size : 8 ) + 5 # Add some padding
99
101
end . max
100
102
end
101
-
103
+
102
104
pdf . bounding_box ( [ 0 , pdf . cursor ] , width : pdf . bounds . width , height : row_heights . sum + 1 ) do
103
105
y_position = pdf . bounds . top
104
-
106
+
105
107
data . each_with_index do |row , row_index |
106
108
row_height = row_heights [ row_index ]
107
109
@@ -111,17 +113,17 @@ def generate_products_table(pdf)
111
113
pdf . fill_rectangle [ 0 , y_position ] , pdf . bounds . width , row_height
112
114
pdf . fill_color "000000"
113
115
end
114
-
116
+
115
117
# Draw horizontal line
116
118
pdf . stroke_horizontal_line 0 , pdf . bounds . width , at : y_position
117
-
119
+
118
120
# Draw cell contents
119
121
x_position = 0
120
122
row . each_with_index do |cell , col_index |
121
123
width = column_widths [ col_index ]
122
124
pdf . bounding_box ( [ x_position , y_position ] , width : width , height : row_height ) do
123
125
pdf . text_box cell . to_s ,
124
- size : 10 ,
126
+ size : 8 ,
125
127
align : :center ,
126
128
valign : :center ,
127
129
overflow : :shrink_to_fit ,
@@ -132,21 +134,21 @@ def generate_products_table(pdf)
132
134
end
133
135
x_position += width
134
136
end
135
-
137
+
136
138
y_position -= row_height
137
139
end
138
-
140
+
139
141
# Draw vertical lines
140
142
column_widths . reduce ( 0 ) do |x_position , width |
141
143
pdf . stroke_vertical_line pdf . bounds . top , pdf . bounds . bottom , at : x_position
142
144
x_position + width
143
145
end
144
146
pdf . stroke_vertical_line pdf . bounds . top , pdf . bounds . bottom , at : pdf . bounds . width
145
-
147
+
146
148
# Draw bottom line
147
149
pdf . stroke_horizontal_line 0 , pdf . bounds . width , at : pdf . bounds . bottom
148
150
end
149
-
151
+
150
152
pdf . move_down 20
151
153
end
152
154
@@ -156,12 +158,19 @@ def generate_totals(pdf)
156
158
discount += ( pp . total_price || 0 ) if pp . returned
157
159
discount
158
160
end
159
-
161
+
160
162
total_price = @production . production_products . sum { |pp | pp . total_price || 0 }
161
- total_to_pay = total_price - total_discount
162
-
163
+
164
+ total_pieces_delivered_price = @production . production_products . sum do |pp |
165
+ ( pp . pieces_delivered || 0 ) * ( pp . unit_price || 0 )
166
+ end
167
+
168
+ total_to_pay = total_pieces_delivered_price - total_discount
169
+
163
170
pdf . text "Total do corte: #{ number_to_currency ( total_price ) } " , style : :bold , align : :right
164
171
pdf . move_down 10
172
+ pdf . text "Total peças entregues: #{ number_to_currency ( total_pieces_delivered_price ) } " , style : :bold , align : :right
173
+ pdf . move_down 10
165
174
pdf . text "Total desconto: #{ number_to_currency ( total_discount ) } " , style : :bold , align : :right
166
175
pdf . move_down 10
167
176
pdf . text "Total a pagar: #{ number_to_currency ( total_to_pay ) } " , style : :bold , align : :right
0 commit comments