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

Decommision getPartialPaymentTrxn function #13718

Merged
merged 1 commit into from
Mar 1, 2019
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
20 changes: 0 additions & 20 deletions CRM/Core/BAO/FinancialTrxn.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,26 +506,6 @@ public static function getTotalPayments($contributionID, $includeRefund = FALSE)
]);
}

/**
* Function records partial payment, complete's contribution if payment is fully paid
* and returns latest payment ie financial trxn
*
* @param array $contribution
* @param array $params
*
* @return \CRM_Financial_DAO_FinancialTrxn
*/
public static function getPartialPaymentTrxn($contribution, $params) {
$trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params);
$paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']);
$total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount');
$cmp = bccomp($total, $paid, 5);
if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount
civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));
}
return $trxn;
}

/**
* Get revenue amount for membership.
*
Expand Down
9 changes: 8 additions & 1 deletion CRM/Financial/BAO/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ public static function create($params) {
}
}
if (!$fullyPaidPayLater) {
$trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params);
$trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params);
$paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']);
$total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount');
$cmp = bccomp($total, $paid, 5);
if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount
civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));
}

if (CRM_Utils_Array::value('line_item', $params) && !empty($trxn)) {
foreach ($params['line_item'] as $values) {
foreach ($values as $id => $amount) {
Expand Down
12 changes: 9 additions & 3 deletions tests/phpunit/CRM/Core/BAO/FinancialTrxnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,23 @@ public function testGetTotalPayments() {
}

/**
* Test getPartialPaymentTrxn function.
* Tests the lines of code that used to be in the getPartialPaymentTrxn fn.
*/
public function testGetPartialPaymentTrxn() {
public function testGetExPartialPaymentTrxn() {
$contributionTest = new CRM_Contribute_BAO_ContributionTest();
list($lineItems, $contribution) = $contributionTest->addParticipantWithContribution();
$contribution = (array) $contribution;
$params = array(
'contribution_id' => $contribution['id'],
'total_amount' => 100.00,
);
$trxn = CRM_Core_BAO_FinancialTrxn::getPartialPaymentTrxn($contribution, $params);
$trxn = CRM_Contribute_BAO_Contribution::recordPartialPayment($contribution, $params);
$paid = CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['contribution_id']);
$total = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $params['contribution_id'], 'total_amount');
$cmp = bccomp($total, $paid, 5);
if ($cmp == 0 || $cmp == -1) {// If paid amount is greater or equal to total amount
civicrm_api3('Contribution', 'completetransaction', array('id' => $contribution['id']));
}

$this->assertEquals('100.00', $trxn->total_amount, 'Amount does not match.');

Expand Down