CRM-16901 - Rebased PR with a few field name and markup improvements
authorDave Greenberg <dave@civicrm.org>
Tue, 24 Nov 2015 22:36:25 +0000 (14:36 -0800)
committermonishdeb <monish.deb@webaccessglobal.com>
Thu, 26 Nov 2015 10:17:18 +0000 (15:47 +0530)
----------------------------------------
* CRM-16901: Offline Recurring Payments
  https://issues.civicrm.org/jira/browse/CRM-16901

14 files changed:
CRM/Contact/Form/Search/Advanced.php
CRM/Contact/Form/Search/Criteria.php
CRM/Contribute/BAO/ContributionRecur.php
CRM/Contribute/BAO/Query.php
CRM/Core/BAO/CustomGroup.php
CRM/Core/BAO/CustomQuery.php
CRM/Core/Payment.php
CRM/Core/Payment/Manual.php
CRM/Core/SelectValues.php
CRM/Upgrade/Incremental/sql/4.7.beta1.mysql.tpl
api/v3/ContributionRecur.php
templates/CRM/Contribute/Form/Search/Common.tpl
templates/CRM/Contribute/Form/Search/ContributionRecur.tpl
xml/templates/civicrm_data.tpl

index 502da90f056edfe526bcc1811c430a5c167f058c..8dea7c2144095e2eaab3bbbbdba58d7f810a6ddc 100644 (file)
@@ -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();
index 15163ee9cca6d4cb233a465baae7a278a788a4e8..5d199a8edf015f2dd1ce7aa1b7b5398224dab084 100644 (file)
@@ -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
+          );
+        }
+      }
+    }
+  }
+
 }
index ce853c5472e5637fa9e297cfc0dc0309155f6f44..9254c6dca875f20ae50372863c37fe7e38c361fd 100644 (file)
@@ -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;
   }
 
index 0e697e97c0ce20a4d170ad74170d24025f5c6916..2f823e1fd626e1e27fec96ca3a3463b8c4e19a65 100644 (file)
@@ -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 ";
index 5a23b77886f72ac0f14e2abd8c2cf03ce2b9429d..232e59f797bca8922eee68a6e5f0f4df08f74344 100644 (file)
@@ -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';
 
index f3b1ddcad3e856648fbaa645df87027b45196c90..fd79201f58290d3d1e229b258a3168853f62824e 100644 (file)
@@ -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',
index 2fc18e2f0d244d40274653d68e811fc38d794486..db6a77f1e92a1c90e93c9850f558283805c94413 100644 (file)
@@ -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;
+  }
+
 }
index 1cedc975db773b59c7fd73b32e3b3f49dc545b4e..a2c15bbe9dacf48766320dc89c6c7b77122345e3 100644 (file)
@@ -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);
+    }
+  }
+
 }
index 4138538dd413dc4b43d41c506b04179e4dd53947..b2b32e71935e68ebe2346421831f152c8dd107bc 100644 (file)
@@ -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'),
index 372f7b90a7f69d5978742b44a2e3beab2bcfcff3..2d37b8e6f82c2f7aab4b293fd9de0ebc1c58a4a4 100644 (file)
@@ -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 )
index a7a0b293de34be55efd5014967dc2b1cf61d80a2..27a5cfe126229db0f58ee1fa7523cad8f27881ae 100644 (file)
@@ -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);
 }
 
index 64df731a536935c328259e9c7a77ef56815c0ca6..e5d362391facca3f5d634d80ec302c73ae6b95a4 100644 (file)
 {include file="CRM/Campaign/Form/addCampaignToComponent.tpl" campaignContext="componentSearch"
 campaignTrClass='' campaignTdClass=''}
 
-<tr>
-  <td colspan="2">
-{include file="CRM/Contribute/Form/Search/ContributionRecur.tpl"}
-</tr>
-
 {if $contributeGroupTree}
 <tr>
   <td colspan="2">
