From: Dave Greenberg Date: Tue, 24 Nov 2015 22:36:25 +0000 (-0800) Subject: CRM-16901 - Rebased PR with a few field name and markup improvements X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=95974e8e44c3c9fc9e02149ef4d60c499be96ecd;p=civicrm-core.git CRM-16901 - Rebased PR with a few field name and markup improvements ---------------------------------------- * CRM-16901: Offline Recurring Payments https://issues.civicrm.org/jira/browse/CRM-16901 --- diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 502da90f05..8dea7c2144 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -110,6 +110,13 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { foreach ($componentPanes as $name => $pane) { // FIXME: we should change the use of $name here to keyword $paneNames[$pane['title']] = $pane['name']; + if ($pane['name'] == 'CiviContribute') { + $paneNames[ts('Recurring Contributions')] = 'recurringcontribution'; + if (array_key_exists('CiviContribute', $this->_searchOptions) + && CRM_Core_Permission::access('CiviContribute')) { + $this->_searchOptions['recurringcontribution'] = 1; + } + } } $hookPanes = array(); diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 15163ee9cc..5d199a8edf 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -556,4 +556,41 @@ class CRM_Contact_Form_Search_Criteria { CRM_Case_BAO_Query::buildSearchForm($form); } + /** + * @param $form + */ + public static function recurringcontribution(&$form) { + $form->add('hidden', 'hidden_recurringcontribution', 1); + // Add field to check if payment is made for recurring contribution + $recurringPaymentOptions = array( + 0 => ts(' All recurring contributions'), + 1 => ts(' Recurring contributions with at least one payment'), + ); + $form->addRadio('contribution_recur_payment_made', ts(''), $recurringPaymentOptions, array('allowClear' => TRUE)); + CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_start_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); + CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_end_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); + CRM_Core_Form_Date::buildDateRange($form, 'contribution_recur_modified_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); + 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'); + $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')); + $contributionRecur = array('ContributionRecur'); + $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $contributionRecur); + if ($groupDetails) { + $form->assign('contributeRecurGroupTree', $groupDetails); + foreach ($groupDetails as $group) { + foreach ($group['fields'] as $field) { + $fieldId = $field['id']; + $elementName = 'custom_' . $fieldId; + CRM_Core_BAO_CustomField::addQuickFormElement($form, + $elementName, + $fieldId, + FALSE, FALSE, TRUE + ); + } + } + } + } + } diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index ce853c5472..9254c6dca8 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -98,6 +98,12 @@ class CRM_Contribute_BAO_ContributionRecur extends CRM_Contribute_DAO_Contributi CRM_Utils_Hook::post('create', 'ContributionRecur', $recurring->id, $recurring); } + if (!empty($params['custom']) && + is_array($params['custom']) + ) { + CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution_recur', $recurring->id); + } + return $result; } diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 0e697e97c0..2f823e1fd6 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -41,6 +41,8 @@ class CRM_Contribute_BAO_Query { static $_contribOrSoftCredit = "only_contribs"; + static $_contribRecurPayment = FALSE; + /** * Function get the import/export fields for contribution. * @@ -503,6 +505,28 @@ class CRM_Contribute_BAO_Query { $query->_tables['civicrm_contribution'] = $query->_whereTables['civicrm_contribution'] = 1; return; + case 'contribution_recur_processor_id': + case 'contribution_recur_trxn_id': + $fieldName = str_replace('contribution_recur_', '', $name); + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution_recur.{$fieldName}", + $op, $value, "String" + ); + $query->_tables['civicrm_contribution_recur'] = $query->_whereTables['civicrm_contribution_recur'] = 1; + return; + + case 'contribution_recur_payment_made': + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_contribution_recur.id", 'IS NOT EMPTY'); + if ($value) { + $query->_qill[$grouping][] = ts("Recurring contributions with at least one payment"); + self::$_contribRecurPayment = TRUE; + } + else { + $query->_qill[$grouping][] = ts("All recurring contributions regardless of payments"); + self::$_contribRecurPayment = FALSE; + } + $query->_tables['civicrm_contribution_recur'] = $query->_whereTables['civicrm_contribution_recur'] = 1; + return; + case 'contribution_note': $value = $strtolower(CRM_Core_DAO::escapeString($value)); if ($wildcard) { @@ -615,8 +639,14 @@ class CRM_Contribute_BAO_Query { case 'civicrm_contribution_recur': if ($mode == 1) { - // in contact mode join directly onto profile - in case no contributions exist yet - $from = " $side JOIN civicrm_contribution_recur ON contact_a.id = civicrm_contribution_recur.contact_id "; + // 'Made payment for the recurring contributions?' is ticked yes + if (self::$_contribRecurPayment == TRUE) { + $from = " $side JOIN civicrm_contribution_recur ON contact_a.id = civicrm_contribution_recur.contact_id "; + $from .= " INNER JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id "; + } + else { + $from = " $side JOIN civicrm_contribution_recur ON contact_a.id = civicrm_contribution_recur.contact_id "; + } } else { $from = " $side JOIN civicrm_contribution_recur ON civicrm_contribution.contribution_recur_id = civicrm_contribution_recur.id "; diff --git a/CRM/Core/BAO/CustomGroup.php b/CRM/Core/BAO/CustomGroup.php index 5a23b77886..232e59f797 100644 --- a/CRM/Core/BAO/CustomGroup.php +++ b/CRM/Core/BAO/CustomGroup.php @@ -1732,6 +1732,9 @@ ORDER BY civicrm_custom_group.weight, case 'Contribution': return 'civicrm_contribution'; + case 'ContributionRecur': + return 'civicrm_contribution_recur'; + case 'Relationship': return 'civicrm_relationship'; diff --git a/CRM/Core/BAO/CustomQuery.php b/CRM/Core/BAO/CustomQuery.php index f3b1ddcad3..fd79201f58 100644 --- a/CRM/Core/BAO/CustomQuery.php +++ b/CRM/Core/BAO/CustomQuery.php @@ -112,6 +112,7 @@ class CRM_Core_BAO_CustomQuery { 'Household' => 'civicrm_contact', 'Organization' => 'civicrm_contact', 'Contribution' => 'civicrm_contribution', + 'ContributionRecur' => 'civicrm_contribution_recur', 'Membership' => 'civicrm_membership', 'Participant' => 'civicrm_participant', 'Group' => 'civicrm_group', diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 2fc18e2f0d..db6a77f1e9 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1279,4 +1279,13 @@ INNER JOIN civicrm_contribution con ON ( con.contribution_recur_id = rec.id ) return substr(implode('-', $validParts), 0, $length); } + /** + * Checks if backoffice recurring edit is allowed + * + * @return bool + */ + public function supportsEditRecurringContribution() { + return FALSE; + } + } diff --git a/CRM/Core/Payment/Manual.php b/CRM/Core/Payment/Manual.php index 1cedc975db..a2c15bbe9d 100644 --- a/CRM/Core/Payment/Manual.php +++ b/CRM/Core/Payment/Manual.php @@ -164,4 +164,29 @@ class CRM_Core_Payment_Manual extends CRM_Core_Payment { return TRUE; } + /** + * Checks if backoffice recurring edit is allowed + * + * @return bool + */ + public function supportsEditRecurringContribution() { + return TRUE; + } + + /** + * Submit a payment using Advanced Integration Method. + * + * @param array $params + * Assoc array of input parameters for this transaction. + */ + public function doDirectPayment(&$params) { + $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id'); + if ($params['is_pay_later']) { + $result['payment_status_id'] = array_search('Pending', $statuses); + } + else { + $result['payment_status_id'] = array_search('Completed', $statuses); + } + } + } diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 4138538dd4..b2b32e7193 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -220,6 +220,7 @@ class CRM_Core_SelectValues { 'Activity' => ts('Activities'), 'Relationship' => ts('Relationships'), 'Contribution' => ts('Contributions'), + 'ContributionRecur' => ts('Recurring Contributions'), 'Group' => ts('Groups'), 'Membership' => ts('Memberships'), 'Event' => ts('Events'), diff --git a/CRM/Upgrade/Incremental/sql/4.7.beta1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.beta1.mysql.tpl index 372f7b90a7..2d37b8e6f8 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.beta1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.beta1.mysql.tpl @@ -1,5 +1,13 @@ {* file to handle db changes in 4.7.beta1 during upgrade *} +-- CRM-16901 Recurring contributions summary report template +SELECT @option_group_id_report := max(id) from civicrm_option_group where name = 'report_template'; +SELECT @contributeCompId := max(id) FROM civicrm_component where name = 'CiviContribute'; +INSERT INTO + `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) +VALUES + (@option_group_id_report, {localize}'{ts escape="sql"}Recurring Contributions Summary{/ts}'{/localize}, 'contribute/recursummary', 'CRM_Report_Form_Contribute_RecurSummary', NULL, 0, NULL, 49, {localize}'{ts escape="sql"}Provides simple summary for each payment instrument for which there are recurring contributions (e.g. Credit Card, Standing Order, Direct Debit etc.), showing within a given date range.{/ts}'{/localize}, 0, 0, 1, @contributeCompId, NULL); + SELECT @parent_id := id from `civicrm_navigation` where name = 'Administration Console' AND domain_id = {$domainID}; INSERT INTO civicrm_navigation ( domain_id, url, label, name, permission, permission_operator, parent_id, is_active, has_separator, weight ) diff --git a/api/v3/ContributionRecur.php b/api/v3/ContributionRecur.php index a7a0b293de..27a5cfe126 100644 --- a/api/v3/ContributionRecur.php +++ b/api/v3/ContributionRecur.php @@ -41,6 +41,8 @@ * api result array */ function civicrm_api3_contribution_recur_create($params) { + _civicrm_api3_custom_format_params($params, $values, 'ContributionRecur'); + $params = array_merge($params, $values); return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); } diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index 64df731a53..e5d362391f 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -160,11 +160,6 @@ {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" campaignContext="componentSearch" campaignTrClass='' campaignTdClass=''} - - -{include file="CRM/Contribute/Form/Search/ContributionRecur.tpl"} - - {if $contributeGroupTree} diff --git a/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl b/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl index b6246cbd0e..567b0e78e9 100644 --- a/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl +++ b/templates/CRM/Contribute/Form/Search/ContributionRecur.tpl @@ -24,52 +24,57 @@ +--------------------------------------------------------------------+ *} -
-
- {ts}Recurring Contributions{/ts} -
-
- - - - - - - - - - - - - - - - - - - - - - - - - -
{ts}Start Date{/ts} - {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_start_date" from='_low' to='_high'} -
{ts}End Date{/ts} - {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_end_date" from='_low' to='_high'} -
{ts}Modified Date{/ts} - {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_modified_date" from='_low' to='_high'} -
{ts}Next Scheduled{/ts} - {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_next_sched_contribution_date" from='_low' to='_high'} -
{ts}Retry Date{/ts} - {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_failure_retry_date" from='_low' to='_high'} -
{ts}Cancel Date{/ts} - {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_cancel_date" from='_low' to='_high'} -
-
- -
- - + + {$form.contribution_recur_payment_made.html} + + + {ts}Start Date{/ts} + + {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_start_date" from='_low' to='_high'} + + + + {ts}End Date{/ts} + + {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_end_date" from='_low' to='_high'} + + + + {ts}Modified Date{/ts} + + {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_modified_date" from='_low' to='_high'} + + + + {ts}Next Scheduled{/ts} + + {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_next_sched_contribution_date" from='_low' to='_high'} + + + + {ts}Retry Date{/ts} + + {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_failure_retry_date" from='_low' to='_high'} + + + + {ts}Cancel Date{/ts} + + {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_cancel_date" from='_low' to='_high'} + + + + {$form.contribution_recur_processor_id.label} + {$form.contribution_recur_processor_id.html} + + + {$form.contribution_recur_trxn_id.label} + {$form.contribution_recur_trxn_id.html} + +{if $contributeRecurGroupTree} + + + {include file="CRM/Custom/Form/Search.tpl" groupTree=$contributeRecurGroupTree showHideLinks=false} + + +{/if} diff --git a/xml/templates/civicrm_data.tpl b/xml/templates/civicrm_data.tpl index 281c6ba27d..2d7f9dd157 100644 --- a/xml/templates/civicrm_data.tpl +++ b/xml/templates/civicrm_data.tpl @@ -635,6 +635,7 @@ VALUES (@option_group_id_report, {localize}'{ts escape="sql"}Mail Detail Report{/ts}'{/localize}, 'mailing/detail', 'CRM_Report_Form_Mailing_Detail', NULL, 0, NULL, 47, {localize}'{ts escape="sql"}Provides reporting on Intended and Successful Deliveries, Unsubscribes and Opt-outs, Replies and Forwards.{/ts}'{/localize}, 0, 0, 1, @mailCompId, NULL), (@option_group_id_report, {localize}'{ts escape="sql"}Contribution and Membership Details{/ts}'{/localize}, 'member/contributionDetail', 'CRM_Report_Form_Member_ContributionDetail', NULL, 0, NULL, 48, {localize}'{ts escape="sql"}Contribution details for any type of contribution, plus associated membership information for contributions which are in payment for memberships.{/ts}'{/localize}, 0, 0, 1, @memberCompId, NULL), (@option_group_id_report, {localize}'{ts escape="sql"}Recurring Contributions Report{/ts}'{/localize}, 'contribute/recur', 'CRM_Report_Form_Contribute_Recur', NULL, 0, NULL, 49, {localize}'{ts escape="sql"}Provides information about the status of recurring contributions{/ts}'{/localize}, 0, 0, 1, @contributeCompId, NULL), + (@option_group_id_report, {localize}'{ts escape="sql"}Recurring Contributions Summary{/ts}'{/localize}, 'contribute/recursummary', 'CRM_Report_Form_Contribute_RecurSummary', NULL, 0, NULL, 49, {localize}'{ts escape="sql"}Provides simple summary for each payment instrument for which there are recurring contributions (e.g. Standing Order and Direct Debit), showing within a given date range.{/ts}'{/localize}, 0, 0, 1, @contributeCompId, NULL), (@option_group_id_acs, '{ts escape="sql"}Scheduled{/ts}', 1, 'Scheduled', NULL, 0, 1, 1, NULL, 0, 1, 1, NULL, NULL), (@option_group_id_acs, '{ts escape="sql"}Completed{/ts}', 2, 'Completed', NULL, 0, NULL, 2, NULL, 0, 1, 1, NULL, NULL),