more work on CRM-12463
authorKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 04:46:08 +0000 (21:46 -0700)
committerKurund Jalmi <kurund@civicrm.org>
Thu, 2 May 2013 04:46:08 +0000 (21:46 -0700)
CRM/Contribute/Form/AbstractEditPayment.php
CRM/Contribute/Form/Contribution.php
CRM/Contribute/Form/SoftCredit.php

index 938e26acc1d0ded4b506a13964fc96a07f450b1f..78f6d64eb4324c2c3060c9026718d19989f5fdc1 100644 (file)
@@ -190,29 +190,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Core_Form {
       $values['note'] = $daoNote->note;
     }
     $this->_contributionType = $values['financial_type_id'];
-
-    $csParams = array('contribution_id' => $id);
-    $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE);
-
-    if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) {
-      $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
-        $softCredit['soft_credit_to'], 'sort_name'
-      );
-    }
-    $values['soft_credit_to'] = CRM_Utils_Array::value('sort_name', $softCredit);
-    $values['softID'] = CRM_Utils_Array::value('soft_credit_id', $softCredit);
-    $values['soft_contact_id'] = CRM_Utils_Array::value('soft_credit_to', $softCredit);
-
-    if (CRM_Utils_Array::value('pcp_id', $softCredit)) {
-      $pcpId = CRM_Utils_Array::value('pcp_id', $softCredit);
-      $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
-      $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute');
-      $values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $softCredit) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
-      $values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $softCredit);
-      $values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $softCredit);
-      $values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $softCredit);
-      $values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $softCredit);
-    }
   }
 
   /**
index 1701c4d3a2e47a7a63666be681b79de975971c6c..fb4eaecfc3eb4d3379ba3e0e5f921516acdd6916 100644 (file)
@@ -151,9 +151,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
    */
   public function preProcess() {
 
-    $resources = CRM_Core_Resources::singleton();
-    $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js');
-
     //check permission for action.
     if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
       CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
@@ -168,6 +165,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       return;
     }
 
+    $resources = CRM_Core_Resources::singleton();
+    $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js');
+
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
 
     // get price set id.
@@ -271,7 +271,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
       CRM_Utils_System::setTitle(ts('Contribution from') . ' ' . $displayName);
     }
-
   }
 
   function setDefaultValues() {
@@ -296,6 +295,9 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       return $defaults;
     }
 
+    // set soft credit defaults
+    CRM_Contribute_Form_SoftCredit::setDefaultValues($defaults);
+
     if ($this->_mode) {
       $config = CRM_Core_Config::singleton();
       // set default country from config if no country set
@@ -497,7 +499,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
       'invoice_id',
       'non_deductible_amount',
       'fee_amount',
-      'net_amount'
+      'net_amount',
     );
     foreach ($additionalDetailFields as $key) {
       if (!empty($defaults[$key])) {
index c4a82a64c90f3a34d554588920e975f9d3e4f8e6..a672e788c0d686349ec1f3af6f240a346b1ce148 100644 (file)
@@ -63,5 +63,34 @@ class CRM_Contribute_Form_SoftCredit {
     }
     $form->addElement('hidden', 'soft_contact_id', '', array('id' => 'soft_contact_id'));
   }
+
+  /**
+   * Function used to set defaults for soft credit block
+   */
+  static function setDefaultValues(&$defaults) {
+    $csParams = array('contribution_id' => $defaults['id']);
+    $softCredit = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($csParams, TRUE);
+
+    if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) {
+      $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
+        $softCredit['soft_credit_to'], 'sort_name'
+      );
+    }
+    $values['soft_credit_to'] = CRM_Utils_Array::value('sort_name', $softCredit);
+    $values['softID'] = CRM_Utils_Array::value('soft_credit_id', $softCredit);
+    $values['soft_contact_id'] = CRM_Utils_Array::value('soft_credit_to', $softCredit);
+
+    if (CRM_Utils_Array::value('pcp_id', $softCredit)) {
+      $pcpId = CRM_Utils_Array::value('pcp_id', $softCredit);
+      $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
+      $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute');
+      $values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $softCredit) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
+      $values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $softCredit);
+      $values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $softCredit);
+      $values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $softCredit);
+      $values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $softCredit);
+    }
+
+  }
 }