From 9330406e1394745b2f88985c81c004b12dc5794e Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Thu, 21 Mar 2013 11:51:42 +0530 Subject: [PATCH] worked on CRM-12155, delete records from civicrm_financial_item --- CRM/Core/BAO/FinancialTrxn.php | 5 +++++ CRM/Price/BAO/LineItem.php | 24 ++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index ed28e23256..75a266cae4 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -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 { diff --git a/CRM/Price/BAO/LineItem.php b/CRM/Price/BAO/LineItem.php index b548a5bb6f..d33e2eaa13 100644 --- a/CRM/Price/BAO/LineItem.php +++ b/CRM/Price/BAO/LineItem.php @@ -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; } /** -- 2.25.1