From 157b21d8dfee0780b9913b64ba9b32a427900daf Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sun, 21 Jul 2013 00:26:59 +0530 Subject: [PATCH] --fixed for CRM-13060 ---------------------------------------- * CRM-13060: Changing the Financial Type for Contribution pages and Events does not update the Financial Type selected for Price Sets and Price Field values http://issues.civicrm.org/jira/browse/CRM-13060 --- CRM/Contribute/BAO/ContributionPage.php | 8 +++++ CRM/Contribute/Form/Contribution/Confirm.php | 2 +- CRM/Price/BAO/FieldValue.php | 38 ++++++++++++++++++++ CRM/Price/BAO/Set.php | 2 +- CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl | 21 +++++++++++ 5 files changed, 69 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/ContributionPage.php b/CRM/Contribute/BAO/ContributionPage.php index 09f6407d34..7ffb50818f 100644 --- a/CRM/Contribute/BAO/ContributionPage.php +++ b/CRM/Contribute/BAO/ContributionPage.php @@ -48,9 +48,17 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio * @static */ public static function &create(&$params) { + $financialTypeId = NULL; + if (CRM_Utils_Array::value('id', $params) && !CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) { + $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id'); + } $dao = new CRM_Contribute_DAO_ContributionPage(); $dao->copyValues($params); $dao->save(); + if ($financialTypeId && CRM_Utils_Array::value('financial_type_id', $params) + && $financialTypeId != $params['financial_type_id']) { + CRM_Price_BAO_FieldValue::updateFinancialType($params['id'], 'civicrm_contribution_page', $params['financial_type_id']); + } return $dao; } diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 293fcdc035..592517fc95 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -936,7 +936,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; - $contributionTypeId = $this->_values['financial_type_id']; + $contributionTypeId = $this->_values['financial_type_id']; $fieldTypes = array(); if (!empty($paymentParams['onbehalf']) && diff --git a/CRM/Price/BAO/FieldValue.php b/CRM/Price/BAO/FieldValue.php index 75323ed984..02fd2cf546 100644 --- a/CRM/Price/BAO/FieldValue.php +++ b/CRM/Price/BAO/FieldValue.php @@ -218,5 +218,43 @@ class CRM_Price_BAO_FieldValue extends CRM_Price_DAO_FieldValue { $fieldValueDAO->id = $id; return $fieldValueDAO->delete(); } + + /** + * Update civicrm_price_field_value.financial_type_id + * when financial_type_id of contribution_page or event is changed + * + * @param int $entityId Id + * @param String $entityTable entity table + * @param String $financialTypeID financial type id + * + * @access public + * @static + */ + static function updateFinancialType($entityId, $entityTable, $financialTypeID) { + if (!$entityId || !$entityTable || !$financialTypeID) { + return FALSE; + } + $setClause[] = "cpfv.financial_type_id = %3 "; + $params = array( + 1 => array($entityId, 'Integer'), + 2 => array($entityTable, 'String'), + 3 => array($financialTypeID, 'Integer'), + 4 => array(CRM_Core_Component::getComponentID('CiviMember'), 'Integer'), + ); + if ($entityTable == 'civicrm_contribution_page') { + $setClause[] = "cps.financial_type_id = CASE +WHEN cps.extends LIKE '%%4%%' +THEN %3 +ELSE cps.financial_type_id +END "; + } + $sql = "UPDATE `civicrm_price_field_value` cpfv +INNER JOIN civicrm_price_field cpf ON cpf.id = cpfv.price_field_id +INNER JOIN civicrm_price_set_entity ces ON cpf.price_set_id = ces.price_set_id +INNER JOIN civicrm_price_set cps ON cps.id = ces.price_set_id +SET " . implode(',', $setClause) . " WHERE ces.entity_id = %1 AND ces.entity_table = %2 AND cpfv.membership_type_id IS NULL"; + // for event discount price sets + CRM_Core_DAO::executeQuery($sql, $params); + } } diff --git a/CRM/Price/BAO/Set.php b/CRM/Price/BAO/Set.php index ecee3b7b01..dba2d03ff7 100644 --- a/CRM/Price/BAO/Set.php +++ b/CRM/Price/BAO/Set.php @@ -540,7 +540,7 @@ WHERE id = %1"; $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { $setTree[$setID]['extends'] = $dao->extends; - $setTree[$setID]['financial_type_id'] = $dao->financial_type_id; + $setTree[$setID]['financial_type_id'] = $dao->financial_type_id; $setTree[$setID]['help_pre'] = $dao->help_pre; $setTree[$setID]['help_post'] = $dao->help_post; $setTree[$setID]['is_quick_config'] = $dao->is_quick_config; diff --git a/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl index d21b25faa5..dcbbb43846 100644 --- a/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl @@ -1 +1,22 @@ {* file to handle db changes in 4.3.6 during upgrade *} +-- CRM-13060 +UPDATE civicrm_price_set_entity cpse +LEFT JOIN civicrm_price_set cps ON cps.id = cpse.price_set_id +LEFT JOIN civicrm_price_field cpf ON cps.id = cpf.price_set_id +LEFT JOIN civicrm_price_field_value cpfv ON cpf.id = cpfv.price_field_id +LEFT JOIN civicrm_event ce ON cpse.entity_id = ce.id AND cpse.entity_table = 'civicrm_event' +LEFT JOIN civicrm_contribution_page ccg ON cpse.entity_id = ccg.id AND cpse.entity_table = 'civicrm_contribution_page' +SET cpfv.financial_type_id = CASE + WHEN cpfv.membership_type_id IS NULL AND ce.id IS NOT NULL + THEN ce.financial_type_id + WHEN cpfv.membership_type_id IS NULL AND ccg.id IS NOT NULL + THEN ccg.financial_type_id + ELSE cpfv.financial_type_id +END, +cps.financial_type_id = CASE + WHEN ce.id IS NOT NULL + THEN ce.financial_type_id + WHEN ccg.id IS NOT NULL + THEN ccg.financial_type_id +END +WHERE cps.is_quick_config = 1; \ No newline at end of file -- 2.25.1