Refactor: Introduce PdfServiceBase for shared PDF fetching functionality and update Invoice/Estimate controllers to utilize new services

This commit is contained in:
2026-02-28 21:59:01 -05:00
parent a34ae46358
commit f921f227e2
5 changed files with 90 additions and 49 deletions

View File

@@ -65,7 +65,8 @@ class EstimateController < ApplicationController
# Renders the estimate PDF or redirects with an error if rendering fails.
def render_pdf(estimate)
send_data( estimate.pdf, filename: "estimate #{estimate.doc_number}.pdf", disposition: :inline, type: "application/pdf" )
pdf, ref = EstimatePdfService.new(qbo: Qbo.first).fetch_pdf(doc_ids: [estimate.id])
send_data( pdf, filename: "estimate #{ref}.pdf", disposition: :inline, type: "application/pdf" )
rescue StandardError => e
log "PDF render failed for Estimate #{estimate&.id}: #{e.message}"
redirect_back fallback_location: root_path, flash: { error: I18n.t(:notice_estimate_not_found) }