From cc9b58f3d01be4cffc0e20e48be95647b4f23e16 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 24 Jul 2013 16:04:18 +0530 Subject: [PATCH] --worked on 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 --- .../Form/ContributionPage/Amount.php | 1 + CRM/Event/BAO/Event.php | 10 ++++-- CRM/Event/Form/ManageEvent/Fee.php | 11 +++++++ CRM/Price/BAO/FieldValue.php | 32 +++++++++++-------- CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl | 7 ++-- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index 381e201c64..de4a9aaed3 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -529,6 +529,7 @@ SELECT id $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; + $setParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $this->_values); $setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute'); $priceSet = CRM_Price_BAO_Set::create($setParams); $priceSetId = $priceSet->id; diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 01c04c91bc..9d9b5f3362 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -90,9 +90,12 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event { */ static function add(&$params) { CRM_Utils_System::flushCache(); - + $financialTypeId = NULL; if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::pre('edit', 'Event', $params['id'], $params); + if (!CRM_Utils_Array::value('skipFinancialType', $params)) { + $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['id'], 'financial_type_id'); + } } else { CRM_Utils_Hook::pre('create', 'Event', NULL, $params); @@ -109,7 +112,10 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event { else { CRM_Utils_Hook::post('create', 'Event', $event->id, $event); } - + if ($financialTypeId && CRM_Utils_Array::value('financial_type_id', $params) + && $financialTypeId != $params['financial_type_id']) { + CRM_Price_BAO_FieldValue::updateFinancialType($params['id'], 'civicrm_event', $params['financial_type_id']); + } return $result; } diff --git a/CRM/Event/Form/ManageEvent/Fee.php b/CRM/Event/Form/ManageEvent/Fee.php index 657033a2bf..90132a827b 100644 --- a/CRM/Event/Form/ManageEvent/Fee.php +++ b/CRM/Event/Form/ManageEvent/Fee.php @@ -627,6 +627,7 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { $setParams['name'] = $eventTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; + $setParams['financial_type_id'] = $params['financial_type_id']; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_Set::create($setParams); @@ -644,6 +645,9 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { $fieldParams['option_id'] = $params['price_field_value']; $priceSet = new CRM_Price_BAO_Set(); $priceSet->id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', CRM_Utils_Array::value('price_field_id', $params), 'price_set_id'); + if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) { + CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Set', $priceSet->id, 'financial_type_id', $params['financial_type_id']); + } } $fieldParams['html_type'] = 'Radio'; CRM_Price_BAO_Set::addTo('civicrm_event', $this->_id, $priceSet->id); @@ -702,11 +706,15 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { $setParams['name'] = $eventTitle . '_' . $params['discount_name'][$j] . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; + $setParams['financial_type_id'] = $params['financial_type_id']; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviEvent'); $priceSet = CRM_Price_BAO_Set::create($setParams); $priceSetID = $priceSet->id; } else { $priceSetID = $discountPriceSets[$j-1]; + if ($this->_defaultValues['financial_type_id'] != $params['financial_type_id']) { + CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Set', $priceSetID, 'financial_type_id', $params['financial_type_id']); + } unset($discountPriceSets[$j-1]); $fieldParams['id'] = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Field', $priceSetID, 'id', 'price_set_id'); } @@ -766,6 +774,9 @@ class CRM_Event_Form_ManageEvent_Fee extends CRM_Event_Form_ManageEvent { //update events table $params['id'] = $this->_id; + // skip update of financial type in price set + $params['skipFinancialType'] = TRUE; + CRM_Event_BAO_Event::add($params); parent::endPostProcess(); diff --git a/CRM/Price/BAO/FieldValue.php b/CRM/Price/BAO/FieldValue.php index 02fd2cf546..d9f5e5d0f9 100644 --- a/CRM/Price/BAO/FieldValue.php +++ b/CRM/Price/BAO/FieldValue.php @@ -234,26 +234,30 @@ class CRM_Price_BAO_FieldValue extends CRM_Price_DAO_FieldValue { 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 "; + // for event discount + $join = $where = ''; + if ($entityTable == 'civicrm_event') { + $join = " LEFT JOIN civicrm_discount cd ON cd.price_set_id = cps.id AND cd.entity_id = %1 AND cd.entity_table = %2 "; + $where = ' OR cd.id IS NOT NULL '; } - $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 + $sql = "UPDATE civicrm_price_set cps +LEFT JOIN civicrm_price_set_entity cpse ON cpse.price_set_id = cps.id AND cpse.entity_id = %1 AND cpse.entity_table = %2 +LEFT JOIN civicrm_price_field cpf ON cpf.price_set_id = cps.id +LEFT JOIN civicrm_price_field_value cpfv ON cpf.id = cpfv.price_field_id +{$join} +SET cpfv.financial_type_id = CASE + WHEN cpfv.membership_type_id IS NOT NULL + THEN cpfv.financial_type_id + ELSE %3 +END, +cps.financial_type_id = %3 +WHERE cpse.id IS NOT NULL {$where}"; + CRM_Core_DAO::executeQuery($sql, $params); } } diff --git a/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl index dcbbb43846..ebb25967db 100644 --- a/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.3.6.mysql.tpl @@ -7,11 +7,10 @@ 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 + WHEN 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 + WHEN ccg.id IS NOT NULL + THEN ccg.financial_type_id END, cps.financial_type_id = CASE WHEN ce.id IS NOT NULL -- 2.25.1