Merge pull request #5086 from deepak-srivastava/CRM-15490
[civicrm-core.git] / CRM / Price / BAO / LineItem.php
index e62eacbdfde11f2a4f1bd57796b3de01b96b2d85..f056ed78a7e38bbab2d907fd71e78cfb52b28c50 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -51,8 +51,7 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem {
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
    *
-   * @return CRM_Price_DAO_LineItem object
-   * @static
+   * @return CRM_Price_DAO_LineItem
    */
   public static function create(&$params) {
     $id = CRM_Utils_Array::value('id', $params);
@@ -85,18 +84,16 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem {
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects.  Typically, the valid params are only
-   * price_field_id.  This is the inverse function of create.  It also
-   * stores all of 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.
    * @param array $defaults
    *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Price_BAO_LineItem object
-   * @static
+   * @return CRM_Price_BAO_LineItem
    */
   public static function retrieve(&$params, &$defaults) {
     $lineItem = new CRM_Price_BAO_LineItem();
@@ -125,7 +122,7 @@ AND li.entity_id = {$entityId}
   }
 
   /**
-   * Wrapper for line item retrieval when contribution ID is known
+   * Wrapper for line item retrieval when contribution ID is known.
    * @param int $contributionID
    *
    * @return array
@@ -138,10 +135,10 @@ AND li.entity_id = {$entityId}
    * Given a participant id/contribution id,
    * return contribution/fee line items
    *
-   * @param $entityId
-   *   Int participant/contribution id.
-   * @param $entity
-   *   String participant/contribution.
+   * @param int $entityId
+   *   participant/contribution id.
+   * @param string $entity
+   *   participant/contribution.
    *
    * @param null $isQuick
    * @param bool $isQtyZero
@@ -149,10 +146,11 @@ AND li.entity_id = {$entityId}
    *
    * @param string $overrideWhereClause
    *   E.g "WHERE contribution id = 7 " per the getLineItemsByContributionID wrapper.
-   * this function precedes the convenience of the contribution id but since it does quite a bit more than just a db retrieval we need to be able to use it even
-   * when we don't want it's entity-id magix
+   *   this function precedes the convenience of the contribution id but since it does quite a bit more than just a db retrieval we need to be able to use it even
+   *   when we don't want it's entity-id magix
    *
-   * @return array of line items
+   * @return array
+   *   Array of line items
    */
   public static function getLineItems($entityId, $entity = 'participant', $isQuick = NULL, $isQtyZero = TRUE, $relatedEntity = FALSE, $overrideWhereClause = '') {
     $whereClause = $fromClause = NULL;
@@ -272,7 +270,7 @@ AND li.entity_id = {$entityId}
    *                          to the price set used for particular event
    * @param array $values
    *   Reference to the values array(.
-  this is
+   *   this is
    *                          lineItem array)
    *
    * @return void
@@ -339,7 +337,6 @@ AND li.entity_id = {$entityId}
    * @param int $entityTable
    *
    * @return bool
-   * @static
    */
   public static function deleteLineItems($entityId, $entityTable) {
     if (!$entityId || !$entityTable) {
@@ -368,7 +365,6 @@ AND li.entity_id = {$entityId}
    * @param bool $update
    *
    * @return void
-   * @static
    */
   public static function processPriceSet($entityId, $lineItem, $contributionDetails = NULL, $entityTable = 'civicrm_contribution', $update = FALSE) {
     if (!$entityId || !is_array($lineItem)
@@ -480,7 +476,6 @@ AND li.entity_id = {$entityId}
    *   Entity Table.
    *
    * @return void
-   * @static
    */
   public static function getLineItemArray(&$params, $entityId = NULL, $entityTable = 'contribution', $isRelatedID = FALSE) {
 
@@ -506,7 +501,7 @@ AND li.entity_id = {$entityId}
           'unit_price' => $totalAmount,
           'line_total' => $totalAmount,
           'financial_type_id' => $financialType,
-          'membership_type_id' => $values['membership_type_id']
+          'membership_type_id' => $values['membership_type_id'],
         );
         break;
       }
@@ -522,7 +517,8 @@ AND li.entity_id = {$entityId}
             $params['is_quick_config'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $setID, 'is_quick_config');
           }
           if (!empty($params['is_quick_config']) && array_key_exists('total_amount', $params)
-            && $totalEntityId == 1) {
+            && $totalEntityId == 1
+          ) {
             $values['line_total'] = $values['unit_price'] = $params['total_amount'];
           }
           $values['id'] = $key;
@@ -533,18 +529,17 @@ AND li.entity_id = {$entityId}
   }
 
   /**
-   * Calculate tax rate in percentage
+   * Calculate tax rate in percentage.
    *
-   * @param $lineItemId
+   * @param array $lineItemId
    *   An assoc array of lineItem.
    *
-   * @return tax rate
-   *
-   * @static
+   * @return int|void
+   *   tax rate
    */
   public static function calculateTaxRate($lineItemId) {
     if ($lineItemId['unit_price'] == 0) {
-      return;
+      return FALSE;
     }
     if ($lineItemId['html_type'] == 'Text') {
       $tax = $lineItemId['tax_amount'] / ($lineItemId['unit_price'] * $lineItemId['qty']) * 100;
@@ -554,4 +549,5 @@ AND li.entity_id = {$entityId}
     }
     return $tax;
   }
+
 }