diff --git a/lib/vehicles/hooks/pdf_hook_listener.rb b/lib/vehicles/hooks/pdf_hook_listener.rb index 3f8365b..5ec99b8 100644 --- a/lib/vehicles/hooks/pdf_hook_listener.rb +++ b/lib/vehicles/hooks/pdf_hook_listener.rb @@ -20,17 +20,27 @@ module Vehicles def pdf_left(context={}) output = [] output << [l(:field_vehicles), context[:issue].vehicle ? context[:issue].vehicle.to_s : nil] - output << [l(:field_vin), context[:issue].vehicle ? pdf_vin(context[:issue].vehicle.vin) : nil] + output << pdf_vin_row(context[:issue].vehicle&.vin) output << [l(:field_notes), context[:issue].vehicle ? context[:issue].vehicle.notes : nil] return output end private - # 17-character VINs are split before the last 8 (what dealerships ask for); others stay whole - def pdf_vin(vin) + # Same as on screen: 17-character VINs with the last 8 in bold (what dealerships ask for when + # ordering parts), older or short VINs plain. Bold needs redmine_qbo's HTML values in its PDF grid; + # with an older redmine_qbo the last 8 are set apart with a space instead. + def pdf_vin_row(vin) vin = vin.to_s - vin.length == 17 ? "#{vin[0, 9]} #{vin[9, 8]}" : vin + return [l(:field_vin), nil] if vin.empty? + return [l(:field_vin), vin] unless vin.length == 17 + + first, last = ERB::Util.h(vin[0, 9]), ERB::Util.h(vin[9, 8]) + if defined?(RedmineQbo::Patches::PdfPatch::PDF_HTML_VALUES) + [l(:field_vin), vin, { html: "#{first}#{last}" }] + else + [l(:field_vin), "#{vin[0, 9]} #{vin[9, 8]}"] + end end end