Merge pull request #5214 from jitendrapurohit/CRM-15934changes
[civicrm-core.git] / CRM / Contribute / BAO / Contribution.php
index 97d53a1dbeba1181620fa8210178e569fae5757f..76accef4136f25088da787ae89edc6c19076738e 100644 (file)
@@ -65,7 +65,16 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   public $_component = NULL;
 
   /**
-   * Class constructor
+   * Possibly obsolete variable.
+   *
+   * If you use it please explain why it is set in the create function here.
+   *
+   * @var string
+   */
+  public $trxn_result_code;
+
+  /**
+   * Class constructor.
    *
    * @return \CRM_Contribute_DAO_Contribution
    */
@@ -76,7 +85,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * Takes an associative array and creates a contribution object
+   * Takes an associative array and creates a contribution object.
    *
    * the function extract all the params it needs to initialize the create a
    * contribution object. the params array could contain additional unused name/value
@@ -196,7 +205,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * Get defaults for new entity
+   * Get defaults for new entity.
    * @return array
    */
   public static function getDefaults() {
@@ -241,9 +250,13 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * @param array $params
+   * Calculate net_amount & fee_amount if they are not set.
    *
-   * @return mixed
+   * Net amount should be total - fee.
+   * This should only be called for new contributions.
+   *
+   * @param array $params
+   *   Params for a new contribution before they are saved.
    */
   public static function calculateMissingAmountParams(&$params) {
     if (!isset($params['fee_amount'])) {
@@ -283,7 +296,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * Takes an associative array and creates a contribution object
+   * Takes an associative array and creates a contribution object.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
@@ -493,12 +506,18 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * convert associative array names to values
-   * and vice-versa.
+   * Convert associative array names to values and vice-versa.
    *
    * This function is used by both the web form layer and the api. Note that
    * the api needs the name => value conversion, also the view layer typically
    * requires value => name conversion
+   *
+   * @param array $defaults
+   * @param string $property
+   * @param array $lookup
+   * @param bool $reverse
+   *
+   * @return bool
    */
   public static function lookupValue(&$defaults, $property, &$lookup, $reverse) {
     $id = $property . '_id';
@@ -522,10 +541,9 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects. We'll tweak this function to be more
-   * full featured over a period of time. This is the inverse function of
-   * create.  It also stores all the retrieved values in the default array
+   * Retrieve DB object based on input parameters.
+   *
+   * It also stores all the retrieved values in the default array.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
@@ -543,7 +561,7 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution {
   }
 
   /**
-   * Combine all the importable fields from the lower levels object
+   * Combine all the importable fields from the lower levels object.
    *
    * The ordering is important, since currently we do not have a weight
    * scheme. Adding weight is super important and should be done in the
@@ -768,7 +786,7 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = civicrm_contribution.conta
   }
 
   /**
-   * Delete the indirect records associated with this contribution first
+   * Delete the indirect records associated with this contribution first.
    *
    * @param int $id
    *
@@ -840,7 +858,7 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = civicrm_contribution.conta
   }
 
   /**
-   * Check if there is a contribution with the same trxn_id or invoice_id
+   * Check if there is a contribution with the same trxn_id or invoice_id.
    *
    * @param array $input
    *   An assoc array of name/value pairs.
@@ -892,7 +910,7 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = civicrm_contribution.conta
   }
 
   /**
-   * Takes an associative array and creates a contribution_product object
+   * Takes an associative array and creates a contribution_product object.
    *
    * the function extract all the params it needs to initialize the create a
    * contribution_product object. the params array could contain additional unused name/value
@@ -910,7 +928,7 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = civicrm_contribution.conta
   }
 
   /**
-   * Get list of contribution fields for profile
+   * Get list of contribution fields for profile.
    * For now we only allow custom contribution fields to be in
    * profile
    *
@@ -945,8 +963,7 @@ INNER JOIN  civicrm_contact contact ON ( contact.id = civicrm_contribution.conta
   }
 
   /**
-   * Add extra fields specific to contribtion
-   *
+   * Add extra fields specific to contribution.
    */
   public static function getSpecialContributionFields() {
     $extraFields = array(
@@ -1008,7 +1025,7 @@ GROUP BY p.id
   }
 
   /**
-   * Get list of contribution In Honor of contact Ids
+   * Get list of contribution In Honor of contact Ids.
    *
    * @param int $honorId
    *   In Honor of Contact ID.
@@ -1046,7 +1063,7 @@ GROUP BY p.id
   }
 
   /**
-   * Get the sort name of a contact for a particular contribution
+   * Get the sort name of a contact for a particular contribution.
    *
    * @param int $id
    *   Id of the contribution.
@@ -1176,7 +1193,7 @@ WHERE  civicrm_contribution.contact_id = civicrm_contact.id
   }
 
   /**
-   * Get the contribution details for component export
+   * Get the contribution details for component export.
    *
    * @param int $exportMode
    *   Export mode.
@@ -1278,7 +1295,7 @@ LEFT JOIN civicrm_option_value contribution_status ON (civicrm_contribution.cont
   }
 
   /**
-   * Delete billing address record related contribution
+   * Delete billing address record related contribution.
    *
    * @param int $contributionId
    * @param int $contactId
@@ -1383,6 +1400,12 @@ LEFT JOIN  civicrm_contribution contribution ON ( componentPayment.contribution_
 
   /**
    * Update contribution as well as related objects.
+   *
+   * @param array $params
+   * @param bool $processContributionObject
+   *
+   * @return array
+   * @throws \Exception
    */
   public static function transitionComponents($params, $processContributionObject = FALSE) {
     // get minimum required values.
@@ -1753,6 +1776,7 @@ LEFT JOIN  civicrm_contribution contribution ON ( componentPayment.contribution_
     $query = "
       SELECT    c.id                 as contribution_id,
                 c.contact_id         as contact_id,
+                c.contribution_recur_id,
                 mp.membership_id     as membership_id,
                 m.membership_type_id as membership_type_id,
                 pp.participant_id    as participant_id,
@@ -1788,6 +1812,9 @@ LEFT JOIN  civicrm_contribution contribution ON ( componentPayment.contribution_
       if ($dao->pledge_payment_id) {
         $pledgePayment[] = $dao->pledge_payment_id;
       }
+      if ($dao->contribution_recur_id) {
+        $componentDetails['contributionRecur'] = $dao->contribution_recur_id;
+      }
     }
 
     if ($pledgePayment) {
@@ -1832,7 +1859,7 @@ LEFT JOIN  civicrm_contribution contribution ON ( componentPayment.contribution_
   }
 
   /**
-   * Get individual id for onbehalf contribution
+   * Get individual id for onbehalf contribution.
    *
    * @param int $contributionId
    *   Contribution id.
@@ -1940,7 +1967,7 @@ INNER JOIN civicrm_activity ON civicrm_activity_contact.activity_id = civicrm_ac
   }
 
   /**
-   * Load objects relations to contribution object
+   * Load objects relations to contribution object.
    * Objects are stored in the $_relatedObjects property
    * In the first instance we are just moving functionality from BASEIpn -
    * @see http://issues.civicrm.org/jira/browse/CRM-9996
@@ -2602,7 +2629,7 @@ WHERE  contribution_id = %1 ";
   }
 
   /**
-   * Check whether subscription is already cancelled
+   * Check whether subscription is already cancelled.
    *
    * @param int $contributionId
    *   Contribution id.
@@ -2626,7 +2653,7 @@ WHERE  contribution_id = %1 ";
   }
 
   /**
-   * Create all financial accounts entry
+   * Create all financial accounts entry.
    *
    * @param array $params
    *   Contribution object, line item array and params for trxn.
@@ -2820,6 +2847,7 @@ WHERE  contribution_id = %1 ";
 
         //Update contribution status
         $params['trxnParams']['status_id'] = $params['contribution']->contribution_status_id;
+        $params['trxnParams']['trxn_id'] = $params['contribution']->trxn_id;
         if (!empty($params['contribution_status_id']) &&
           $params['prevContribution']->contribution_status_id != $params['contribution']->contribution_status_id
         ) {
@@ -2925,7 +2953,7 @@ WHERE  contribution_id = %1 ";
   }
 
   /**
-   * Update all financial accounts entry
+   * Update all financial accounts entry.
    *
    * @param array $params
    *   Contribution object, line item array and params for trxn.
@@ -3097,7 +3125,7 @@ WHERE  contribution_id = %1 ";
   }
 
   /**
-   * Check status validation on update of a contribution
+   * Check status validation on update of a contribution.
    *
    * @param array $values
    *   Previous form values before submit.
@@ -3135,7 +3163,7 @@ WHERE  contribution_id = %1 ";
   }
 
   /**
-   * Delete contribution of contact
+   * Delete contribution of contact.
    *
    * CRM-12155
    *
@@ -3191,7 +3219,7 @@ WHERE  contribution_id = %1 ";
   }
 
   /**
-   * Validate financial type
+   * Validate financial type.
    *
    * CRM-13231
    *
@@ -3214,7 +3242,7 @@ WHERE  contribution_id = %1 ";
 
 
   /**
-   * Function to record additional payment for partial and refund contributions
+   * Function to record additional payment for partial and refund contributions.
    *
    * @param int $contributionId
    *   is the invoice contribution id (got created after processing participant payment).
@@ -3432,7 +3460,7 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']})
   }
 
   /**
-   * Get list of payments displayed by Contribute_Page_PaymentInfo
+   * Get list of payments displayed by Contribute_Page_PaymentInfo.
    *
    * @param int $id
    * @param $component