Skip to content

Commit

Permalink
Merge pull request #12775 from eileenmcnaughton/cancel
Browse files Browse the repository at this point in the history
Fix metadata on cancel_reason so it is an exportable field
  • Loading branch information
eileenmcnaughton committed Nov 8, 2018
2 parents d7aafc7 + 927898c commit 8703fe4
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 10 deletions.
7 changes: 4 additions & 3 deletions CRM/Contribute/BAO/Query.php
Expand Up @@ -506,7 +506,9 @@ public static function whereClauseSingle(&$values, &$query) {
return;
}
$whereTable = $fields[$fldName];
$value = trim($value);
if (!is_array($value)) {
$value = trim($value);
}

$dataType = "String";
if (!empty($whereTable['type'])) {
Expand Down Expand Up @@ -929,8 +931,7 @@ public static function buildSearchForm(&$form) {
$form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
$form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');

// Adding Cancelled Contribution fields -- CRM-21343
$form->add('text', 'contribution_cancel_reason', ts('Cancellation / Refund Reason'), array('size' => 40));
$form->addField('cancel_reason');
CRM_Core_Form_Date::buildDateRange($form, 'contribution_cancel_date', 1, '_low', '_high', ts('From:'), FALSE);
$form->addElement('hidden', 'contribution_cancel_date_range_error');

Expand Down
4 changes: 2 additions & 2 deletions CRM/Contribute/DAO/Contribution.php
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contribute/Contribution.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:45a20d00d01766a61687cbac5cef1482)
* (GenCodeChecksum:eec525df6c3c6151861750217f3ebe5d)
*/

/**
Expand Down Expand Up @@ -584,7 +584,7 @@ public static function &fields() {
'cancel_reason' => [
'name' => 'cancel_reason',
'type' => CRM_Utils_Type::T_TEXT,
'title' => ts('Cancel Reason'),
'title' => ts('Cancellation / Refund Reason'),
'import' => TRUE,
'where' => 'civicrm_contribution.cancel_reason',
'headerPattern' => '/(cancel.?)?reason/i',
Expand Down
8 changes: 8 additions & 0 deletions CRM/Contribute/Form/Search.php
Expand Up @@ -62,6 +62,14 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
*/
protected $_prefix = "contribute_";


/**
* Explicitly declare the entity api name.
*/
public function getDefaultEntity() {
return 'Contribution';
}

/**
* Processing needed for buildForm and later.
*/
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Contribute/Form/Search/Common.tpl
Expand Up @@ -158,8 +158,8 @@
{include file="CRM/Contribute/Form/PCP.js.tpl"}
</td>
<td>
{$form.contribution_cancel_reason.label}<br />
{$form.contribution_cancel_reason.html}
{$form.cancel_reason.label}<br />
{$form.cancel_reason.html}
</td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Contribute/Form/SearchTest.php
Expand Up @@ -542,14 +542,14 @@ public function testCancelledFilter() {
'form_value' => array('cancel_reason' => 'Invalid Credit Card Number'),
'expected_count' => 1,
'expected_contribution' => array($Contribution3['id']),
'expected_qill' => "Cancel Reason Like '%Invalid Credit Card Number%'",
'expected_qill' => "Cancellation / Refund Reason Like '%Invalid Credit Card Number%'",
),
// Case 3: Search for Cancelled Date and Cancelled Reason
array(
'form_value' => array('cancel_date' => date('Y-m-d'), 'cancel_reason' => 'Insufficient funds'),
'expected_count' => 1,
'expected_contribution' => array($Contribution1['id']),
'expected_qill' => "Cancel Date Like '%" . date('Y-m-d') . "%'ANDCancel Reason Like '%Insufficient funds%'",
'expected_qill' => "Cancel Date Like '%" . date('Y-m-d') . "%'ANDCancellation / Refund Reason Like '%Insufficient funds%'",
),
);

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Export/BAO/ExportTest.php
Expand Up @@ -2065,7 +2065,7 @@ protected function getContributeHeaderDefinition() {
95 => 'Invoice Reference',
96 => 'Invoice Number',
97 => 'Currency',
98 => 'Cancel Reason',
98 => 'Cancellation / Refund Reason',
99 => 'Receipt Date',
100 => 'Product Name',
101 => 'SKU',
Expand Down
15 changes: 15 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Expand Up @@ -302,6 +302,21 @@ public function testGetContributionReturnFunctionality() {
}
}

/**
* Test cancel reason works as a filter.
*/
public function testFilterCancelReason() {
$params = $this->_params;
$params['cancel_date'] = 'yesterday';
$params['cancel_reason'] = 'You lose sucker';
$this->callAPISuccess('Contribution', 'create', $params);
$params = $this->_params;
$params['cancel_date'] = 'yesterday';
$params['cancel_reason'] = 'You are a winner';
$this->callAPISuccess('Contribution', 'create', $params);
$this->callAPISuccessGetCount('Contribution', ['cancel_reason' => 'You are a winner'], 1);
}

/**
* We need to ensure previous tested behaviour still works as part of the api contract.
*/
Expand Down
3 changes: 3 additions & 0 deletions xml/schema/Contribute/Contribution.xml
Expand Up @@ -286,10 +286,13 @@
<field>
<name>cancel_reason</name>
<type>text</type>
<title>Cancellation / Refund Reason</title>
<import>true</import>
<export>true</export>
<headerPattern>/(cancel.?)?reason/i</headerPattern>
<html>
<type>Text</type>
<size>40</size>
</html>
<add>1.3</add>
</field>
Expand Down

0 comments on commit 8703fe4

Please sign in to comment.