-- CRM-15055, fixed for multiple membership
authorPradeep Nayak <pradeep.nayak@webaccess.co.in>
Sat, 30 Aug 2014 14:01:40 +0000 (19:31 +0530)
committerPradeep Nayak <pradeep.nayak@webaccess.co.in>
Wed, 3 Sep 2014 09:27:19 +0000 (14:57 +0530)
----------------------------------------
* CRM-15055: Line item for membership entity should be created even when Record Payment is not checked
  https://issues.civicrm.org/jira/browse/CRM-15055

CRM/Member/BAO/Membership.php
CRM/Member/Form/Membership.php

index 3c99d44e3a1c77a840ba05055134e1f3607a32a7..d8735c4f218332f7372aa4a7702c3ff8beae57dd 100644 (file)
@@ -318,7 +318,6 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
     }
     
     $params['skipLineItem'] = TRUE;
-    $params['contribution'] = NULL;
     
     //record contribution for this membership
     if (!empty($params['contribution_status_id']) && empty($params['relate_contribution_id'])) {
@@ -327,7 +326,7 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
     }
     
     if (CRM_Utils_Array::value('lineItems', $params) && empty($params['contributionId'])) {
-      CRM_Price_BAO_LineItem::processPriceSet($membership->id, $params['lineItems'], $params['contribution']);
+      CRM_Price_BAO_LineItem::processPriceSet($membership->id, $params['lineItems'], CRM_Utils_Array::value('contribution', $params));
     }
 
     //insert payment record for this membership
index 2137d4484770484480adf7bd274a44ed1d9880f2..c1994939760985cfc5bcfe32641bec10d183427a 100644 (file)
@@ -1303,7 +1303,13 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
         $formValues['financial_type_id']
       );
     }
-
+    $membershipLineItems = array();
+    foreach ($lineItem[$this->_priceSetId] as $key => $value) {
+      if (!empty($value['membership_type_id'])) {
+        $membershipLineItems[$value['membership_type_id']] = $value;
+        unset($lineItem[$this->_priceSetId][$key]);
+      }
+    }
     // process line items, until no previous line items.
     if (!empty($lineItem)) {
       $params['lineItems'] = $lineItem;
@@ -1529,8 +1535,10 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
         }
 
         $membershipParams = array_merge($membershipTypeValues[$memType], $params);
+        $membershipParams['lineItems'][$this->_priceSetId][] = $membershipLineItems[$memType];
         $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids);
-
+        $params['contribution'] = CRM_Utils_Array::value('contribution', $membershipParams);
+        unset($params['lineItems']);
         $this->_membershipIDs[] = $membership->id;
         $createdMemberships[$memType] = $membership;
         $count++;
@@ -1629,8 +1637,10 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
           if (!empty($softParams)) {
             $membershipParams['soft_credit'] = $softParams;
           }
-
+          
+          $membershipParams['lineItems'][$this->_priceSetId][] = $membershipLineItems[$memType];
           $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids);
+          $params['contribution'] = CRM_Utils_Array::value('contribution', $membershipParams);
           unset($params['lineItems']);
 
           $this->_membershipIDs[] = $membership->id;
@@ -1645,6 +1655,7 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
         if (!empty($priceFieldOp['membership_type_id'])) {
           $priceFieldOp['start_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['start_date'], '%d%f %b, %Y') : '-';
 
+
           $priceFieldOp['end_date'] = $membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'] ? CRM_Utils_Date::customFormat($membershipTypeValues[$priceFieldOp['membership_type_id']]['end_date'], '%d%f %b, %Y') : '-';
         }
         else {