-- CRM-15055, create line item for membership wne no contribution is recorded
authorPradeep Nayak <pradeep.nayak@webaccess.co.in>
Sat, 30 Aug 2014 14:01:04 +0000 (19:31 +0530)
committerPradeep Nayak <pradeep.nayak@webaccess.co.in>
Wed, 3 Sep 2014 09:27:18 +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 d900d6f28ed42a12966edd694295b840c99d14d4..3c99d44e3a1c77a840ba05055134e1f3607a32a7 100644 (file)
@@ -316,12 +316,19 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership {
         'membership_id'
       );
     }
-
+    
+    $params['skipLineItem'] = TRUE;
+    $params['contribution'] = NULL;
+    
     //record contribution for this membership
     if (!empty($params['contribution_status_id']) && empty($params['relate_contribution_id'])) {
       $memInfo = array_merge($params, array('membership_id' => $membership->id));
       $params['contribution'] = self::recordMembershipContribution($memInfo, $ids);
     }
+    
+    if (CRM_Utils_Array::value('lineItems', $params) && empty($params['contributionId'])) {
+      CRM_Price_BAO_LineItem::processPriceSet($membership->id, $params['lineItems'], $params['contribution']);
+    }
 
     //insert payment record for this membership
     if (!empty($params['relate_contribution_id'])) {
@@ -2804,7 +2811,7 @@ WHERE      civicrm_membership.is_test = 0";
       'contact_id', 'total_amount', 'receive_date', 'financial_type_id',
       'payment_instrument_id', 'trxn_id', 'invoice_id', 'is_test',
       'contribution_status_id', 'check_number', 'campaign_id', 'is_pay_later',
-      'membership_id',
+      'membership_id', 'skipLineItem'
     );
     foreach ($recordContribution as $f) {
       $contributionParams[$f] = CRM_Utils_Array::value($f, $params);
index 7b01f96c0dfca67f29c28b517b12174bef7ce051..2137d4484770484480adf7bd274a44ed1d9880f2 100644 (file)
@@ -271,6 +271,7 @@ class CRM_Member_Form_Membership extends CRM_Member_Form {
 
     $this->setPageTitle(ts('Membership'));
 
+
     parent::preProcess();
   }
 
@@ -1243,6 +1244,12 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
     }
 
     $membershipType = implode(', ', $membershipTypes);
+    
+    //do cleanup line  items if membership edit the Membership Fee.
+    $params['contributionId'] = CRM_Utils_Array::value('contribution_id', $this->_defaultValues);
+    if (empty($params['contributionId']) && $this->_id) {
+      CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_membership');
+    }
 
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
@@ -1624,6 +1631,7 @@ WHERE   id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
           }
 
           $membership = CRM_Member_BAO_Membership::create($membershipParams, $ids);
+          unset($params['lineItems']);
 
           $this->_membershipIDs[] = $membership->id;
           $createdMemberships[$memType] = $membership;