From 4f3846df4f88c6d3d62beec133c6ec89216fe4e2 Mon Sep 17 00:00:00 2001 From: Deepak Srivastava Date: Thu, 6 Mar 2014 18:04:49 +0530 Subject: [PATCH] QILL, Overall Results Counter, Export duplicate bug, Moving/renaming amount column fixes --- CRM/Contribute/BAO/Query.php | 34 +++--- CRM/Contribute/Selector/Search.php | 128 ++++++++++++--------- CRM/Export/BAO/Export.php | 17 +-- templates/CRM/Contribute/Form/Selector.tpl | 18 ++- 4 files changed, 116 insertions(+), 81 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 092726307c..db981c061c 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -143,7 +143,7 @@ class CRM_Contribute_BAO_Query { // LCD 716 if (!empty($query->_returnProperties['contribution_soft_credit_name'])) { - $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.display_name as contribution_soft_credit_name"; + $query->_select['contribution_soft_credit_name'] = "civicrm_contact_d.sort_name as contribution_soft_credit_name"; $query->_element['contribution_soft_credit_name'] = 1; // also include contact id. Will help build hyperlinks @@ -372,7 +372,7 @@ class CRM_Contribute_BAO_Query { $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1; } else if ($value == 'both_related') { $query->_where[$grouping][] = "contribution_search_scredit_combined.filter_id IS NOT NULL"; - $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Both But Related'); + $query->_qill[$grouping][] = ts('Contributions OR Soft Credits? - Soft Credits with related Hard Credit'); $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; $query->_tables['civicrm_contribution_soft'] = $query->_whereTables['civicrm_contribution_soft'] = 1; } else if ($value == 'both') { @@ -405,7 +405,7 @@ class CRM_Contribute_BAO_Query { $scTypes = $value; $names[] = $softCreditTypes[$value]; } - $query->_qill[$grouping][] = ts('Contribution Status %1', array(1 => $op)) . " '" . implode("' " . ts('or') . " '", $names) . "'"; + $query->_qill[$grouping][] = ts('Soft Credit Type %1', array(1 => $op)) . " '" . implode("' " . ts('or') . " '", $names) . "'"; $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause( "civicrm_contribution_soft.soft_credit_type_id", @@ -806,11 +806,14 @@ class CRM_Contribute_BAO_Query { if (in_array(self::$_contribOrSoftCredit, array("only_scredits", "both_related", "both"))) { if (!$tempTableFilled) { + // build a temp table which is union of contributions and soft credits + // note: group-by in first part ensures uniqueness in counts $tempQuery = " CREATE TEMPORARY TABLE IF NOT EXISTS contribution_search_scredit_combined AS SELECT con.id as id, con.contact_id, cso.id as filter_id, NULL as scredit_id FROM civicrm_contribution con - LEFT JOIN civicrm_contribution_soft cso ON con.id = cso.contribution_id + LEFT JOIN civicrm_contribution_soft cso ON con.id = cso.contribution_id + GROUP BY id, contact_id, scredit_id UNION ALL SELECT scredit.contribution_id as id, scredit.contact_id, scredit.id as filter_id, scredit.id as scredit_id FROM civicrm_contribution_soft as scredit"; @@ -822,6 +825,18 @@ class CRM_Contribute_BAO_Query { return FALSE; } + static function softCreditReturnProperties($isExportMode = False) { + $properties = array( + 'contribution_soft_credit_name' => 1, + 'contribution_soft_credit_amount' => 1, + 'contribution_soft_credit_type' => 1, + ); + if ($isExportMode) { + $properties['contribution_soft_credit_contribution_id'] = 1; + } + return $properties; + } + static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_CONTRIBUTE) { @@ -864,14 +879,7 @@ class CRM_Contribute_BAO_Query { 'contribution_campaign_id' => 1, ); if (self::isSoftCreditOptionEnabled()) { - $properties = array_merge( - $properties, array( - 'contribution_soft_credit_name' => 1, - 'contribution_soft_credit_amount' => 1, - 'contribution_soft_credit_type' => 1, - 'contribution_soft_credit_contribution_id' => 1, - ) - ); + $properties = array_merge($properties, self::softCreditReturnProperties()); } if ($includeCustomFields) { // also get all the custom contribution properties @@ -988,7 +996,7 @@ class CRM_Contribute_BAO_Query { $options = array( 'only_contribs' => ts('Contributions Only'), 'only_scredits' => ts('Soft Credits Only'), - 'both_related' => ts('Both But Related'), + 'both_related' => ts('Soft Credits with related Hard Credit'), 'both' => ts('Both'), ); $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, array('class' => "crm-select2")); diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index 1301561e42..44ed3df808 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -307,6 +307,10 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { + if ($this->_includeSoftCredits) { + // especial sort order when rows include soft credits + $sort = "civicrm_contribution.receive_date DESC, civicrm_contribution.id, civicrm_contribution_soft.id"; + } $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, @@ -440,42 +444,60 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C public function &getColumnHeaders($action = NULL, $output = NULL) { self::$_columnHeaders = array( array( - 'name' => ts('Amount'), + 'name' => $this->_includeSoftCredits ? ts('Contribution Amount') : ts('Amount'), 'sort' => 'total_amount', 'direction' => CRM_Utils_Sort::DONTCARE, ), - array( - 'name' => ts('Type'), - 'sort' => 'financial_type_id', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), - array( - 'name' => ts('Source'), - 'sort' => 'contribution_source', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), - array( - 'name' => ts('Received'), - 'sort' => 'receive_date', - 'direction' => CRM_Utils_Sort::DESCENDING, - ), - array( - 'name' => ts('Thank-you Sent'), - 'sort' => 'thankyou_date', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), - array( - 'name' => ts('Status'), - 'sort' => 'contribution_status_id', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), - array( - 'name' => ts('Premium'), - 'sort' => 'product_name', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), ); - + if ($this->_includeSoftCredits) { + self::$_columnHeaders = + array_merge( + self::$_columnHeaders, + array( + array( + 'name' => ts('Soft Credit Amount'), + 'sort' => 'contribution_soft_credit_amount', + 'direction' => CRM_Utils_Sort::DONTCARE, + ) + ) + ); + } + self::$_columnHeaders = + array_merge( + self::$_columnHeaders, + array( + array( + 'name' => ts('Type'), + 'sort' => 'financial_type_id', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), + array( + 'name' => ts('Source'), + 'sort' => 'contribution_source', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), + array( + 'name' => ts('Received'), + 'sort' => 'receive_date', + 'direction' => CRM_Utils_Sort::DESCENDING, + ), + array( + 'name' => ts('Thank-you Sent'), + 'sort' => 'thankyou_date', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), + array( + 'name' => ts('Status'), + 'sort' => 'contribution_status_id', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), + array( + 'name' => ts('Premium'), + 'sort' => 'product_name', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), + ) + ); if (!$this->_single) { $pre = array( array('desc' => ts('Contact Type')), @@ -488,31 +510,29 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C self::$_columnHeaders = array_merge($pre, self::$_columnHeaders); } if ($this->_includeSoftCredits) { - $softCreditColumns = - array( + self::$_columnHeaders = + array_merge( + self::$_columnHeaders, array( - 'name' => ts('Soft Credit For'), - 'sort' => 'contribution_soft_credit_name', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), - array( - 'name' => ts('Soft Credit Amount'), - 'sort' => 'contribution_soft_credit_amount', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), - array( - 'name' => ts('Soft Credit Type'), - 'sort' => 'contribution_soft_credit_type', - 'direction' => CRM_Utils_Sort::DONTCARE, - ), + array( + 'name' => ts('Soft Credit For'), + 'sort' => 'contribution_soft_credit_name', + 'direction' => CRM_Utils_Sort::DONTCARE, + ), + array( + 'name' => ts('Soft Credit Type'), + 'sort' => 'contribution_soft_credit_type', + 'direction' => CRM_Utils_Sort::ASCENDING, + ), + ) ); - self::$_columnHeaders = array_merge(self::$_columnHeaders, $softCreditColumns); } - self::$_columnHeaders = array_merge( - self::$_columnHeaders, array( - array('desc' => ts('Actions')) - ) - ); + self::$_columnHeaders = + array_merge( + self::$_columnHeaders, array( + array('desc' => ts('Actions')) + ) + ); return self::$_columnHeaders; } diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php index 4c28c86941..0ba5b3fce7 100644 --- a/CRM/Export/BAO/Export.php +++ b/CRM/Export/BAO/Export.php @@ -309,11 +309,11 @@ class CRM_Export_BAO_Export { if ($queryMode != CRM_Contact_BAO_Query::MODE_CONTACTS) { $componentReturnProperties = CRM_Contact_BAO_Query::defaultReturnProperties($queryMode); if ($queryMode == CRM_Contact_BAO_Query::MODE_CONTRIBUTE) { - // Following is not automatically populated because contribution search doesn't require them by default - $componentReturnProperties['contribution_soft_credit_name'] = 1; - $componentReturnProperties['contribution_soft_credit_amount'] = 1; - $componentReturnProperties['contribution_soft_credit_type'] = 1; - $componentReturnProperties['contribution_soft_credit_contribution_id'] = 1; + // soft credit columns are not automatically populated, because contribution search doesn't require them by default + $componentReturnProperties = + array_merge( + $componentReturnProperties, + CRM_Contribute_BAO_Query::softCreditReturnProperties()); } $returnProperties = array_merge($returnProperties, $componentReturnProperties); @@ -562,9 +562,10 @@ INSERT INTO {$componentTable} SELECT distinct gc.contact_id FROM civicrm_group_c switch ($exportMode) { case CRM_Export_Form_Select::CONTRIBUTE_EXPORT: - if (!CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled()) { - // apply group-by only when no soft credit columns are included - $groupBy = 'GROUP BY civicrm_contribution.id'; + $groupBy = 'GROUP BY civicrm_contribution.id'; + if (CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled()) { + // especial group by when soft credit columns are included + $groupBy = 'GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.scredit_id'; } break; diff --git a/templates/CRM/Contribute/Form/Selector.tpl b/templates/CRM/Contribute/Form/Selector.tpl index 7b341377d7..838345074b 100644 --- a/templates/CRM/Contribute/Form/Selector.tpl +++ b/templates/CRM/Contribute/Form/Selector.tpl @@ -62,11 +62,18 @@ {$row.contact_type} {$row.sort_name} {/if} - {$row.total_amount|crmMoney:$row.currency} {if $row.amount_level }
({$row.amount_level}){/if} - {if $row.contribution_recur_id} -
{ts}(Recurring Contribution){/ts} + {if $row.contribution_soft_credit_amount} +   + {else} + {$row.total_amount|crmMoney:$row.currency} {if $row.amount_level }
({$row.amount_level}){/if} + {if $row.contribution_recur_id} +
{ts}(Recurring Contribution){/ts} + {/if} + + {/if} + {if $softCreditColumns} + {$row.contribution_soft_credit_amount|crmMoney:$row.currency} {/if} - {$row.financial_type} {$row.contribution_source} {$row.receive_date|crmDate} @@ -79,8 +86,7 @@ {$row.product_name} {if $softCreditColumns} - {$row.contribution_soft_credit_name} - {$row.contribution_soft_credit_amount|crmMoney:$row.currency} + {$row.contribution_soft_credit_name} {$row.contribution_soft_credit_type} {/if} {$row.action|replace:'xx':$row.contribution_id} -- 2.25.1