From: Pradeep Nayak Date: Sat, 13 Feb 2016 11:31:13 +0000 (+0530) Subject: --CRM-16259, added entity_table check in join, simplified code X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fa7a1ebd4abc8accc992c111a6dc78117c7e7ef4;p=civicrm-core.git --CRM-16259, added entity_table check in join, simplified code --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 0bd3e8d37f..fab631fbae 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -4831,7 +4831,7 @@ LIMIT 1;"; // get financial item $sql = "SELECT fi.id, li.price_field_value_id FROM civicrm_financial_item fi - INNER JOIN civicrm_line_item li ON li.id = fi.entity_id + INNER JOIN civicrm_line_item li ON li.id = fi.entity_id and fi.entity_table = 'civicrm_line_item' WHERE li.contribution_id = %1"; $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($params['contribution_id'], 'Integer'))); while ($dao->fetch()) { diff --git a/api/v3/Payment.php b/api/v3/Payment.php index 0884bb4d4f..4c63037a9d 100644 --- a/api/v3/Payment.php +++ b/api/v3/Payment.php @@ -134,16 +134,16 @@ function civicrm_api3_payment_create(&$params) { } // Get contribution $contribution = civicrm_api3('Contribution', 'getsingle', array('id' => $params['contribution_id'])); - $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - if ($contributionStatus[$contribution['contribution_status_id']] != 'Partially paid' - && !($contributionStatus[$contribution['contribution_status_id']] == 'Pending' && $contribution['is_pay_later'] == TRUE) + $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus($contribution['contribution_status_id'], 'name'); + if ($contributionStatus != 'Partially paid' + && !($contributionStatus == 'Pending' && $contribution['is_pay_later'] == TRUE) ) { throw new API_Exception('Please select a contribution which has a partial or pending payment'); } else { // Check if pending contribution $fullyPaidPayLater = FALSE; - if ($contributionStatus[$contribution['contribution_status_id']] == 'Pending') { + if ($contributionStatus == 'Pending') { $cmp = bccomp($contribution['total_amount'], $params['total_amount'], 5); // Total payment amount is the whole amount paid against pending contribution if ($cmp == 0 || $cmp == -1) { @@ -158,7 +158,7 @@ function civicrm_api3_payment_create(&$params) { civicrm_api3('Contribution', 'create', array( 'id' => $contribution['id'], - 'contribution_status_id' => array_search('Partially paid', $contributionStatus), + 'contribution_status_id' => 'Partially paid', ) ); } @@ -176,7 +176,7 @@ function civicrm_api3_payment_create(&$params) { // get financial item $sql = "SELECT fi.id FROM civicrm_financial_item fi - INNER JOIN civicrm_line_item li ON li.id = fi.entity_id + INNER JOIN civicrm_line_item li ON li.id = fi.entity_id and fi.entity_table = 'civicrm_line_item' WHERE li.contribution_id = %1 AND li.id = %2"; $sqlParams = array( 1 => array($params['contribution_id'], 'Integer'), diff --git a/tests/phpunit/api/v3/PaymentTest.php b/tests/phpunit/api/v3/PaymentTest.php index 70ce0b5306..54964756ff 100644 --- a/tests/phpunit/api/v3/PaymentTest.php +++ b/tests/phpunit/api/v3/PaymentTest.php @@ -495,7 +495,7 @@ class api_v3_PaymentTest extends CiviUnitTestCase { } /** - * Test create payment api for paylater contribution with partial payment + * Test create payment api for paylater contribution with partial payment. */ public function testCreatePaymentPayLaterPartialPayment() { $this->createLoggedInUser();