From 5a9c4d4ab76d1427f6dccc2361fbbff393e94555 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 20 Mar 2013 03:41:13 +0530 Subject: [PATCH] -- worked on CRM-12127 --- CRM/Member/BAO/MembershipType.php | 30 ++++++++++++++----- CRM/Member/Form/Membership.php | 30 +++++++++---------- .../Incremental/sql/4.3.beta4.mysql.tpl | 19 +++++++++++- templates/CRM/Member/Form/Membership.tpl | 13 ++++++-- 4 files changed, 66 insertions(+), 26 deletions(-) diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index 3f1f48c9ae..93366dfc49 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -118,8 +118,8 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { self::createMembershipPriceField($params, $ids, $previousID, $membershipType->id); // update all price field value for quick config when membership type is set CRM-11718 - if (CRM_Utils_Array::value('membershipType', $ids) && CRM_Utils_Array::value('financial_type_id', $params)) { - self::updateAllPriceFieldValue($ids['membershipType'], $params['financial_type_id']); + if (CRM_Utils_Array::value('membershipType', $ids)) { + self::updateAllPriceFieldValue($ids['membershipType'], $params); } return $membershipType; @@ -684,6 +684,8 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { $fieldParams['is_display_amounts'] = $fieldParams['is_required'] = 0; $fieldParams['weight'] = $fieldParams['option_weight'][1] = 1; $fieldParams['option_label'][1] = $params['name']; + $fieldParams['option_description'][1] = $params['description']; + $fieldParams['membership_type_id'][1] = $membershipTypeId; $fieldParams['option_amount'][1] = empty($params['minimum_fee']) ? 0 : $params['minimum_fee']; $fieldParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params); @@ -725,6 +727,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { } } $results['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params); + $results['description'] = $params['description']; CRM_Price_BAO_FieldValue::add($results, $optionsIds); } } @@ -736,15 +739,28 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { * * @param integer financial type id */ - static function updateAllPriceFieldValue($membershipTypeId, $financialTypeId) { + static function updateAllPriceFieldValue($membershipTypeId, $params) { + if (CRM_Utils_Array::value('minimum_fee', $params)){ + $amount = $params['minimum_fee']; + } + else { + $amount = 0; + } $query = "UPDATE `civicrm_price_field_value` cpfv INNER JOIN civicrm_price_field cpf on cpf.id = cpfv.price_field_id INNER JOIN civicrm_price_set cps on cps.id = cpf.price_set_id -SET cpfv.financial_type_id = %2 -WHERE cpfv.membership_type_id = %1 AND cps.is_quick_config = 1"; +SET cpfv.financial_type_id = %2, +cpfv.label = %3, +cpfv.amount = %4, +cpfv.description = %5 +WHERE cpfv.membership_type_id = %1 AND cps.is_quick_config = 1 AND cps.name != 'default_membership_type_amount'"; $params = array(1 => array($membershipTypeId, 'Integer'), - 2 => array($financialTypeId, 'Integer')); - CRM_Core_DAO::executeQuery($query, $params); + 2 => array($params['financial_type_id'], 'Integer'), + 3 => array($params['name'], 'String'), + 4 => array($amount, 'Float'), + 5 => array($params['description'], 'String'), + ); + CRM_Core_DAO::executeQuery($query, $params); } } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 4dd959e000..8abcd36337 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -464,7 +464,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { $this->assign('autoRenewOption', CRM_Price_BAO_Set::checkAutoRenewForPriceSet($this->_priceSetId)); $this->assign('optionsMembershipTypes', $optionsMembershipTypes); - $this->assign( 'contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet) ); + $this->assign('contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet)); // get only price set form elements. if ($getOnlyPriceSetElements) { @@ -684,10 +684,6 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?')); - $this->add('select', 'financial_type_id', - ts( 'Financial Type' ), - array(''=>ts( '- select -' )) + CRM_Contribute_PseudoConstant::financialType( ) ); - $this->add('text', 'total_amount', ts('Amount')); $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); @@ -729,6 +725,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //add field for amount to allow an amount to be entered that differs from minimum $this->add('text', 'total_amount', ts('Amount')); } + $this->add('select', 'financial_type_id', + ts('Financial Type'), + array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType() + ); if ($this->_context != 'standalone') { //CRM-10223 - allow contribution to be recorded against different contact // causes a conflict in standalone mode so skip in standalone for now @@ -888,6 +888,10 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; if ($priceSetId && !$self->_mode && !CRM_Utils_Array::value('record_contribution', $params)) { $errors['record_contribution'] = ts('Record Membership Payment is required when you using price set.'); } + + if (!$priceSetId && $self->_mode && !CRM_Utils_Array::value('financial_type_id', $params)) { + $errors['financial_type_id'] = ts('Please enter the financial Type.'); + } if (CRM_Utils_Array::value('payment_processor_id', $params)) { // make sure that credit card number and cvv are valid @@ -1001,8 +1005,8 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; //total amount condition arise when membership type having no //minimum fee if (isset($params['record_contribution'])) { - if ( ! $params['financial_type_id'] ) { - $errors['financial_type_id'] = ts('Please enter the financial Type.'); + if (!$params['financial_type_id']) { + $errors['financial_type_id'] = ts('Please enter the financial Type.'); } if (CRM_Utils_System::isNull($params['total_amount'])) { $errors['total_amount'] = ts('Please enter the contribution.'); @@ -1094,7 +1098,6 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $this->_params, $lineItem[$priceSetId]); $params['total_amount'] = CRM_Utils_Array::value('amount', $this->_params); $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $formValues); - $isPaymentRecorded = CRM_Utils_Array::value('record_contribution', $formValues); if (!empty($lineItem[$priceSetId])) { foreach ($lineItem[$priceSetId] as &$li) { if (CRM_Utils_Array::value('membership_type_id', $li)) { @@ -1106,7 +1109,7 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; ///CRM-11529 for quick config backoffice transactions //when financial_type_id is passed in form, update the //lineitems with the financial type selected in form - if ($isPaymentRecorded && $isQuickConfig && $submittedFinancialType) { + if ($isQuickConfig && $submittedFinancialType) { $li['financial_type_id'] = $submittedFinancialType; } } @@ -1282,18 +1285,15 @@ WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; else { $params['total_amount'] = CRM_Utils_Array::value('total_amount', $formValues, 0); } - - if ($priceSetId) { + + if ($priceSetId && !$isQuickConfig) { $params['financial_type_id'] = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_Set', $priceSetId, 'financial_type_id' ); } else { - $params['financial_type_id'] = CRM_Core_DAO::getFieldValue( 'CRM_Member_DAO_MembershipType', - end($this->_memTypeSelected), - 'financial_type_id' - ); + $params['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $formValues); } $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], diff --git a/CRM/Upgrade/Incremental/sql/4.3.beta4.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.3.beta4.mysql.tpl index e8fbb154a9..a5b4a141ea 100644 --- a/CRM/Upgrade/Incremental/sql/4.3.beta4.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.3.beta4.mysql.tpl @@ -12,4 +12,21 @@ ALTER TABLE civicrm_option_value DROP INDEX index_option_group_id_name, ADD INDEX index_option_group_id_name (option_group_id, name(128)); - +-- CRM-12127 +UPDATE civicrm_membership_type cmt +LEFT JOIN civicrm_price_field_value cpfv ON cpfv.membership_type_id = cmt.id +LEFT JOIN civicrm_price_field cpf ON cpf.id = cpfv.price_field_id +LEFT JOIN civicrm_price_set cps ON cps.id = cpf.price_set_id +SET +cpfv.financial_type_id = cmt.financial_type_id, +{if !$multilingual} + cpfv.label = cmt.name, + cpfv.description = cmt.description, +{else} + {foreach from=$locales item=locale} + cpfv.label_{$locale} = cmt.name_{$locale}, + cpfv.description_{$locale} = cmt.description_{$locale}, + {/foreach} +{/if} +cpfv.amount = cmt.minimum_fee +WHERE cps.is_quick_config = 1 AND cpfv.membership_type_id IS NOT NULL; \ No newline at end of file diff --git a/templates/CRM/Member/Form/Membership.tpl b/templates/CRM/Member/Form/Membership.tpl index d79f07c7bc..85ad40ccd1 100644 --- a/templates/CRM/Member/Form/Membership.tpl +++ b/templates/CRM/Member/Form/Membership.tpl @@ -164,6 +164,11 @@ {ts}If Status Override is checked, the selected status will remain in force (it will NOT be modified by the automated status update script).{/ts} {elseif $membershipMode} + + {$form.financial_type_id.label} + {$form.financial_type_id.html}
+ {ts}Select the appropriate financial type for this payment.{/ts} + {$form.total_amount.label} {$form.total_amount.html}
@@ -437,11 +442,10 @@ } } {/literal}{/if}{literal} - - // skip this for test and live modes because financial type is set automatically - cj("#financial_type_id").val( allMemberships[memType]['financial_type_id'] ); } + // skip this for test and live modes because financial type is set automatically + cj("#financial_type_id").val(allMemberships[memType]['financial_type_id']); var term = cj('#num_terms').val(); if ( term ) { var feeTotal = allMemberships[memType]['total_amount_numeric'] * term; @@ -608,6 +612,7 @@ cj( "#mem_type_id" ).hide( ); cj('#total_amount').attr("readonly", true); cj( "#num_terms_row" ).hide( ); + cj(".crm-membership-form-block-financial_type_id-mode").hide(); {/literal}{/if}{literal} function buildAmount( priceSetId ) { @@ -627,6 +632,7 @@ cj( "#totalAmountORPriceSet" ).show( ); cj('#total_amount').removeAttr("readonly"); cj( "#num_terms_row").show( ); + cj(".crm-membership-form-block-financial_type_id-mode").show(); {/literal}{if $allowAutoRenew}{literal} cj('#autoRenew').hide(); @@ -653,6 +659,7 @@ cj( "#totalAmountORPriceSet" ).hide( ); cj( "#mem_type_id" ).hide( ); cj( "#num_terms_row" ).hide( ); + cj(".crm-membership-form-block-financial_type_id-mode").hide(); } buildMaxRelated(cj('#membership_type_id_1', false).val()); -- 2.25.1