diff --git a/lib/query/query_payments.rb b/lib/query/query_payments.rb index a958d031..7fb3119d 100644 --- a/lib/query/query_payments.rb +++ b/lib/query/query_payments.rb @@ -335,6 +335,11 @@ module QueryPayments } end + + def self.get_dedication_or_empty(*path) + "json_extract_path_text(coalesce(nullif(trim(both from donations.dedication), ''), '{}')::json, #{path.map{|i| "'#{i}'"}.join(',')})" + end + def self.export_selects ["to_char(payments.date::timestamptz, 'YYYY-MM-DD HH24:MI:SS TZ') AS date", '(payments.gross_amount / 100.0)::money::text AS gross_amount', @@ -344,7 +349,13 @@ module QueryPayments .concat(QuerySupporters.supporter_export_selections) .concat([ "coalesce(donations.designation, 'None') AS designation", - 'donations.dedication AS "Honorarium/Memorium"', + "#{get_dedication_or_empty('type')}::text AS \"Dedication Type\"", + "#{get_dedication_or_empty('name')}::text AS \"Dedicated To: Name\"", + "#{get_dedication_or_empty('supporter_id')}::text AS \"Dedicated To: Supporter ID\"", + "#{get_dedication_or_empty('contact', 'email')}::text AS \"Dedicated To: Email\"", + "#{get_dedication_or_empty('contact', "phone")}::text AS \"Dedicated To: Phone\"", + "#{get_dedication_or_empty( "contact", "address")}::text AS \"Dedicated To: Address\"", + "#{get_dedication_or_empty( "note")}::text AS \"Dedicated To: Note\"", 'donations.anonymous', 'donations.comment', "coalesce(nullif(campaigns_for_export.name, ''), 'None') AS campaign", diff --git a/spec/support/mock_helpers.rb b/spec/support/mock_helpers.rb index 5e2bbcbf..7ad6d901 100644 --- a/spec/support/mock_helpers.rb +++ b/spec/support/mock_helpers.rb @@ -1,7 +1,13 @@ # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later module MockHelpers def self.payment_export_headers() - ["Date",'Gross Amount', 'Fee Total', 'Net Amount','Type', 'Last Name', 'First Name','Full Name', 'Organization', 'Email', 'Phone', 'Address', 'City', 'State', 'Postal Code', 'Country', 'Anonymous?', 'Supporter Id', 'Designation', 'Honorarium/Memorium', 'Anonymous','Comment','Campaign', 'Campaign Gift Level', 'Event Name', 'Payment', 'Check Number', 'Donation Note'] + ["Date",'Gross Amount', 'Fee Total', 'Net Amount','Type', 'Last Name', 'First Name','Full Name', 'Organization', 'Email', 'Phone', 'Address', 'City', 'State', 'Postal Code', 'Country', 'Anonymous?', 'Supporter Id', 'Designation', "Dedication Type", + "Dedicated To: Name", + "Dedicated To: Supporter Id", + "Dedicated To: Email", + "Dedicated To: Phone", + "Dedicated To: Address", + "Dedicated To: Note", 'Anonymous','Comment','Campaign', 'Campaign Gift Level', 'Event Name', 'Payment', 'Check Number', 'Donation Note'] end def self.recurring_donation_export_headers()