}
$this->assign('htmlFields', $htmlFields);
parent::buildQuickForm();
- $this->addFormRule(array('CRM_Admin_Form_Preferences_Contribute', 'formRule'), $this);
- }
-
- /**
- * Global validation rules for the form.
- *
- * @param array $values
- * posted values of the form
- * @param $files
- * @param $self
- *
- * @return array
- * list of errors to be posted back to the form
- */
- public static function formRule($values, $files, $self) {
- $errors = array();
- if (CRM_Utils_Array::value('deferred_revenue_enabled', $values)) {
- $errorMessage = CRM_Financial_BAO_FinancialAccount::validateTogglingDeferredRevenue();
- if ($errorMessage) {
- // Since the error msg is too long and
- // takes the whole space to display inline
- // therefore setting blank text to highlight the field
- // setting actual error msg to _qf_default to show in pop-up screen
- $errors['deferred_revenue_enabled'] = ' ';
- $errors['_qf_default'] = $errorMessage;
- }
- }
- return $errors;
}
/**
$params['prevContribution'] = self::getOriginalContribution($contributionID);
}
- // CRM-16189
- CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID);
if ($contributionID && !empty($params['revenue_recognition_date']) && !empty($params['prevContribution'])
&& !($contributionStatus[$params['prevContribution']->contribution_status_id] == 'Pending')
&& !self::allowUpdateRevenueRecognitionDate($contributionID)
CRM_Utils_Hook::pre('create', 'Event', NULL, $params);
}
- // CRM-16189
- if (!empty($params['financial_type_id'])) {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id']);
- }
-
$event = new CRM_Event_DAO_Event();
$event->copyValues($params);
$this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'),
array('class' => 'crm-form-submit cancel')
);
-
+ if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
+ $deferredFinancialType = CRM_Financial_BAO_FinancialAccount::getDeferredFinancialType();
+ $this->assign('deferredFinancialType', array_keys($deferredFinancialType));
+ }
$this->buildAmountLabel();
parent::buildQuickForm();
}
}
}
}
- // CRM-16189
- try {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($values['financial_type_id']);
- }
- catch (CRM_Core_Exception $e) {
- $errors['financial_type_id'] = $e->getMessage();
- }
return empty($errors) ? TRUE : $errors;
}
}
if ($isError) {
- $error = ts('Revenue recognition date can only be specified if the financial type selected has a deferred revenue account configured. 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');
+ $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('\ 1', $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
-<ul>
-<li>those specified for each membership type at Admin > CiviMember > Membership Types, edit</li>
-<li>on the Fees tab when managing events</li>
-<li>the default financial type associated with a membership or event price set</li>
-<li>the financial type for a membership price set field option when the membership type is non-blank</li>
-<li>as the financial type for a price set field with participant count > 0</li>
-<li>as the financial type for a price set field option with participant count > 0</li>
-</ul>
-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 .= '<ul>';
- $financialTypes = CRM_Contribute_PseudoConstant::financialType();
- $financialTypes = array_diff_key($financialTypes, $deferredFinancialType);
- foreach ($financialTypes as $financialType) {
- $message .= "<li>{$financialType}</li>";
- }
- $message .= '</ul>';
- return $message;
- }
- }
- }
- return NULL;
- }
-
/**
* Retrieve all Deferred Financial Accounts.
*
}
}
- // CRM-16189
- if (!empty($params['financial_type_id'])) {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType(
- $params['financial_type_id']
- );
- }
-
// action is taken depending upon the mode
$membershipType = new CRM_Member_DAO_MembershipType();
$membershipType->copyValues($params);
$this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule'));
$this->assign('membershipTypeId', $this->_id);
+
+ if (CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled')) {
+ $deferredFinancialType = CRM_Financial_BAO_FinancialAccount::getDeferredFinancialType();
+ $this->assign('deferredFinancialType', array_keys($deferredFinancialType));
+ }
}
/**
}
}
- // CRM-16189
- try {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id']);
- }
- catch (CRM_Core_Exception $e) {
- $errors['financial_type_id'] = $e->getMessage();
- }
-
return empty($errors) ? TRUE : $errors;
}
if (!$priceFieldID) {
$priceFieldID = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceFieldValue', $id, 'price_field_id');
}
- if (!empty($params['financial_type_id'])) {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType(
- $params['financial_type_id'],
- $priceFieldID,
- 'PriceField'
- );
- }
if (!empty($params['is_default'])) {
$query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE price_field_id = %1';
$p = array(1 => array($params['price_field_id'], 'Integer'));
else {
$priceSetID = CRM_Utils_Array::value('id', $params);
}
- // CRM-16189
- if ($validatePriceSet && !empty($params['financial_type_id'])) {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType(
- $params['financial_type_id'],
- $priceSetID
- );
- }
$priceSetBAO = new CRM_Price_BAO_PriceSet();
$priceSetBAO->copyValues($params);
if (self::eventPriceSetDomainID()) {
if ($fields['financial_type_id'] == '') {
$errors['financial_type_id'] = ts('Financial Type is a required field');
}
- else {
- // CRM-16189
- try {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_sid);
- }
- catch (CRM_Core_Exception $e) {
- $errors['financial_type_id'] = $e->getMessage();
- }
- }
}
//avoid the same price field label in Within PriceSet
}
$_flagOption = $_emptyRow = 0;
- // CRM-16189
- try {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['option_financial_type_id'][$index], $form->_fid, 'PriceField');
- }
- catch(CRM_Core_Exception $e) {
- $errors["option_financial_type_id[{$index}]"] = $e->getMessage();
- }
}
if (!empty($memTypesIDS)) {
) {
$errors['count'] = ts('Participant count can not be greater than max participants.');
}
- // CRM-16189
- try {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_fid, 'PriceField');
- }
- catch (CRM_Core_Exception $e) {
- $errors['financial_type_id'] = $e->getMessage();
- }
return empty($errors) ? TRUE : $errors;
}
if ($asciiValue >= 48 && $asciiValue <= 57) {
$errors['title'] = ts("Name cannot not start with a digit");
}
- // CRM-16189
- if (!empty($fields['extends'])
- && (array_key_exists(CRM_Core_Component::getComponentID('CiviEvent'), $fields['extends'])
- || array_key_exists(CRM_Core_Component::getComponentID('CiviMember'), $fields['extends']))
- ) {
- try {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id']);
- }
- catch (CRM_Core_Exception $e) {
- $errors['financial_type_id'] = $e->getMessage();
- }
- }
return empty($errors) ? TRUE : $errors;
}
</div>
</div>
+{include file="CRM/common/deferredFinancialType.tpl" context='Event'}
{include file="CRM/common/showHide.tpl"}
<script type="text/javascript">
{if $price}
});
</script>
{/literal}
-{/if}
+{/if}
\ No newline at end of file
</div>
</div>
+{include file="CRM/common/deferredFinancialType.tpl" context='MembershipType'}
{literal}
<script type="text/javascript">
CRM.$(function($) {
--- /dev/null
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2017 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*}
+{if isset($deferredFinancialType)}
+<div id='warningDialog' style="display:none;"></div>
+{literal}
+<script type="text/javascript">
+CRM.$(function($) {
+ var more = $('.crm-button input.validate').click(function(e) {
+ var message = "{/literal} {if $context eq 'Event'}
+ {ts}Note: Revenue for this event registration will not be deferred as the financial type does not have a deferred revenue account setup for it. If you want the revenue to be deferred, please select a different Financial Type with a Deferred Revenue account setup for it, or setup a Deferred Revenue account for this Financial Type.{/ts}
+ {else if $context eq 'MembershipType'}
+ {ts}Note: Revenue for these types of memberships will not be deferred as the financial type does not have a deferred revenue account setup for it. If you want the revenue to be deferred, please select a different Financial Type with a Deferred Revenue account setup for it, or setup a Deferred Revenue account for this Financial Type.{/ts}
+ {/if}
+ {literal}";
+ var deferredFinancialType = {/literal}{$deferredFinancialType|@json_encode}{literal};
+ var financialType = parseInt($('#financial_type_id').val());
+ if ($.inArray(financialType, deferredFinancialType) == -1) {
+ return confirm(message);
+ }
+ });
+});
+</script>
+{/literal}
+{/if}
$this->fail("Missed expected exception");
}
catch (CRM_Core_Exception $e) {
- $this->assertEquals('Revenue recognition date can only be specified if the financial type selected has a deferred revenue account configured. 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', $e->getMessage());
+ $this->assertEquals('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.', $e->getMessage());
}
}
- /**
- * Test if financial type has Deferred Revenue Account is relationship with Financial Account.
- *
- */
- public function testValidateFinancialType() {
- Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1'));
- $financialTypes = CRM_Contribute_PseudoConstant::financialType();
- foreach ($financialTypes as $key => $value) {
- try {
- CRM_Financial_BAO_FinancialAccount::validateFinancialType($key);
- if (!in_array($value, array('Member Dues', 'Event Fee'))) {
- $this->fail("Missed expected exception");
- }
- }
- catch (CRM_Core_Exception $e) {
- if (in_array($value, array('Member Dues', 'Event Fees'))) {
- $this->fail("Should not call exception");
- }
- else {
- $this->assertEquals('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', $e->getMessage());
- }
- }
- }
- }
-
- /**
- * Test Validate if Deferred Account is set for Financial Type.
- */
- public function testValidateTogglingDeferredRevenue() {
- $orgContactID = $this->organizationCreate();
-
- //create relationship
- $params = array(
- 'name_a_b' => 'Relation 1',
- 'name_b_a' => 'Relation 2',
- 'contact_type_a' => 'Individual',
- 'contact_type_b' => 'Organization',
- 'is_reserved' => 1,
- 'is_active' => 1,
- );
- $relationshipTypeId = $this->relationshipTypeCreate($params);
- $ids = array();
- $params = array(
- 'name' => 'test type',
- 'domain_id' => 1,
- 'description' => NULL,
- 'minimum_fee' => 10,
- 'duration_unit' => 'year',
- 'member_of_contact_id' => $orgContactID,
- 'relationship_type_id' => $relationshipTypeId,
- 'period_type' => 'fixed',
- 'duration_interval' => 1,
- 'financial_type_id' => 1,
- 'visibility' => 'Public',
- 'is_active' => 1,
- );
-
- $membershipType = CRM_Member_BAO_MembershipType::add($params, $ids);
-
- $membership = $this->assertDBNotNull('CRM_Member_BAO_MembershipType', $orgContactID,
- 'name', 'member_of_contact_id',
- 'Database check on updated membership record.'
- );
- $error = CRM_Financial_BAO_FinancialAccount::validateTogglingDeferredRevenue();
- $this->assertTrue(!empty($error), "Error message did not appear");
- $this->membershipTypeDelete(array('id' => $membershipType->id));
- }
-
/**
* Test testGetAllDeferredFinancialAccount.
*/