Skip to content

Commit 12b25c7

Browse files
authored
Merge pull request #346 from Purple-Stock/staging
update the payment pdf
2 parents eb2facb + d881c6f commit 12b25c7

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

app/models/services/pdf/payment_order_pdf_generator.rb

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ def generate_tailor_details(pdf)
4646
def generate_products_table(pdf)
4747
pdf.text "Peças Entregues", size: 14, style: :bold
4848
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+
5252
total_all_rows = 0
5353
total_discount = 0
54-
54+
5555
@production.production_products.each do |pp|
5656
unit_price = pp.unit_price || 0
5757
total_price = pp.total_price || 0
@@ -60,12 +60,13 @@ def generate_products_table(pdf)
6060
returned_discount = pp.returned ? total_price : 0
6161
total_discount_row = discount + returned_discount
6262
adjusted_price = unit_price * adjusted_quantity - total_discount_row
63-
63+
6464
total_all_rows += total_price
6565
total_discount += total_discount_row
66-
66+
6767
data << [
6868
pp.product.name,
69+
pp.quantity,
6970
pp.pieces_delivered,
7071
number_to_currency(unit_price),
7172
pp.dirty,
@@ -76,10 +77,11 @@ def generate_products_table(pdf)
7677
number_to_currency(adjusted_price)
7778
]
7879
end
79-
80+
8081
# Add a row for totals
8182
data << [
8283
"Total",
84+
@production.production_products.sum(:quantity),
8385
@production.production_products.sum(:pieces_delivered),
8486
"",
8587
@production.production_products.sum(:dirty),
@@ -89,19 +91,19 @@ def generate_products_table(pdf)
8991
number_to_currency(total_discount),
9092
number_to_currency(total_all_rows - total_discount)
9193
]
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+
9597
# Calculate row heights
9698
row_heights = data.map do |row|
9799
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
99101
end.max
100102
end
101-
103+
102104
pdf.bounding_box([0, pdf.cursor], width: pdf.bounds.width, height: row_heights.sum + 1) do
103105
y_position = pdf.bounds.top
104-
106+
105107
data.each_with_index do |row, row_index|
106108
row_height = row_heights[row_index]
107109

@@ -111,17 +113,17 @@ def generate_products_table(pdf)
111113
pdf.fill_rectangle [0, y_position], pdf.bounds.width, row_height
112114
pdf.fill_color "000000"
113115
end
114-
116+
115117
# Draw horizontal line
116118
pdf.stroke_horizontal_line 0, pdf.bounds.width, at: y_position
117-
119+
118120
# Draw cell contents
119121
x_position = 0
120122
row.each_with_index do |cell, col_index|
121123
width = column_widths[col_index]
122124
pdf.bounding_box([x_position, y_position], width: width, height: row_height) do
123125
pdf.text_box cell.to_s,
124-
size: 10,
126+
size: 8,
125127
align: :center,
126128
valign: :center,
127129
overflow: :shrink_to_fit,
@@ -132,21 +134,21 @@ def generate_products_table(pdf)
132134
end
133135
x_position += width
134136
end
135-
137+
136138
y_position -= row_height
137139
end
138-
140+
139141
# Draw vertical lines
140142
column_widths.reduce(0) do |x_position, width|
141143
pdf.stroke_vertical_line pdf.bounds.top, pdf.bounds.bottom, at: x_position
142144
x_position + width
143145
end
144146
pdf.stroke_vertical_line pdf.bounds.top, pdf.bounds.bottom, at: pdf.bounds.width
145-
147+
146148
# Draw bottom line
147149
pdf.stroke_horizontal_line 0, pdf.bounds.width, at: pdf.bounds.bottom
148150
end
149-
151+
150152
pdf.move_down 20
151153
end
152154

@@ -156,12 +158,19 @@ def generate_totals(pdf)
156158
discount += (pp.total_price || 0) if pp.returned
157159
discount
158160
end
159-
161+
160162
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+
163170
pdf.text "Total do corte: #{number_to_currency(total_price)}", style: :bold, align: :right
164171
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
165174
pdf.text "Total desconto: #{number_to_currency(total_discount)}", style: :bold, align: :right
166175
pdf.move_down 10
167176
pdf.text "Total a pagar: #{number_to_currency(total_to_pay)}", style: :bold, align: :right

0 commit comments

Comments
 (0)