Skip to content

Commit

Permalink
Merge pull request #15834 from francescbassas/patch-16
Browse files Browse the repository at this point in the history
dev/core#1386 Allow advanced search for contributions without a soft credit related
  • Loading branch information
seamuslee001 authored Feb 21, 2020
2 parents e1ae2a8 + 66495d2 commit ee4ac4e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions CRM/Contribute/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,18 @@ public static function whereClauseSingle(&$values, &$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;
}
Expand Down Expand Up @@ -497,7 +503,7 @@ public static function from($name, $mode, $side) {
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 ";
Expand Down Expand Up @@ -582,13 +588,13 @@ public static function from($name, $mode, $side) {
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";
}
Expand Down Expand Up @@ -663,7 +669,7 @@ public static function isSoftCreditOptionEnabled($queryParams = []) {
}
}
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
Expand Down Expand Up @@ -966,8 +972,9 @@ public static function buildSearchForm(&$form) {
$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(
Expand Down

0 comments on commit ee4ac4e

Please sign in to comment.