From: eileen Date: Wed, 8 Jun 2016 01:19:07 +0000 (-0600) Subject: CRM-18701 fix setting of membership amount set on the fly for backoffice membership... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1a1a2f4f5c2be0aee0d38b1638add1cb224d888d;p=civicrm-core.git CRM-18701 fix setting of membership amount set on the fly for backoffice membership form --- diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 652bc5be0d..be78982b37 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -1191,7 +1191,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $lineItem = array($this->_priceSetId => array()); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], - $formValues, $lineItem[$this->_priceSetId]); + $formValues, $lineItem[$this->_priceSetId], NULL, $this->_priceSetId); if (CRM_Utils_Array::value('tax_amount', $formValues)) { $params['tax_amount'] = $formValues['tax_amount']; diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 99f3eb5b8d..1de8b075d7 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -609,7 +609,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $lineItem = array(); $this->_params = $this->setPriceSetParameters($this->_params); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], - $this->_params, $lineItem[$this->_priceSetId] + $this->_params, $lineItem[$this->_priceSetId], NULL, $this->_priceSetId ); //CRM-11529 for quick config backoffice transactions //when financial_type_id is passed in form, update the diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index f13a13cee7..c1d5b09be2 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -323,14 +323,14 @@ AND li.entity_id = {$entityId} * @param array $params * Reference to form values. * @param array $fields - * Array of fields belonging. - * to the price set used for particular event + * Array of fields belonging to the price set used for particular event * @param array $values * Reference to the values array(. * this is * lineItem array) + * @param string $amount_override */ - public static function format($fid, $params, $fields, &$values) { + public static function format($fid, $params, $fields, &$values, $amount_override = NULL) { if (empty($params["price_{$fid}"])) { return; } @@ -350,7 +350,7 @@ AND li.entity_id = {$entityId} } foreach ($params["price_{$fid}"] as $oid => $qty) { - $price = $options[$oid]['amount']; + $price = $amount_override === NULL ? $options[$oid]['amount'] : $amount_override; // lets clean the price in case it is not yet cleant // CRM-10974 diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index b907c88a0a..1b52e187fe 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -747,14 +747,26 @@ WHERE id = %1"; * This parameter appears to only be relevant to determining whether memberships should be auto-renewed. * (and is effectively a boolean for 'is_membership' which could be calculated from the line items.) */ - public static function processAmount($fields, &$params, &$lineItem, $component = '') { + public static function processAmount($fields, &$params, &$lineItem, $component = '', $priceSetID = NULL) { // using price set $totalPrice = $totalTax = 0; + // CRM-18701 Sometimes the amount in the price set is overridden by the amount on the form. + // This is notably the case with memberships and we need to put this amount + // on the line item rather than the calculated amount. + // This seems to only affect radio link items as that is the use case for the 'quick config' + // set up (which allows a free form field). + $amount_override = NULL; if ($component) { $autoRenew = array(); $autoRenew[0] = $autoRenew[1] = $autoRenew[2] = 0; } + if ($priceSetID) { + $priceFields = self::filterPriceFieldsFromParams($priceSetID, $params); + if (count($priceFields) == 1 && !empty($params['total_amount'])) { + $amount_override = $params['total_amount']; + } + } foreach ($fields as $id => $field) { if (empty($params["price_{$id}"]) || (empty($params["price_{$id}"]) && $params["price_{$id}"] == NULL) @@ -793,7 +805,7 @@ WHERE id = %1"; $params["price_{$id}"] = array($params["price_{$id}"] => 1); $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]); - CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem); + CRM_Price_BAO_LineItem::format($id, $params, $field, $lineItem, $amount_override); if (CRM_Utils_Array::value('tax_rate', $field['options'][$optionValueId])) { $lineItem = self::setLineItem($field, $lineItem, $optionValueId); $totalTax += $field['options'][$optionValueId]['tax_amount']; diff --git a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php index af64808e4d..269f4c1c16 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php @@ -197,6 +197,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase { 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], ), 1); + $this->_checkFinancialRecords(array('id' => $contribution['id'], 'total_amount' => 50, 'financial_account_id' => 2), 'online'); } /** diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index f3bc8d4f2f..d7eb6a75bb 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -482,6 +482,8 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase { 'entity_table' => 'civicrm_membership', 'contribution_id' => $contribution['id'], ), 1); + + $this->_checkFinancialRecords(array('id' => $contribution['id'], 'total_amount' => 50, 'financial_account_id' => 2), 'online'); $this->mut->checkMailLog(array( '50', 'Receipt text', diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 08f91f733a..8f657a0db1 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -3526,13 +3526,13 @@ AND ( TABLE_NAME LIKE 'civicrm_value_%' ) $compareParams = array( 'amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 1, - 'financial_account_id' => 1, + 'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1), ); if ($context == 'payLater') { $compareParams = array( 'amount' => CRM_Utils_Array::value('total_amount', $params, 100), 'status_id' => 3, - 'financial_account_id' => 1, + 'financial_account_id' => CRM_Utils_Array::value('financial_account_id', $params, 1), ); } $this->assertDBCompareValues('CRM_Financial_DAO_FinancialItem', $fitemParams, $compareParams);