CRM-16189, added function to validate financial account
authorPradeep Nayak <pradpnayak@gmail.com>
Wed, 15 Jun 2016 14:43:36 +0000 (20:13 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Fri, 24 Jun 2016 14:32:55 +0000 (20:02 +0530)
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

Conflicts:

CRM/Financial/BAO/FinancialAccount.php

CRM/Financial/BAO/FinancialAccount.php

index 64aa86879b55b43d4eb1bc2817869fc13d4117c1..0240999414962ece33d7fca217f101231f167882 100644 (file)
@@ -302,4 +302,33 @@ WHERE ce.entity_table = 'civicrm_financial_type' AND ce.account_relationship = %
     return $deferredFinancialType;
   }
 
+  /**
+   * check if financial account is referenced by financial item
+   *
+   * @param $financialAccountId Integer
+   *
+  * @param $financialAccountTypeID Integer
+  *
+   * @return bool
+  *
+  */
+ public static function validateFinancialAccount($financialAccountId, $financialAccountTypeID = NULL) {
+   if (!$financialAccountId) {
+      return FALSE;
+   }
+    $sql = "SELECT f.financial_account_type_id FROM civicrm_financial_account f
+NNER JOIN civicrm_financial_item fi ON fi.financial_account_id = f.id
+INNER JOIN civicrm_option_value cv ON cv.value = f.financial_account_type_id AND cv.name IN ('Revenue', 'Liability')
+INNER JOIN civicrm_option_group cg ON cg.id = cv.option_group_id
+AND  cg.name = 'financial_account_type'
+WHERE f.id = %1
+LIMIT 1";
+    $params = array(1 => array($financialAccountId, 'Integer'));
+    $result = CRM_Core_DAO::singleValueQuery($sql, $params);
+   if ($result && $result != $financialAccountTypeID) {
+      return TRUE;
+    }
+    return FALSE;
+  }
+
 }