Esempio n. 1
0
 /**                                                           
  * Delete the indirect records associated with this contribution first
  * 
  * @return $results no of deleted Contribution on success, false otherwise
  * @access public 
  * @static 
  */
 static function deleteContribution($id)
 {
     require_once 'CRM/Utils/Hook.php';
     CRM_Utils_Hook::pre('delete', 'Contribution', $id, CRM_Core_DAO::$_nullArray);
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $results = null;
     //delete activity record
     require_once "CRM/Activity/BAO/Activity.php";
     $params = array('source_record_id' => $id, 'activity_type_id' => 6);
     // activity type id for contribution
     CRM_Activity_BAO_Activity::deleteActivity($params);
     //delete billing address if exists for this contribution.
     self::deleteAddress($id);
     //update pledge and pledge payment, CRM-3961
     require_once 'CRM/Pledge/BAO/Payment.php';
     CRM_Pledge_BAO_Payment::resetPledgePayment($id);
     // remove entry from civicrm_price_set_entity, CRM-5095
     require_once 'CRM/Price/BAO/Set.php';
     if (CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) {
         CRM_Price_BAO_Set::removeFrom('civicrm_contribution', $id);
     }
     // cleanup line items.
     require_once 'CRM/Price/BAO/Field.php';
     require_once 'CRM/Event/BAO/ParticipantPayment.php';
     $participantId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $id, 'participant_id', 'contribution_id');
     // delete any related entity_financial_trxn and financial_trxn records.
     require_once 'CRM/Core/BAO/FinancialTrxn.php';
     CRM_Core_BAO_FinancialTrxn::deleteFinancialTrxn($id, 'civicrm_contribution');
     if ($participantId) {
         require_once 'CRM/Price/BAO/LineItem.php';
         CRM_Price_BAO_LineItem::deleteLineItems($participantId, 'civicrm_participant');
     } else {
         require_once 'CRM/Price/BAO/LineItem.php';
         CRM_Price_BAO_LineItem::deleteLineItems($id, 'civicrm_contribution');
     }
     $dao = new CRM_Contribute_DAO_Contribution();
     $dao->id = $id;
     $results = $dao->delete();
     $transaction->commit();
     CRM_Utils_Hook::post('delete', 'Contribution', $dao->id, $dao);
     // delete the recently created Contribution
     require_once 'CRM/Utils/Recent.php';
     $contributionRecent = array('id' => $id, 'type' => 'Contribution');
     CRM_Utils_Recent::del($contributionRecent);
     return $results;
 }