From 3fe911287a95c9e74e6508cadd5753be21682a24 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 15 Mar 2019 13:31:16 -0500 Subject: [PATCH] Add Campaign ID and campaign creator email to a payment report --- lib/query/query_payments.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/query/query_payments.rb b/lib/query/query_payments.rb index 0a0cf3dc..bef9a8bd 100644 --- a/lib/query/query_payments.rb +++ b/lib/query/query_payments.rb @@ -313,7 +313,7 @@ module QueryPayments .select(*export_selects) .left_outer_join('campaign_gifts', 'campaign_gifts.donation_id=donations.id') .left_outer_join('campaign_gift_options', 'campaign_gifts.campaign_gift_option_id=campaign_gift_options.id') - .left_outer_join('campaigns campaigns_for_export', 'donations.campaign_id=campaigns_for_export.id') + .left_outer_join("(#{campaigns_with_creator_email}) AS campaigns_for_export", 'donations.campaign_id=campaigns_for_export.id') .left_outer_join(tickets_subquery, 'tickets.payment_id=payments.id') .left_outer_join('events events_for_export', 'events_for_export.id=tickets.event_id OR donations.event_id=events_for_export.id') .left_outer_join('offsite_payments', 'offsite_payments.payment_id=payments.id') @@ -332,7 +332,7 @@ module QueryPayments .select(*export_selects) .left_outer_join('campaign_gifts', 'campaign_gifts.donation_id=donations.id') .left_outer_join('campaign_gift_options', 'campaign_gifts.campaign_gift_option_id=campaign_gift_options.id') - .left_outer_join('campaigns campaigns_for_export', 'donations.campaign_id=campaigns_for_export.id') + .left_outer_join("(#{campaigns_with_creator_email}) AS campaigns_for_export", 'donations.campaign_id=campaigns_for_export.id') .left_outer_join(tickets_subquery, 'tickets.payment_id=payments.id') .left_outer_join('events events_for_export', 'events_for_export.id=tickets.event_id OR donations.event_id=events_for_export.id') .left_outer_join('offsite_payments', 'offsite_payments.payment_id=payments.id') @@ -363,6 +363,8 @@ module QueryPayments 'donations.anonymous', 'donations.comment', "coalesce(nullif(campaigns_for_export.name, ''), 'None') AS campaign", + "campaigns_for_export.id AS campaign_id", + "coalesce(nullif(campaigns_for_export.creator_email, ''), '') AS campaign_creator_email", "coalesce(nullif(campaign_gift_options.name, ''), 'None') AS campaign_gift_level", 'events_for_export.name AS event_name', 'payments.id AS payment_id', @@ -454,4 +456,8 @@ module QueryPayments def self.campaign_and_child_query_as_raw_string "SELECT c_temp.id from campaigns c_temp where c_temp.id=$id OR c_temp.parent_campaign_id=$id" end + + def self.campaigns_with_creator_email + Qexpr.new.select('campaigns.*, users.email AS creator_email').from(:campaigns).left_outer_join(:profiles, "profiles.id = campaigns.profile_id").left_outer_join(:users, 'users.id = profiles.user_id') + end end