worked on CRM-12155, delete records from civicrm_financial_item
authorKurund Jalmi <kurund@civicrm.org>
Thu, 21 Mar 2013 06:21:42 +0000 (11:51 +0530)
committerKurund Jalmi <kurund@civicrm.org>
Thu, 21 Mar 2013 06:21:42 +0000 (11:51 +0530)
CRM/Core/BAO/FinancialTrxn.php
CRM/Price/BAO/LineItem.php

index ed28e23256e88a5eafb6ff31567234649639cf6f..75a266cae440941e092eb5c72c759752ae552581 100644 (file)
@@ -270,6 +270,11 @@ WHERE lt.entity_id = %1 ";
       // delete financial transaction
       $query = 'DELETE FROM civicrm_financial_trxn WHERE id = %1';
       CRM_Core_DAO::executeQuery($query, array(1 => array($fids['financialTrxnId'], 'Integer')));
+
+      // delete financial item record
+      $query = 'DELETE FROM civicrm_financial_item WHERE entity_table="civicrm_financial_trxn" AND entity_id = %1';
+      CRM_Core_DAO::executeQuery($query, array(1 => array($fids['financialTrxnId'], 'Integer')));
+
       return TRUE;
     }
     else {
index b548a5bb6f1223046d74670202e535d6f43d229b..d33e2eaa1339791dbc602b2d40b5efe9ff2d0ebb 100644 (file)
@@ -242,18 +242,34 @@ class CRM_Price_BAO_LineItem extends CRM_Price_DAO_LineItem {
    * @static
    */
   public static function deleteLineItems($entityId, $entityTable) {
-    $result = FALSE;
     if (!$entityId || !$entityTable) {
-      return $result;
+      return FALSE;
     }
 
     if ($entityId && !is_array($entityId)) {
       $entityId = array($entityId);
     }
 
-    $query = "DELETE FROM civicrm_line_item where entity_id IN ('" . implode("','", $entityId) . "') AND entity_table = '$entityTable'";
+    // we need to fetch the line item ids that needs to be deleted.
+    $query = "SELECT id FROM civicrm_line_item WHERE entity_id IN ('" . implode("','", $entityId) . "') AND entity_table = '$entityTable'";
     $dao = CRM_Core_DAO::executeQuery($query);
-    return $result;
+
+    $lineItemIds = array();
+    while($dao->fetch()) {
+      $lineItemIds[$dao->id] = $dao->id;
+    }
+
+    // delete line item records from financial item
+    if (!empty($lineItemIds)) {
+      $query = "DELETE FROM civicrm_financial_item WHERE entity_id IN ('" . implode("','", $lineItemIds) . "') AND entity_table = 'civicrm_line_item'";
+      CRM_Core_DAO::executeQuery($query);
+    }
+
+    // delete records from line item
+    $query = "DELETE FROM civicrm_line_item WHERE entity_id IN ('" . implode("','", $entityId) . "') AND entity_table = '$entityTable'";
+    CRM_Core_DAO::executeQuery($query);
+
+    return TRUE;
   }
 
   /**