X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FFinancial%2FBAO%2FFinancialItem.php;h=3df83df8ed4e91c28c936ffc1c1acdd4795e7344;hb=2efcf0c212127e3281834edf26b64d2bbd5e0bb5;hp=76d1fff87ba333a4aaf153731a2ad59929eb31cb;hpb=f8c36033b83eb127a5443595b7aea3c6e68cd855;p=civicrm-core.git diff --git a/CRM/Financial/BAO/FinancialItem.php b/CRM/Financial/BAO/FinancialItem.php index 76d1fff87b..3df83df8ed 100644 --- a/CRM/Financial/BAO/FinancialItem.php +++ b/CRM/Financial/BAO/FinancialItem.php @@ -203,4 +203,47 @@ class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem { return null; } } + + /** + * check if contact is present in financial_item table + * + * CRM-12929 + * + * @param array $contactIds an array contact id's + * + * @param array $error error to display + * + * @return array + * @access public + * @static + */ + static function checkContactPresent($contactIds, &$error) { + if (empty($contactIds)) { + return FALSE; + } + + $allowPermDelete = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'allowPermDeleteFinancial'); + + if (!$allowPermDelete) { + $sql = 'SELECT DISTINCT(cc.id), cc.display_name FROM civicrm_contact cc +INNER JOIN civicrm_contribution con ON con.contact_id = cc.id +WHERE cc.id IN (' . implode (',', $contactIds) . ') AND con.is_test = 0'; + $dao = CRM_Core_DAO::executeQuery($sql); + if ($dao->N) { + while ($dao->fetch()) { + $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid=$dao->id"); + $not_deleted[$dao->id] = "$dao->display_name"; + } + + $errorStatus = ''; + if (is_array($error)) { + $errorStatus = ''; + } + + $error['_qf_default'] = $errorStatus . ts('This contact(s) can not be permanently deleted because the contact record is linked to one or more live financial transactions. Deleting this contact would result in the loss of financial data.'); + return $error; + } + } + return FALSE; + } }