From d91e7892c3ec2307c79e3482f79d661eefb43337 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sun, 13 Mar 2022 22:36:34 -0400 Subject: [PATCH] Added PDF hooks --- lib/pdf_patch.rb | 19 ++++++++----------- lib/qbo_hook_listener.rb | 25 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/lib/pdf_patch.rb b/lib/pdf_patch.rb index ed659b0..6c717c7 100644 --- a/lib/pdf_patch.rb +++ b/lib/pdf_patch.rb @@ -55,16 +55,10 @@ module IssuesPdfHelperPatch left << [l(:field_priority), issue.priority] left << [l(:field_customer), customer] left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id') - #left << [l(:field_category), issue.category] unless issue.disabled_core_fields.include?('category_id') - #left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id') - - v = Vehicle.find_by_id(issue.vehicles_id) - vehicle = v ? v.to_s : nil - vin = v ? v.vin : nil - notes = v ? v.notes : nil - left << [l(:field_vehicles), vehicle] - left << [l(:field_vin), vin ? vin.gsub(/(.{9})/, '\1 ') : nil] - #left << [l(:field_notes), notes] + + logger.debug "Calling :pdf_left hook" + context = Redmine::Hook.call_hook :pdf_left, { array: left, issue: issue } + left = left + context.first unless context.nil? right = [] right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date') @@ -72,7 +66,10 @@ module IssuesPdfHelperPatch right << [l(:field_done_ratio), "#{issue.done_ratio}%"] unless issue.disabled_core_fields.include?('done_ratio') right << [l(:field_estimated_hours), l_hours(issue.estimated_hours)] unless issue.disabled_core_fields.include?('estimated_hours') right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project) - right << [l(:field_notes), notes] + + logger.debug "Calling :pdf_right hook" + context = Redmine::Hook.call_hook :pdf_right, { array: right, issue: issue } + right = right + context.first unless context.nil? rows = left.size > right.size ? left.size : right.size while left.size < rows diff --git a/lib/qbo_hook_listener.rb b/lib/qbo_hook_listener.rb index bcd6de4..1853444 100644 --- a/lib/qbo_hook_listener.rb +++ b/lib/qbo_hook_listener.rb @@ -11,7 +11,7 @@ # TODO move this into seperate plugin class QboHookListener < Redmine::Hook::Listener - # Load the javascript to support the autocomplete forms + # Check to see if the Invoice custom field VIN matches def process_invoice_custom_fields(context = {}) Rails.logger.debug "QboHookListener.process_invoice_custom_fields" issue = context[:issue] @@ -46,4 +46,27 @@ class QboHookListener < Redmine::Hook::Listener return { issue: issue, invoice: invoice, is_changed: is_changed } end + # Add vehicle information to the left side of the pdf attribute block + def pdf_left(context = {}) + left = [] + issue = context[:issue] + v = Vehicle.find_by_id(issue.vehicles_id) + vehicle = v.to_s unless v.nil? + vin = v.vin.gsub(/(.{9})/, '\1 ') unless v.nil? + + left << [l(:field_vehicles), vehicle] + left << [l(:field_vin), vin] + return left + end + + # Add vehicle information to the right side of the pdf attribute block + def pdf_right(context = {}) + right = [] + issue = context[:issue] + v = Vehicle.find_by_id(issue.vehicles_id) + notes = v unless v.nil? + right << [l(:field_notes), notes] + return right + end + end