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-21424 Set receipt date when downloading pdf receipt #11289

Merged
merged 3 commits into from
Nov 18, 2017
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
3 changes: 1 addition & 2 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4721,8 +4721,7 @@ public static function sendMail(&$input, &$ids, $contributionID, &$values,
}
$values['contribution_status'] = CRM_Core_PseudoConstant::getLabel('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution->contribution_status_id);
$return = $contribution->composeMessageArray($input, $ids, $values, $returnMessageText);
// Contribution ID should really always be set. But ?
if (!$returnMessageText && (!isset($input['receipt_update']) || $input['receipt_update']) && empty($contribution->receipt_date)) {
if ((!isset($input['receipt_update']) || $input['receipt_update']) && empty($contribution->receipt_date)) {
civicrm_api3('Contribution', 'create', array('receipt_date' => 'now', 'id' => $contribution->id));
}
return $return;
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1405,4 +1405,42 @@ public function testContributionWithDeferredRevenue() {
), $checkAgainst);
}

/**
* CRM-21424 Check if the receipt update is set after composing the receipt message
*/
public function testSendMailUpdateReceiptDate() {
$ids = $values = array();
$contactId = $this->individualCreate();
$params = array(
'contact_id' => $contactId,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => 'Donation',
'source' => 'SSF',
'contribution_status_id' => 'Completed',
);
/* first test the scenario when sending an email */
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contributionId = $contribution['id'];
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null');
$input = array('receipt_update' => 0);
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values);
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null');
$input = array('receipt_update' => 1);
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values);
$this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set');

/* repeat the same scenario for downloading a pdf */
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$contributionId = $contribution['id'];
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After creating receipt date must be null');
$input = array('receipt_update' => 0);
/* setting the lasast parameter (returnmessagetext) to TRUE is done by the download of the pdf */
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values, TRUE);
$this->assertDBNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail, with the explicit instruction not to update receipt date stays null');
$input = array('receipt_update' => 1);
CRM_Contribute_BAO_Contribution::sendMail($input, $ids, $contributionId, $values, TRUE);
$this->assertDBNotNull('CRM_Contribute_BAO_Contribution', $contributionId, 'receipt_date', 'id', 'After sendMail with the permission to allow update receipt date must be set');
}

}