Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21050: Use datepicker for all date fields used in contribution backoffice form #10841

Merged
merged 2 commits into from
Jan 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
59 changes: 12 additions & 47 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 @@ -1311,10 +1288,9 @@ protected function generatePane($type, $defaults) {
public function testSubmit($params, $action, $creditCardMode = NULL) {
$defaults = array(
'soft_credit_contact_id' => array(),
'receive_date' => date('Y-m-d H:i:s'),
'receipt_date' => '',
'receipt_date_time' => '',
'cancel_date' => '',
'cancel_date_time' => '',
'hidden_Premium' => 1,
);
$this->_bltID = 5;
Expand Down Expand Up @@ -1608,17 +1584,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
4 changes: 2 additions & 2 deletions api/v3/examples/ContributionPage/Submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function contribution_page_submit_example() {
),
'cvv2' => 123,
'pledge_id' => '1',
'cid' => '77',
'contact_id' => '77',
'cid' => '83',
'contact_id' => '83',
'amount' => '100',
'is_pledge' => TRUE,
'pledge_block_id' => 2,
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
2 changes: 0 additions & 2 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1203,8 +1203,6 @@ public function createContributionWithTax() {
$form->testSubmit(array(
'total_amount' => 100,
'financial_type_id' => $financialType['id'],
'receive_date' => '04/21/2015',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update the format on these dates rather than remove?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton 2 reasons why I removed it:

  1. Provided the default value of current date time in the desired format here
  2. In these unit-tests receive date has no importance, however I have retained in some UT like here where it's needed.

Or do you still want to update their formats?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that seems fine - sounds like we are not losing any test data

'receive_date_time' => '11:27PM',
'contact_id' => $contactId,
'contribution_status_id' => 1,
'price_set_id' => 0,
Expand Down
Loading