From 4582b8c5b98aaf4810d1878de8b149717c839c42 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sun, 13 Feb 2022 10:03:43 -0500 Subject: [PATCH] Added estimate search in side bar --- app/controllers/estimate_controller.rb | 26 ++++++++++++++++++++++---- app/models/qbo_estimate.rb | 8 ++++++++ app/views/estimates/_search.html.erb | 4 ++++ app/views/estimates/_sidebar.html.erb | 2 ++ app/views/qbo/_sidebar.html.erb | 2 ++ config/locales/en.yml | 7 +++++-- config/routes.rb | 3 +++ lib/view_hook_listener.rb | 2 +- 8 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 app/views/estimates/_search.html.erb create mode 100644 app/views/estimates/_sidebar.html.erb create mode 100644 app/views/qbo/_sidebar.html.erb diff --git a/app/controllers/estimate_controller.rb b/app/controllers/estimate_controller.rb index 5f72247..11c5e8d 100644 --- a/app/controllers/estimate_controller.rb +++ b/app/controllers/estimate_controller.rb @@ -18,10 +18,28 @@ class EstimateController < ApplicationController # Downloads and forwards the estimate pdf # def show - base = QboEstimate.get_base - estimate = base.fetch_by_id(params[:id]) - @pdf = base.pdf(estimate) - send_data @pdf, filename: "estimate #{estimate.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" + e = QboEstimate.find_by_id(params[:id]) if params[:id] + e = QboEstimate.find_by_doc_number(params[:search]) if params[:search] + + begin + send_data e.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" + rescue + redirect_to :back, :flash => { :error => "Estimate not found" } + end + end + + # + # Downloads estimate by document number + # + def doc + e = QboEstimate.find_by_doc_number(params[:id]) if params[:id] + e = QboEstimate.find_by_doc_number(params[:search]) if params[:search] + + begin + send_data e.pdf, filename: "estimate #{e.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" + rescue + redirect_to :back, :flash => { :error => "Estimate not found" } + end end end diff --git a/app/models/qbo_estimate.rb b/app/models/qbo_estimate.rb index d2d17b3..d43fe06 100644 --- a/app/models/qbo_estimate.rb +++ b/app/models/qbo_estimate.rb @@ -55,4 +55,12 @@ class QboEstimate < ActiveRecord::Base qbo_estimate.id = estimate.id qbo_estimate.save! end + + # download the pdf from quickbooks + def pdf + base = QboEstimate.get_base + estimate = base.fetch_by_id(id) + return base.pdf(estimate) + end + end diff --git a/app/views/estimates/_search.html.erb b/app/views/estimates/_search.html.erb new file mode 100644 index 0000000..40ea37b --- /dev/null +++ b/app/views/estimates/_search.html.erb @@ -0,0 +1,4 @@ +<%= form_tag("/qbo/estimate/doc", :method => "get", id: "est-search-form") do %> + <%= text_field_tag :search, params[:search], placeholder: t(:label_search_estimates) %> + <%= submit_tag t(:label_search) %> +<% end %> diff --git a/app/views/estimates/_sidebar.html.erb b/app/views/estimates/_sidebar.html.erb new file mode 100644 index 0000000..dce48b5 --- /dev/null +++ b/app/views/estimates/_sidebar.html.erb @@ -0,0 +1,2 @@ +

Estimate

+<%= render :partial => 'estimates/search' %> diff --git a/app/views/qbo/_sidebar.html.erb b/app/views/qbo/_sidebar.html.erb new file mode 100644 index 0000000..6114da6 --- /dev/null +++ b/app/views/qbo/_sidebar.html.erb @@ -0,0 +1,2 @@ +<%= render :partial => 'customers/sidebar' %> +<%= render :partial => 'estimates/sidebar' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index df9763a..175a932 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,6 +1,6 @@ #The MIT License (MIT) # -#Copyright (c) 2017 rick barrette +#Copyright (c) 2022 rick barrette # #Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # @@ -9,6 +9,7 @@ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # English strings go here for Rails i18n +# Usage t(:label) en: # my_label: "My label" field_customer: "Customer" @@ -16,9 +17,11 @@ en: field_qbo_employee: "Employee" field_qbo_invoice: "Invoice" field_qbo_estimate: "Estimate" - field_vehicles: "Vehicle" + field_vehicles: "Vehicles" field_vehicle: "Vehicle" field_vin: "VIN" field_notes: "Notes" field_qbo_billed: "Billed" label_week: "Week" + label_search_estimates: "Search Estimates" + label_search: "Search" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index d057732..b738998 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ get 'qbo/sync', :to => 'qbo#sync' # Estimate & Invoice PDF get 'qbo/estimate/:id', :to => 'estimate#show', as: :estimate +get 'qbo/estimate/doc/:id', :to => 'estimate#doc', as: :estimate_doc get 'qbo/invoice/:id', :to => 'invoice#show', as: :invoice #manual billing @@ -47,3 +48,5 @@ end #allow for just vehicles too resources :vehicles + +#resources :qbo_estimates diff --git a/lib/view_hook_listener.rb b/lib/view_hook_listener.rb index f93b7a9..e5786bd 100644 --- a/lib/view_hook_listener.rb +++ b/lib/view_hook_listener.rb @@ -1,3 +1,3 @@ class ViewHookListener < Redmine::Hook::ViewListener - render_on :view_layouts_base_sidebar, :partial => "customers/sidebar" + render_on :view_layouts_base_sidebar, :partial => "qbo/sidebar" end