CRM-16189, Added function to check payment associated with contribution has Membershi...
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 9 Aug 2016 11:20:41 +0000 (16:50 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Mon, 29 Aug 2016 13:19:20 +0000 (18:49 +0530)
----------------------------------------
* CRM-16189: Improve support for Accrual Method bookkeeping
  https://issues.civicrm.org/jira/browse/CRM-16189

CRM/Contribute/BAO/Contribution.php

index a8223d8089fcbc4ae8b06f96b0402ebbf2e47f19..f757472edf18191ed94c4de2c4fac9c162ba0b8c 100644 (file)
@@ -5246,4 +5246,32 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
     }
   }
 
+  /**
+   * Check if contribution has participant/membership payment.
+   *
+   * @param int $contributionId
+   *   Contribution ID
+   *
+   * @return bool
+   */
+  public static function allowUpdateRevenueRecognitionDate($contributionId) {
+    // get line item for contribution
+    $lineItems = CRM_Price_BAO_LineItem::getLineItems($contributionId, 'contribution', NULL, TRUE, TRUE);
+    // check if line item is for membership or participant
+    foreach ($lineItems as $items) {
+      if ($items['entity_table'] == 'civicrm_participant') {
+        $Update = FALSE;
+        break;
+      }
+      elseif ($items['entity_table'] == 'civicrm_membership') {
+        $Update = FALSE;
+      }
+      else {
+        $Update = TRUE;
+        break;
+      }
+    }
+    return $flag;
+  }
+
 }