Skip to content

Commit

Permalink
CRM-21050, fixed code to set receive date with correct timestamp
Browse files Browse the repository at this point in the history
----------------------------------------
* CRM-21050: credit card invoice: receive time set to 12:00
  https://issues.civicrm.org/jira/browse/CRM-21050
  • Loading branch information
pradpnayak authored and monishdeb committed Jan 1, 2018
1 parent ec7b6f8 commit c08d817
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/AdditionalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
56 changes: 11 additions & 45 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
8 changes: 4 additions & 4 deletions templates/CRM/Contribute/Form/Contribution.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
{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>
Expand Down Expand Up @@ -179,7 +179,7 @@
<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}
Expand All @@ -203,7 +203,7 @@
</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>
Expand Down Expand Up @@ -235,7 +235,7 @@
</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>
Expand Down

0 comments on commit c08d817

Please sign in to comment.