CIVI-28 Added check for lineitems and delete operations from actions
authorEdsel <edsel.lopez@jmaconsulting.biz>
Tue, 14 Apr 2015 08:00:00 +0000 (13:30 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Mon, 21 Sep 2015 10:42:44 +0000 (16:12 +0530)
CRM/Contribute/Form/Task/Delete.php
CRM/Contribute/Selector/Search.php

index 222eba1a96a556e58aa457fbde994f9a44e1eafa..eb0e4855451ff6c00c51d8d614dcf9ec6884da71 100644 (file)
@@ -61,7 +61,41 @@ class CRM_Contribute_Form_Task_Delete extends CRM_Contribute_Form_Task {
    * Build the form object.
    */
   public function buildQuickForm() {
-    $this->addDefaultButtons(ts('Delete Contributions'), 'done');
+    $count = 0;
+    foreach ($this->_contributionIds as $key => $id) {
+      $finTypeID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $id, 'financial_type_id');
+      if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($finTypeID))) {
+        unset($this->_contributionIds[$key]);
+        $count++;
+      }
+      // Now check for lineItems
+      if ($lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($id)) {
+        foreach ($lineItems as $items) { 
+          if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
+            unset($this->_contributionIds[$key]);
+            $count++;
+            break;
+          }
+        }
+      }
+    }
+    if ($count && empty($this->_contributionIds)) {
+      CRM_Core_Session::setStatus(ts('1 contribution could not be deleted.', array('plural' => '%count contributions could not be deleted.', 'count' => $count)), ts('Error'), 'error');
+      $this->addButtons(array(
+        array(
+          'type' => 'back',
+          'name' => ts('Cancel'),
+        ),
+       )
+      );
+    }
+    elseif ($count && !empty($this->_contributionIds)) {
+      CRM_Core_Session::setStatus(ts('1 contribution will not be deleted.', array('plural' => '%count contributions will not be deleted.', 'count' => $count)), ts('Warning'), 'warning');
+      $this->addDefaultButtons(ts('Delete Contributions'), 'done');
+    }
+    else {
+      $this->addDefaultButtons(ts('Delete Contributions'), 'done');
+    }
   }
 
   /**
index 9d5fba445d0f9a3f6c319df58f05e09310420542..21aae9b0ab8ddf8dfcfa93be06bdc5cd8cbf88e5 100644 (file)
@@ -374,11 +374,9 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C
         }
         if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
           unset($links[CRM_Core_Action::UPDATE]);
-          break;
         }
         if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) {
           unset($links[CRM_Core_Action::DELETE]);
-          break;
         }
       }
       if ($checkLineItem) {