3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Contribute_BAO_Query
extends CRM_Core_BAO_Query
{
35 public static $_contribOrSoftCredit = "only_contribs";
37 public static $_contribRecurPayment = NULL;
40 * Function get the searchable fields for contribution.
42 * This is basically the contribution fields plus some related entity fields.
44 * @param bool $checkPermission
47 * Associative array of contribution fields
49 public static function getFields($checkPermission = TRUE) {
50 if (!isset(\Civi
::$statics[__CLASS__
]) ||
!isset(\Civi
::$statics[__CLASS__
]['fields']) ||
!isset(\Civi
::$statics[__CLASS__
]['contribution'])) {
51 $fields = CRM_Contribute_BAO_Contribution
::exportableFields($checkPermission);
52 CRM_Contribute_BAO_Contribution
::appendPseudoConstantsToFields($fields);
53 unset($fields['contribution_contact_id']);
54 \Civi
::$statics[__CLASS__
]['fields']['contribution'] = $fields;
56 return \Civi
::$statics[__CLASS__
]['fields']['contribution'];
60 * If contributions are involved, add the specific contribute fields.
62 * @param CRM_Contact_BAO_Query $query
64 public static function select(&$query) {
65 // if contribute mode add contribution id
66 if ($query->_mode
& CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
) {
67 $query->_select
['contribution_id'] = "civicrm_contribution.id as contribution_id";
68 $query->_element
['contribution_id'] = 1;
69 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
72 // get accounting code
73 if (!empty($query->_returnProperties
['accounting_code'])) {
74 $query->_select
['accounting_code'] = "civicrm_financial_account.accounting_code as accounting_code";
75 $query->_element
['accounting_code'] = 1;
76 $query->_tables
['civicrm_accounting_code'] = 1;
77 $query->_tables
['civicrm_financial_account'] = 1;
80 if (!empty($query->_returnProperties
['contribution_note'])) {
81 $query->_select
['contribution_note'] = "civicrm_note.note as contribution_note";
82 $query->_element
['contribution_note'] = 1;
83 $query->_tables
['contribution_note'] = 1;
84 $query->_tables
['civicrm_contribution'] = 1;
87 if (!empty($query->_returnProperties
['contribution_batch'])) {
88 $query->_select
['contribution_batch'] = "civicrm_batch.title as contribution_batch";
89 $query->_element
['contribution_batch'] = 1;
90 $query->_tables
['civicrm_financial_trxn'] = 1;
91 $query->_tables
['contribution_batch'] = 1;
94 if (!empty($query->_returnProperties
['contribution_campaign_title'])) {
95 $query->_select
['contribution_campaign_title'] = "civicrm_campaign.title as contribution_campaign_title";
96 $query->_element
['contribution_campaign_title'] = $query->_tables
['civicrm_campaign'] = 1;
99 self
::addSoftCreditFields($query);
105 * @param CRM_Contact_BAO_Query $query
107 public static function where(&$query) {
108 self
::initializeAnySoftCreditClause($query);
109 foreach (array_keys($query->_params
) as $id) {
110 if (empty($query->_params
[$id][0])) {
113 if (substr($query->_params
[$id][0], 0, 13) == 'contribution_' ||
substr($query->_params
[$id][0], 0, 10) == 'financial_' ||
substr($query->_params
[$id][0], 0, 8) == 'payment_') {
114 if ($query->_mode
== CRM_Contact_BAO_QUERY
::MODE_CONTACTS
) {
115 $query->_useDistinct
= TRUE;
119 $query->_params
[$id][0] == 'contribution_type_id' ||
120 $query->_params
[$id][0] == 'contribution_type'
122 CRM_Core_Session
::setStatus(
123 ts('The contribution type criteria is now obsolete, please update your smart group'),
130 self
::whereClauseSingle($query->_params
[$id], $query);
136 * Get where clause for a single value.
138 * @param array $values
139 * @param CRM_Contact_BAO_Query $query
141 public static function whereClauseSingle(&$values, &$query) {
142 list($name, $op, $value, $grouping, $wildcard) = $values;
145 $fields = self
::getFields();
147 if (!empty($value) && !is_array($value)) {
148 $quoteValue = "\"$value\"";
151 $recurrringFields = CRM_Contribute_BAO_ContributionRecur
::getRecurringFields();
152 unset($recurrringFields['contribution_recur_payment_made']);
153 foreach ($recurrringFields as $dateField => $dateFieldTitle) {
154 if (self
::buildDateWhere($values, $query, $name, $dateField, $dateFieldTitle)) {
158 // These are legacy names.
159 // @todo enotices when these are hit so we can start to elimnate them.
161 'financial_type' => 'financial_type_id',
162 'contribution_page' => 'contribution_page_id',
163 'payment_instrument' => 'payment_instrument_id',
164 // or payment_instrument_id?
165 'contribution_payment_instrument' => 'contribution_payment_instrument_id',
166 'contribution_status' => 'contribution_status_id',
169 $name = isset($fieldAliases[$name]) ?
$fieldAliases[$name] : $name;
171 if (in_array($name, $fieldAliases)) {
172 $qillName = array_search($name, $fieldAliases);
174 $pseudoExtraParam = [];
177 case 'contribution_date':
178 case 'contribution_date_low':
179 case 'contribution_date_low_time':
180 case 'contribution_date_high':
181 case 'contribution_date_high_time':
182 // process to / from date
183 $query->dateQueryBuilder($values,
184 'civicrm_contribution', 'contribution_date', 'receive_date', ts('Contribution Date')
188 case 'contribution_amount':
189 case 'contribution_amount_low':
190 case 'contribution_amount_high':
191 // process min/max amount
192 $query->numberRangeBuilder($values,
193 'civicrm_contribution', 'contribution_amount',
194 'total_amount', 'Contribution Amount',
199 case 'contribution_thankyou_date_is_not_null':
202 $query->_qill
[$grouping][] = ts('Contribution Thank-you Sent');
206 $query->_qill
[$grouping][] = ts('Contribution Thank-you Not Sent');
208 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution.thankyou_date", $op);
209 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
212 case 'contribution_receipt_date_is_not_null':
215 $query->_qill
[$grouping][] = ts('Contribution Receipt Sent');
219 $query->_qill
[$grouping][] = ts('Contribution Receipt Not Sent');
221 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution.receipt_date", $op);
222 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
225 case 'contribution_cancel_date':
226 case 'contribution_cancel_date_low':
227 case 'contribution_cancel_date_low_time':
228 case 'contribution_cancel_date_high':
229 case 'contribution_cancel_date_high_time':
230 // process to / from date
231 $query->dateQueryBuilder($values,
232 'civicrm_contribution', 'contribution_cancel_date', 'cancel_date', ts('Cancelled / Refunded Date')
236 case 'financial_type_id':
238 case 'invoice_number':
239 case 'payment_instrument_id':
240 case 'contribution_payment_instrument_id':
241 case 'contribution_page_id':
242 case 'contribution_status_id':
243 case 'contribution_id':
244 case 'contribution_currency_type':
245 case 'contribution_currency':
246 case 'contribution_source':
247 case 'contribution_trxn_id':
248 case 'contribution_check_number':
249 case 'contribution_contact_id':
250 case (strpos($name, '_amount') !== FALSE):
251 case (strpos($name, '_date') !== FALSE && $name != 'contribution_fulfilled_date'):
252 case 'contribution_campaign_id':
254 $fieldNamesNotToStripContributionFrom = [
255 'contribution_currency_type',
256 'contribution_status_id',
257 'contribution_page_id',
259 // @todo these are mostly legacy params. Find a better way to deal with them.
260 if (!in_array($name, $fieldNamesNotToStripContributionFrom)
262 if (!isset($fields[$name])) {
263 $qillName = str_replace('contribution_', '', $qillName);
265 $name = str_replace('contribution_', '', $name);
267 if (in_array($name, ['contribution_currency', 'contribution_currency_type'])) {
268 $qillName = $name = 'currency';
269 $pseudoExtraParam = ['labelColumn' => 'name'];
272 $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type
::typeToString($fields[$qillName]['type']) : 'String';
274 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution.$name", $op, $value, $dataType);
275 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', $name, $value, $op, $pseudoExtraParam);
276 if (!($name == 'id' && $value == 0)) {
277 $query->_qill
[$grouping][] = ts('%1 %2 %3', [1 => $fields[$qillName]['title'], 2 => $op, 3 => $value]);
279 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
282 case 'contribution_pcp_made_through_id':
283 case 'contribution_soft_credit_type_id':
285 if ($name == 'contribution_pcp_made_through_id') {
286 $qillName = $name = 'pcp_id';
287 $fields[$name] = ['title' => ts('Personal Campaign Page'), 'type' => 2];
289 if ($name == 'contribution_soft_credit_type_id') {
290 $qillName = str_replace('_id', '', $qillName);
291 $fields[$qillName]['type'] = $fields[$qillName]['data_type'];
292 $name = str_replace('contribution_', '', $name);
294 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution_soft.$name",
295 $op, $value, CRM_Utils_Type
::typeToString($fields[$qillName]['type'])
297 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Contribute_DAO_ContributionSoft', $name, $value, $op);
298 $query->_qill
[$grouping][] = ts('%1 %2 %3', [1 => $fields[$qillName]['title'], 2 => $op, 3 => $value]);
299 $query->_tables
['civicrm_contribution_soft'] = $query->_whereTables
['civicrm_contribution_soft'] = 1;
302 case 'contribution_or_softcredits':
303 if ($value == 'only_scredits') {
304 $query->_where
[$grouping][] = "contribution_search_scredit_combined.scredit_id IS NOT NULL";
305 $query->_qill
[$grouping][] = ts('Contributions OR Soft Credits? - Soft Credits Only');
306 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
307 $query->_tables
['civicrm_contribution_soft'] = $query->_whereTables
['civicrm_contribution_soft'] = 1;
309 elseif ($value == 'both_related') {
310 $query->_where
[$grouping][] = "contribution_search_scredit_combined.filter_id IS NOT NULL";
311 $query->_qill
[$grouping][] = ts('Contributions OR Soft Credits? - Soft Credits with related Hard Credit');
312 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
313 $query->_tables
['civicrm_contribution_soft'] = $query->_whereTables
['civicrm_contribution_soft'] = 1;
315 elseif ($value == 'both') {
316 $query->_qill
[$grouping][] = ts('Contributions OR Soft Credits? - Both');
317 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
318 $query->_tables
['civicrm_contribution_soft'] = $query->_whereTables
['civicrm_contribution_soft'] = 1;
320 // default option: $value == 'only_contribs'
323 case 'contribution_is_test':
324 // By default is Contribution Search form we choose is_test = 0 in otherwords always show active contribution
325 // so in case if any one choose any Yes/No avoid the default clause otherwise it will be conflict in whereClause
326 $key = array_search('civicrm_contribution.is_test = 0', $query->_where
[$grouping]);
328 unset($query->_where
[$grouping][$key]);
330 case 'contribution_test':
331 // We dont want to include all tests for sql OR CRM-7827
332 if (!$value ||
$query->getOperator() != 'OR') {
333 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution.is_test", $op, $value, "Boolean");
335 $query->_qill
[$grouping][] = ts("Only Display Test Contributions");
337 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
341 case 'contribution_is_pay_later':
342 case 'contribution_pay_later':
343 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution.is_pay_later", $op, $value, "Boolean");
345 $query->_qill
[$grouping][] = ts("Find Pay Later Contributions");
348 $query->_qill
[$grouping][] = ts("Exclude Pay Later Contributions");
350 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
353 case 'contribution_recurring':
355 $query->_where
[$grouping][] = "civicrm_contribution.contribution_recur_id IS NOT NULL";
356 $query->_qill
[$grouping][] = ts("Find Recurring Contributions");
357 $query->_tables
['civicrm_contribution_recur'] = $query->_whereTables
['civicrm_contribution_recur'] = 1;
360 $query->_where
[$grouping][] = "civicrm_contribution.contribution_recur_id IS NULL";
361 $query->_qill
[$grouping][] = ts("Exclude Recurring Contributions");
365 case 'contribution_recur_id':
366 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution.contribution_recur_id",
367 $op, $value, "Integer"
369 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
372 case 'contribution_recur_payment_processor_id':
373 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution_recur.payment_processor_id", $op, $value, "String");
374 $paymentProcessors = civicrm_api3('PaymentProcessor', 'get', []);
375 $paymentProcessorNames = [];
376 foreach ($value as $paymentProcessorId) {
377 $paymentProcessorNames[] = $paymentProcessors['values'][$paymentProcessorId]['name'];
379 $query->_qill
[$grouping][] = ts("Recurring Contribution Payment Processor %1 %2", [1 => $op, 2 => implode(', ', $paymentProcessorNames)]);
380 $query->_tables
['civicrm_contribution_recur'] = $query->_whereTables
['civicrm_contribution_recur'] = 1;
383 case 'contribution_recur_processor_id':
384 case 'contribution_recur_trxn_id':
385 $fieldName = str_replace('contribution_recur_', '', $name);
386 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution_recur.{$fieldName}",
387 $op, $value, "String"
389 $recurFields = CRM_Contribute_DAO_ContributionRecur
::fields();
390 $query->_qill
[$grouping][] = ts("Recurring Contribution %1 %2 '%3'", [1 => $recurFields[$fieldName]['title'], 2 => $op, 3 => $value]);
391 $query->_tables
['civicrm_contribution_recur'] = $query->_whereTables
['civicrm_contribution_recur'] = 1;
394 case 'contribution_recur_payment_made':
395 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution_recur.id", 'IS NOT EMPTY');
397 $query->_qill
[$grouping][] = ts("Recurring contributions with at least one payment");
398 self
::$_contribRecurPayment = TRUE;
401 $query->_qill
[$grouping][] = ts("All recurring contributions regardless of payments");
402 self
::$_contribRecurPayment = FALSE;
404 $query->_tables
['civicrm_contribution_recur'] = $query->_whereTables
['civicrm_contribution_recur'] = 1;
407 case 'contribution_recur_contribution_status_id':
408 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution_recur.contribution_status_id", $op, $value, 'String');
409 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Contribute_DAO_ContributionRecur', 'contribution_status_id', $value, $op, $pseudoExtraParam);
410 $query->_qill
[$grouping][] = ts("Recurring Contribution Status %1 '%2'", [1 => $op, 2 => $value]);
411 $query->_tables
['civicrm_contribution_recur'] = $query->_whereTables
['civicrm_contribution_recur'] = 1;
414 case 'contribution_note':
415 $value = CRM_Core_DAO
::escapeString($value);
420 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_note.note', $op, $value, "String");
421 $query->_qill
[$grouping][] = ts('Contribution Note %1 %2', [1 => $op, 2 => $quoteValue]);
422 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = $query->_whereTables
['contribution_note'] = 1;
425 case 'contribution_membership_id':
426 $query->_where
[$grouping][] = " civicrm_membership.id $op $value";
427 $query->_tables
['contribution_membership'] = $query->_whereTables
['contribution_membership'] = 1;
431 case 'contribution_participant_id':
432 $query->_where
[$grouping][] = " civicrm_participant.id $op $value";
433 $query->_tables
['contribution_participant'] = $query->_whereTables
['contribution_participant'] = 1;
436 case 'contribution_pcp_display_in_roll':
437 $query->_where
[$grouping][] = " civicrm_contribution_soft.pcp_display_in_roll $op '$value'";
439 $query->_qill
[$grouping][] = ts("Personal Campaign Page Honor Roll");
442 $query->_qill
[$grouping][] = ts("NOT Personal Campaign Page Honor Roll");
444 $query->_tables
['civicrm_contribution_soft'] = $query->_whereTables
['civicrm_contribution_soft'] = 1;
447 case 'contribution_batch_id':
448 list($qillOp, $qillValue) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Batch_BAO_EntityBatch', 'batch_id', $value, $op);
449 $query->_qill
[$grouping][] = ts('Batch Name %1 %2', [1 => $qillOp, 2 => $qillValue]);
450 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_entity_batch.batch_id', $op, $value);
451 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
452 $query->_tables
['civicrm_financial_trxn'] = $query->_whereTables
['civicrm_financial_trxn'] = 1;
453 $query->_tables
['contribution_batch'] = $query->_whereTables
['contribution_batch'] = 1;
456 case 'contribution_product_id':
457 // CRM-16713 - contribution search by premiums on 'Find Contribution' form.
459 list($operator, $productValue) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Contribute_DAO_Product', $name, $value, $op);
460 $query->_qill
[$grouping][] = ts('%1 %2 %3', [1 => $fields[$qillName]['title'], 2 => $operator, 3 => $productValue]);
461 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_product.id", $op, $value);
462 $query->_tables
['civicrm_product'] = $query->_whereTables
['civicrm_product'] = 1;
465 case 'contribution_is_payment':
466 $query->_where
[$grouping][] = " civicrm_financial_trxn.is_payment $op $value";
467 $query->_tables
['civicrm_financial_trxn'] = $query->_whereTables
['civicrm_financial_trxn'] = 1;
470 case 'financial_trxn_card_type_id':
471 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_financial_trxn.card_type_id', $op, $value);
472 $query->_tables
['civicrm_financial_trxn'] = $query->_whereTables
['civicrm_financial_trxn'] = 1;
473 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
474 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Financial_DAO_FinancialTrxn', 'card_type_id', $value, $op);
475 $query->_qill
[$grouping][] = ts('Card Type %1 %2', [1 => $op, 2 => $value]);
478 case 'financial_trxn_pan_truncation':
479 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_financial_trxn.pan_truncation', $op, $value);
480 $query->_tables
['civicrm_financial_trxn'] = $query->_whereTables
['civicrm_financial_trxn'] = 1;
481 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
482 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Financial_DAO_FinancialTrxn', 'pan_truncation', $value, $op);
483 $query->_qill
[$grouping][] = ts('Card Number %1 %2', [1 => $op, 2 => $value]);
487 //all other elements are handle in this case
488 $fldName = substr($name, 13);
489 CRM_Financial_BAO_FinancialType
::getAvailableFinancialTypes($financialTypes);
490 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_contribution.financial_type_id", 'IN', array_keys($financialTypes), 'String');
491 if (!isset($fields[$fldName])) {
493 CRM_Core_Session
::setStatus(ts(
494 'We did not recognize the search field: %1. Please check and fix your contribution related smart groups.',
500 $whereTable = $fields[$fldName];
501 if (!is_array($value)) {
502 $value = trim($value);
505 $dataType = "String";
506 if (!empty($whereTable['type'])) {
507 $dataType = CRM_Utils_Type
::typeToString($whereTable['type']);
510 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause($whereTable['where'], $op, $value, $dataType);
511 $query->_qill
[$grouping][] = "$whereTable[title] $op $quoteValue";
512 list($tableName) = explode('.', $whereTable['where'], 2);
513 $query->_tables
[$tableName] = $query->_whereTables
[$tableName] = 1;
514 if ($tableName == 'civicrm_contribution_product') {
515 $query->_tables
['civicrm_product'] = $query->_whereTables
['civicrm_product'] = 1;
516 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
519 $query->_tables
['civicrm_contribution'] = $query->_whereTables
['civicrm_contribution'] = 1;
527 * @param string $name
528 * @param string $mode
529 * @param string $side
531 * @return NULL|string
533 public static function from($name, $mode, $side) {
536 case 'civicrm_contribution':
537 $from = " $side JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id ";
538 if (in_array(self
::$_contribOrSoftCredit, ["only_scredits", "both_related", "both"])) {
539 // switch the from table if its only soft credit search
540 $from = " $side JOIN contribution_search_scredit_combined ON contribution_search_scredit_combined.contact_id = contact_a.id ";
541 $from .= " $side JOIN civicrm_contribution ON civicrm_contribution.id = contribution_search_scredit_combined.id ";
542 $from .= " $side JOIN civicrm_contribution_soft ON civicrm_contribution_soft.id = contribution_search_scredit_combined.scredit_id";
546 case 'civicrm_contribution_recur':
548 // 'Made payment for the recurring contributions?' is ticked yes
549 $from = " $side JOIN civicrm_contribution_recur ON contact_a.id = civicrm_contribution_recur.contact_id ";
550 if (self
::$_contribRecurPayment == TRUE) {
551 $from .= " INNER JOIN civicrm_contribution cr ON cr.contribution_recur_id = civicrm_contribution_recur.id ";
555 $from = " $side JOIN civicrm_contribution_recur ON civicrm_contribution.contribution_recur_id = civicrm_contribution_recur.id ";
559 case 'civicrm_financial_type':
560 if ($mode & CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
) {
561 $from = " INNER JOIN civicrm_financial_type ON civicrm_contribution.financial_type_id = civicrm_financial_type.id ";
564 $from = " $side JOIN civicrm_financial_type ON civicrm_contribution.financial_type_id = civicrm_financial_type.id ";
568 case 'civicrm_financial_account':
569 if ($mode & CRM_Contact_BAO_Query
::MODE_CONTACTS
) {
570 $from = " $side JOIN civicrm_financial_account ON contact_a.id = civicrm_financial_account.contact_id ";
574 case 'civicrm_accounting_code':
575 if ($mode & CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
) {
576 $from = " $side JOIN civicrm_entity_financial_account ON civicrm_entity_financial_account.entity_id = civicrm_contribution.financial_type_id AND civicrm_entity_financial_account.entity_table = 'civicrm_financial_type' ";
577 $from .= " INNER JOIN civicrm_financial_account ON civicrm_financial_account.id = civicrm_entity_financial_account.financial_account_id ";
578 $from .= " INNER JOIN civicrm_option_value cov ON cov.value = civicrm_entity_financial_account.account_relationship AND cov.name = 'Income Account is' ";
579 $from .= " INNER JOIN civicrm_option_group cog ON cog.id = cov.option_group_id AND cog.name = 'account_relationship' ";
583 case 'civicrm_contribution_page':
584 $from = " $side JOIN civicrm_contribution_page ON civicrm_contribution.contribution_page_id = civicrm_contribution_page.id";
587 case 'civicrm_product':
588 $from = " $side JOIN civicrm_contribution_product ON civicrm_contribution_product.contribution_id = civicrm_contribution.id";
589 $from .= " $side JOIN civicrm_product ON civicrm_contribution_product.product_id =civicrm_product.id ";
592 case 'contribution_softcredit_type':
593 $from = " $side JOIN civicrm_option_group option_group_contribution_softcredit_type ON
594 (option_group_contribution_softcredit_type.name = 'soft_credit_type')";
595 $from .= " $side JOIN civicrm_option_value contribution_softcredit_type ON
596 ( civicrm_contribution_soft.soft_credit_type_id = contribution_softcredit_type.value
597 AND option_group_contribution_softcredit_type.id = contribution_softcredit_type.option_group_id )";
600 case 'contribution_note':
601 $from .= " $side JOIN civicrm_note ON ( civicrm_note.entity_table = 'civicrm_contribution' AND
602 civicrm_contribution.id = civicrm_note.entity_id )";
605 case 'contribution_membership':
606 $from = " $side JOIN civicrm_membership_payment ON civicrm_membership_payment.contribution_id = civicrm_contribution.id";
607 $from .= " $side JOIN civicrm_membership ON civicrm_membership_payment.membership_id = civicrm_membership.id ";
610 case 'civicrm_campaign':
611 //CRM-16764 - get survey clause from campaign bao
612 if (!CRM_Campaign_BAO_Query
::$_applySurveyClause) {
613 $from = " $side JOIN civicrm_campaign ON civicrm_campaign.id = civicrm_contribution.campaign_id";
617 case 'contribution_participant':
618 $from = " $side JOIN civicrm_participant_payment ON civicrm_participant_payment.contribution_id = civicrm_contribution.id";
619 $from .= " $side JOIN civicrm_participant ON civicrm_participant_payment.participant_id = civicrm_participant.id ";
622 case 'civicrm_contribution_soft':
623 if (!in_array(self
::$_contribOrSoftCredit, ["only_scredits", "both_related", "both"])) {
624 $from = " $side JOIN civicrm_contribution_soft ON civicrm_contribution_soft.contribution_id = civicrm_contribution.id";
628 case 'civicrm_contribution_soft_contact':
629 if (in_array(self
::$_contribOrSoftCredit, ["only_scredits", "both_related", "both"])) {
630 $from .= " $side JOIN civicrm_contact civicrm_contact_d ON (civicrm_contribution.contact_id = civicrm_contact_d.id )
631 AND contribution_search_scredit_combined.scredit_id IS NOT NULL";
634 $from .= " $side JOIN civicrm_contact civicrm_contact_d ON (civicrm_contribution_soft.contact_id = civicrm_contact_d.id )";
638 case 'civicrm_contribution_soft_email':
639 $from .= " $side JOIN civicrm_email as soft_email ON (civicrm_contact_d.id = soft_email.contact_id )";
642 case 'civicrm_contribution_soft_phone':
643 $from .= " $side JOIN civicrm_phone as soft_phone ON (civicrm_contact_d.id = soft_phone.contact_id )";
646 case 'contribution_batch':
647 $from .= " $side JOIN civicrm_entity_batch ON ( civicrm_entity_batch.entity_table = 'civicrm_financial_trxn'
648 AND civicrm_financial_trxn.id = civicrm_entity_batch.entity_id )";
650 $from .= " $side JOIN civicrm_batch ON civicrm_entity_batch.batch_id = civicrm_batch.id";
653 case 'civicrm_financial_trxn':
654 $from .= " $side JOIN civicrm_entity_financial_trxn ON (
655 civicrm_entity_financial_trxn.entity_table = 'civicrm_contribution'
656 AND civicrm_contribution.id = civicrm_entity_financial_trxn.entity_id )";
658 $from .= " $side JOIN civicrm_financial_trxn ON (
659 civicrm_entity_financial_trxn.financial_trxn_id = civicrm_financial_trxn.id )";
666 * Initialise the soft credit clause.
668 * @param CRM_Contact_BAO_Query $query
670 public static function initializeAnySoftCreditClause(&$query) {
671 // @todo have a generic initialize on all components that gets called every query
672 // & rename this to match that fn name.
673 if ($query->_mode
& CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
) {
674 if (self
::isSoftCreditOptionEnabled($query->_params
)) {
675 unset($query->_distinctComponentClause
);
676 $query->_rowCountClause
= " count(civicrm_contribution.id)";
677 $query->_groupByComponentClause
= " GROUP BY contribution_search_scredit_combined.id, contribution_search_scredit_combined.contact_id, contribution_search_scredit_combined.scredit_id ";
680 $query->_distinctComponentClause
= ' civicrm_contribution.id';
686 * Check if soft credits are enables.
688 * @param array $queryParams
692 public static function isSoftCreditOptionEnabled($queryParams = []) {
693 static $tempTableFilled = FALSE;
694 if (!empty($queryParams)) {
695 foreach (array_keys($queryParams) as $id) {
696 if (empty($queryParams[$id][0])) {
699 if ($queryParams[$id][0] == 'contribution_or_softcredits') {
700 self
::$_contribOrSoftCredit = $queryParams[$id][2];
704 if (in_array(self
::$_contribOrSoftCredit,
705 ["only_scredits", "both_related", "both"])) {
706 if (!$tempTableFilled) {
707 // build a temp table which is union of contributions and soft credits
708 // note: group-by in first part ensures uniqueness in counts
710 CREATE TEMPORARY TABLE IF NOT EXISTS contribution_search_scredit_combined AS
711 SELECT con.id as id, con.contact_id, cso.id as filter_id, NULL as scredit_id
712 FROM civicrm_contribution con
713 LEFT JOIN civicrm_contribution_soft cso ON con.id = cso.contribution_id
714 GROUP BY id, contact_id, scredit_id, cso.id
716 SELECT scredit.contribution_id as id, scredit.contact_id, scredit.id as filter_id, scredit.id as scredit_id
717 FROM civicrm_contribution_soft as scredit";
718 CRM_Core_DAO
::executeQuery($tempQuery);
719 $tempTableFilled = TRUE;
727 * Get return properties for soft credits.
729 * @param bool $isExportMode
733 public static function softCreditReturnProperties($isExportMode = FALSE) {
735 'contribution_soft_credit_name' => 1,
736 'contribution_soft_credit_amount' => 1,
737 'contribution_soft_credit_type' => 1,
740 $properties['contribution_soft_credit_contact_id'] = 1;
741 $properties['contribution_soft_credit_contribution_id'] = 1;
747 * Get the list of fields required to populate the selector.
749 * The default return properties array returns far too many fields for 'everyday use. Every field you add to this array
750 * kills a small kitten so add carefully.
752 * @param array $queryParams
755 public static function selectorReturnProperties($queryParams) {
758 'contact_sub_type' => 1,
760 'financial_type' => 1,
761 'contribution_source' => 1,
765 'thankyou_date' => 1,
767 // Without this value here we get an e-notice BUT the value does not appear to be rendered anywhere.
768 'contribution_campaign_id' => 1,
769 'contribution_status_id' => 1,
770 // @todo return this & fix query to do pseudoconstant thing.
771 'contribution_status' => 1,
774 'contribution_recur_id' => 1,
776 if (self
::isSiteHasProducts()) {
777 $properties['product_name'] = 1;
778 $properties['contribution_product_id'] = 1;
780 if (self
::isSoftCreditOptionEnabled($queryParams)) {
781 $properties = array_merge($properties, self
::softCreditReturnProperties());
788 * Do any products exist in this site's database.
792 public static function isSiteHasProducts() {
793 if (!isset(\Civi
::$statics[__CLASS__
]['has_products'])) {
794 \Civi
::$statics[__CLASS__
]['has_products'] = (bool) CRM_Core_DAO
::singleValueQuery('SELECT id FROM civicrm_contribution_product LIMIT 1');
796 return \Civi
::$statics[__CLASS__
]['has_products'];
800 * Function you should avoid.
802 * This function returns default properties for contribution queries. However, they are
803 * far more than are required in 'most' cases and you should always try to return the return properties
804 * you actually require.
806 * It would be nice to throw an e-notice when this is called but it would trash the tests :-(.
809 * @param bool $includeCustomFields
813 public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) {
815 if ($mode & CRM_Contact_BAO_Query
::MODE_CONTRIBUTE
) {
820 'contact_sub_type' => 1,
826 'financial_type' => 1,
828 'contribution_source' => 1,
832 'thankyou_date' => 1,
838 'accounting_code' => 1,
840 'payment_instrument' => 1,
842 'payment_instrument_id' => 1,
844 'contribution_check_number' => 1,
846 'non_deductible_amount' => 1,
855 'invoice_number' => 1,
859 'cancel_reason' => 1,
873 'contribution_status' => 1,
875 'contribution_status_id' => 1,
877 'contribution_recur_id' => 1,
881 'contribution_note' => 1,
883 'contribution_batch' => 1,
885 'contribution_campaign_title' => 1,
887 'contribution_campaign_id' => 1,
891 if (self
::isSiteHasProducts()) {
892 $properties['fulfilled_date'] = 1;
893 $properties['product_name'] = 1;
894 $properties['contribution_product_id'] = 1;
895 $properties['product_option'] = 1;
896 $properties['sku'] = 1;
897 $properties['contribution_start_date'] = 1;
898 $properties['contribution_end_date'] = 1;
900 if (self
::isSoftCreditOptionEnabled()) {
901 $properties = array_merge($properties, self
::softCreditReturnProperties());
903 if ($includeCustomFields) {
904 // also get all the custom contribution properties
905 $fields = CRM_Core_BAO_CustomField
::getFieldsForImport('Contribution');
906 if (!empty($fields)) {
907 foreach ($fields as $name => $dontCare) {
908 $properties[$name] = 1;
917 * Add all the elements shared between contribute search and advnaced search.
919 * @param CRM_Core_Form $form
921 public static function buildSearchForm(&$form) {
923 // Added contribution source
924 $form->addElement('text', 'contribution_source', ts('Contribution Source'), CRM_Core_DAO
::getAttribute('CRM_Contribute_DAO_Contribution', 'source'));
926 CRM_Core_Form_Date
::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE);
928 // This hidden element added for displaying Date Range error correctly. Definitely a dirty hack, but... it works.
929 $form->addElement('hidden', 'contribution_date_range_error');
930 $form->addFormRule(['CRM_Contribute_BAO_Query', 'formRule'], $form);
932 $form->add('text', 'contribution_amount_low', ts('From'), ['size' => 8, 'maxlength' => 8]);
933 $form->addRule('contribution_amount_low', ts('Please enter a valid money value (e.g. %1).', [1 => CRM_Utils_Money
::format('9.99', ' ')]), 'money');
935 $form->add('text', 'contribution_amount_high', ts('To'), ['size' => 8, 'maxlength' => 8]);
936 $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', [1 => CRM_Utils_Money
::format('99.99', ' ')]), 'money');
938 $form->addField('cancel_reason', ['entity' => 'Contribution']);
939 CRM_Core_Form_Date
::buildDateRange($form, 'contribution_cancel_date', 1, '_low', '_high', ts('From:'), FALSE);
940 $form->addElement('hidden', 'contribution_cancel_date_range_error');
942 // Adding select option for curreny type -- CRM-4711
943 $form->add('select', 'contribution_currency_type',
948 CRM_Core_PseudoConstant
::get('CRM_Contribute_DAO_Contribution', 'currency', ['labelColumn' => 'name']),
949 FALSE, ['class' => 'crm-select2']
953 CRM_Financial_BAO_FinancialType
::getAvailableFinancialTypes($financialTypes, CRM_Core_Action
::VIEW
);
954 $form->addSelect('financial_type_id',
955 ['entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search', 'options' => $financialTypes]
958 $form->add('select', 'contribution_page_id',
959 ts('Contribution Page'),
960 CRM_Contribute_PseudoConstant
::contributionPage(),
961 FALSE, ['class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')]
964 // use contribution_payment_instrument_id instead of payment_instrument_id
965 // Contribution Edit form (pop-up on contribution/Contact(display Result as Contribution) open on search form),
966 // then payment method change action not working properly because of same html ID present two time on one page
967 $form->addSelect('contribution_payment_instrument_id',
968 ['entity' => 'contribution', 'field' => 'payment_instrument_id', 'multiple' => 'multiple', 'label' => ts('Payment Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')]
972 'contribution_pcp_made_through_id',
973 ts('Personal Campaign Page'),
974 CRM_Contribute_PseudoConstant
::pcPage(), FALSE, ['class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -')]);
976 $statusValues = CRM_Core_PseudoConstant
::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id');
977 $form->add('select', 'contribution_status_id',
978 ts('Contribution Status'), $statusValues,
979 FALSE, ['class' => 'crm-select2', 'multiple' => 'multiple']
982 // Add fields for thank you and receipt
983 $form->addYesNo('contribution_thankyou_date_is_not_null', ts('Thank-you sent?'), TRUE);
984 $form->addYesNo('contribution_receipt_date_is_not_null', ts('Receipt sent?'), TRUE);
986 $form->addYesNo('contribution_pay_later', ts('Contribution is Pay Later?'), TRUE);
987 $form->addYesNo('contribution_recurring', ts('Contribution is Recurring?'), TRUE);
989 $form->addYesNo('contribution_test', ts('Contribution is a Test?'), TRUE);
991 // Add field for transaction ID search
992 $form->addElement('text', 'contribution_trxn_id', ts("Transaction ID"));
993 $form->addElement('text', 'invoice_number', ts("Invoice Number"));
994 $form->addElement('text', 'contribution_check_number', ts('Check Number'));
996 // Add field for pcp display in roll search
997 $form->addYesNo('contribution_pcp_display_in_roll', ts('Personal Campaign Page Honor Roll?'), TRUE);
999 // Soft credit related fields
1001 'only_contribs' => ts('Contributions Only'),
1002 'only_scredits' => ts('Soft Credits Only'),
1003 'both_related' => ts('Soft Credits with related Hard Credit'),
1004 'both' => ts('Both'),
1006 $form->add('select', 'contribution_or_softcredits', ts('Contributions OR Soft Credits?'), $options, FALSE, ['class' => "crm-select2"]);
1008 'contribution_soft_credit_type_id',
1010 'entity' => 'contribution_soft',
1011 'field' => 'soft_credit_type_id',
1013 'context' => 'search',
1017 $form->addField('financial_trxn_card_type_id', ['entity' => 'FinancialTrxn', 'name' => 'card_type_id', 'action' => 'get']);
1019 $form->add('text', 'financial_trxn_pan_truncation', ts('Card Number'), [
1022 'autocomplete' => 'off',
1025 if (CRM_Contribute_BAO_Query
::isSiteHasProducts()) {
1026 // CRM-16713 - contribution search by premiums on 'Find Contribution' form.
1027 $form->add('select', 'contribution_product_id',
1029 CRM_Contribute_PseudoConstant
::products(),
1031 'class' => 'crm-select2',
1032 'multiple' => 'multiple',
1033 'placeholder' => ts('- any -'),
1038 self
::addCustomFormFields($form, ['Contribution']);
1040 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($form, 'contribution_campaign_id');
1043 $batches = CRM_Contribute_PseudoConstant
::batch();
1045 if (!empty($batches)) {
1046 $form->add('select', 'contribution_batch_id',
1049 '' => ts('- any -'),
1051 'IS NULL' => ts('None'),
1053 FALSE, ['class' => 'crm-select2']
1057 $form->assign('validCiviContribute', TRUE);
1058 $form->setDefaults(['contribution_test' => 0]);
1060 CRM_Contribute_BAO_ContributionRecur
::recurringContribution($form);
1066 * @todo better function comment needed - what IS the point of this?
1068 * @param array $tables
1070 public static function tableNames(&$tables) {
1071 // Add contribution table
1072 if (!empty($tables['civicrm_product'])) {
1073 $tables = array_merge(['civicrm_contribution' => 1], $tables);
1076 if (!empty($tables['civicrm_contribution_product']) && empty($tables['civicrm_product'])) {
1077 $tables['civicrm_product'] = 1;
1082 * Add the where for dates.
1084 * @param array $values
1085 * Array of query values.
1086 * @param object $query
1088 * @param string $name
1089 * Query field that is set.
1090 * @param string $field
1091 * Name of field to be set.
1092 * @param string $title
1093 * Title of the field.
1097 public static function buildDateWhere(&$values, $query, $name, $field, $title) {
1098 $fieldPart = strpos($name, $field);
1099 if ($fieldPart === FALSE) {
1102 // we only have recurring dates using this ATM so lets' short cut to find the table name
1103 $table = 'contribution_recur';
1104 $fieldName = explode($table . '_', $field);
1105 $query->dateQueryBuilder($values,
1106 'civicrm_' . $table, $field, $fieldName[1], $title
1112 * Custom form rules.
1114 * @param array $fields
1115 * @param array $files
1116 * @param CRM_Core_Form $form
1118 * @return bool|array
1120 public static function formRule($fields, $files, $form) {
1123 if (!empty($fields['contribution_date_high']) && !empty($fields['contribution_date_low'])) {
1124 CRM_Utils_Rule
::validDateRange($fields, 'contribution_date', $errors, ts('Date Received'));
1126 if (!empty($fields['contribution_cancel_date_high']) && !empty($fields['contribution_cancel_date_low'])) {
1127 CRM_Utils_Rule
::validDateRange($fields, 'contribution_cancel_date', $errors, ts('Cancel Date'));
1130 return empty($errors) ?
TRUE : $errors;
1134 * Add the soft credit fields to the select fields.
1136 * Extracted into separate function to improve readability of main select function.
1140 private static function addSoftCreditFields(&$query) {
1141 $includeSoftCredits = self
::isSoftCreditOptionEnabled($query->_params
);
1142 if (!empty($query->_returnProperties
['contribution_soft_credit_name'])) {
1143 if ($includeSoftCredits) {
1144 $query->_select
['contribution_soft_credit_name'] = "civicrm_contact_d.sort_name as contribution_soft_credit_name";
1145 // also include contact id. Will help build hyperlinks
1146 $query->_select
['contribution_soft_credit_contact_id'] = "civicrm_contact_d.id as contribution_soft_credit_contact_id";
1148 $query->_element
['contribution_soft_credit_name'] = 1;
1149 $query->_element
['contribution_soft_credit_contact_id'] = 1;
1151 $query->_tables
['civicrm_contribution'] = 1;
1152 $query->_tables
['civicrm_contribution_soft'] = 1;
1153 $query->_tables
['civicrm_contribution_soft_contact'] = 1;
1156 if (!empty($query->_returnProperties
['contribution_soft_credit_contact_id'])) {
1157 $query->_tables
['civicrm_contribution'] = 1;
1158 $query->_tables
['civicrm_contribution_soft'] = 1;
1159 $query->_tables
['civicrm_contribution_soft_contact'] = 1;
1162 if (!empty($query->_returnProperties
['contribution_soft_credit_amount'])) {
1163 if ($includeSoftCredits) {
1164 $query->_select
['contribution_soft_credit_amount'] = "civicrm_contribution_soft.amount as contribution_soft_credit_amount";
1166 $query->_element
['contribution_soft_credit_amount'] = 1;
1167 $query->_tables
['civicrm_contribution'] = 1;
1168 $query->_tables
['civicrm_contribution_soft'] = 1;
1171 if (!empty($query->_returnProperties
['contribution_soft_credit_type'])) {
1172 if ($includeSoftCredits) {
1173 $query->_select
['contribution_soft_credit_type'] = "contribution_softcredit_type.label as contribution_soft_credit_type";
1175 $query->_element
['contribution_soft_credit_type'] = 1;
1176 $query->_tables
['civicrm_contribution'] = 1;
1177 $query->_tables
['contribution_softcredit_type'] = 1;
1180 if (!empty($query->_returnProperties
['contribution_soft_credit_contribution_id'])) {
1181 if ($includeSoftCredits) {
1182 $query->_select
['contribution_soft_credit_contribution_id'] = "civicrm_contribution_soft.contribution_id as contribution_soft_credit_contribution_id";
1184 $query->_element
['contribution_soft_credit_contribution_id'] = 1;
1185 $query->_tables
['civicrm_contribution'] = 1;
1186 $query->_tables
['civicrm_contribution_soft'] = 1;
1189 if (!empty($query->_returnProperties
['contribution_soft_credit_email'])) {
1190 $query->_select
['contribution_soft_credit_email'] = "soft_email.email as contribution_soft_credit_email";
1191 $query->_element
['contribution_soft_credit_email'] = 1;
1192 $query->_tables
['civicrm_contribution'] = 1;
1193 $query->_tables
['civicrm_contribution_soft'] = 1;
1194 $query->_tables
['civicrm_contribution_soft_contact'] = 1;
1195 $query->_tables
['civicrm_contribution_soft_email'] = 1;
1198 if (!empty($query->_returnProperties
['contribution_soft_credit_phone'])) {
1199 $query->_select
['contribution_soft_credit_email'] = "soft_phone.phone as contribution_soft_credit_phone";
1200 $query->_element
['contribution_soft_credit_phone'] = 1;
1201 $query->_tables
['civicrm_contribution'] = 1;
1202 $query->_tables
['civicrm_contribution_soft'] = 1;
1203 $query->_tables
['civicrm_contribution_soft_contact'] = 1;
1204 $query->_tables
['civicrm_contribution_soft_phone'] = 1;
1207 if (!empty($query->_returnProperties
['contribution_soft_credit_pcp_id'])) {
1208 $query->_select
['contribution_soft_credit_pcp_id'] = "civicrm_contribution_soft.pcp_id as contribution_soft_credit_pcp_id";
1209 $query->_element
['contribution_soft_credit_pcp_id'] = 1;
1210 $query->_tables
['civicrm_contribution'] = 1;
1211 $query->_tables
['civicrm_contribution_soft'] = 1;