Merge pull request #10818 from eileenmcnaughton/recur_date
authorMonish Deb <monish.deb@jmaconsulting.biz>
Mon, 7 Aug 2017 12:03:48 +0000 (17:33 +0530)
committerGitHub <noreply@github.com>
Mon, 7 Aug 2017 12:03:48 +0000 (17:33 +0530)
CRM-21027 Fix next recurring payment not accurately calculated

CRM/Contribute/BAO/ContributionRecur.php
tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php
tests/phpunit/api/v3/ContributionTest.php

index 24937e2af971e6b1aeba2800128af3f6167b6b9c..bb6d30b735cd5d788d99dc062547a29a154c856c 100644 (file)
@@ -816,9 +816,8 @@ INNER JOIN civicrm_contribution       con ON ( con.id = mp.contribution_id )
    * @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;
     }
index 759c4faedf549408ec8a7d585db7130f4b472933..0f13083b219a1cb8ced3a16efbaf426ac6d6e4fc 100644 (file)
@@ -99,7 +99,7 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase {
    */
   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 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase {
       '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']));
   }
index 2b8239ba18199ad535bedb2913d6ddeade26209b..2ee0bd32e4504b33f650556395eb3667cf230777 100644 (file)
@@ -2671,6 +2671,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
       '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;
   }