From 5258facb885f2fd76327bfcbb159cf5e2eda89d3 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 4 Aug 2017 20:49:32 +1200 Subject: [PATCH] CRM-21027 Fix next recurring payment not accurately calculated when effective date passed in --- CRM/Contribute/BAO/ContributionRecur.php | 5 ++--- .../CRM/Contribute/BAO/ContributionRecurTest.php | 4 ++-- tests/phpunit/api/v3/ContributionTest.php | 10 ++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionRecur.php b/CRM/Contribute/BAO/ContributionRecur.php index 24937e2af971..bb6d30b735cd 100644 --- a/CRM/Contribute/BAO/ContributionRecur.php +++ b/CRM/Contribute/BAO/ContributionRecur.php @@ -816,9 +816,8 @@ public static function getRecurringFields() { * @throws \CiviCRM_API3_Exception */ public static function updateOnNewPayment($recurringContributionID, $paymentStatus, $effectiveDate) { - if (empty($effectiveDate)) { - $effectiveDate = date('Y-m-d'); - } + + $effectiveDate = $effectiveDate ? date('Y-m-d', strtotime($effectiveDate)) : date('Y-m-d'); if (!in_array($paymentStatus, array('Completed', 'Failed'))) { return; } diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php index 759c4faedf54..0f13083b219a 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php @@ -99,7 +99,7 @@ public function testCancelRecur() { */ public function testSupportFinancialTypeChange() { $contributionRecur = $this->callAPISuccess('contribution_recur', 'create', $this->_params); - $contribution = $this->callAPISuccess('contribution', 'create', array( + $this->callAPISuccess('contribution', 'create', array( 'contribution_recur_id' => $contributionRecur['id'], 'total_amount' => '3.00', 'financial_type_id' => 1, @@ -107,7 +107,7 @@ public function testSupportFinancialTypeChange() { 'currency' => 'USD', 'contact_id' => $this->individualCreate(), 'contribution_status_id' => 1, - 'recieve_date' => 'yesterday', + 'receive_date' => 'yesterday', )); $this->assertTrue(CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($contributionRecur['id'])); } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 2b8239ba1819..2ee0bd32e450 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -2671,6 +2671,16 @@ public function getScheduledDateData() { 'receive_date' => '2012-02-29', 'expected' => '2012-03-29 00:00:00', ); + $result['receive_date_includes_time']['2012-01-01-1-month'] = array( + 'data' => array( + 'start_date' => '2012-01-01', + 'frequency_interval' => 1, + 'frequency_unit' => 'month', + 'next_sched_contribution_date' => '2012-02-29', + ), + 'receive_date' => '2012-02-29 16:00:00', + 'expected' => '2012-03-29 00:00:00', + ); return $result; }