Class: Pdf::Document::ReturnInstructions
- Inherits:
-
BaseService
- Object
- BaseService
- Pdf::Document::ReturnInstructions
- Includes:
- Base
- Defined in:
- app/services/pdf/document/return_instructions.rb
Overview
Service object: return instructions.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- QR_GRID_COLUMNS =
Per-package paperless QR codes are laid out this many per row in the grid
(instead of one full page per box). Label Broker IDs are short, so the QR
is low-density and scans fine at the resulting size; drop this if a counter
scanner ever struggles. 5
Constants included from Base
Base::FONT, Base::NIMBUS_SANS_PATH, Base::NIMBUS_SANS_PATH_BOLD, Base::WY_LOGO_PATH
Instance Method Summary collapse
-
#call(rma, options = {}) ⇒ Object
Builds the customer-facing return-instructions PDF.
Instance Method Details
#call(rma, options = {}) ⇒ Object
Builds the customer-facing return-instructions PDF.
When the RMA's return shipments carry a paperless QR/barcode (attached
by Delivery#generate_labels from ShipEngine's paperless_download
response), the PDF interleaves QR pages alongside the printable-label
fallback so the customer can pick whichever works at the counter.
Three layouts (paperless_layout_for):
:per_package— every return shipment has its own QR. Page order:
instructions → (QR page + printable label) per shipment.:shipment_level— one QR covers all boxes (typically USPS Label
Broker on an MPS). Page order: instructions → single QR page → all
printable labels.:none— no QR, today's flow unchanged.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/services/pdf/document/return_instructions.rb', line 32 def call(rma, = {}) layout = paperless_layout_for(rma) combined_pdf = PdfCombinator.new combined_pdf << generate_instructions_pdf(rma, paperless_layout: layout) case layout when :per_package # Paperless (USPS Label Broker): QR only. A paperless label has no # separate printable shipping label — `label_download` is the QR page # itself. Lay all the box QR codes out in one compact grid (one per box, # labeled Box N) rather than a full page each. qr_shipments = rma.return_shipments.select(&:paperless_qr_png) combined_pdf << generate_paperless_qr_grid(rma, qr_shipments) if qr_shipments.any? when :shipment_level qr_shipment = rma.return_shipments.detect(&:paperless_qr_png) combined_pdf << generate_paperless_qr_page(rma, qr_shipment, scope: :shipment_level) else # :none rma.return_labels.each do |upload| combined_pdf << PdfCombinator.load(upload..path) end end result_hsh = { rma: rma, options: , file_name: rma.instructions_file_name } if [:output_to_file] path = [:output_to_file_path] || File.join(Rails.application.config.x.temp_storage_path.to_s, result_hsh[:file_name]) combined_pdf.save(path) result_hsh[:pdf_file_path] = path else result_hsh[:pdf_data] = combined_pdf.to_pdf end Result.new(**result_hsh) end |