Skip to content

Commit

Permalink
Merge pull request #12894 from seamuslee001/5.7
Browse files Browse the repository at this point in the history
5.7
  • Loading branch information
totten authored Oct 3, 2018
2 parents 3f8a216 + 811de8e commit 412c1f4
Show file tree
Hide file tree
Showing 4 changed files with 664 additions and 29 deletions.
66 changes: 37 additions & 29 deletions CRM/Report/Form/Contribute/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ public function __construct() {
'contribution_id' => array(
'name' => 'id',
'required' => TRUE,
'default' => TRUE,
'title' => ts('Contribution'),
),
),
Expand All @@ -262,6 +263,7 @@ public function __construct() {
'dao' => 'CRM_Contribute_DAO_ContributionSoft',
'fields' => array(
'soft_credit_type_id' => array('title' => ts('Soft Credit Type')),
'soft_credit_amount' => ['title' => ts('Soft Credit amount'), 'name' => 'amount', 'type' => CRM_Utils_Type::T_MONEY],
),
'filters' => array(
'soft_credit_type_id' => array(
Expand All @@ -272,6 +274,12 @@ public function __construct() {
'type' => CRM_Utils_Type::T_STRING,
),
),
'group_bys' => array(
'soft_credit_id' => array(
'name' => 'id',
'title' => ts('Soft Credit'),
),
),
),
'civicrm_financial_trxn' => array(
'dao' => 'CRM_Financial_DAO_FinancialTrxn',
Expand Down Expand Up @@ -376,18 +384,7 @@ public function from() {
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_contribution']}.contact_id
AND {$this->_aliases['civicrm_contribution']}.is_test = 0";

if (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) ==
'both'
) {
$this->_from .= "\n LEFT JOIN civicrm_contribution_soft contribution_soft_civireport
ON contribution_soft_civireport.contribution_id = {$this->_aliases['civicrm_contribution']}.id";
}
elseif (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) ==
'soft_credits_only'
) {
$this->_from .= "\n INNER JOIN civicrm_contribution_soft contribution_soft_civireport
ON contribution_soft_civireport.contribution_id = {$this->_aliases['civicrm_contribution']}.id";
}
$this->joinContributionToSoftCredit();
$this->appendAdditionalFromJoins();
}

Expand Down Expand Up @@ -533,9 +530,7 @@ public function beginPostProcessCommon() {
}
// 1. use main contribution query to build temp table 1
$sql = $this->buildQuery();
$tempQuery = "CREATE TEMPORARY TABLE civireport_contribution_detail_temp1 {$this->_databaseAttributes} AS {$sql}";
$this->temporaryTables['civireport_contribution_detail_temp1'] = ['name' => 'civireport_contribution_detail_temp1', 'temporary' => TRUE];
$this->executeReportQuery($tempQuery);
$this->createTemporaryTable('civireport_contribution_detail_temp1', $sql);
$this->setPager();

