// 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
$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') {
$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",
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";
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) {
'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
$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"));
* @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,
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')),
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;
}
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);
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;
<td>{$row.contact_type}</td>
<td><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contact_id`"}">{$row.sort_name}</a></td>
{/if}
- <td class="right bold crm-contribution-amount"><span class="nowrap">{$row.total_amount|crmMoney:$row.currency}</span> {if $row.amount_level }<br /> ({$row.amount_level}){/if}
- {if $row.contribution_recur_id}
- <br /> {ts}(Recurring Contribution){/ts}
+ {if $row.contribution_soft_credit_amount}
+ <td class="right bold crm-contribution-amount"> </td>
+ {else}
+ <td class="right bold crm-contribution-amount"><span class="nowrap">{$row.total_amount|crmMoney:$row.currency}</span> {if $row.amount_level }<br /> ({$row.amount_level}){/if}
+ {if $row.contribution_recur_id}
+ <br /> {ts}(Recurring Contribution){/ts}
+ {/if}
+ </td>
+ {/if}
+ {if $softCreditColumns}
+ <td class="right bold crm-contribution-soft_credit_amount"><span class="nowrap">{$row.contribution_soft_credit_amount|crmMoney:$row.currency}</span></td>
{/if}
- </td>
<td class="crm-contribution-type crm-contribution-type_{$row.financial_type_id} crm-financial-type crm-financial-type_{$row.financial_type_id}">{$row.financial_type}</td>
<td class="crm-contribution-source">{$row.contribution_source}</td>
<td class="crm-contribution-receive_date">{$row.receive_date|crmDate}</td>
</td>
<td class="crm-contribution-product_name">{$row.product_name}</td>
{if $softCreditColumns}
- <td class="crm-contribution-soft_credit_name"><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contribution_soft_credit_contact_id`"}">{$row.contribution_soft_credit_name}</a></td>
- <td class="right bold crm-contribution-soft_credit_amount"><span class="nowrap">{$row.contribution_soft_credit_amount|crmMoney:$row.currency}</span></td>
+ <td class="crm-contribution-soft_credit_name"><a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$row.contribution_soft_credit_contact_id`"}">{$row.contribution_soft_credit_name}</a></td>
<td class="crm-contribution-soft_credit_type">{$row.contribution_soft_credit_type}</td>
{/if}
<td>{$row.action|replace:'xx':$row.contribution_id}</td>