From 66495d25d8218366e846402cfbd904020651dfd7 Mon Sep 17 00:00:00 2001 From: francescbassas Date: Wed, 19 Feb 2020 18:05:35 +0100 Subject: [PATCH] dev/core#1386 Allow advanced search for contributions without a soft credit related --- CRM/Contribute/BAO/Query.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 53546df6d8..6b3b85908e 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -295,12 +295,18 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { } elseif ($value == 'both_related') { $query->_where[$grouping][] = "contribution_search_scredit_combined.filter_id IS NOT NULL"; - $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Soft Credits with related Hard Credit'); + $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Contributions and their related soft credit'); $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1; } elseif ($value == 'both') { - $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Both'); + $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - All'); + $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; + $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1; + } + elseif ($value == 'only_contribs_unsoftcredited') { + $query->_where[$grouping][] = "contribution_search_scredit_combined.filter_id IS NULL"; + $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Contributions without a soft credit'); $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1; } @@ -513,7 +519,7 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { switch ($name) { case 'civicrm_contribution': $from = " $side JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id "; - if (in_array(self::$_contribOrSoftCredit, ["only_scredits", "both_related", "both"])) { + if (in_array(self::$_contribOrSoftCredit, ["only_scredits", "both_related", "both", "only_contribs_unsoftcredited"])) { // switch the from table if its only soft credit search $from = " $side JOIN " . \Civi::$statics[__CLASS__]['soft_credit_temp_table_name'] . " as contribution_search_scredit_combined ON contribution_search_scredit_combined.contact_id = contact_a.id "; $from .= " $side JOIN civicrm_contribution ON civicrm_contribution.id = contribution_search_scredit_combined.id "; @@ -598,13 +604,13 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { break; case 'civicrm_contribution_soft': - if (!in_array(self::$_contribOrSoftCredit, ["only_scredits", "both_related", "both"])) { + if (!in_array(self::$_contribOrSoftCredit, ["only_scredits", "both_related", "both", "only_contribs_unsoftcredited"])) { $from = " $side JOIN civicrm_contribution_soft ON civicrm_contribution_soft.contribution_id = civicrm_contribution.id"; } break; case 'civicrm_contribution_soft_contact': - if (in_array(self::$_contribOrSoftCredit, ["only_scredits", "both_related", "both"])) { + if (in_array(self::$_contribOrSoftCredit, ["only_scredits", "both_related", "both", "only_contribs_unsoftcredited"])) { $from .= " $side JOIN civicrm_contact civicrm_contact_d ON (civicrm_contribution.contact_id = civicrm_contact_d.id ) AND contribution_search_scredit_combined.scredit_id IS NOT NULL"; } @@ -679,7 +685,7 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { } } if (in_array(self::$_contribOrSoftCredit, - ["only_scredits", "both_related", "both"])) { + ["only_scredits", "both_related", "both", "only_contribs_unsoftcredited"])) { if (!isset(\Civi::$statics[__CLASS__]['soft_credit_temp_table_name'])) { // build a temp table which is union of contributions and soft credits // note: group-by in first part ensures uniqueness in counts @@ -987,8 +993,9 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { $options = [ 'only_contribs' => ts('Contributions Only'), 'only_scredits' => ts('Soft Credits Only'), - 'both_related' => ts('Soft Credits with related Hard Credit'), - 'both' => ts('Both'), + 'both_related' => ts('Contributions and their related soft credit'), + 'both' => ts('All'), + 'only_contribs_unsoftcredited' => ts('Contributions without a soft credit'), ]; $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, ['class' => "crm-select2"]); $form->addSelect( -- 2.25.1