From 2439fa7b8947b9ce65ac27bcf613fbcc16e9aaa7 Mon Sep 17 00:00:00 2001 From: Klaas Eikelboom Date: Thu, 16 Nov 2017 16:38:19 +0000 Subject: [PATCH 1/3] CRM-21424 Set receipt date when downloading pdf receipt --- CRM/Contribute/BAO/Contribution.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 0be55b010c53..08c216815823 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4722,7 +4722,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; From 82b862f8bc328c73a0b478007a5b3dc2266f5cee Mon Sep 17 00:00:00 2001 From: Klaas Eikelboom Date: Fri, 17 Nov 2017 17:42:48 +0000 Subject: [PATCH 2/3] remove obsolete comment --- CRM/Contribute/BAO/Contribution.php | 1 - 1 file changed, 1 deletion(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 08c216815823..38ed46ff134d 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4721,7 +4721,6 @@ 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 ((!isset($input['receipt_update']) || $input['receipt_update']) && empty($contribution->receipt_date)) { civicrm_api3('Contribution', 'create', array('receipt_date' => 'now', 'id' => $contribution->id)); } From 1db3ddea7e9b35c02b654b3b35c45c2be945957e Mon Sep 17 00:00:00 2001 From: Klaas Eikelboom Date: Sat, 18 Nov 2017 19:58:20 +0000 Subject: [PATCH 3/3] Added test --- .../CRM/Contribute/BAO/ContributionTest.php | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index 586b1bc2d913..f78d958ef6fc 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -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'); + } + }