diff --git a/app/services/ticket_pdf_generator.rb b/app/services/ticket_pdf_generator.rb index 68e929a..5277d05 100755 --- a/app/services/ticket_pdf_generator.rb +++ b/app/services/ticket_pdf_generator.rb @@ -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 diff --git a/app/views/events/payment_success.html.erb b/app/views/events/payment_success.html.erb index 7728897..877b757 100755 --- a/app/views/events/payment_success.html.erb +++ b/app/views/events/payment_success.html.erb @@ -64,7 +64,7 @@ Vos billets - +
<% @tickets.each do |ticket| %>
@@ -82,9 +82,9 @@
- +
- <%= 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 %> @@ -93,7 +93,7 @@ <% end %>
- +
@@ -119,7 +119,7 @@

Important

- 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.

@@ -128,15 +128,15 @@
- <%= 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 %> 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 %> @@ -147,4 +147,4 @@
- \ No newline at end of file + diff --git a/app/views/orders/payment_success.html.erb b/app/views/orders/payment_success.html.erb index d42f5ca..8a9181f 100644 --- a/app/views/orders/payment_success.html.erb +++ b/app/views/orders/payment_success.html.erb @@ -64,7 +64,7 @@

Vos billets

- + <% @order.tickets.each do |ticket| %>
@@ -127,7 +127,7 @@

Gardez vos billets sur votre téléphone ou imprimez-les.

<% @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 %> @@ -188,4 +188,4 @@
-
\ No newline at end of file + diff --git a/app/views/tickets/payment_success.html.erb b/app/views/tickets/payment_success.html.erb index 7728897..877b757 100755 --- a/app/views/tickets/payment_success.html.erb +++ b/app/views/tickets/payment_success.html.erb @@ -64,7 +64,7 @@ Vos billets - +
<% @tickets.each do |ticket| %>
@@ -82,9 +82,9 @@
- +
- <%= 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 %> @@ -93,7 +93,7 @@ <% end %>
- +
@@ -119,7 +119,7 @@

Important

- 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.

@@ -128,15 +128,15 @@
- <%= 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 %> 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 %> @@ -147,4 +147,4 @@
- \ No newline at end of file +