index b6246cbd0ebc89fa460b42be1c08f448be4129b2..567b0e78e99648caed455e1aaefa26ccc84c608f 100644 (file)
  +--------------------------------------------------------------------+
 *}
 
-<div class="crm-accordion-wrapper crm-contactDetails-accordion
-   {if empty($contribution_recur_pane_open)} collapsed{/if}" id="contribution_recur">
-  <div class="crm-accordion-header">
-    {ts}Recurring Contributions{/ts}
-  </div>
-  <div class="crm-accordion-body">
-    <table class="form-layout-compressed">
-      <tr>
-        <td>{ts}Start Date{/ts}</td>
-        <td>
-          {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_start_date" from='_low' to='_high'}
-        </td>
-      </tr>
-      <tr>
-        <td>{ts}End Date{/ts}</td>
-        <td>
-          {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_end_date" from='_low' to='_high'}
-        </td>
-      </tr>
-      <tr>
-        <td>{ts}Modified Date{/ts}</td>
-        <td>
-          {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_modified_date" from='_low' to='_high'}
-        </td>
-      </tr>
-      <tr>
-        <td>{ts}Next Scheduled{/ts}</td>
-        <td>
-          {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_next_sched_contribution_date" from='_low' to='_high'}
-        </td>
-      </tr>
-      <tr>
-        <td>{ts}Retry Date{/ts}</td>
-        <td>
-          {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_failure_retry_date" from='_low' to='_high'}
-        </td>
-      </tr>
-      <tr>
-        <td>{ts}Cancel Date{/ts}</td>
-        <td>
-          {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_cancel_date" from='_low' to='_high'}
-        </td>
-      </tr>
-    </table>
-  </div>
-  <!-- /.crm-accordion-body -->
-</div><!-- /.crm-accordion-wrapper -->
-
-
+<tr>
+  <td colspan="4">{$form.contribution_recur_payment_made.html}</td>
+</tr>
+<tr>
+  <td>{ts}Start Date{/ts}</td>
+  <td>
+    {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_start_date" from='_low' to='_high'}
+  </td>
+</tr>
+<tr>
+  <td>{ts}End Date{/ts}</td>
+  <td>
+    {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_end_date" from='_low' to='_high'}
+  </td>
+</tr>
+<tr>
+  <td>{ts}Modified Date{/ts}</td>
+  <td>
+    {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_modified_date" from='_low' to='_high'}
+  </td>
+</tr>
+<tr>
+  <td>{ts}Next Scheduled{/ts}</td>
+  <td>
+    {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_next_sched_contribution_date" from='_low' to='_high'}
+  </td>
+</tr>
+<tr>
+  <td>{ts}Retry Date{/ts}</td>
+  <td>
+    {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_failure_retry_date" from='_low' to='_high'}
+  </td>
+</tr>
+<tr>
+  <td>{ts}Cancel Date{/ts}</td>
+  <td>
+    {include file="CRM/Core/DateRange.tpl" fieldName="contribution_recur_cancel_date" from='_low' to='_high'}
+  </td>
+</tr>
+<tr>
+  <td colspan="2">{$form.contribution_recur_processor_id.label}</td>
+  <td>{$form.contribution_recur_processor_id.html}</td>
+</tr>
+<tr>
+  <td colspan="2">{$form.contribution_recur_trxn_id.label}</td>
+  <td>{$form.contribution_recur_trxn_id.html}</td>
+</tr>
+{if $contributeRecurGroupTree}
+  <tr>
+    <td colspan="4">
+      {include file="CRM/Custom/Form/Search.tpl" groupTree=$contributeRecurGroupTree showHideLinks=false}
+    </td>
+  </tr>
+{/if}
index 281c6ba27ddd0edea713926283472c379fa6128b..2d7f9dd1571950b468be9d842224f303f13758fa 100644 (file)
@@ -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),