From 9ce8bcfc8856a221f7b83c1feb448da88299f93b Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Fri, 29 Mar 2013 16:59:35 +0530 Subject: [PATCH] --fixed for CRM-12233 --- CRM/Contribute/Form/Contribution/Confirm.php | 18 ++++- CRM/Contribute/Form/Contribution/Main.php | 69 +++++++++---------- .../Form/ContributionPage/Amount.php | 2 +- CRM/Member/BAO/Membership.php | 1 + CRM/Member/Form/MembershipBlock.php | 2 +- CRM/Price/BAO/Field.php | 7 +- 6 files changed, 56 insertions(+), 43 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index 521ae07ee5..64d81a7971 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -885,7 +885,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr $priceFieldIds = $this->get('memberPriceFieldIDS'); if (!empty($priceFieldIds)) { - $contributionTypeID = CRM_Core_DAO::getFieldValue( 'CRM_Price_DAO_Set', $priceFieldIds['id'], 'financial_type_id' ); + $contributionTypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceFieldIds['id'], 'financial_type_id'); unset($priceFieldIds['id']); $membershipTypeIds = array(); $membershipTypeTerms = array(); @@ -902,15 +902,27 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } } $membershipParams['selectMembership'] = $membershipTypeIds; - $membershipParams['financial_type_id'] = $contributionTypeID; + $membershipParams['financial_type_id'] = $contributionTypeID; $membershipParams['types_terms'] = $membershipTypeTerms; } if (CRM_Utils_Array::value('selectMembership', $membershipParams)) { + // CRM-12233 + if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) { + foreach ($this->_values['fee'] as $key => $feeValues) { + if ($feeValues['name'] == 'membership_amount') { + $fieldId = $this->_params['price_' . $key]; + $this->_memLineItem[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId]; + unset($this->_lineItem[$this->_priceSetId][$fieldId]); + break; + } + } + } + CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID, $this, $premiumParams, $customFieldsFormatted, $fieldTypes ); - } + } } else { // at this point we've created a contact and stored its address etc diff --git a/CRM/Contribute/Form/Contribution/Main.php b/CRM/Contribute/Form/Contribution/Main.php index 5d6f2f1c8d..49267838f3 100644 --- a/CRM/Contribute/Form/Contribution/Main.php +++ b/CRM/Contribute/Form/Contribution/Main.php @@ -599,7 +599,6 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); - } /** @@ -812,6 +811,33 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } } + // CRM-12233 + if ($membershipIsActive && !$self->_membershipBlock['is_required'] + && $self->_values['amount_block_is_active']) { + $membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL; + foreach ($self->_values['fee'] as $fieldKey => $fieldValue) { + if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldKey, $fields) == 0) { + $membershipFieldId = $fieldKey; + } + elseif ($membershipFieldId) { + if ($fieldValue['name'] == 'other_amount') { + $otherFieldId = $fieldKey; + } + elseif ($fieldValue['name'] == 'contribution_amount') { + $contributionFieldId = $fieldKey; + } + + if (!$errorKey || CRM_Utils_Array::value('price_' . $contributionFieldId, $fields) == '0') { + $errorKey = $fieldKey; + } + } + } + + if ($membershipFieldId && (!CRM_Utils_Array::value('price_' . $contributionFieldId, $fields) + && !CRM_Utils_Array::value('price_' . $otherFieldId, $fields))) { + $errors["price_{$errorKey}"] = ts('Additional Amount is required.'); + } + } if (empty($check)) { if ($self->_useForMember == 1 && $membershipIsActive) { $errors['_qf_default'] = ts('Select at least one option from Membership Type(s).'); @@ -882,39 +908,10 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } } - $fieldId = $memPresent = $membershipLabel = $fieldOption = $proceFieldAmount = NULL; - if ($self->_separateMembershipPayment == 0 && $self->_quickConfig) { - foreach ($self->_priceSet['fields'] as $fieldKey => $fieldVal) { - if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldId, $fields)) { - $fieldId = $fieldVal['id']; - $fieldOption = $fields['price_' . $fieldId]; - $memPresent = TRUE; - } - else { - if (CRM_Utils_Array::value('price_' . $fieldKey, $fields) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) { - $fieldId = $fieldVal['id']; - if ($fieldVal['name'] == 'other_amount') { - $proceFieldAmount = $self->_submitValues['price_' . $fieldId]; - } - else $proceFieldAmount = $fieldVal['options'][$self->_submitValues['price_' . $fieldId]]['amount']; - unset($fields['price_' . $fieldId]); - break; - } - } - } - } - CRM_Price_BAO_Set::processAmount($self->_values['fee'], $fields, $lineItem ); - if ($proceFieldAmount) { - if ($proceFieldAmount < $lineItem[$fieldOption]['line_total']) { - $errors["price_$fieldId"] = ts('The Membership you have selected requires a minimum contribution of %1', - array(1 => CRM_Utils_Money::format($lineItem[$fieldOption]['line_total'])) - ); - } - $fields['amount'] = $proceFieldAmount; - } + if ($fields['amount'] < 0) { $errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly'); } @@ -1227,24 +1224,26 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu } //If the membership & contribution is used in contribution page & not seperate payment - $fieldId = $memPresent = $membershipLabel = $fieldOption = $proceFieldAmount = $is_quick_config = NULL; + $fieldId = $memPresent = $membershipLabel = $fieldOption = $is_quick_config = NULL; + $proceFieldAmount = 0; if ($this->_separateMembershipPayment == 0) { $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config'); if ($is_quick_config) { foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) { - if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldId, $params)) { + if ($fieldVal['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldKey , $params)) { $fieldId = $fieldVal['id']; $fieldOption = $params['price_' . $fieldId]; + $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount']; $memPresent = TRUE; } else { if (CRM_Utils_Array::value('price_' . $fieldKey, $params) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) { $fieldId = $fieldVal['id']; if ($fieldVal['name'] == 'other_amount') { - $proceFieldAmount = $this->_submitValues['price_' . $fieldId]; + $proceFieldAmount += $this->_submitValues['price_' . $fieldId]; } else { - $proceFieldAmount = $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount']; + $proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount']; } unset($params['price_' . $fieldId]); break; diff --git a/CRM/Contribute/Form/ContributionPage/Amount.php b/CRM/Contribute/Form/ContributionPage/Amount.php index 46c6d94acb..381e201c64 100644 --- a/CRM/Contribute/Form/ContributionPage/Amount.php +++ b/CRM/Contribute/Form/ContributionPage/Amount.php @@ -294,7 +294,7 @@ SELECT id } } $hasMembershipBlk = TRUE; - if ($membershipBlock->is_separate_payment && !$fields['amount_block_is_active']) { + if ($membershipBlock->is_separate_payment && !CRM_Utils_Array::value('amount_block_is_active', $fields)) { $errors['amount_block_is_active'] = ts('To disable Contribution Amounts section you need to first disable Separate Membership Payment option from Membership Settings.'); } } diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 64f42266a1..c1ad123c85 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1255,6 +1255,7 @@ AND civicrm_membership.is_test = %2"; $memBlockDetails = CRM_Member_BAO_Membership::getMembershipBlock($form->_id); if (CRM_Utils_Array::value('is_separate_payment', $memBlockDetails) && !$paymentDone) { + $form->_lineItem = $form->_memLineItem; $contributionType = new CRM_Financial_DAO_FinancialType( ); $contributionType->id = CRM_Utils_Array::value('financial_type_id', $membershipDetails); if (!$contributionType->find(TRUE)) { diff --git a/CRM/Member/Form/MembershipBlock.php b/CRM/Member/Form/MembershipBlock.php index 0815ff7849..2191665575 100644 --- a/CRM/Member/Form/MembershipBlock.php +++ b/CRM/Member/Form/MembershipBlock.php @@ -371,7 +371,7 @@ class CRM_Member_Form_MembershipBlock extends CRM_Contribute_Form_ContributionPa CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults); if (!CRM_Utils_Array::value('id', $editedResults)) { $fieldParams['name'] = strtolower(CRM_Utils_String::munge('Membership Amount', '_', 245)); - $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : 'Membership Amount'; + $fieldParams['label'] = CRM_Utils_Array::value('new_title', $params) ? $params['new_title'] : 'Membership'; if (!CRM_Utils_Array::value('mem_price_field_id', $params)) { CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_Field', 0, 1, array('price_set_id' => $priceSetID)); } diff --git a/CRM/Price/BAO/Field.php b/CRM/Price/BAO/Field.php index b5eeba126c..31b1d55744 100644 --- a/CRM/Price/BAO/Field.php +++ b/CRM/Price/BAO/Field.php @@ -259,7 +259,7 @@ class CRM_Price_BAO_Field extends CRM_Price_DAO_Field { $currencyName = $config->defaultCurrency; if (!isset($label)) { - $label = (property_exists($qf,'_membershipBlock') && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock) && $field->name == 'contribution_amount' && !CRM_Utils_Array::value('is_allow_other_amount', $otherAmount)) ? ts('Additional Contribution') : $field->label; + $label = (property_exists($qf,'_membershipBlock') && $field->name == 'contribution_amount') ? ts('Additional Contribution') : $field->label; } if ($field->name == 'contribution_amount') { @@ -298,7 +298,7 @@ class CRM_Price_BAO_Field extends CRM_Price_DAO_Field { } // if seperate membership payment is used with quick config priceset then change the other amount label - if (property_exists($qf,'_membershipBlock') && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock) && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf,'_contributionAmount')) { + if (property_exists($qf,'_membershipBlock') && $qf->_quickConfig && $field->name == 'other_amount' && !property_exists($qf,'_contributionAmount')) { $label = ts('Additional Contribution'); $useRequired = 0; } @@ -405,7 +405,8 @@ class CRM_Price_BAO_Field extends CRM_Price_DAO_Field { $element = &$qf->addGroup($choice, $elementName, $label); // make contribution field required for quick config when membership block is enabled - if (($field->name == 'contribution_amount' || $field->name == 'membership_amount') && property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock) && !$field->is_required) { + if (($field->name == 'membership_amount' || ($field->name == 'contribution_amount' && CRM_Utils_Array::value('is_separate_payment', $qf->_membershipBlock))) + && property_exists($qf, '_membershipBlock') && !empty($qf->_membershipBlock) && !$field->is_required) { $useRequired = $field->is_required = TRUE; } -- 2.25.1