// 2. customize main contribution query for soft credit, and build temp table 2 with soft credit contributions only
Expand All @@ -551,13 +546,10 @@ public function beginPostProcessCommon() {

$select = str_ireplace('contribution_civireport.total_amount', 'contribution_soft_civireport.amount', $this->_select);
$select = str_ireplace("'Contribution' as", "'Soft Credit' as", $select);
// We really don't want to join soft credit in if not required.
if (!empty($this->_groupBy) && !$this->noDisplayContributionOrSoftColumn) {
$this->_groupBy .= ', contribution_soft_civireport.amount';
}

// we inner join with temp1 to restrict soft contributions to those in temp1 table.
// no group by here as we want to display as many soft credit rows as actually exist.
$sql = "{$select} {$this->_from} {$this->_where}";
$sql = "{$select} {$this->_from} {$this->_where} $this->_groupBy";
$tempQuery = "CREATE TEMPORARY TABLE civireport_contribution_detail_temp2 {$this->_databaseAttributes} AS {$sql}";
$this->executeReportQuery($tempQuery);
$this->temporaryTables['civireport_contribution_detail_temp2'] = ['name' => 'civireport_contribution_detail_temp2', 'temporary' => TRUE];
Expand All @@ -583,7 +575,7 @@ public function beginPostProcessCommon() {
if ($this->isContributionBaseMode
) {
$this->executeReportQuery(
"CREATE TEMPORARY TABLE civireport_contribution_detail_temp3 {$this->_databaseAttributes} AS (SELECT * FROM civireport_contribution_detail_temp1)"
"CREATE TEMPORARY TABLE civireport_contribution_detail_temp3 {$this->_databaseAttributes} AS (SELECT * FROM {$this->temporaryTables['civireport_contribution_detail_temp1']['name']})"
);
}
elseif (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) ==
Expand All @@ -595,7 +587,7 @@ public function beginPostProcessCommon() {
}
else {
$this->executeReportQuery("CREATE TEMPORARY TABLE civireport_contribution_detail_temp3 {$this->_databaseAttributes}
(SELECT * FROM civireport_contribution_detail_temp1)
(SELECT * FROM {$this->temporaryTables['civireport_contribution_detail_temp1']['name']})
UNION ALL
(SELECT * FROM civireport_contribution_detail_temp2)");
}
Expand All @@ -606,12 +598,11 @@ public function beginPostProcessCommon() {
/**
* Store group bys into array - so we can check elsewhere what is grouped.
*
* If we are generating a table of soft credits we do not want to be using
* group by.
* If we are generating a table of soft credits we need to group by them.
*/
protected function storeGroupByArray() {
if ($this->queryMode === 'SoftCredit') {
$this->_groupByArray = [];
$this->_groupByArray = [$this->_aliases['civicrm_contribution_soft'] . '.id'];
}
else {
parent::storeGroupByArray();
Expand Down Expand Up @@ -744,7 +735,7 @@ public function alterDisplay(&$rows) {
array_key_exists('civicrm_contribution_contribution_id', $row)
) {
$query = "
SELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount, civicrm_contribution_currency
SELECT civicrm_contact_id, civicrm_contact_sort_name, civicrm_contribution_total_amount_sum, civicrm_contribution_currency
FROM civireport_contribution_detail_temp2
WHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}";
$dao = CRM_Core_DAO::executeQuery($query);
Expand All @@ -755,7 +746,7 @@ public function alterDisplay(&$rows) {
$dao->civicrm_contact_id);
$string = $string . ($string ? $separator : '') .
"<a href='{$url}'>{$dao->civicrm_contact_sort_name}</a> " .
CRM_Utils_Money::format($dao->civicrm_contribution_total_amount, $dao->civicrm_contribution_currency);
CRM_Utils_Money::format($dao->civicrm_contribution_total_amount_sum, $dao->civicrm_contribution_currency);
}
$rows[$rowNum]['civicrm_contribution_soft_credits'] = $string;
}
Expand All @@ -767,7 +758,7 @@ public function alterDisplay(&$rows) {
) {
$query = "
SELECT civicrm_contact_id, civicrm_contact_sort_name
FROM civireport_contribution_detail_temp1
FROM {$this->temporaryTables['civireport_contribution_detail_temp1']['name']}
WHERE civicrm_contribution_contribution_id={$row['civicrm_contribution_contribution_id']}";
$dao = CRM_Core_DAO::executeQuery($query);
$string = '';
Expand Down Expand Up @@ -920,7 +911,7 @@ public function sectionTotals() {
public function softCreditFrom() {

$this->_from = "
FROM civireport_contribution_detail_temp1 temp1_civireport
FROM {$this->temporaryTables['civireport_contribution_detail_temp1']['name']} temp1_civireport
INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
ON temp1_civireport.civicrm_contribution_contribution_id = {$this->_aliases['civicrm_contribution']}.id
INNER JOIN civicrm_contribution_soft contribution_soft_civireport
Expand Down Expand Up @@ -975,4 +966,21 @@ public function appendAdditionalFromJoins() {
$this->addFinancialTrxnFromClause();
}

/**
* Add join to the soft credit table.
*/
protected function joinContributionToSoftCredit() {
if (!CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) && !$this->isTableSelected('civicrm_contribution_soft')) {
return;
}
$joinType = ' LEFT ';
if (CRM_Utils_Array::value('contribution_or_soft_value', $this->_params) == 'soft_credits_only') {
$joinType = ' INNER ';
}
$this->_from .= "
$joinType JOIN civicrm_contribution_soft {$this->_aliases['civicrm_contribution_soft']}
ON {$this->_aliases['civicrm_contribution_soft']}.contribution_id = {$this->_aliases['civicrm_contribution']}.id
";
}

}
11 changes: 11 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ Other resources for identifying changes are:
* https://github.com/civicrm/civicrm-joomla
* https://github.com/civicrm/civicrm-wordpress

# CiviCRM 5.6.0

Released October 3, 2018

- **[Synopsis](release-notes/5.6.0.md#synopsis)**
- **[Features](release-notes/5.6.0.md#features)**
- **[Bugs resolved](release-notes/5.6.0.md#bugs)**
- **[Miscellany](release-notes/5.6.0.md#misc)**
- **[Credits](release-notes/5.6.0.md#credits)**
- **[Feedback](release-notes/5.6.0.md#feedback)**

## CiviCRM 5.5.0

Released September 5, 2018
Expand Down
Loading

0 comments on commit 412c1f4

Please sign in to comment.