Merge branch 'feat/ticket' into develop

This commit is contained in:
kbe
2025-09-06 21:31:34 +02:00
4 changed files with 135 additions and 34 deletions

View File

@@ -16,19 +16,120 @@ class TicketPdfGenerator
end
def generate
Prawn::Document.new(page_size: "A4", margin: 40) do |pdf|
# Simple header
create_simple_header(pdf)
# Event and ticket info in compact layout
create_ticket_info(pdf)
# QR code section
create_qr_section(pdf)
# Simple footer
create_simple_footer(pdf)
Prawn::Document.new(page_size: [ 350, 600 ], margin: 20) do |pdf|
# Header
pdf.fill_color "2D1B69"
pdf.font "Helvetica", style: :bold, size: 24
pdf.text ENV.fetch("APP_NAME", "Aperonight"), align: :center
pdf.move_down 10
# Event name
pdf.fill_color "000000"
pdf.font "Helvetica", style: :bold, size: 18
pdf.text ticket.event.name, align: :center
pdf.move_down 10
# Ticket info box
pdf.stroke_color "E5E7EB"
pdf.fill_color "F9FAFB"
pdf.rounded_rectangle [ 0, pdf.cursor ], 310, 150, 10
pdf.fill_and_stroke
pdf.move_down 10
pdf.fill_color "000000"
pdf.font "Helvetica", size: 12
# Customer name
pdf.indent 10 do
pdf.text "Ticket Holder:", style: :bold
pdf.text "#{ticket.first_name} #{ticket.last_name}"
end
pdf.move_down 8
# Ticket details
pdf.indent 10 do
pdf.text "Ticket Type:", style: :bold
pdf.text ticket.ticket_type.name
end
pdf.move_down 8
pdf.indent 10 do
pdf.text "Price:", style: :bold
pdf.text "#{ticket.price_euros}"
end
pdf.move_down 8
pdf.indent 10 do
pdf.text "Date & Time:", style: :bold
pdf.text ticket.event.start_time.strftime("%B %d, %Y at %I:%M %p")
end
pdf.move_down 20
# Venue information
pdf.fill_color "374151"
pdf.font "Helvetica", style: :bold, size: 14
pdf.text "Venue Information"
pdf.move_down 8
pdf.font "Helvetica", size: 11
pdf.text ticket.event.venue_name, style: :bold
pdf.text ticket.event.venue_address
pdf.move_down 20
# QR Code
pdf.fill_color "000000"
pdf.font "Helvetica", style: :bold, size: 14
pdf.text "QR Code", align: :center
pdf.move_down 10
# Ensure all required data is present before generating QR code
if ticket.qr_code.blank?
raise "Ticket QR code is missing"
end
# Build QR code data with safe association loading
qr_code_data = build_qr_code_data(ticket)
# Validate QR code data before creating QR code
if qr_code_data.blank? || qr_code_data == "{}"
Rails.logger.error "QR code data is empty: ticket_id=#{ticket.id}, qr_code=#{ticket.qr_code}, event_id=#{ticket.ticket_type&.event_id}, user_id=#{ticket.order&.user_id}"
raise "QR code data is empty or invalid"
end
# Ensure qr_code_data is a proper string for QR code generation
unless qr_code_data.is_a?(String) && qr_code_data.length > 2
Rails.logger.error "QR code data is not a valid string: #{qr_code_data.inspect} (class: #{qr_code_data.class})"
raise "QR code data must be a valid string"
end
# Generate QR code - prawn-qrcode expects the data string directly
pdf.print_qr_code(qr_code_data, extent: 120, align: :center)
pdf.move_down 15
# QR code text
pdf.font "Helvetica", size: 8
pdf.fill_color "6B7280"
pdf.text "#{ticket.qr_code}", align: :center
# Ticket ID
pdf.font "Helvetica", size: 8
pdf.fill_color "6B7280"
pdf.text "Ticket ID: #{ticket.id}", align: :center
# Footer
pdf.move_down 30
pdf.stroke_color "E5E7EB"
pdf.horizontal_line 0, 310
pdf.move_down 6
pdf.font "Helvetica", size: 8
pdf.fill_color "6B7280"
pdf.text "This ticket is valid for one entry only.", align: :center
pdf.text "Present this ticket at the venue entrance.", align: :center
pdf.move_down 5
pdf.text "Generated on #{Time.current.strftime('%B %d, %Y at %I:%M %p')}", align: :center
end.render
end

View File

