Skip to content

Instantly share code, notes, and snippets.

@KevinSia
Created December 19, 2020 05:49
Show Gist options
  • Save KevinSia/a0e0d9450bf535834346611bb60fd89e to your computer and use it in GitHub Desktop.
Save KevinSia/a0e0d9450bf535834346611bb60fd89e to your computer and use it in GitHub Desktop.
require 'prawn'
arr = HallSession
.joins(:check_in_sessions, :hall)
.group('check_in_sessions.hall_session_id, auditorium_halls.name, hall_sessions.start_at, hall_sessions.end_at, hall_sessions.id')
.select('auditorium_halls.name as hall_name, hall_sessions.start_at, hall_sessions.end_at, COUNT(*) as c')
.order('hall_name, start_at, end_at')
.map do |ci|
[
ci.hall_name,
ci.start_at.strftime('%H:%M'),
ci.end_at.strftime('%H:%M'),
ci.c
]
end
header = %w[Hall\ Name Session\ Start\ At Session\ End\ At Count]
pdf = Prawn::Document.new(page_size: 'A4')
pdf.font_size(20) { pdf.text 'Hall sessions check-ins' }
pdf.move_down 10
pdf.table(
[header] + arr,
width: pdf.bounds.width
)
pdf.render_file 'test.pdf'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment