From c08d8172cb567e23cc2bd09670f95ceb9cce178c Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Thu, 10 Aug 2017 02:51:11 +0530 Subject: [PATCH] CRM-21050, fixed code to set receive date with correct timestamp ---------------------------------------- * CRM-21050: credit card invoice: receive time set to 12:00 https://issues.civicrm.org/jira/browse/CRM-21050 --- CRM/Contribute/Form/AdditionalInfo.php | 2 +- CRM/Contribute/Form/Contribution.php | 56 ++++--------------- .../Form/AdditionalInfo/AdditionalDetail.tpl | 2 +- .../CRM/Contribute/Form/Contribution.tpl | 8 +-- 4 files changed, 17 insertions(+), 51 deletions(-) diff --git a/CRM/Contribute/Form/AdditionalInfo.php b/CRM/Contribute/Form/AdditionalInfo.php index e6423b02f462..d8b6b5ff7fd3 100644 --- a/CRM/Contribute/Form/AdditionalInfo.php +++ b/CRM/Contribute/Form/AdditionalInfo.php @@ -96,7 +96,7 @@ public static function buildAdditionalDetail(&$form) { $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'), diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 04310298e833..cc8bb741f4f8 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -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 @@ public function setDefaultValues() { 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 @@ public function buildQuickForm() { } // 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 @@ protected function processCreditCard($submittedValues, $lineItem, $contactID) { 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 @@ protected function processCreditCard($submittedValues, $lineItem, $contactID) { 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); @@ -1598,17 +1575,6 @@ protected function submit($submittedValues, $action, $pledgePaymentID) { '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"); diff --git a/templates/CRM/Contribute/Form/AdditionalInfo/AdditionalDetail.tpl b/templates/CRM/Contribute/Form/AdditionalInfo/AdditionalDetail.tpl index d0dced90077a..22739276db97 100644 --- a/templates/CRM/Contribute/Form/AdditionalInfo/AdditionalDetail.tpl +++ b/templates/CRM/Contribute/Form/AdditionalInfo/AdditionalDetail.tpl @@ -40,7 +40,7 @@ {ts}Unique internal reference ID for this contribution.{/ts} {$form.creditnote_id.label}{$form.creditnote_id.html}
{ts}Unique internal Credit Note ID for this contribution.{/ts} - {$form.thankyou_date.label}{include file="CRM/common/jcalendar.tpl" elementName=thankyou_date}
+ {$form.thankyou_date.label}{$form.thankyou_date.html}
{ts}Date that a thank-you message was sent to the contributor.{/ts} diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 8d7d73fd9852..55fef650d6dc 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -139,7 +139,7 @@ {if $contributionMode && $processorSupportsFutureStartDate} {ts}Start Date{/ts} - {if $hideCalender neq true}{include file="CRM/common/jcalendar.tpl" elementName=receive_date}{else}{$receive_date|crmDate}{/if}
+ {if $hideCalender neq true}{$form.receive_date.html}{/if}
{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} @@ -179,7 +179,7 @@ {$form.cancel_date.label} {if $hideCalendar neq true} - {include file="CRM/common/jcalendar.tpl" elementName=cancel_date} + {$form.cancel_date.html} {else} {$form.cancel_date.value|crmDate} {/if} @@ -203,7 +203,7 @@ {$form.receive_date.label} - {include file="CRM/common/jcalendar.tpl" elementName=receive_date}
+ {$form.receive_date.html}
{ts}The date this contribution was received.{/ts} @@ -235,7 +235,7 @@ {$form.receipt_date.label} - {include file="CRM/common/jcalendar.tpl" elementName=receipt_date}
+ {$form.receipt_date.html}
{ts}Date that a receipt was sent to the contributor.{/ts}