CRM-18460 - Contribution Aggregate custom search - use relative date fields
authorJon goldberg <jon@palantetech.coop>
Thu, 21 Apr 2016 21:09:53 +0000 (17:09 -0400)
committerdeb.monish <monish.deb@webaccessglobal.com>
Fri, 2 Dec 2016 11:16:37 +0000 (16:46 +0530)
CRM/Contact/Form/Search/Custom/ContributionAggregate.php
templates/CRM/Contact/Form/Search/Custom/ContributionAggregate.tpl

index c5015b0a3a1dc907ac4bbbe9325842ef778d817e..c1036761db5dfdaecfff4f04eaf42a39dae8f987 100644 (file)
@@ -83,9 +83,7 @@ class CRM_Contact_Form_Search_Custom_ContributionAggregate extends CRM_Contact_F
       ts('...and $')
     );
     $form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
-
-    $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
-    $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
+    CRM_Core_Form_Date::buildDateRange($form, 'contribution_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
 
     $form->addSelect('financial_type_id',
       array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search')
@@ -95,7 +93,7 @@ class CRM_Contact_Form_Search_Custom_ContributionAggregate extends CRM_Contact_F
      * If you are using the sample template, this array tells the template fields to render
      * for the search form.
      */
-    $form->assign('elements', array('min_amount', 'max_amount', 'start_date', 'end_date'));
+    $form->assign('elements', array('min_amount', 'max_amount'));
   }
 
   /**
@@ -202,15 +200,15 @@ civicrm_contact AS contact_a {$this->_aclFrom}
     $clauses[] = "contrib.contact_id = contact_a.id";
     $clauses[] = "contrib.is_test = 0";
 
-    $startTime = !empty($this->_formValues['start_date_time']) ? $this->_formValues['start_date_time'] : '00:00:00';
-    $endTime = !empty($this->_formValues['end_date_time']) ? $this->_formValues['end_date_time'] : '23:59:59';
+    $relative = $this->_formValues['contribution_date_relative'];
+    $startDate = $this->_formValues['contribution_date_low'];
+    $endDate = $this->_formValues['contribution_date_high'];
+    list($startDate, $endDate) = CRM_Utils_Date::getFromTo($relative, $startDate, $endDate);
 
-    $startDate = CRM_Utils_Date::processDate($this->_formValues['start_date'], $startTime);
     if ($startDate) {
       $clauses[] = "contrib.receive_date >= $startDate";
     }
 
-    $endDate = CRM_Utils_Date::processDate($this->_formValues['end_date'], $endTime);
     if ($endDate) {
       $clauses[] = "contrib.receive_date <= $endDate";
     }
index db6d66d9475c3992b6d96ce8617b06472949f14f..343f862c7f8200fcf61825ad114be207478eab54 100644 (file)
             {foreach from=$elements item=element}
                 <tr class="crm-contact-custom-search-form-row-{$element}">
                     <td class="label">{$form.$element.label}</td>
-                    {if $element eq 'start_date'}
-                        <td>{include file="CRM/common/jcalendar.tpl" elementName=start_date}</td>
-                    {elseif $element eq 'end_date'}
-                        <td>{include file="CRM/common/jcalendar.tpl" elementName=end_date}</td>
-                    {else}
-                        <td>{$form.$element.html}</td>
-                    {/if}
+                    <td>{$form.$element.html}</td>
                 </tr>
             {/foreach}
+            <tr class="crm-contact-custom-search-contributionDetails-form-block-receive_date">
+              <td><label>{ts}Contribution Dates{/ts}</label></td>
+              {include file="CRM/Core/DateRange.tpl" fieldName="contribution_date" from='_low' to='_high'}
+            </tr>
             <tr class="crm-contact-custom-search-contributionDetails-form-block-financial_type">
                 <td class="label">{ts}Financial Type{/ts}</td>
                 <td>{$form.financial_type_id.html|crmAddClass:twenty}</td>