diff --git a/CRM/Contribute/Form/ManagePremiums.php b/CRM/Contribute/Form/ManagePremiums.php index 82d52b84b4bbab60e1cd76d9b0055b932fae04a6..5d0c5ed5531a05a122b5bf8c93cffbacc9a2c28a 100644 --- a/CRM/Contribute/Form/ManagePremiums.php +++ b/CRM/Contribute/Form/ManagePremiums.php @@ -250,7 +250,7 @@ class CRM_Contribute_Form_ManagePremiums extends CRM_Contribute_Form { } } // CRM-13231 financial type required if product has cost - if (CRM_Utils_Array::value('cost', $params)) { + if (CRM_Utils_Array::value('cost', $params) && !CRM_Utils_Array::value('financial_type_id', $params)) { $errors['financial_type_id'] = ts('Financial Type is required for product having cost.'); } $fileLocation = $files['uploadFile']['tmp_name']; diff --git a/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl index b5ce8df174990d3cd3a7323fab1a57f0d84a8288..5aae59df6ab7b4328e499f99e7a2b5a09ce4eb8b 100644 --- a/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl @@ -51,6 +51,7 @@ SELECT @option_group_id_arel := max(id) from civicrm_option_group where name = ' 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 @domainContactId := contact_id from civicrm_domain where id = {$domainID}; SELECT @option_value_rel_id_exp := value FROM civicrm_option_value WHERE option_group_id = @option_group_id_arel AND name = 'Expense Account is'; @@ -73,4 +74,23 @@ 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 +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; + +-- Add COGS account relationship +SELECT @option_value_rel_id_cg := value FROM civicrm_option_value WHERE option_group_id = @option_group_id_arel AND name = 'Cost of Sales Account is'; +SELECT @opCost := value FROM civicrm_option_value WHERE name = 'Cost of Sales' 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 = @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 +LEFT JOIN civicrm_entity_financial_account ceft +ON ceft.entity_id = cft.id AND ceft.account_relationship = @option_value_rel_id_cg AND ceft.entity_table = 'civicrm_financial_type' +WHERE ceft.entity_id IS NULL; \ No newline at end of file