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_Pledge_BAO_Query
extends CRM_Core_BAO_Query
{
38 * @param bool $checkPermission
42 public static function getFields($checkPermission = TRUE) {
43 return CRM_Pledge_BAO_Pledge
::exportableFields($checkPermission);
47 * Build select for Pledge.
49 * @param CRM_Contact_BAO_Query $query
51 public static function select(&$query) {
53 $statusId = implode(',', array_keys(CRM_Core_PseudoConstant
::accountOptionValues("contribution_status", NULL, " AND v.name IN ('Pending', 'Overdue')")));
54 if (($query->_mode
& CRM_Contact_BAO_Query
::MODE_PLEDGE
) ||
!empty($query->_returnProperties
['pledge_id'])) {
55 $query->_select
['pledge_id'] = 'civicrm_pledge.id as pledge_id';
56 $query->_element
['pledge_id'] = 1;
57 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
61 if (!empty($query->_returnProperties
['pledge_amount'])) {
62 $query->_select
['pledge_amount'] = 'civicrm_pledge.amount as pledge_amount';
63 $query->_element
['pledge_amount'] = 1;
64 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
67 if (!empty($query->_returnProperties
['pledge_original_installment_amount'])) {
68 $query->_select
['pledge_original_installment_amount'] = 'civicrm_pledge.original_installment_amount as pledge_original_installment_amount';
69 $query->_element
['pledge_original_installment_amount'] = 1;
70 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
73 if (!empty($query->_returnProperties
['installments'])) {
74 $query->_select
['installments'] = 'civicrm_pledge.installments as installments';
75 $query->_element
['installments'] = 1;
76 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
79 if (!empty($query->_returnProperties
['pledge_create_date'])) {
80 $query->_select
['pledge_create_date'] = 'civicrm_pledge.create_date as pledge_create_date';
81 $query->_element
['pledge_create_date'] = 1;
82 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
85 if (!empty($query->_returnProperties
['pledge_end_date'])) {
86 $query->_select
['pledge_end_date'] = 'civicrm_pledge.end_date as pledge_end_date';
87 $query->_element
['pledge_end_date'] = 1;
88 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
91 if (!empty($query->_returnProperties
['pledge_start_date'])) {
92 $query->_select
['pledge_start_date'] = 'civicrm_pledge.start_date as pledge_start_date';
93 $query->_element
['pledge_start_date'] = 1;
94 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
97 if (!empty($query->_returnProperties
['pledge_status_id'])) {
98 $query->_select
['pledge_status_id'] = 'pledge_status.value as pledge_status_id';
99 $query->_element
['pledge_status'] = 1;
100 $query->_tables
['pledge_status'] = $query->_whereTables
['pledge_status'] = 1;
101 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
104 if (!empty($query->_returnProperties
['pledge_status'])) {
105 $query->_select
['pledge_status'] = 'pledge_status.label as pledge_status';
106 $query->_element
['pledge_status'] = 1;
107 $query->_tables
['pledge_status'] = $query->_whereTables
['pledge_status'] = 1;
108 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
111 if (!empty($query->_returnProperties
['pledge_total_paid'])) {
112 $query->_select
['pledge_total_paid'] = ' (SELECT sum(civicrm_pledge_payment.actual_amount) FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id = 1 ) as pledge_total_paid';
113 $query->_element
['pledge_total_paid'] = 1;
116 if (!empty($query->_returnProperties
['pledge_next_pay_date'])) {
117 $query->_select
['pledge_next_pay_date'] = " (SELECT civicrm_pledge_payment.scheduled_date FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id IN ({$statusId}) ORDER BY civicrm_pledge_payment.scheduled_date ASC LIMIT 0, 1) as pledge_next_pay_date";
118 $query->_element
['pledge_next_pay_date'] = 1;
121 if (!empty($query->_returnProperties
['pledge_next_pay_amount'])) {
122 $query->_select
['pledge_next_pay_amount'] = " (SELECT civicrm_pledge_payment.scheduled_amount FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id IN ({$statusId}) ORDER BY civicrm_pledge_payment.scheduled_date ASC LIMIT 0, 1) as pledge_next_pay_amount";
123 $query->_element
['pledge_next_pay_amount'] = 1;
125 $query->_select
['pledge_outstanding_amount'] = " (SELECT sum(civicrm_pledge_payment.scheduled_amount) FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id = 6 ) as pledge_outstanding_amount";
126 $query->_element
['pledge_outstanding_amount'] = 1;
129 if (!empty($query->_returnProperties
['pledge_financial_type'])) {
130 $query->_select
['pledge_financial_type'] = "(SELECT civicrm_financial_type.name FROM civicrm_financial_type WHERE civicrm_financial_type.id = civicrm_pledge.financial_type_id) as pledge_financial_type";
131 $query->_element
['pledge_financial_type'] = 1;
132 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
135 if (!empty($query->_returnProperties
['pledge_contribution_page_id'])) {
136 $query->_select
['pledge_contribution_page_id'] = 'civicrm_pledge.contribution_page_id as pledge_contribution_page_id';
137 $query->_element
['pledge_contribution_page_id'] = 1;
138 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
141 if (!empty($query->_returnProperties
['pledge_payment_id'])) {
142 $query->_select
['pledge_payment_id'] = 'civicrm_pledge_payment.id as pledge_payment_id';
143 $query->_element
['pledge_payment_id'] = 1;
144 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
147 if (!empty($query->_returnProperties
['pledge_payment_scheduled_amount'])) {
148 $query->_select
['pledge_payment_scheduled_amount'] = 'civicrm_pledge_payment.scheduled_amount as pledge_payment_scheduled_amount';
149 $query->_element
['pledge_payment_scheduled_amount'] = 1;
150 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
153 if (!empty($query->_returnProperties
['pledge_payment_scheduled_date'])) {
154 $query->_select
['pledge_payment_scheduled_date'] = 'civicrm_pledge_payment.scheduled_date as pledge_payment_scheduled_date';
155 $query->_element
['pledge_payment_scheduled_date'] = 1;
156 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
159 if (!empty($query->_returnProperties
['pledge_payment_paid_amount'])) {
160 $query->_select
['pledge_payment_paid_amount'] = 'civicrm_pledge_payment.actual_amount as pledge_payment_paid_amount';
161 $query->_element
['pledge_payment_paid_amount'] = 1;
162 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
165 if (!empty($query->_returnProperties
['pledge_payment_paid_date'])) {
166 $query->_select
['pledge_payment_paid_date'] = 'payment_contribution.receive_date as pledge_payment_paid_date';
167 $query->_element
['pledge_payment_paid_date'] = 1;
168 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
169 $query->_tables
['payment_contribution'] = $query->_whereTables
['payment_contribution'] = 1;
172 if (!empty($query->_returnProperties
['pledge_payment_reminder_date'])) {
173 $query->_select
['pledge_payment_reminder_date'] = 'civicrm_pledge_payment.reminder_date as pledge_payment_reminder_date';
174 $query->_element
['pledge_payment_reminder_date'] = 1;
175 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
178 if (!empty($query->_returnProperties
['pledge_payment_reminder_count'])) {
179 $query->_select
['pledge_payment_reminder_count'] = 'civicrm_pledge_payment.reminder_count as pledge_payment_reminder_count';
180 $query->_element
['pledge_payment_reminder_count'] = 1;
181 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
184 if (!empty($query->_returnProperties
['pledge_payment_status_id'])) {
185 $query->_select
['pledge_payment_status_id'] = 'payment_status.name as pledge_payment_status_id';
186 $query->_element
['pledge_payment_status_id'] = 1;
187 $query->_tables
['payment_status'] = $query->_whereTables
['payment_status'] = 1;
188 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
191 if (!empty($query->_returnProperties
['pledge_payment_status'])) {
192 $query->_select
['pledge_payment_status'] = 'payment_status.label as pledge_payment_status';
193 $query->_element
['pledge_payment_status'] = 1;
194 $query->_tables
['payment_status'] = $query->_whereTables
['payment_status'] = 1;
195 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
198 if (!empty($query->_returnProperties
['pledge_frequency_interval'])) {
199 $query->_select
['pledge_frequency_interval'] = 'civicrm_pledge.frequency_interval as pledge_frequency_interval';
200 $query->_element
['pledge_frequency_interval'] = 1;
201 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
204 if (!empty($query->_returnProperties
['pledge_frequency_unit'])) {
205 $query->_select
['pledge_frequency_unit'] = 'civicrm_pledge.frequency_unit as pledge_frequency_unit';
206 $query->_element
['pledge_frequency_unit'] = 1;
207 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
210 if (!empty($query->_returnProperties
['pledge_is_test'])) {
211 $query->_select
['pledge_is_test'] = 'civicrm_pledge.is_test as pledge_is_test';
212 $query->_element
['pledge_is_test'] = 1;
213 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
215 if (!empty($query->_returnProperties
['pledge_campaign_id'])) {
216 $query->_select
['pledge_campaign_id'] = 'civicrm_pledge.campaign_id as pledge_campaign_id';
217 $query->_element
['pledge_campaign_id'] = 1;
218 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
221 if (!empty($query->_returnProperties
['pledge_currency'])) {
222 $query->_select
['pledge_currency'] = 'civicrm_pledge.currency as pledge_currency';
223 $query->_element
['pledge_currency'] = 1;
224 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
231 public static function where(&$query) {
233 foreach (array_keys($query->_params
) as $id) {
234 if (empty($query->_params
[$id][0])) {
237 if (substr($query->_params
[$id][0], 0, 7) == 'pledge_') {
238 if ($query->_mode
== CRM_Contact_BAO_Query
::MODE_CONTACTS
) {
239 $query->_useDistinct
= TRUE;
241 $grouping = $query->_params
[$id][3];
242 self
::whereClauseSingle($query->_params
[$id], $query);
248 * Get where clause for field.
250 * @todo most of this could be replaced by using metadata.
252 * @param array $values
253 * @param \CRM_Contact_BAO_Query $query
255 * @throws \CRM_Core_Exception
257 public static function whereClauseSingle(&$values, &$query) {
258 if ($query->buildDateRangeQuery($values)) {
259 // @todo - move this to Contact_Query in or near the call to
260 // $this->buildRelativeDateQuery($values);
263 list($name, $op, $value, $grouping, $wildcard) = $values;
266 case 'pledge_amount':
267 case 'pledge_amount_low':
268 case 'pledge_amount_high':
269 // process min/max amount
270 $query->numberRangeBuilder($values,
271 'civicrm_pledge', 'pledge_amount', 'amount', 'Pledge Amount'
275 case 'pledge_installments_low':
276 case 'pledge_installments_high':
277 // process min/max amount
278 $query->numberRangeBuilder($values,
279 'civicrm_pledge', 'pledge_installments', 'installments', 'Number of Installments'
283 case 'pledge_acknowledge_date_is_not_null':
286 $query->_qill
[$grouping][] = ts('Pledge Acknowledgement Sent');
290 $query->_qill
[$grouping][] = ts('Pledge Acknowledgement Not Sent');
292 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_pledge.acknowledge_date", $op);
295 case 'pledge_payment_status_id':
296 case 'pledge_status_id':
297 if ($name == 'pledge_status_id') {
298 $tableName = 'civicrm_pledge';
299 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
300 $label = "Pledge Status";
301 $qillDAO = 'CRM_Pledge_DAO_Pledge';
302 $qillField = 'status_id';
305 $tableName = 'civicrm_pledge_payment';
306 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
307 $label = "Pledge Payment Status";
308 $qillDAO = 'CRM_Contribute_DAO_Contribution';
309 $qillField = 'contribution_status_id';
312 if (!empty($value) && is_array($value) && !in_array(key($value), CRM_Core_DAO
::acceptedSQLOperators(), TRUE)) {
313 $value = ['IN' => $value];
316 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("$tableName.$name",
321 list($qillop, $qillVal) = CRM_Contact_BAO_Query
::buildQillForFieldValue($qillDAO, $qillField, $value, $op);
322 $query->_qill
[$grouping][] = ts('%1 %2 %3', [1 => $label, 2 => $qillop, 3 => $qillVal]);
326 case 'pledge_is_test':
327 // We dont want to include all tests for sql OR CRM-7827
328 if (!$value ||
$query->getOperator() != 'OR') {
329 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.is_test',
335 $query->_qill
[$grouping][] = ts('Pledge is a Test');
337 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
341 case 'pledge_financial_type_id':
342 $type = CRM_Contribute_PseudoConstant
::financialType($value);
343 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.financial_type_id',
348 $query->_qill
[$grouping][] = ts('Financial Type - %1', [1 => $type]);
349 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
352 case 'pledge_contribution_page_id':
353 $page = CRM_Contribute_PseudoConstant
::contributionPage($value);
354 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.contribution_page_id',
359 $query->_qill
[$grouping][] = ts('Financial Page - %1', [1 => $page]);
360 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
364 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_pledge.id",
369 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
372 case 'pledge_frequency_interval':
373 $query->_where
[$grouping][] = "civicrm_pledge.frequency_interval $op $value";
374 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
377 case 'pledge_frequency_unit':
378 $query->_where
[$grouping][] = "civicrm_pledge.frequency_unit $op $value";
379 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
382 case 'pledge_contact_id':
383 case 'pledge_campaign_id':
384 $name = str_replace('pledge_', '', $name);
385 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause("civicrm_pledge.$name", $op, $value, 'Integer');
386 list($op, $value) = CRM_Contact_BAO_Query
::buildQillForFieldValue('CRM_Pledge_DAO_Pledge', $name, $value, $op);
387 $label = ($name == 'campaign_id') ?
'Campaign' : 'Contact ID';
388 $query->_qill
[$grouping][] = ts('%1 %2 %3', [1 => $label, 2 => $op, 3 => $value]);
389 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
397 * @param string $name
398 * @param string $mode
399 * @param string $side
401 * @return null|string
403 public static function from($name, $mode, $side) {
407 case 'civicrm_pledge':
408 $from = " $side JOIN civicrm_pledge ON civicrm_pledge.contact_id = contact_a.id ";
411 case 'pledge_status':
412 $from .= " $side JOIN civicrm_option_group option_group_pledge_status ON (option_group_pledge_status.name = 'pledge_status')";
413 $from .= " $side JOIN civicrm_option_value pledge_status ON (civicrm_pledge.status_id = pledge_status.value AND option_group_pledge_status.id = pledge_status.option_group_id ) ";
416 case 'pledge_financial_type':
417 $from .= " $side JOIN civicrm_financial_type ON civicrm_pledge.financial_type_id = civicrm_financial_type.id ";
420 case 'civicrm_pledge_payment':
421 $from .= " $side JOIN civicrm_pledge_payment ON civicrm_pledge_payment.pledge_id = civicrm_pledge.id ";
424 case 'payment_contribution':
425 $from .= " $side JOIN civicrm_contribution payment_contribution ON civicrm_pledge_payment.contribution_id = payment_contribution.id ";
428 case 'payment_status':
429 $from .= " $side JOIN civicrm_option_group option_group_payment_status ON (option_group_payment_status.name = 'contribution_status')";
430 $from .= " $side JOIN civicrm_option_value payment_status ON (civicrm_pledge_payment.status_id = payment_status.value AND option_group_payment_status.id = payment_status.option_group_id ) ";
438 * Ideally this function should include fields that are displayed in the selector.
441 * @param bool $includeCustomFields
445 public static function defaultReturnProperties(
447 $includeCustomFields = TRUE
451 if ($mode & CRM_Contact_BAO_Query
::MODE_PLEDGE
) {
454 'contact_sub_type' => 1,
458 'pledge_amount' => 1,
459 'pledge_total_paid' => 1,
460 'pledge_create_date' => 1,
461 'pledge_start_date' => 1,
462 'pledge_next_pay_date' => 1,
463 'pledge_next_pay_amount' => 1,
464 'pledge_status' => 1,
465 'pledge_status_id' => 1,
466 'pledge_is_test' => 1,
467 'pledge_contribution_page_id' => 1,
468 'pledge_financial_type' => 1,
469 'pledge_frequency_interval' => 1,
470 'pledge_frequency_unit' => 1,
471 'pledge_currency' => 1,
472 'pledge_campaign_id' => 1,
479 * This includes any extra fields that might need for export etc.
481 * @param string $mode
485 public static function extraReturnProperties($mode) {
488 if ($mode & CRM_Contact_BAO_Query
::MODE_PLEDGE
) {
490 'pledge_balance_amount' => 1,
491 'pledge_payment_id' => 1,
492 'pledge_payment_scheduled_amount' => 1,
493 'pledge_payment_scheduled_date' => 1,
494 'pledge_payment_paid_amount' => 1,
495 'pledge_payment_paid_date' => 1,
496 'pledge_payment_reminder_date' => 1,
497 'pledge_payment_reminder_count' => 1,
498 'pledge_payment_status_id' => 1,
499 'pledge_payment_status' => 1,
502 // also get all the custom pledge properties
503 $fields = CRM_Core_BAO_CustomField
::getFieldsForImport('Pledge');
504 if (!empty($fields)) {
505 foreach ($fields as $name => $dontCare) {
506 $properties[$name] = 1;
514 * Get the metadata for fields to be included on the grant search form.
516 * @throws \CiviCRM_API3_Exception
518 public static function getSearchFieldMetadata() {
523 'pledge_create_date',
525 $metadata = civicrm_api3('Pledge', 'getfields', [])['values'];
526 return array_intersect_key($metadata, array_flip($fields));
530 * Get the metadata for fields to be included on the grant search form.
532 * @throws \CiviCRM_API3_Exception
534 public static function getPledgePaymentSearchFieldMetadata() {
536 'pledge_payment_scheduled_date',
538 $metadata = civicrm_api3('PledgePayment', 'getfields', [])['values'];
539 return array_intersect_key($metadata, array_flip($fields));
543 * Build the search for for pledges.
545 * @param CRM_Pledge_Form_Search|\CRM_Contact_Form_Search_Advanced $form
547 * @throws \CRM_Core_Exception
548 * @throws \CiviCRM_API3_Exception
550 public static function buildSearchForm(&$form) {
551 // pledge related dates
552 $form->addSearchFieldMetadata(['Pledge' => self
::getSearchFieldMetadata()]);
553 $form->addSearchFieldMetadata(['PledgePayment' => self
::getPledgePaymentSearchFieldMetadata()]);
554 $form->addFormFieldsFromMetadata();
556 $form->addYesNo('pledge_test', ts('Pledge is a Test?'), TRUE);
557 $form->add('text', 'pledge_amount_low', ts('From'), ['size' => 8, 'maxlength' => 8]);
558 $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', [1 => CRM_Utils_Money
::format('9.99', ' ')]), 'money');
560 $form->add('text', 'pledge_amount_high', ts('To'), ['size' => 8, 'maxlength' => 8]);
561 $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', [1 => CRM_Utils_Money
::format('99.99', ' ')]), 'money');
563 $form->addYesNo('pledge_acknowledge_date_is_not_null', ts('Acknowledgement sent?'), TRUE);
565 $form->add('text', 'pledge_installments_low', ts('From'), ['size' => 8, 'maxlength' => 8]);
566 $form->addRule('pledge_installments_low', ts('Please enter a number'), 'integer');
568 $form->add('text', 'pledge_installments_high', ts('To'), ['size' => 8, 'maxlength' => 8]);
569 $form->addRule('pledge_installments_high', ts('Please enter number.'), 'integer');
571 $form->add('select', 'pledge_payment_status_id',
572 ts('Pledge Payment Status'), CRM_Pledge_BAO_PledgePayment
::buildOptions('status_id'),
573 FALSE, ['class' => 'crm-select2', 'multiple' => 'multiple']
576 $form->add('select', 'pledge_financial_type_id',
577 ts('Financial Type'),
578 ['' => ts('- select -')] + CRM_Contribute_PseudoConstant
::financialType(),
579 FALSE, ['class' => 'crm-select2']
582 $form->add('select', 'pledge_contribution_page_id',
583 ts('Contribution Page'),
584 ['' => ts('- any -')] + CRM_Contribute_PseudoConstant
::contributionPage(),
585 FALSE, ['class' => 'crm-select2']
588 // add fields for pledge frequency
589 $form->add('text', 'pledge_frequency_interval', ts('Every'), ['size' => 8, 'maxlength' => 8]);
590 $form->addRule('pledge_frequency_interval', ts('Please enter valid Pledge Frequency Interval'), 'integer');
591 $frequencies = CRM_Core_OptionGroup
::values('recur_frequency_units');
592 foreach ($frequencies as $val => $label) {
593 $freqUnitsDisplay["'{$val}'"] = ts('%1(s)', [1 => $label]);
596 $form->add('select', 'pledge_frequency_unit',
597 ts('Pledge Frequency'),
598 ['' => ts('- any -')] +
$freqUnitsDisplay
601 self
::addCustomFormFields($form, ['Pledge']);
603 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($form, 'pledge_campaign_id');
605 $form->assign('validCiviPledge', TRUE);
606 $form->setDefaults(['pledge_test' => 0]);
612 public static function tableNames(&$tables) {
614 if (!empty($tables['pledge_status']) ||
!empty($tables['civicrm_pledge_payment'])) {
615 $tables = array_merge(['civicrm_pledge' => 1], $tables);