apply highlighting and showing supplier name to invoice pdf

This commit is contained in:
viehlieb 2025-05-22 14:55:35 +02:00
parent 45db0575b1
commit a65120eefc
9 changed files with 96 additions and 72 deletions

View file

@ -81,12 +81,22 @@ class GroupOrderInvoicePdf < RenderPdf
data = [I18n.t('documents.group_order_invoice_pdf.vat_exempt_rows')]
move_down 10
# no sinle group_order_id, capice? get all the articles.
group_order_articles = GroupOrderArticle.where(group_order_ids: @options.group_order_ids)
group_order_articles = GroupOrderArticle.where(group_order_id: @options[:group_order_ids])
separate_deposits = FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
supplier = ""
headlines = []
index = 0
group_order_articles.each do |goa|
# if no unit is received, nothing is to be charged
next if goa.result.to_i == 0
index +=1
if goa.group_order.order.supplier.name != supplier
headlines << index
supplier = goa.group_order.order.supplier.name
data << [supplier,"","",""]
index +=1
end
goa_total_price = separate_deposits ? goa.total_price_without_deposit : goa.total_price
data << [goa.order_article.article.name,
goa.result.to_i,
@ -108,9 +118,9 @@ class GroupOrderInvoicePdf < RenderPdf
table.position = :center
table.cells.border_width = 1
table.cells.border_color = '666666'
table.row(0).column(0..4).width = 80
table.row(0).column(0).width = 180
table.row(headlines).font_style= :bold
table.row(0).border_bottom_width = 2
table.columns(1).align = :right
table.columns(1..6).align = :right
@ -172,13 +182,21 @@ class GroupOrderInvoicePdf < RenderPdf
else
[I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)]
end
goa_tax_hash = GroupOrderArticle.where(group_order_id: @options[:group_order_ids]).find_each.group_by { |oat| oat.order_article.price.tax }
goa_tax_hash.each do |tax, group_order_articles|
group_order_articles.each do |goa|
# if no unit is received, nothing is to be charged
group_order_articles = GroupOrderArticle.where(group_order_id: @options[:group_order_ids]).includes(group_order: { order: :supplier })
index = 0
supplier_headlines = []
group_order_articles.group_by { |goa| goa.group_order.order.supplier.name }.each do |supplier_name, articles|
data << [supplier_name, "", "", "", "", ""]
index += 1
supplier_headlines << index
articles.each do |goa|
next if goa.result.to_i == 0
index += 1
order_article = goa.order_article
tax = order_article.price.tax
goa_total_net = goa.result * order_article.price.price
goa_total_fc = separate_deposits ? goa.total_price_without_deposit : goa.total_price
@ -236,6 +254,9 @@ class GroupOrderInvoicePdf < RenderPdf
table.row(0).border_bottom_width = 2
table.columns(1).align = :right
table.columns(1..6).align = :right
supplier_headlines.each do |row_index|
table.row(row_index).columns(0..6).style(font_style: :bold)
end
end
if marge > 0