CRM-17684 Expand Auto-Renew membership search to seach subscription status
authorEllen Hendricks <ellen.hendricks@sprydigital.com>
Tue, 10 May 2016 21:00:29 +0000 (16:00 -0500)
committerEllen Hendricks <ellen.hendricks@sprydigital.com>
Tue, 10 May 2016 21:00:29 +0000 (16:00 -0500)
----------------------------------------
* CRM-17684: Find Memberships with no auto-renew
  https://issues.civicrm.org/jira/browse/CRM-17684

CRM/Member/BAO/Query.php
templates/CRM/Member/Form/Search.hlp
templates/CRM/Member/Form/Search/Common.tpl

index b226fa853939cc9eb3180b5d886c623ef0dd902c..6fcb7e1228f8048e36e6c18d05ba2b171d15cc1f 100644 (file)
@@ -262,8 +262,36 @@ class CRM_Member_BAO_Query {
         return;
 
       case 'member_auto_renew':
-        $op = "!=";
-        if ($value) {
+        $op = "=";
+        if ($value == 1) {
+          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NULL";
+          $query->_qill[$grouping][] = ts("Membership is NOT Auto-Renew");
+        }
+        elseif ($value == 2) {
+          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
+          $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause(
+            "ccr.contribution_status_id",
+            $op,
+            array_search(
+              'In Progress',
+              CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
+            ),
+            "Integer");
+          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and In Progress");
+        } 
+        elseif ($value == 3) {
+          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
+          $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause(
+            "ccr.contribution_status_id",
+            $op,
+            array_search(
+              'Failed',
+              CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
+            ),
+            "Integer");
+          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and Failed");
+        } 
+        elseif ($value == 4) {
           $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
           $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause(
             "ccr.contribution_status_id",
@@ -274,11 +302,12 @@ class CRM_Member_BAO_Query {
             ),
             "Integer"
           );
-          $query->_qill[$grouping][] = ts("Membership is Auto-Renew");
-        }
-        else {
-          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NULL";
-          $query->_qill[$grouping][] = ts("Membership is NOT Auto-Renew");
+          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and Cancelled");
+        } 
+        elseif ($value == 5) {
+          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
+          $query->_where[$grouping][] = " ccr.end_date IS NOT NULL";
+          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and Ended");
         }
         $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
         return;
@@ -393,6 +422,7 @@ class CRM_Member_BAO_Query {
         'membership_recur_id' => 1,
         'member_campaign_id' => 1,
         'member_is_override' => 1,
+        'member_auto_renew' => '1',
       );
 
       if ($includeCustomFields) {
@@ -444,7 +474,18 @@ class CRM_Member_BAO_Query {
 
     $form->addYesNo('member_is_primary', ts('Primary Member?'), TRUE);
     $form->addYesNo('member_pay_later', ts('Pay Later?'), TRUE);
-    $form->addYesNo('member_auto_renew', ts('Auto-Renew?'), TRUE);
+
+    $form->add('select', 'member_auto_renew',
+      ts('Auto-Renew Subscription Status?'),
+      array(
+        '1' => ts('- None -'),
+        '2' => ts('In Progress'),
+        '3' => ts('Failed'),
+        '4' => ts('Cancelled'),
+        '5' => ts('Ended'),
+      )
+    );
+
     $form->addYesNo('member_test', ts('Membership is a Test?'), TRUE);
     $form->addYesNo('member_is_override', ts('Membership Status Is Override?'), TRUE);
 
index 6f1c228e61bcbab7846058b99ddb5664476a016c..5dd6e9df517ea8c46f9c94e81d9a303d6ee11ad0 100644 (file)
     <li>{ts}Select neither to show all memberships{/ts}</li>
   </ul>
 {/htxt}
+{htxt id="id-member_auto_renew-title"}
+  {ts}Auto-Renew Subscription Status{/ts}
+{/htxt}
+{htxt id="id-member_auto_renew"}
+  <ul>
+    <li>{ts}Select "None" to display memberships that have never had an auto-renew subscription.{/ts}</li>
+    <li>{ts}Select "In Progress" to display memberships with current auto-renew subscriptions.{/ts}</li>
+    <li>{ts}Select "Failed" to display memberships with failed subscription payment.{/ts}</li>
+    <li>{ts}Select "Cancelled" to display memberships with cancelled auto-renew subscriptions.{/ts}</li>
+    <li>{ts}Select "Ended" to display memberships with an ended auto-renew subscription.{/ts}</li>
+  </ul>
+{/htxt}
+
index 2a9b859b627999a12839dea7f2a53e0870b479e9..569463018546e36cadccb51a26ecb894cfafaa85 100644 (file)
     {$form.member_pay_later.label}&nbsp;{$form.member_pay_later.html}
     </p>
     <p>
-    {$form.member_auto_renew.label}&nbsp;{$form.member_auto_renew.html}
+      {if $form.member_auto_renew}
+          <label>{$form.member_auto_renew.label}</label>
+          {help id="id-member_auto_renew" file="CRM/Member/Form/Search.hlp"}
+          <br/>
+          {$form.member_auto_renew.html}
+        {/if}
     </p>
     <p>
     {$form.member_is_override.label}