/** * Delete all pledge payments. * * @param int $id * Pledge id. * * @return bool */ public static function deletePayments($id) { if (!CRM_Utils_Rule::positiveInteger($id)) { return FALSE; } $transaction = new CRM_Core_Transaction(); $payment = new CRM_Pledge_DAO_PledgePayment(); $payment->pledge_id = $id; if ($payment->find()) { while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } self::del($payment->id); } } $transaction->commit(); return TRUE; }
/** * Find payments which can be safely canceled. * * @param int $pledgeID * @return array of int (civicrm_pledge_payment.id) */ public static function findCancelablePayments($pledgeID) { $statuses = array_flip(CRM_Contribute_PseudoConstant::contributionStatus()); $paymentDAO = new CRM_Pledge_DAO_PledgePayment(); $paymentDAO->pledge_id = $pledgeID; $paymentDAO->whereAdd(sprintf("status_id IN (%d,%d)", $statuses['Overdue'], $statuses['Pending'])); $paymentDAO->find(); $paymentIDs = array(); while ($paymentDAO->fetch()) { $paymentIDs[] = $paymentDAO->id; } return $paymentIDs; }
/** * Function to delete the pledge * * @param int $id pledge id * * @access public * @static * */ static function deletePledge($id) { CRM_Utils_Hook::pre('delete', 'Pledge', $id, CRM_Core_DAO::$_nullArray); $transaction = new CRM_Core_Transaction(); //check for no Completed Payment records with the pledge $payment = new CRM_Pledge_DAO_PledgePayment(); $payment->pledge_id = $id; $payment->find(); while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } $dao = new CRM_Pledge_DAO_Pledge(); $dao->id = $id; $results = $dao->delete(); $transaction->commit(); CRM_Utils_Hook::post('delete', 'Pledge', $dao->id, $dao); // delete the recently created Pledge $pledgeRecent = array('id' => $id, 'type' => 'Pledge'); CRM_Utils_Recent::del($pledgeRecent); return $results; }