From 6a3d8d2d642a9688b4d17324093444fcc596ffdf Mon Sep 17 00:00:00 2001 From: Web Access Date: Thu, 4 Jun 2015 16:16:59 +0530 Subject: [PATCH] Fix for CRM-16451 --- CRM/Contribute/Form/Contribution.php | 5 ++++- CRM/Price/BAO/PriceSet.php | 11 ++++++----- templates/CRM/Contribute/Form/Contribution.tpl | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 537ab02d64..087e108895 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -797,11 +797,14 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $hasPriceSets = FALSE; if ($buildPriceSet) { $hasPriceSets = TRUE; + // CRM-16451: set financial type of 'Price Set' in back office contribution + // instead of selecting manually + $financialTypeIds = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute', 'financial_type_id'); $element = $this->add('select', 'price_set_id', ts('Choose price set'), array( '' => ts('Choose price set'), ) + $priceSets, - NULL, array('onchange' => "buildAmount( this.value );") + NULL, array('onchange' => "buildAmount( this.value, ".json_encode($financialTypeIds).");") ); if ($this->_online && !($this->_action & CRM_Core_Action::UPDATE)) { $element->freeze(); diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index b2fa31930c..e79e9bdad5 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -436,19 +436,20 @@ WHERE ct.id = cp.financial_type_id AND * @param bool $withInactive * Whether or not to include inactive entries. * @param bool|string $extendComponentName name of the component like 'CiviEvent','CiviContribute' + * @param string $column name of the column. * * @return array * associative array of id => name */ - public static function getAssoc($withInactive = FALSE, $extendComponentName = FALSE) { - $query = ' + public static function getAssoc($withInactive = FALSE, $extendComponentName = FALSE, $column = 'title') { + $query = " SELECT - DISTINCT ( price_set_id ) as id, title + DISTINCT ( price_set_id ) as id, {$column} FROM civicrm_price_field, civicrm_price_set WHERE - civicrm_price_set.id = civicrm_price_field.price_set_id AND is_quick_config = 0 '; + civicrm_price_set.id = civicrm_price_field.price_set_id AND is_quick_config = 0 "; if (!$withInactive) { $query .= ' AND civicrm_price_set.is_active = 1 '; @@ -470,7 +471,7 @@ WHERE ct.id = cp.financial_type_id AND $dao = CRM_Core_DAO::executeQuery($query); while ($dao->fetch()) { - $priceSets[$dao->id] = $dao->title; + $priceSets[$dao->id] = $dao->$column; } return $priceSets; } diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index f836a1f853..f545deebd9 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -543,9 +543,11 @@ {if $buildPriceSet}{literal}buildAmount( );{/literal}{/if} {literal} -function buildAmount( priceSetId ) { - if (!priceSetId) priceSetId = cj("#price_set_id").val( ); +// CRM-16451: set financial type of 'Price Set' in back office contribution +// instead of selecting manually +function buildAmount( priceSetId, financialtypeIds ) { + if (!priceSetId) priceSetId = cj("#price_set_id").val( ); var fname = '#priceset'; if (!priceSetId) { // hide price set fields. @@ -557,6 +559,10 @@ function buildAmount( priceSetId ) { var choose = "{/literal}{ts}Choose price set{/ts}{literal}"; cj("#price_set_id option[value='']").html( choose ); + cj('label[for="total_amount"]').text('{/literal}{ts}Total Amount{/ts}{literal}'); + cj(".crm-contribution-form-block-financial_type_id").show(); + cj("#financial_type_id option[value='']").attr('selected', true); + //we might want to build recur block. if (cj("#is_recur")) buildRecurBlock( null ); return; @@ -586,6 +592,10 @@ function buildAmount( priceSetId ) { cj( "#totalAmount").hide( ); var manual = "{/literal}{ts}Manual contribution amount{/ts}{literal}"; cj("#price_set_id option[value='']").html( manual ); + + cj('label[for="total_amount"]').text('{/literal}{ts}Price Sets{/ts}{literal}'); + cj("#financial_type_id option[value="+financialtypeIds[priceSetId]+"]").prop('selected', true); + cj(".crm-contribution-form-block-financial_type_id").css("display", "none"); } function adjustPayment( ) { -- 2.25.1