return $params;
}
+ /**
+ * Check financial type validation on update of a contribution.
+ *
+ * @param Integer $financialTypeId
+ * Value of latest Financial Type.
+ *
+ * @param Integer
+ * Contribution Id.
+ *
+ * @param array $errors
+ * List of errors.
+ *
+ * @return bool
+ */
+ public static function checkFinancialTypeChange($financialTypeId, $contributionId, &$errors) {
+ if (!empty($financialTypeId)) {
+ $oldFinancialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'financial_type_id');
+ if ($oldFinancialTypeId == $financialTypeId) {
+ return FALSE;
+ }
+ }
+ $sql = 'SELECT financial_type_id FROM civicrm_line_item WHERE contribution_id = %1 GROUP BY financial_type_id;';
+ $params = array(
+ '1' => array($contributionId, 'Integer')
+ );
+ $result = CRM_Core_DAO::executeQuery($sql, $params);
+ if ($result->N > 1) {
+ $errors['financial_type_id'] = ts('One or more line items have a different financial type than the contribution. Editing the financial type is not yet supported in this situation.');
+ }
+ }
+
}
if ($self->_id && $self->_values['contribution_status_id'] != $fields['contribution_status_id']) {
CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
}
-
+ // CRM-16015, add form-rule to restrict change of financial type if using price field of different financial type
+ if ($self->_id && $self->_values['financial_type_id'] != $fields['financial_type_id']) {
+ CRM_Contribute_BAO_Contribution::checkFinancialTypeChange(NULL, $self->_id, $errors);
+ }
//FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
if (!empty($fields['fee_amount']) && !empty($fields['financial_type_id']) && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id'])) {
$errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
throw new API_Exception($error['contribution_status_id']);
}
}
-
+ if (!empty($params['id']) && !empty($params['financial_type_id'])) {
+ $error = array();
+ CRM_Contribute_BAO_Contribution::checkFinancialTypeChange($params['financial_type_id'], $params['id'], $error);
+ if (array_key_exists('financial_type_id', $error)) {
+ throw new API_Exception($error['financial_type_id']);
+ }
+ }
_civicrm_api3_contribution_create_legacy_support_45($params);
// Make sure tax calculation is handled via api.