CRM-12463
authoryashodha <yashodha.chaku@webaccess.co.in>
Wed, 1 May 2013 22:32:27 +0000 (04:02 +0530)
committeryashodha <yashodha.chaku@webaccess.co.in>
Wed, 1 May 2013 22:32:27 +0000 (04:02 +0530)
CRM/Contribute/BAO/Contribution.php

index f66809ef8897a55c5a0acfcf6a23f25b793cd426..e92fe3a1ad52d0e096cbf67f3019842f95cf5cf0 100644 (file)
@@ -115,6 +115,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
       'fee_amount',
       'non_deductible_amount',
     );
+
     //if priceset is used, no need to cleanup money
     if (CRM_Utils_Array::value('skipCleanMoney', $params)) {
       unset($moneyFields[0]);
@@ -158,13 +159,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
     if (CRM_Utils_Array::value('contribution', $ids)) {
       $contributionId['id'] = $ids['contribution'];
       $params['prevContribution'] = self::getValues($contributionId, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
-      /*if (CRM_Utils_Array::value('soft_credit_to', $params)) {
-        foreach (array('financial_type_id', 'total_amount') as $field) {
-          if (!isset($contribution->$field)) {
-            $contribution->$field = $params['prevContribution']->$field;
-          }
-        }
-      }*/
     }
 
     $result = $contribution->save();
@@ -177,9 +171,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
     $params['contribution'] = $contribution;
     self::recordFinancialAccounts($params, $ids);
 
-    // Add soft_contribution details as part of fix for CRM-8908
-    //$contribution->soft_credit_to = CRM_Utils_Array::value('soft_credit_to', $params);
-
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
 
@@ -241,56 +232,10 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
       }
     }
 
-    /*if (CRM_Utils_Array::value('contribution', $ids) &&
-      !CRM_Utils_Array::value('softID', $params)
-    ) {
-      if ($softID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionSoft', $ids['contribution'], 'id', 'contribution_id')) {
-        $params['softID'] = $softID;
-      }
-      }*/
-
     $transaction = new CRM_Core_Transaction();
 
-    // delete the soft credit record if no soft credit contact ID AND no PCP is set in the form
-    /*if (CRM_Utils_Array::value('contribution', $ids) &&
-      (!CRM_Utils_Array::value('soft_credit_to', $params) &&
-        !CRM_Utils_Array::value('pcp_made_through_id', $params)
-      ) &&
-      CRM_Utils_Array::value('softID', $params)
-    ) {
-      $softCredit = new CRM_Contribute_DAO_ContributionSoft();
-      $softCredit->id = $params['softID'];
-      $softCredit->delete();
-      }*/
-
     $contribution = self::add($params, $ids);
 
-    /*    if (CRM_Utils_Array::value('deleteSoftCredit', $params, TRUE)) {
-      // first delete soft credits if any
-      CRM_Contribute_BAO_ContributionSoft::del($contribution->id);
-
-      if ($pcp = CRM_Utils_Array::value('pcp_made_through_id', $params)) {
-        $softParams = array();  
-        $softParams['contribution_id'] = $contribution->id;
-        $softParams['pcp_id'] = $pcp['pcp_made_through_id'];
-        $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
-           $pcp['pcp_id'], 'contact_id'
-        );
-        $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
-        $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
-        $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
-        CRM_Contribute_BAO_ContributionSoft::add($softParams);
-      }
-      elseif (CRM_Utils_Array::value('soft_credit', $params)) {
-        $softParams = $params['soft_credit'];  
-        foreach ($softParams as $softParam) {
-          $softParam['contribution_id'] = $contribution->id;
-          $softParam['currency'] = $contribution->currency;
-          CRM_Contribute_BAO_ContributionSoft::add($softParam);
-        } 
-      } 
-    }
-    */
     if (is_a($contribution, 'CRM_Core_Error')) {
       $transaction->rollback();
       return $contribution;
@@ -307,7 +252,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
     $session = CRM_Core_Session::singleton();
 
     if (CRM_Utils_Array::value('note', $params)) {
-
       $noteParams = array(
         'entity_table' => 'civicrm_contribution',
         'note' => $params['note'],
@@ -360,63 +304,29 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
         // first delete soft credits if any                                                                                                                                                            
         CRM_Contribute_BAO_ContributionSoft::del($contribution->id);
 
-        if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
-            $softParams = array();
-            $softParams['contribution_id'] = $contribution->id;
-            $softParams['pcp_id'] = $pcp['pcp_made_through_id'];
-            $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
-              $pcp['pcp_made_through_id'], 'contact_id'
-            );
-            $softParams['currency'] = $contribution->currency;
-            $softParams['amount'] = $contribution->total_amount;
-            $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
-            $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
-            $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
-            CRM_Contribute_BAO_ContributionSoft::add($softParams);
-        }
-        elseif (CRM_Utils_Array::value('soft_credit', $params)) {
-          $softParams = $params['soft_credit'];
-          foreach ($softParams as $softParam) {
-            $softParam['contribution_id'] = $contribution->id;
-            $softParam['currency'] = $contribution->currency;
-            CRM_Contribute_BAO_ContributionSoft::add($softParam);
-          }
-        }
-    }
-    /*    if (CRM_Utils_Array::value('soft_credit_to', $params) ||
-      CRM_Utils_Array::value('pcp_made_through_id', $params)
-    ) {
-      $csParams = array();
-      if ($id = CRM_Utils_Array::value('softID', $params)) {
-        $csParams['id'] = $params['softID'];
-      }
-
-      $csParams['contribution_id'] = $contribution->id;
-      // If pcp_made_through_id set, we define soft_credit_to contact based on selected PCP,
-      // else use passed soft_credit_to
-      if (CRM_Utils_Array::value('pcp_made_through_id', $params)) {
-        $csParams['pcp_display_in_roll'] = $params['pcp_display_in_roll'] ? 1 : 0;
-        foreach (array(
-          'pcp_roll_nickname', 'pcp_personal_note') as $val) {
-          $csParams[$val] = $params[$val];
-        }
-
-        $csParams['pcp_id'] = CRM_Utils_Array::value('pcp_made_through_id', $params);
-        $csParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
-          $csParams['pcp_id'], 'contact_id'
+      if ($pcp = CRM_Utils_Array::value('pcp', $params)) {
+        $softParams = array();
+        $softParams['contribution_id'] = $contribution->id;
+        $softParams['pcp_id'] = $pcp['pcp_made_through_id'];
+        $softParams['contact_id'] = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP',
+          $pcp['pcp_made_through_id'], 'contact_id'
         );
+        $softParams['currency'] = $contribution->currency;
+        $softParams['amount'] = $contribution->total_amount;
+        $softParams['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcp);
+        $softParams['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcp);
+        $softParams['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcp);
+        CRM_Contribute_BAO_ContributionSoft::add($softParams);
       }
-      else {
-        $csParams['contact_id'] = $params['soft_credit_to'];
-        $csParams['pcp_id'] = '';
+      elseif (CRM_Utils_Array::value('soft_credit', $params)) {
+        $softParams = $params['soft_credit'];
+        foreach ($softParams as $softParam) {
+          $softParam['contribution_id'] = $contribution->id;
+          $softParam['currency'] = $contribution->currency;
+          CRM_Contribute_BAO_ContributionSoft::add($softParam);
+        }
       }
-
-      // first stage: we register whole amount as credited to given person
-      $csParams['amount'] = $contribution->total_amount;
-
-      self::addSoftContribution($csParams);
     }
-    */
     $transaction->commit();
 
     // do not add to recent items for import, CRM-4399