CRM-21050, fixed code to set receive date with correct timestamp
authorPradeep Nayak <pradpnayak@gmail.com>
Wed, 9 Aug 2017 21:21:11 +0000 (02:51 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Wed, 3 Jan 2018 03:58:33 +0000 (09:28 +0530)
----------------------------------------
* CRM-21050: credit card invoice: receive time set to 12:00
  https://issues.civicrm.org/jira/browse/CRM-21050

CRM/Contribute/Form/AdditionalInfo.php
CRM/Contribute/Form/Contribution.php
templates/CRM/Contribute/Form/AdditionalInfo/AdditionalDetail.tpl
templates/CRM/Contribute/Form/Contribution.tpl

index e6423b02f462a2905d85bd00251af041ef05c888..d8b6b5ff7fd3509dd4e77c2410de16f9c13cc4ab 100644 (file)
@@ -96,7 +96,7 @@ class CRM_Contribute_Form_AdditionalInfo {
 
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
 
-    $form->addDateTime('thankyou_date', ts('Thank-you Sent'), FALSE, array('formatType' => 'activityDateTime'));
+    $form->addField('thankyou_date', array('entity' => 'contribution'), FALSE, FALSE);
 
     // add various amounts
     $nonDeductAmount = &$form->add('text', 'non_deductible_amount', ts('Non-deductible Amount'),
index 89bb290064e3e4793f2d7a709cdaab164f97f6b7..fab5b05a94f03627788c65d1cc43acaa1d4de012 100644 (file)
@@ -203,6 +203,13 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
    */
   protected $statusMessageTitle;
 
+  /**
+   * Explicitly declare the form context.
+   */
+  public function getDefaultContext() {
+    return 'create';
+  }
+
   /**
    * Set variables up before form is built.
    */
@@ -418,28 +425,11 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     else {
       $defaults['refund_trxn_id'] = isset($defaults['trxn_id']) ? $defaults['trxn_id'] : NULL;
     }
-    $dates = array(
-      'receive_date',
-      'receipt_date',
-      'cancel_date',
-      'thankyou_date',
-    );
-    foreach ($dates as $key) {
-      if (!empty($defaults[$key])) {
-        list($defaults[$key], $defaults[$key . '_time'])
-          = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime');
-      }
-    }
 
     if (!$this->_id && empty($defaults['receive_date'])) {
-      list($defaults['receive_date'],
-        $defaults['receive_date_time']
-        ) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
+      $defaults['receive_date'] = date('Y-m-d H:i:s');
     }
 
-    $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults),
-      CRM_Utils_Array::value('receive_date_time', $defaults)
-    ));
     $currency = CRM_Utils_Array::value('currency', $defaults);
     $this->assign('currency', $currency);
     // Hack to get currency info to the js layer. CRM-11440.
@@ -698,15 +688,14 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     }
 
     // add various dates
-    $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
+    $this->addField('receive_date', array('entity' => 'contribution'), FALSE, FALSE);
+    $this->addField('receipt_date', array('entity' => 'contribution'), FALSE, FALSE);
+    $this->addField('cancel_date', array('entity' => 'contribution', 'label' => ts('Cancelled / Refunded Date')), FALSE, FALSE);
 
     if ($this->_online) {
       $this->assign('hideCalender', TRUE);
     }
 
-    $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
-    $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
-
     $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
 
     $totalAmount = NULL;
@@ -1082,13 +1071,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       CRM_Core_Config::singleton()->defaultCurrency
     );
 