@@ -64,7 +64,7 @@
</svg>
Vos billets
</h2>
<div class="space-y-4">
<% @tickets.each do |ticket| %>
<div class="bg-gradient-to-r from-purple-50 to-indigo-50 rounded-xl border border-purple-100 p-5">
@@ -82,9 +82,9 @@
</div>
</div>
</div>
<div class="flex items-center space-x-2">
<%= link_to download_ticket_path(ticket, format: :pdf),
<%= link_to ticket_download_path(ticket.qr_code, format: :pdf),
class: "inline-flex items-center px-4 py-2 bg-gradient-to-r from-purple-600 to-indigo-600 text-white rounded-lg hover:from-purple-700 hover:to-indigo-700 transition-all duration-200 text-sm font-medium shadow-sm" do %>
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
@@ -93,7 +93,7 @@
<% end %>
</div>
</div>
<div class="mt-4 pt-4 border-t border-purple-100 flex items-center justify-between">
<div class="flex items-center">
<svg class="w-4 h-4 text-gray-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -119,7 +119,7 @@
<div>
<h3 class="font-bold text-blue-800 mb-1">Important</h3>
<p class="text-sm text-blue-700">
Veuillez télécharger et sauvegarder vos billets. Présentez-les à l'entrée du lieu pour accéder à l'événement.
Veuillez télécharger et sauvegarder vos billets. Présentez-les à l'entrée du lieu pour accéder à l'événement.
Un email de confirmation avec vos billets a été envoyé à votre adresse email.
</p>
</div>
@@ -128,15 +128,15 @@
<!-- Action Buttons -->
<div class="flex flex-col sm:flex-row gap-4 justify-center">
<%= link_to dashboard_path,
<%= link_to dashboard_path,
class: "inline-flex items-center justify-center px-6 py-3 bg-gradient-to-r from-purple-600 to-indigo-600 text-white rounded-xl hover:from-purple-700 hover:to-indigo-700 transition-all duration-200 font-medium shadow-sm" do %>
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path>
</svg>
Tableau de bord
<% end %>
<%= link_to events_path,
<%= link_to events_path,
class: "inline-flex items-center justify-center px-6 py-3 bg-white text-gray-700 rounded-xl border border-gray-300 hover:bg-gray-50 transition-all duration-200 font-medium shadow-sm" do %>
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
@@ -147,4 +147,4 @@
</div>
</div>
</div>
</div>
</div>

View File

@@ -64,7 +64,7 @@
<!-- Tickets List -->
<div class="space-y-4">
<h3 class="text-lg font-semibold text-gray-900 mb-4">Vos billets</h3>
<% @order.tickets.each do |ticket| %>
<div class="flex items-center justify-between py-3 border-b border-gray-100 last:border-b-0">
<div class="flex-1 min-w-0">
@@ -127,7 +127,7 @@
<p class="text-gray-600 text-sm mb-3">Gardez vos billets sur votre téléphone ou imprimez-les.</p>
<div class="space-y-2">
<% @order.tickets.each do |ticket| %>
<%= link_to download_ticket_path(ticket), class: "inline-flex items-center px-3 py-2 border border-purple-300 rounded-md text-sm font-medium text-purple-700 bg-purple-50 hover:bg-purple-100 transition-colors mr-2 mb-2" do %>
<%= link_to ticket_download_path(ticket.qr_code), class: "inline-flex items-center px-3 py-2 border border-purple-300 rounded-md text-sm font-medium text-purple-700 bg-purple-50 hover:bg-purple-100 transition-colors mr-2 mb-2" do %>
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
</svg>
@@ -188,4 +188,4 @@
</div>
</div>
</div>
</div>
</div>

View File

@@ -64,7 +64,7 @@
</svg>
Vos billets
</h2>
<div class="space-y-4">
<% @tickets.each do |ticket| %>
<div class="bg-gradient-to-r from-purple-50 to-indigo-50 rounded-xl border border-purple-100 p-5">
@@ -82,9 +82,9 @@
</div>
</div>
</div>
<div class="flex items-center space-x-2">
<%= link_to download_ticket_path(ticket, format: :pdf),
<%= link_to ticket_download_path(ticket.qr_code, format: :pdf),
class: "inline-flex items-center px-4 py-2 bg-gradient-to-r from-purple-600 to-indigo-600 text-white rounded-lg hover:from-purple-700 hover:to-indigo-700 transition-all duration-200 text-sm font-medium shadow-sm" do %>
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
@@ -93,7 +93,7 @@
<% end %>
</div>
</div>
<div class="mt-4 pt-4 border-t border-purple-100 flex items-center justify-between">
<div class="flex items-center">
<svg class="w-4 h-4 text-gray-500 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
@@ -119,7 +119,7 @@
<div>
<h3 class="font-bold text-blue-800 mb-1">Important</h3>
<p class="text-sm text-blue-700">
Veuillez télécharger et sauvegarder vos billets. Présentez-les à l'entrée du lieu pour accéder à l'événement.
Veuillez télécharger et sauvegarder vos billets. Présentez-les à l'entrée du lieu pour accéder à l'événement.
Un email de confirmation avec vos billets a été envoyé à votre adresse email.
</p>
</div>
@@ -128,15 +128,15 @@
<!-- Action Buttons -->
<div class="flex flex-col sm:flex-row gap-4 justify-center">
<%= link_to dashboard_path,
<%= link_to dashboard_path,
class: "inline-flex items-center justify-center px-6 py-3 bg-gradient-to-r from-purple-600 to-indigo-600 text-white rounded-xl hover:from-purple-700 hover:to-indigo-700 transition-all duration-200 font-medium shadow-sm" do %>
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path>
</svg>
Tableau de bord
<% end %>
<%= link_to events_path,
<%= link_to events_path,
class: "inline-flex items-center justify-center px-6 py-3 bg-white text-gray-700 rounded-xl border border-gray-300 hover:bg-gray-50 transition-all duration-200 font-medium shadow-sm" do %>
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"></path>
@@ -147,4 +147,4 @@
</div>
</div>
</div>
</div>
</div>