From 494fdf05835188164a8ed1996f48de07ac4c223a Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Thu, 14 Sep 2017 17:32:09 +0530 Subject: [PATCH] CRM-21183: Updating Partially paid contribution to Completed doesn't update membership --- CRM/Contribute/BAO/Contribution.php | 6 ++- .../CRM/Member/Form/MembershipTest.php | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 53b6448fb0..7b6b39360c 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -1832,16 +1832,18 @@ LEFT JOIN civicrm_contribution contribution ON ( componentPayment.contribution_ } } elseif ($contributionStatusId == array_search('Completed', $contributionStatuses)) { + $pending = array_search('Pending', $contributionStatuses); + $partaillyPaid = array_search('Partially paid', $contributionStatuses); // only pending contribution related object processed. if ($previousContriStatusId && - ($previousContriStatusId != array_search('Pending', $contributionStatuses)) + (!in_array($previousContriStatusId, array($pending, $partaillyPaid))) ) { // this is case when we already processed contribution object. return $updateResult; } elseif (!$previousContriStatusId && - $contribution->contribution_status_id != array_search('Pending', $contributionStatuses) + (!in_array($contribution->contribution_status_id, array($pending, $partaillyPaid))) ) { // this is case when we are going to process contribution object later. return $updateResult; diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index 18cf759ed3..5ad6286d54 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -865,6 +865,46 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { )); } + /** + * Test if membership is updated to New after contribution + * is updated from Partially paid to Completed. + */ + public function testSubmitUpdateMembershipFromPartiallyPaid() { + $memStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'validate'); + + //Perform a pay later membership contribution. + $this->testSubmitPayLaterWithBilling(); + $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $this->assertEquals($membership['status_id'], array_search('Pending', $memStatus)); + $contribution = $this->callAPISuccessGetSingle('MembershipPayment', array( + 'membership_id' => $membership['id'], + )); + + //Update contribution to Partially paid. + $prevContribution = $this->callAPISuccess('Contribution', 'create', array( + 'id' => $contribution['contribution_id'], + 'contribution_status_id' => 8, + )); + $prevContribution = $prevContribution['values'][1]; + + //Complete the contribution from offline form. + $form = new CRM_Contribute_Form_Contribution(); + $submitParams = array( + 'id' => $contribution['contribution_id'], + 'contribution_status_id' => 1, + 'price_set_id' => 0, + ); + $fields = array('total_amount', 'net_amount', 'financial_type_id', 'receive_date', 'contact_id', 'payment_instrument_id'); + foreach ($fields as $val) { + $submitParams[$val] = $prevContribution[$val]; + } + $form->testSubmit($submitParams, CRM_Core_Action::UPDATE); + + //Check if Membership is updated to New. + $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId)); + $this->assertEquals($membership['status_id'], array_search('New', $memStatus)); + } + /** * Test the submit function of the membership form. */ -- 2.25.1