--CRM-16259, added entity_table check in join, simplified code
authorPradeep Nayak <pradpnayak@gmail.com>
Sat, 13 Feb 2016 11:31:13 +0000 (17:01 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Wed, 17 Feb 2016 12:33:28 +0000 (18:03 +0530)
CRM/Contribute/BAO/Contribution.php
api/v3/Payment.php
tests/phpunit/api/v3/PaymentTest.php

index 0bd3e8d37fa74fe71f2bd193d462e2390876d45e..fab631fbaec21b1fbc1891cf674c6c8c7636e1d4 100644 (file)
@@ -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()) {
index 0884bb4d4f27050857d1f350e92ceff737001fce..4c63037a9d94609f7158110c05784067138ba18f 100644 (file)
@@ -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'),
index 70ce0b5306c1b4301fa688bad8359d8691ae7c9c..54964756ff685751853ec08df293539fa8769efe 100644 (file)
@@ -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();