self::deleteContribution($contribution->id);
}
}
+ /**
+ * Function to validate financial type
+ *
+ * CRM-13231
+ *
+ * @param integer $financialTypeId Financial Type id
+ *
+ * @access public
+ * @static
+ */
+ static function validateFinancialType($financialTypeId, $relationName = 'Expense Account is') {
+ $expenseTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE '{$relationName}' "));
+ $financialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $expenseTypeId);
+
+ if (!$financialAccount) {
+ return CRM_Contribute_PseudoConstant::financialType($financialTypeId);
+ }
+ return FALSE;
+ }
}
}
//FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
- if (CRM_Utils_Array::value('fee_amount', $fields)) {
- $financialAccount = array();
- CRM_Core_PseudoConstant::populate($financialAccount,
- 'CRM_Financial_DAO_EntityFinancialAccount',
- $all = TRUE,
- $retrieve = 'financial_account_id',
- $filter = NULL,
- " account_relationship = 5 AND entity_id = {$fields['financial_type_id']} ");
- if (!current($financialAccount)) {
- $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for this Financial Type");
- }
+ if (CRM_Utils_Array::value('fee_amount', $fields)
+ && $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;
}
return $errors;
}
}
}
}
-
+
+ if (CRM_Utils_Array::value('payment_processor', $fields)
+ && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($self->_defaultValues['financial_type_id'])) {
+ $errors['payment_processor'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
+ }
+
if (CRM_Utils_Array::value('is_recur_interval', $fields)) {
foreach(array_keys($fields['payment_processor']) as $paymentProcessorID) {
$paymentProcessorTypeId = CRM_Core_DAO::getFieldValue(
$this->addDateTime('start_date', ts('Start Date'));
$this->addDateTime('end_date', ts('End Date'));
- $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this->_id);
+ $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);
parent::buildQuickForm();
}
* @static
* @access public
*/
- static function formRule($values, $files, $contributionPageId) {
+ static function formRule($values, $files, $self) {
$errors = array();
-
+ $contributionPageId = $self->_id;
//CRM-4286
if (strstr($values['title'], '/')) {
$errors['title'] = ts("Please do not use '/' in Title");
if (($end < $start) && ($end != 0)) {
$errors['end_date'] = ts('End date should be after Start date.');
}
-
+
+ if (CRM_Utils_Array::value('payment_processor', $self->_values)
+ && $financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($values['financial_type_id'])) {
+ $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
+ }
+
//dont allow on behalf of save when
//pre or post profile consists of membership fields
if ($contributionPageId && CRM_Utils_Array::value('is_organization', $values)) {
$conProfileType = "'Includes Profile (top of page)'";
}
}
-
+
if ($contributionProfiles['custom_post_id']) {
$postProfileType = CRM_Core_BAO_UFField::getProfileType($contributionProfiles['custom_post_id']);
if ($postProfileType == 'Membership') {
if (isset($params['imageOption'])) {
if ($params['imageOption'] == 'thumbnail') {
if (!$params['imageUrl']) {
- $errors['imageUrl'] = 'Image URL is Required ';
+ $errors['imageUrl'] = ts('Image URL is Required');
}
if (!$params['thumbnailUrl']) {
- $errors['thumbnailUrl'] = 'Thumbnail URL is Required ';
+ $errors['thumbnailUrl'] = ts('Thumbnail URL is Required');
}
}
}
-
+ // CRM-13231 financial type required if product has cost
+ if (CRM_Utils_Array::value('cost', $params)) {
+ $errors['financial_type_id'] = ts('Financial Type is required for product having cost.');
+ }
$fileLocation = $files['uploadFile']['tmp_name'];
if ($fileLocation != "") {
list($width, $height) = getimagesize($fileLocation);
}
else {
$accountRelationShipId = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_EntityFinancialAccount', $financialTypeAccountId, 'account_relationship');
- CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship because it is being referenced by one or more of the following types of records: Contributions, Contribution Pages, or Membership Types. Consider disabling this type instead if you no longer want it used.', array(1 => $relationValues[$accountRelationShipId])));
+ CRM_Core_Session::setStatus(ts('You cannot remove an account with a %1 relationship because it is being referenced by one or more of the following types of records: Contributions, Contribution Pages, or Membership Types. Consider disabling this type instead if you no longer want it used.', array(1 => $relationValues[$accountRelationShipId])), NUll, 'error');
}
return CRM_Utils_System::redirect( CRM_Utils_System::url( 'civicrm/admin/financial/financialType/accounts', "reset=1&action=browse&aid={$accountId}" ));
}
//delete from financial Type table
$financialType = new CRM_Financial_DAO_EntityFinancialAccount( );
$financialType->id = $financialTypeAccountId;
+ $financialType->find(TRUE);
$financialType->delete();
+ CRM_Core_Session::setStatus(ts('Unbalanced transactions may be created if you delete %1 account.', array(1 => $relationValues[$financialType->account_relationship])));
}
/**
SELECT @opCost := value FROM civicrm_option_value WHERE name = 'Cost of Sales' and option_group_id = @option_group_id_fat;
SELECT @financialAccountId := id FROM civicrm_financial_account WHERE is_default = 1 and financial_account_type_id = @opCost;
+-- CRM-13231
+INSERT IGNORE INTO civicrm_financial_account (id, name, contact_id, financial_account_type_id, description, account_type_code, accounting_code, is_active, is_default)
+VALUES (@financialAccountId, 'Premiums', @domainContactId, @opCost, 'Account to record cost of premiums provided to payors', 'COGS', '5100', 1, 1);
+
+SELECT @financialAccountId := id FROM civicrm_financial_account WHERE is_default = 1 and financial_account_type_id = @opCost;
+
INSERT INTO civicrm_entity_financial_account(entity_table, entity_id, account_relationship, financial_account_id)
SELECT 'civicrm_financial_type', cft.id, @option_value_rel_id_cg, @financialAccountId
FROM civicrm_financial_type cft
-- for Expense Account is
SELECT @option_value_rel_id_exp := value FROM civicrm_option_value WHERE option_group_id = @option_group_id_arel AND name = 'Expense Account is';
SELECT @opexp := value FROM civicrm_option_value WHERE name = 'Expenses' and option_group_id = @option_group_id_fat;
+SET @financialAccountId := '';
SELECT @financialAccountId := id FROM civicrm_financial_account WHERE is_default = 1 and financial_account_type_id = @opexp;
+-- CRM-13231
+INSERT IGNORE INTO civicrm_financial_account (id, name, contact_id, financial_account_type_id, description, account_type_code, accounting_code, is_active, is_default)
+VALUES (@financialAccountId, 'Banking Fees', @domainContactId, @opexp, 'Payment processor fees and manually recorded banking fees', 'EXP', '5200', 1, 1);
+
+SELECT @financialAccountId := id FROM civicrm_financial_account WHERE is_default = 1 and financial_account_type_id = @opexp;
+
+
INSERT INTO civicrm_entity_financial_account(entity_table, entity_id, account_relationship, financial_account_id)
SELECT 'civicrm_financial_type', cft.id, @option_value_rel_id_exp, @financialAccountId
FROM civicrm_financial_type cft
LEFT JOIN civicrm_entity_financial_account ceft
-ON ceft.entity_id = cft.id AND ceft.account_relationship = 5 AND ceft.entity_table = 'civicrm_financial_type'
+ON ceft.entity_id = cft.id AND ceft.account_relationship = @option_value_rel_id_exp AND ceft.entity_table = 'civicrm_financial_type'
WHERE ceft.entity_id IS NULL;
-- CRM-13096
DROP TABLE IF EXISTS civicrm_official_receipt;
+
+-- CRM-13231
+SELECT @option_group_id_arel := max(id) from civicrm_option_group where name = 'account_relationship';
+SELECT @option_group_id_fat := max(id) from civicrm_option_group where name = 'financial_account_type';
+SELECT @opexp := value FROM civicrm_option_value WHERE name = 'Expenses' and option_group_id = @option_group_id_fat;
+SELECT @financialAccountId := id FROM civicrm_financial_account WHERE is_default = 1 and financial_account_type_id = @opexp;
+
+SELECT @option_value_rel_id_exp := value FROM civicrm_option_value WHERE option_group_id = @option_group_id_arel AND name = 'Expense Account is';
+
+INSERT IGNORE INTO civicrm_financial_account (id, name, contact_id, financial_account_type_id, description, account_type_code, accounting_code, is_active, is_default)
+VALUES (@financialAccountId, 'Banking Fees', @domainContactId, @opexp, 'Payment processor fees and manually recorded banking fees', 'EXP', '5200', 1, 1);
+
+SELECT @financialAccountId := id FROM civicrm_financial_account WHERE is_default = 1 and financial_account_type_id = @opexp;
+
+INSERT INTO civicrm_entity_financial_account(entity_table, entity_id, account_relationship, financial_account_id)
+SELECT 'civicrm_financial_type', cft.id, @option_value_rel_id_exp, @financialAccountId
+FROM civicrm_financial_type cft
+LEFT JOIN civicrm_entity_financial_account ceft
+ON ceft.entity_id = cft.id AND ceft.account_relationship = @option_value_rel_id_exp AND ceft.entity_table = 'civicrm_financial_type'
+WHERE ceft.entity_id IS NULL;
+
+UPDATE civicrm_financial_trxn cft
+INNER JOIN civicrm_entity_financial_trxn ceft ON ceft.financial_trxn_id = cft .id
+INNER JOIN civicrm_entity_financial_trxn ceft1 ON ceft1.financial_trxn_id = cft .id
+INNER JOIN civicrm_financial_item cfi ON cfi.id = ceft1.entity_id
+INNER JOIN civicrm_contribution cc ON cc.id = ceft.entity_id
+INNER JOIN civicrm_entity_financial_account cefa ON cefa.entity_id = cc.financial_type_id
+SET cft.to_financial_account_id = cefa.financial_account_id
+WHERE ceft.entity_table = 'civicrm_contribution' AND ceft1.entity_table = 'civicrm_financial_item' AND cfi.entity_table = 'civicrm_financial_trxn' AND cft.to_financial_account_id IS NULL AND cefa.entity_table = 'civicrm_financial_type' AND cefa.account_relationship = @option_value_rel_id_exp;
\ No newline at end of file
{if $action eq 8}
<div class="messages status">
<div class="icon inform-icon"></div>
- {ts}WARNING: You cannot delete a financial type if it is currently used by any Contributions, Contribution Pages or Membership Types. Consider disabling this option instead.{/ts} {ts}Deleting a financial type cannot be undone.{/ts} {ts}Do you want to continue?{/ts}
+ {ts}WARNING: You cannot delete a financial type if it is currently used by any Contributions, Contribution Pages or Membership Types. Consider disabling this option instead.{/ts} {ts}Deleting a financial type cannot be undone. Unbalanced transactions may be created if you delete this account.{/ts} {ts}Do you want to continue?{/ts}
</div>
{else}
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>