X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FFinancial%2FBAO%2FFinancialAccount.php;h=d439be5498a612b1e6062634b91f3cf45420a8d4;hb=928a340b95528a9c44dfd335d6d31b183d910763;hp=182865e66cfcf6b1dcae3800674408eea5b949fa;hpb=42e98b939314ad080e1eb8ae3d9ae749061c5b9d;p=civicrm-core.git diff --git a/CRM/Financial/BAO/FinancialAccount.php b/CRM/Financial/BAO/FinancialAccount.php index 182865e66c..c23542e997 100644 --- a/CRM/Financial/BAO/FinancialAccount.php +++ b/CRM/Financial/BAO/FinancialAccount.php @@ -1,9 +1,9 @@ CiviContribute > Financial Accounts, then configure it for financial types at Administer > CiviContribution > Financial Types, Accounts'); + $error = ts('Revenue Recognition Date cannot be processed unless there is a Deferred Revenue account setup for the Financial Type. Please remove Revenue Recognition Date, select a different Financial Type with a Deferred Revenue account setup for it, or setup a Deferred Revenue account for this Financial Type.'); throw new CRM_Core_Exception($error); } return $isError; } - /** - * Check if financial type has Deferred Revenue Account is relationship - * with Financial Account. - * - * @param int $financialTypeId - * Financial Type Id. - * - * @param int $entityID - * Holds id for PriceSet/PriceField/PriceFieldValue. - * - * @param string $entity - * Entity like PriceSet/PriceField/PriceFieldValue. - * - * @return bool - * - */ - public static function validateFinancialType($financialTypeId, $entityID = NULL, $entity = NULL) { - if (!CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) { - return FALSE; - } - if ($entityID) { - $query = ' SELECT ps.extends FROM civicrm_price_set ps'; - $params = array( - 1 => array('ps', 'Text'), - 2 => array($entityID, 'Integer'), - ); - if ($entity == 'PriceField') { - $params[1] = array('pf', 'Text'); - $query .= ' INNER JOIN civicrm_price_field pf ON pf.price_set_id = ps.id '; - } - $query .= ' WHERE %1.id = %2'; - $extends = CRM_Core_DAO::singleValueQuery($query, $params); - $extends = explode('', $extends); - if (!(in_array(CRM_Core_Component::getComponentID('CiviEvent'), $extends) - || in_array(CRM_Core_Component::getComponentID('CiviMember'), $extends)) - ) { - return FALSE; - } - } - $deferredFinancialType = self::getDeferredFinancialType(); - if (!array_key_exists($financialTypeId, $deferredFinancialType)) { - throw new CRM_Core_Exception(ts('Deferred revenue account is not configured for selected financial type. Please have an administrator set up the deferred revenue account at Administer > CiviContribute > Financial Accounts, then configure it for financial types at Administer > CiviContribution > Financial Types, Accounts')); - } - return FALSE; - } - - /** - * Validate if Deferred Account is set for Financial Type - * when Deferred Revenue is enabled - * - * @return string - * - */ - public static function validateTogglingDeferredRevenue() { - $deferredFinancialType = self::getDeferredFinancialType(); - $message = ts('Before Deferred Revenue can be enabled, a Deferred Revenue Account relationship must be defined for all financial types currently used for Memberships and Events, including - -In other words, please create deferred revenue accounts at Administer > CiviContribute > Financial Accounts, then configure them for the following financial types at Administer > CiviContribute > Financial Types, accounts:'); - $tables = array( - 'civicrm_membership_type', - 'civicrm_event', - 'civicrm_price_set', - 'civicrm_price_field_value', - ); - $params[2] = array('', 'Text'); - if (!empty($deferredFinancialType)) { - $params[2] = array(' AND financial_type_id NOT IN (' . implode(',', array_keys($deferredFinancialType)) . ') ', 'Text'); - } - $query_1 = 'SELECT %5.id FROM %4 WHERE %5.is_active = 1'; - $query_2 = $query_1 . ' %2'; - foreach ($tables as $table) { - $params[4] = array($table, 'Text'); - $params[5] = array($table, 'Text'); - $dao = CRM_Core_DAO::executeQuery($query_1, $params); - if ($dao->N) { - if (in_array($table, array('civicrm_price_set', 'civicrm_price_field_value'))) { - $query_2 .= " AND civicrm_price_set.name NOT IN ('default_contribution_amount', 'default_membership_type_amount') AND (civicrm_price_set.extends LIKE '%1%' OR civicrm_price_set.extends like '3')"; - if ($table == 'civicrm_price_field_value') { - $string = $table . ' INNER JOIN civicrm_price_field ON civicrm_price_field.id = civicrm_price_field_value.price_field_id INNER JOIN civicrm_price_set ON civicrm_price_set.id = civicrm_price_field.price_set_id '; - $params[4] = array($string, 'Text'); - $params[2][0] = str_replace('financial_type_id', "{$table}.financial_type_id", $params[2][0]); - } - } - $dao = CRM_Core_DAO::executeQuery($query_2, $params); - if ($dao->N) { - $message .= ''; - return $message; - } - } - } - return NULL; - } - /** * Retrieve all Deferred Financial Accounts. * @@ -561,4 +452,26 @@ In other words, please create deferred revenue accounts at Administer > CiviCont return $financialAccount; } + /** + * Get Organization Name associated with Financial Account. + * + * @param bool $checkPermissions + * + * @return array + * + */ + public static function getOrganizationNames($checkPermissions = TRUE) { + $result = civicrm_api3('FinancialAccount', 'get', array( + 'return' => array("contact_id.organization_name", "contact_id"), + 'contact_id.is_deleted' => 0, + 'options' => array('limit' => 0), + 'check_permissions' => $checkPermissions, + )); + $organizationNames = array(); + foreach ($result['values'] as $values) { + $organizationNames[$values['contact_id']] = $values['contact_id.organization_name']; + } + return $organizationNames; + } + }