Atualização da dos Arquivos PDF Holerite e relatório

This commit is contained in:
2026-06-17 15:10:56 -03:00
parent 0a12b10acc
commit 69448ddabd
5 changed files with 4297 additions and 6 deletions

View File

@@ -10,7 +10,9 @@ module Pdf
CINZA = '6B7280'
def initialize
@pdf = Prawn::Document.new(page_size: 'A4', margin: [40, 40, 60, 40])
# Margem inferior folgada (72) para o rodapé repetido (desenhado em y=20)
# não sobrepor o conteúdo.
@pdf = Prawn::Document.new(page_size: 'A4', margin: [40, 40, 72, 40])
end
def render

View File

@@ -41,17 +41,18 @@ module Pdf
qtd = resumo[tipo] || 0
next if qtd.zero?
valor = @entregas.where(tipo: tipo).sum(:valor_aplicado)
unit = qtd.zero? ? 0 : (valor / qtd)
sinal = tipo == 'desconto' ? '-' : '+'
[cfg[:label], qtd.to_s, "#{sinal} #{moeda(valor)}"]
[cfg[:label], qtd.to_s, moeda(unit), "#{sinal} #{moeda(valor)}"]
end.compact
linhas = [['Descrição', 'Qtd', 'Valor']] + por_tipo
linhas = [['Descrição', 'Qtd', 'Unit.', 'Valor']] + por_tipo
@pdf.table(linhas, header: true, width: @pdf.bounds.width,
cell_style: { size: 10, padding: [6, 8] }) do |t|
t.row(0).background_color = PRETO
t.row(0).text_color = 'FFFFFF'
t.row(0).font_style = :bold
t.columns(1..2).align = :right
t.columns(1..3).align = :right
end
total = @entregas.sum { |e| e.desconto? ? -e.valor_aplicado : e.valor_aplicado }
@@ -67,6 +68,15 @@ module Pdf
at: [16, @pdf.cursor - 24], size: 22, style: :bold
@pdf.move_down 64
# Detalhamento: total de entregas e veículos atendidos no período
total_entregas = @entregas.count
veiculos = @entregas.map { |e| e.entrega_original&.vehicle }.compact.uniq
@pdf.fill_color CINZA
@pdf.text "Total de entregas: #{total_entregas}", size: 9
@pdf.text "Veículos atendidos: #{veiculos.any? ? veiculos.join(', ') : '—'}", size: 9
@pdf.fill_color '000000'
@pdf.move_down 8
# QR Code de login rápido
desenhar_qrcode if @user_motorista&.login_token.present?

View File

@@ -36,13 +36,17 @@ module Pdf
(i + 1).to_s,
original&.vehicle.presence || '—',
original ? "NF #{original.numero_nf}" : '—',
original ? original.address.to_s.first(45) : '—',
original ? original.address.to_s : '—',
e.tipo_cor[:label],
(e.desconto? ? '-' : '') + moeda(e.valor_aplicado)
]
end
# Larguras fixas para as colunas estreitas; a coluna 3 (Endereço) fica
# automática e recebe o espaço restante, quebrando em várias linhas em
# vez de truncar no meio da palavra.
@pdf.table(linhas, header: true, width: @pdf.bounds.width,
column_widths: { 0 => 22, 1 => 70, 2 => 60, 4 => 95, 5 => 60 },
cell_style: { size: 8, padding: [4, 6] }) do |t|
t.row(0).background_color = PRETO
t.row(0).text_color = 'FFFFFF'
@@ -57,7 +61,9 @@ module Pdf
@pdf.fill_color '000000'
end
# Totais por tipo
# Totais por tipo — mantém RESUMO + Total + Assinaturas juntos, evitando
# título órfão no pé da página e sobreposição com o rodapé.
@pdf.start_new_page if @pdf.cursor < 200
secao "RESUMO"
# reorder(nil): remove o .order(:created_at) da relação — senão o Postgres
# recusa "GROUP BY tipo ORDER BY created_at" (PG::GroupingError → 500).