mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
created get_estimate to remove redundant code
This commit is contained in:
@@ -15,15 +15,20 @@ class EstimateController < ApplicationController
|
|||||||
before_action :require_user, :unless => proc {|c| session[:token].nil? }
|
before_action :require_user, :unless => proc {|c| session[:token].nil? }
|
||||||
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
|
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
|
||||||
|
|
||||||
|
def get_estimate
|
||||||
|
estimate = Estimate.find_by_id(params[:id]) if params[:id]
|
||||||
|
estimate = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
||||||
|
return estimate
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Downloads and forwards the estimate pdf
|
# Downloads and forwards the estimate pdf
|
||||||
#
|
#
|
||||||
def show
|
def show
|
||||||
e = Estimate.find_by_id(params[:id]) if params[:id]
|
estimate = get_estimate
|
||||||
e = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
send_data e.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
send_data estimate.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
||||||
rescue
|
rescue
|
||||||
redirect_to :back, :flash => { :error => "Estimate not found" }
|
redirect_to :back, :flash => { :error => "Estimate not found" }
|
||||||
end
|
end
|
||||||
@@ -33,11 +38,10 @@ class EstimateController < ApplicationController
|
|||||||
# Downloads estimate by document number
|
# Downloads estimate by document number
|
||||||
#
|
#
|
||||||
def doc
|
def doc
|
||||||
e = Estimate.find_by_doc_number(params[:id]) if params[:id]
|
estimate = get_estimate
|
||||||
e = Estimate.find_by_doc_number(params[:search]) if params[:search]
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
send_data e.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
send_data estimate.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf"
|
||||||
rescue
|
rescue
|
||||||
redirect_to :back, :flash => { :error => "Estimate not found" }
|
redirect_to :back, :flash => { :error => "Estimate not found" }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user