--fixed for CRM-12233
authorPradeep Nayak <pradeep@pradeep.(none)>
Fri, 29 Mar 2013 11:29:35 +0000 (16:59 +0530)
committerPradeep Nayak <pradeep@pradeep.(none)>
Fri, 29 Mar 2013 11:29:35 +0000 (16:59 +0530)
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/Main.php
CRM/Contribute/Form/ContributionPage/Amount.php
CRM/Member/BAO/Membership.php
CRM/Member/Form/MembershipBlock.php
CRM/Price/BAO/Field.php

index 521ae07ee50cf01c4108c1fe013da546ed4ff399..64d81a79719460f0a62c414ab4ea41dd538aaf3c 100644 (file)
@@ -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
index 5d6f2f1c8d0f236854ce5276160ad816ae0224ca..49267838f3f1a25f612477fe40899fdd370286b1 100644 (file)
@@ -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;
index 46c6d94acb635401cd25057348983b8a1598919f..381e201c64e889af90f08e6a3fc81fc07731271d 100644 (file)
@@ -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.');
       }
     }
index 64f42266a10cbb150711e6fba27fb03507bbb2f9..c1ad123c8527f12bad528b246d31bbb12132943d 100644 (file)
@@ -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)) {
index 0815ff7849e3519651b8c224098714c9bfb170ec..2191665575aa756eb03c2a63cafb3c48609d9339 100644 (file)
@@ -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));
           }
index b5eeba126cfe5a8cafc0ec24e51d1bb963ecf7c0..31b1d5574424eceaf5e8a702256894a23bd8e228 100644 (file)
@@ -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;
         }