Merge pull request #4997 from monishdeb/CRM-15536
[civicrm-core.git] / CRM / Core / BAO / FinancialTrxn.php
index 2a8e0a3dd68bacae27c43a44b91a34515ccc6486..869a633c5d1abef50233a969be34853660ac4990 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        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -32,7 +32,6 @@
  * $Id$
  *
  */
-
 class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
   /**
    * Class constructor
@@ -40,7 +39,6 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
    * @return \CRM_Financial_DAO_FinancialTrxn
    */
   /**
-   *
    */
   public function __construct() {
     parent::__construct();
@@ -55,8 +53,7 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
    * @param string $trxnEntityTable
    *   Entity_table.
    *
-   * @return CRM_Core_BAO_FinancialTrxn object
-   * @static
+   * @return CRM_Core_BAO_FinancialTrxn
    */
   public static function create(&$params, $trxnEntityTable = NULL) {
     $trxn = new CRM_Financial_DAO_FinancialTrxn();
@@ -70,8 +67,8 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
     $trxn->save();
 
     // save to entity_financial_trxn table
-    $entityFinancialTrxnParams =
-      array(
+    $entityFinancialTrxnParams
+      array(
         'entity_table' => "civicrm_contribution",
         'financial_trxn_id' => $trxn->id,
         'amount' => $params['total_amount'],
@@ -80,10 +77,10 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
 
     if (!empty($trxnEntityTable)) {
       $entityFinancialTrxnParams['entity_table'] = $trxnEntityTable['entity_table'];
-      $entityFinancialTrxnParams['entity_id']    = $trxnEntityTable['entity_id'];
+      $entityFinancialTrxnParams['entity_id'] = $trxnEntityTable['entity_id'];
     }
     else {
-      $entityFinancialTrxnParams['entity_id'] =  $params['contribution_id'];
+      $entityFinancialTrxnParams['entity_id'] = $params['contribution_id'];
     }
 
     $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
@@ -127,8 +124,7 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
    * @param array $defaults
    *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Contribute_BAO_ContributionType object
-   * @static
+   * @return CRM_Contribute_BAO_ContributionType
    */
   public static function retrieve(&$params, &$defaults) {
     $financialItem = new CRM_Financial_DAO_FinancialTrxn();
@@ -150,9 +146,9 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn {
    *   To get single trxn id for a entity table i.e last or first.
    * @param bool $newTrxn
    *
-   * @return array $tag array of category id's the contact belongs to.
+   * @return array
+   *   array of category id's the contact belongs to.
    *
-   * @static
    */
   public static function getFinancialTrxnId($entity_id, $orderBy = 'ASC', $newTrxn = FALSE) {
     $ids = array('entityFinancialTrxnId' => NULL, 'financialTrxnId' => NULL);
@@ -193,9 +189,9 @@ LIMIT 1;";
    * @param int $entity_id
    *   Id of the entity usually the contactID.
    *
-   * @return array $tag array of catagory id's the contact belongs to.
+   * @return array
+   *   array of catagory id's the contact belongs to.
    *
-   * @static
    */
   public static function getFinancialTrxnTotal($entity_id) {
     $query = "
@@ -216,9 +212,9 @@ WHERE ft.entity_table = 'civicrm_contribution' AND ft.entity_id = %1
    *   Id of the latest payment.
    *
    *
-   * @return array $payment array of previous payments
+   * @return array
+   *   array of previous payments
    *
-   * @static
    */
   public static function getPayments($financial_trxn_id) {
     $query = "
@@ -269,9 +265,9 @@ WHERE  ef2.financial_trxn_id =%1
    * @param string $entity_table
    *   Name of the entity table usually 'civicrm_contact'.
    *
-   * @return array $tag array of catagory id's the contact belongs to.
+   * @return array
+   *   array of catagory id's the contact belongs to.
    *
-   * @static
    */
   public static function getFinancialTrxnLineTotal($entity_id, $entity_table = 'civicrm_contribution') {
     $query = "SELECT lt.price_field_value_id AS id, ft.financial_trxn_id,ft.amount AS amount FROM civicrm_entity_financial_trxn AS ft
@@ -280,7 +276,7 @@ LEFT JOIN civicrm_line_item AS lt ON lt.id = fi.entity_id AND lt.entity_table =
 WHERE lt.entity_id = %1 ";
 
     $sqlParams = array(1 => array($entity_id, 'Integer'), 2 => array($entity_table, 'String'));
-    $dao =  CRM_Core_DAO::executeQuery($query, $sqlParams);
+    $dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
     while ($dao->fetch()) {
       $result[$dao->financial_trxn_id][$dao->id] = $dao->amount;
     }
@@ -298,7 +294,6 @@ WHERE lt.entity_id = %1 ";
    * @param int $entity_id
    * @return bool
    *   TRUE on success, FALSE otherwise.
-   * @static
    */
   public static function deleteFinancialTrxn($entity_id) {
     $query = "DELETE ceft1, cfi, ceft, cft FROM `civicrm_financial_trxn` cft
@@ -316,7 +311,6 @@ WHERE ceft.entity_id = %1";
   /**
    * Create financial transaction for premium
    *
-   * @static
    */
   public static function createPremiumTrxn($params) {
     if ((empty($params['financial_type_id']) || empty($params['contributionId'])) && empty($params['oldPremium'])) {
@@ -366,7 +360,6 @@ WHERE ceft.entity_id = %1";
    * @param array $params
    *   To create trxn entries.
    *
-   * @static
    */
   public static function recordFees($params) {
     $expenseTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' "));
@@ -391,24 +384,23 @@ WHERE ceft.entity_id = %1";
     $params['trxnParams']['from_financial_account_id'] = $params['to_financial_account_id'];
     $params['trxnParams']['to_financial_account_id'] = $financialAccount;
     $params['trxnParams']['total_amount'] = $amount;
-    $params['trxnParams']['fee_amount'] =
-      $params['trxnParams']['net_amount'] = 0;
-    $params['trxnParams']['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status','Completed','name');
+    $params['trxnParams']['fee_amount'] = $params['trxnParams']['net_amount'] = 0;
+    $params['trxnParams']['status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
     $params['trxnParams']['contribution_id'] = $contributionId;
     $trxn = self::create($params['trxnParams']);
     if (empty($params['entity_id'])) {
       $financialTrxnID = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['trxnParams']['contribution_id'], 'DESC');
       $params['entity_id'] = $financialTrxnID['financialTrxnId'];
     }
-    $fItemParams =
-      array(
+    $fItemParams
+      array(
         'financial_account_id' => $financialAccount,
         'contact_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', $domainId, 'contact_id'),
         'created_date' => date('YmdHis'),
         'transaction_date' => date('YmdHis'),
         'amount' => $amount,
         'description' => 'Fee',
-        'status_id' => CRM_Core_OptionGroup::getValue('financial_item_status','Paid','name'),
+        'status_id' => CRM_Core_OptionGroup::getValue('financial_item_status', 'Paid', 'name'),
         'entity_table' => 'civicrm_financial_trxn',
         'entity_id' => $params['entity_id'],
         'currency' => $params['trxnParams']['currency'],
@@ -417,18 +409,17 @@ WHERE ceft.entity_id = %1";
     $financialItem = CRM_Financial_BAO_FinancialItem::create($fItemParams, NULL, $trxnIDS);
   }
 
-  /*
-   * get partial payment amount and type of it
-   * return @array : payment type => amount
-   * payment type  : 'amount_owed' or 'refund_due'
-   */
   /**
+   * get partial payment amount and type of it
+   *
    * @param int $entityId
    * @param string $entityName
    * @param bool $returnType
-   * @param NULL $lineItemTotal
+   * @param int $lineItemTotal
    *
    * @return array|int|NULL|string
+   *   [payment type => amount]
+   *   payment type: 'amount_owed' or 'refund_due'
    */
   public static function getPartialPaymentWithType($entityId, $entityName = 'participant', $returnType = TRUE, $lineItemTotal = NULL) {
     $value = NULL;
@@ -479,7 +470,7 @@ WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFina
         if ($returnType) {
           $value = array();
           if ($paymentVal < 0) {
-            $value['refund_due']  = $paymentVal;
+            $value['refund_due'] = $paymentVal;
           }
           elseif ($paymentVal > 0) {
             $value['amount_owed'] = $paymentVal;
@@ -492,4 +483,5 @@ WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFina
     }
     return $value;
   }
+
 }