CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_next_sched_contribution_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_failure_retry_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_cancel_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');
+
+ // Add field for contribution status
+ $form->addSelect('contribution_recur_contribution_status_id',
+ array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search', 'options' => CRM_Contribute_PseudoConstant::contributionStatus())
+ );
+
$form->addElement('text', 'contribution_recur_processor_id', ts('Processor ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'processor_id'));
$form->addElement('text', 'contribution_recur_trxn_id', ts('Transaction ID'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionRecur', 'trxn_id'));
}
}
+ /**
+ * Test CRM_Contribute_Form_Search Recurring Contribution Status Id filters
+ */
+ public function testContributionRecurStatusFilter() {
+ $this->quickCleanup($this->_tablesToTruncate);
+ $contactID1 = $this->individualCreate(array(), 1);
+ $contactID2 = $this->individualCreate(array(), 2);
+ // "In Progress" recurring contribution for contactID1
+ $ContributionRecur1 = $this->callAPISuccess('ContributionRecur', 'create', array(
+ 'sequential' => 1,
+ 'contact_id' => $contactID1,
+ 'frequency_interval' => 1,
+ 'frequency_unit' => "month",
+ 'amount' => 11,
+ 'currency' => "CAD",
+ 'payment_instrument_id' => 1,
+ 'contribution_status_id' => 5,
+ 'financial_type_id' => "Donation",
+ ));
+ $Contribution1 = $this->callAPISuccess('Contribution', 'create', array(
+ 'financial_type_id' => 1,
+ 'total_amount' => 11,
+ 'receive_date' => date('Ymd'),
+ 'receive_date_time' => NULL,
+ 'payment_instrument_id' => 1,
+ 'contribution_status_id' => 1,
+ 'contact_id' => $contactID1,
+ 'contribution_recur_id' => $ContributionRecur1['id'],
+ 'financial_type_id' => "Donation",
+ ));
+ $params = array(
+ 'to_financial_account_id' => 1,
+ 'status_id' => 1,
+ 'contribution_id' => $Contribution1['id'],
+ 'payment_instrument_id' => 1,
+ 'card_type_id' => 1,
+ 'total_amount' => 11,
+ );
+ CRM_Core_BAO_FinancialTrxn::create($params);
+ // "Completed" recurring contribution for contactID2
+ $ContributionRecur2 = $this->callAPISuccess('ContributionRecur', 'create', array(
+ 'sequential' => 1,
+ 'contact_id' => $contactID2,
+ 'frequency_interval' => 1,
+ 'frequency_unit' => "month",
+ 'amount' => 22,
+ 'currency' => "CAD",
+ 'payment_instrument_id' => 1,
+ 'contribution_status_id' => 1,
+ 'financial_type_id' => "Donation",
+ ));
+ $Contribution2 = $this->callAPISuccess('Contribution', 'create', array(
+ 'financial_type_id' => 1,
+ 'total_amount' => 22,
+ 'receive_date' => date('Ymd'),
+ 'receive_date_time' => NULL,
+ 'payment_instrument' => 1,
+ 'contribution_status_id' => 1,
+ 'contact_id' => $contactID2,
+ 'contribution_recur_id' => $ContributionRecur2['id'],
+ 'financial_type_id' => "Donation",
+ ));
+ $params = array(
+ 'to_financial_account_id' => 1,
+ 'status_id' => 1,
+ 'contribution_id' => $Contribution2['id'],
+ 'payment_instrument_id' => 1,
+ 'card_type_id' => 1,
+ 'total_amount' => 22,
+ );
+ CRM_Core_BAO_FinancialTrxn::create($params);
+
+ $useCases = array(
+ // Case 1: Search for ONLY those recurring contributions with status "In Progress"
+ array(
+ 'form_value' => array('contribution_recur_contribution_status_id' => 5),
+ 'expected_count' => 1,
+ 'expected_contact' => array($contactID1),
+ 'expected_qill' => "Recurring Contribution Status = 'In Progress'",
+ ),
+ // Case 2: Search for ONLY those recurring contributions with status "Completed"
+ array(
+ 'form_value' => array('contribution_recur_contribution_status_id' => 1),
+ 'expected_count' => 1,
+ 'expected_contact' => array($contactID2),
+ 'expected_qill' => "Recurring Contribution Status = 'Completed'",
+ ),
+ // Case 3: Search for ONLY those recurring contributions with status "Cancelled"
+ array(
+ 'form_value' => array('contribution_recur_contribution_status_id' => 3),
+ 'expected_count' => 0,
+ 'expected_contact' => array(),
+ 'expected_qill' => "Recurring Contribution Status = 'Cancelled'",
+ ),
+ );
+
+ foreach ($useCases as $case) {
+ $fv = $case['form_value'];
+ $query = new CRM_Contact_BAO_Query(CRM_Contact_BAO_Query::convertFormValues($fv));
+ list($select, $from, $where, $having) = $query->query();
+
+ // get and assert contribution count
+ $contacts = CRM_Core_DAO::executeQuery(sprintf('SELECT DISTINCT contact_a.id %s %s AND contact_a.id IS NOT NULL', $from, $where))->fetchAll();
+ foreach ($contacts as $key => $value) {
+ $contacts[$key] = $value['id'];
+ }
+ // assert the contribution count
+ $this->assertEquals($case['expected_count'], count($contacts));
+ // assert the contribution IDs
+ $this->checkArrayEquals($case['expected_contact'], $contacts);
+ // get and assert qill string
+ $qill = trim(implode($query->getOperator(), CRM_Utils_Array::value(0, $query->qill())));
+ $this->assertEquals($case['expected_qill'], $qill);
+ }
+ }
+
}