* CRM-16189, Added checks to validate financial type to have deferred relationship
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
https://issues.civicrm.org/jira/browse/CRM-16189
* CRM-16189, fixed notice error and code stylings
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
https://issues.civicrm.org/jira/browse/CRM-16189
* CRM-16189, updated code to include error msg
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
https://issues.civicrm.org/jira/browse/CRM-16189
CRM_Utils_Hook::pre('create', 'Event', NULL, $params);
}
+ // CRM-16189
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType(
+ CRM_Utils_Array::value('financial_type_id', $params)
+ );
+ if ($isError) {
+ 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'));
+ }
+
$event = new CRM_Event_DAO_Event();
$event->copyValues($params);
}
}
}
+ // CRM-16189
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($values['financial_type_id']);
+ if ($isError) {
+ $errors['financial_type_id'] = 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 empty($errors) ? TRUE : $errors;
}
}
}
+ // CRM-16189
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType(
+ CRM_Utils_Array::value('financial_type_id', $params)
+ );
+ if ($isError) {
+ 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'));
+ }
+
// action is taken depending upon the mode
$membershipType = new CRM_Member_DAO_MembershipType();
$membershipType->copyValues($params);
}
}
+ // CRM-16189
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($params['financial_type_id']);
+ if ($isError) {
+ $errors['financial_type_id'] = 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 empty($errors) ? TRUE : $errors;
}
self::updateAmountAndFeeLevel($id, $prevLabel, $params['label']);
}
}
+ // CRM-16189
+ $priceFieldID = CRM_Utils_Array::value('price_field_id', $params);
+ if (!$priceFieldID) {
+ $priceFieldID = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceFieldValue', $id, 'price_field_id');
+ }
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType(
+ CRM_Utils_Array::value('financial_type_id', $params),
+ $priceFieldID,
+ 'PriceField'
+ );
+ if ($isError) {
+ 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'));
+ }
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'));
if (empty($params['id']) && empty($params['name'])) {
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 242);
}
+ $priceSetID = NULL;
+ $validatePriceSet = TRUE;
if (!empty($params['extends']) && is_array($params['extends'])) {
+ if (!array_key_exists(CRM_Core_Component::getComponentID('CiviEvent'), $params['extends'])
+ || !array_key_exists(CRM_Core_Component::getComponentID('CiviMember'), $params['extends'])
+ ) {
+ $validatePriceSet = FALSE;
+ }
$params['extends'] = CRM_Utils_Array::implodePadded($params['extends']);
}
+ else {
+ $priceSetID = CRM_Utils_Array::value('id', $params);
+ }
+ // CRM-16189
+ if ($validatePriceSet) {
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType(
+ CRM_Utils_Array::value('financial_type_id', $params),
+ $priceSetID
+ );
+ if ($isError) {
+ 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'));
+ }
+ }
$priceSetBAO = new CRM_Price_BAO_PriceSet();
$priceSetBAO->copyValues($params);
if (self::eventPriceSetDomainID()) {
* Incomplete row checking is also required.
*/
if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) &&
- $fields['html_type'] == 'Text' && $fields['price'] == NULL
+ $fields['html_type'] == 'Text'
) {
- $errors['price'] = ts('Price is a required field');
- }
-
- if (($form->_action & CRM_Core_Action::ADD || $form->_action & CRM_Core_Action::UPDATE) &&
- $fields['html_type'] == 'Text' && $fields['financial_type_id'] == ''
- ) {
- $errors['financial_type_id'] = ts('Financial Type is a required field');
+ if ($fields['price'] == NULL) {
+ $errors['price'] = ts('Price is a required field');
+ }
+ if ($fields['financial_type_id'] == '') {
+ $errors['financial_type_id'] = ts('Financial Type is a required field');
+ }
+ else {
+ // CRM-16189
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_sid);
+ if ($isError) {
+ $errors['financial_type_id'] = 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');
+ }
+ }
}
//avoid the same price field label in Within PriceSet
}
$_flagOption = $_emptyRow = 0;
+ // CRM-16189
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['option_financial_type_id'][$index], $form->_fid, 'PriceField');
+ if ($isError) {
+ $errors["option_financial_type_id[{$index}]"] = 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');
+ }
}
if (!empty($memTypesIDS)) {
) {
$errors['count'] = ts('Participant count can not be greater than max participants.');
}
-
+ // CRM-16189
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id'], $form->_fid, 'PriceField');
+ if ($isError) {
+ $errors['financial_type_id'] = 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 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']))
+ ) {
+ $isError = CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id']);
+ if ($isError) {
+ $errors['financial_type_id'] = 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 empty($errors) ? TRUE : $errors;
}