-    if (!empty($this->_params['receive_date'])) {
-      $this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
-    }
-    else {
-      $this->_params['receive_date'] = $now;
-    }
-
     $this->_params['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params);
     $this->_params['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params);
     $this->_params['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params);
@@ -1134,11 +1116,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
     if (!empty($this->_params['is_email_receipt'])) {
       $this->_params['receipt_date'] = $now;
     }
-    else {
-      $this->_params['receipt_date'] = CRM_Utils_Date::processDate($this->_params['receipt_date'],
-        $params['receipt_date_time'], TRUE
-      );
-    }
 
     $this->set('params', $this->_params);
 
@@ -1608,17 +1585,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
           '01-' . implode('-', $formValues['revenue_recognition_date'])
         );
       }
-      $dates = array(
-        'receive_date',
-        'receipt_date',
-        'cancel_date',
-      );
-
-      foreach ($dates as $d) {
-        if (isset($formValues[$d])) {
-          $params[$d] = CRM_Utils_Date::processDate($formValues[$d], CRM_Utils_Array::value($d . '_time', $formValues), TRUE);
-        }
-      }
 
       if (!empty($formValues['is_email_receipt'])) {
         $params['receipt_date'] = date("Y-m-d");
index d0dced90077ab61d152a9f5c1cdea84d52fe8b9d..22739276db97c842fb577a928b60bc80441ba793 100644 (file)
@@ -40,7 +40,7 @@
             <span class="description">{ts}Unique internal reference ID for this contribution.{/ts}</span></td></tr>
         <tr class="crm-contribution-form-block-creditnote_id"><td class="label">{$form.creditnote_id.label}</td><td{$valueStyle}>{$form.creditnote_id.html}<br />
             <span class="description">{ts}Unique internal Credit Note ID for this contribution.{/ts}</span></td></tr>
-        <tr class="crm-contribution-form-block-thankyou_date"><td class="label">{$form.thankyou_date.label}</td><td>{include file="CRM/common/jcalendar.tpl" elementName=thankyou_date}<br />
+        <tr class="crm-contribution-form-block-thankyou_date"><td class="label">{$form.thankyou_date.label}</td><td>{$form.thankyou_date.html}<br />
             <span class="description">{ts}Date that a thank-you message was sent to the contributor.{/ts}</span></td></tr>
     </table>
 </div>
index 8d7d73fd9852253e4f68ab63db65f073867a8425..55fef650d6dc3a102880ee7396cfe2a700ba4653 100644 (file)
     {if $contributionMode && $processorSupportsFutureStartDate}
     <tr id='start_date' class="crm-contribution-form-block-receive_date">
       <td class="label">{ts}Start Date{/ts}</td>
-      <td {$valueStyle}>{if $hideCalender neq true}{include file="CRM/common/jcalendar.tpl" elementName=receive_date}{else}{$receive_date|crmDate}{/if}<br />
+      <td {$valueStyle}>{if $hideCalender neq true}{$form.receive_date.html}{/if}<br />
         <span class="description">{ts}You can set a start date for recurring contributions and the first payment will be on that date. For a single post-dated contribution you must select recurring and choose one installment{/ts}</span>
       </td>
     </tr>
               <td class="label">{$form.cancel_date.label}</td>
               <td>
                 {if $hideCalendar neq true}
-                  {include file="CRM/common/jcalendar.tpl" elementName=cancel_date}
+                  {$form.cancel_date.html}
                 {else}
                   {$form.cancel_date.value|crmDate}
                 {/if}
       </tr>
       <tr class="crm-contribution-form-block-receive_date">
         <td class="label">{$form.receive_date.label}</td>
-        <td {$valueStyle}>{include file="CRM/common/jcalendar.tpl" elementName=receive_date}<br />
+        <td>{$form.receive_date.html}<br />
           <span class="description">{ts}The date this contribution was received.{/ts}</span>
         </td>
       </tr>
     </tr>
     <tr id="receiptDate" class="crm-contribution-form-block-receipt_date">
       <td class="label">{$form.receipt_date.label}</td>
-      <td>{include file="CRM/common/jcalendar.tpl" elementName=receipt_date}<br />
+      <td>{$form.receipt_date.html}<br />
         <span class="description">{ts}Date that a receipt was sent to the contributor.{/ts}</span>
       </td>
     </tr>