/** * combine all the exportable fields from the lower levels object * * @return array array of exportable Fields * @access public */ function &exportableFields() { if (!self::$_exportableFields) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } require_once 'CRM/Pledge/DAO/Pledge.php'; $fields = CRM_Pledge_DAO_Pledge::export(); require_once 'CRM/Pledge/DAO/Payment.php'; $fields = array_merge($fields, CRM_Pledge_DAO_Payment::export()); //set title to calculated fields $calculatedFields = array('pledge_total_paid' => array('title' => ts('Total Paid')), 'pledge_balance_amount' => array('title' => ts('Balance Amount')), 'pledge_next_pay_date' => array('title' => ts('Next Payment Date')), 'pledge_next_pay_amount' => array('title' => ts('Next Payment Amount')), 'pledge_payment_paid_amount' => array('title' => ts('Paid Amount')), 'pledge_payment_paid_date' => array('title' => ts('Paid Date')), 'pledge_payment_status' => array('title' => ts('Pledge Payment Status'), 'name' => 'pledge_payment_status', 'data_type' => CRM_Utils_Type::T_STRING)); $pledgeFields = array('pledge_status' => array('title' => 'Pledge Status', 'name' => 'pledge_status', 'data_type' => CRM_Utils_Type::T_STRING), 'pledge_frequency_unit' => array('title' => 'Pledge Frequency Unit', 'name' => 'pledge_frequency_unit', 'data_type' => CRM_Utils_Type::T_ENUM), 'pledge_frequency_interval' => array('title' => 'Pledge Frequency Interval', 'name' => 'pledge_frequency_interval', 'data_type' => CRM_Utils_Type::T_INT), 'pledge_contribution_page_id' => array('title' => 'Pledge Contribution Page Id', 'name' => 'pledge_contribution_page_id', 'data_type' => CRM_Utils_Type::T_INT)); $fields = array_merge($fields, $pledgeFields, $calculatedFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Pledge')); self::$_exportableFields = $fields; } return self::$_exportableFields; }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields =& self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['pledge_payment'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
function loadObjects(&$input, &$ids, &$objects, $required) { $contribution =& $objects['contribution']; $objects['membership'] = null; $objects['contributionRecur'] = null; $objects['contributionType'] = null; $objects['event'] = null; $objects['participant'] = null; $objects['pledge_payment'] = null; require_once 'CRM/Contribute/DAO/ContributionType.php'; $contributionType =& new CRM_Contribute_DAO_ContributionType(); $contributionType->id = $contribution->contribution_type_id; if (!$contributionType->find(true)) { CRM_Core_Error::debug_log_message("Could not find contribution type record: {$contributionTypeID}"); echo "Failure: Could not find contribution type record for {$contributionTypeID}<p>"; return false; } $objects['contributionType'] = $contributionType; $paymentProcessorID = null; if ($input['component'] == 'contribute') { // get the contribution page id from the contribution // and then initialize the payment processor from it if (!$contribution->contribution_page_id) { if (!CRM_Utils_Array::value('pledge_payment', $ids)) { // return if we are just doing an optional validation if (!$required) { return true; } CRM_Core_Error::debug_log_message("Could not find contribution page for contribution record: {$contributionID}"); echo "Failure: Could not find contribution page for contribution record: {$contributionID}<p>"; return false; } } //for offline pldedge we dont have contribution page. if (!CRM_Utils_Array::value('pledge_payment', $ids)) { // get the payment processor id from contribution page $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contribution->contribution_page_id, 'payment_processor_id'); } // now retrieve the other optional objects if (isset($ids['membership'])) { require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $ids['membership']; if (!$membership->find(true)) { CRM_Core_Error::debug_log_message("Could not find membership record: {$membershipID}"); echo "Failure: Could not find membership record: {$membershipID}<p>"; return false; } $membership->join_date = CRM_Utils_Date::isoToMysql($membership->join_date); $membership->start_date = CRM_Utils_Date::isoToMysql($membership->start_date); $membership->end_date = CRM_Utils_Date::isoToMysql($membership->end_date); $membership->reminder_date = CRM_Utils_Date::isoToMysql($membership->reminder_date); $objects['membership'] =& $membership; } if (isset($ids['pledge_payment'])) { require_once 'CRM/Pledge/DAO/Payment.php'; $objects['pledge_payment'] = array(); foreach ($ids['pledge_payment'] as $key => $paymentID) { $payment = new CRM_Pledge_DAO_Payment(); $payment->id = $paymentID; if (!$payment->find(true)) { CRM_Core_Error::debug_log_message("Could not find pledge payment record: {$pledge_paymentID}"); echo "Failure: Could not find pledge payment record: {$pledge_paymentID}<p>"; return false; } $objects['pledge_payment'][] = $payment; } } if (isset($ids['contributionRecur'])) { require_once 'CRM/Contribute/DAO/ContributionRecur.php'; $recur =& new CRM_Contribute_DAO_ContributionRecur(); $recur->id = $ids['contributionRecur']; if (!$recur->find(true)) { CRM_Core_Error::debug_log_message("Could not find recur record: {$contributionRecurID}"); echo "Failure: Could not find recur record: {$contributionRecurID}<p>"; return false; } $objects['contributionRecur'] =& $recur; } } else { // we are in event mode // make sure event exists and is valid require_once 'CRM/Event/DAO/Event.php'; $event =& new CRM_Event_DAO_Event(); $event->id = $ids['event']; if ($ids['event'] && !$event->find(true)) { CRM_Core_Error::debug_log_message("Could not find event: {$eventID}"); echo "Failure: Could not find event: {$eventID}<p>"; return false; } $objects['event'] =& $event; require_once 'CRM/Event/DAO/Participant.php'; $participant =& new CRM_Event_DAO_Participant(); $participant->id = $ids['participant']; if ($ids['participant'] && !$participant->find(true)) { CRM_Core_Error::debug_log_message("Could not find participant: {$participantID}"); echo "Failure: Could not find participant: {$participantID}<p>"; return false; } $participant->register_date = CRM_Utils_Date::isoToMysql($participant->register_date); $objects['participant'] =& $participant; $paymentProcessorID = $objects['event']->payment_processor_id; } if (!$paymentProcessorID) { if ($required) { CRM_Core_Error::debug_log_message("Could not find payment processor for contribution record: {$contributionID}"); echo "Failure: Could not find payment processor for contribution record: {$contributionID}<p>"; return false; } } else { require_once 'CRM/Core/BAO/PaymentProcessor.php'; $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($paymentProcessorID, $contribution->is_test ? 'test' : 'live'); $ids['paymentProcessor'] = $paymentProcessorID; $objects['paymentProcessor'] =& $paymentProcessor; } return true; }
/** * combine all the exportable fields from the lower levels object * * @return array array of exportable Fields * @access public */ function &exportableFields() { if (!self::$_exportableFields) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } require_once 'CRM/Pledge/DAO/Pledge.php'; $fields = CRM_Pledge_DAO_Pledge::export(); require_once 'CRM/Pledge/DAO/Payment.php'; $fields = array_merge($fields, CRM_Pledge_DAO_Payment::export()); //set title to calculated fields $calculatedFields = array('pledge_total_paid' => array('title' => ts('Total Paid')), 'pledge_balance_amount' => array('title' => ts('Balance Amount')), 'pledge_next_pay_date' => array('title' => ts('Next Payment Date')), 'pledge_next_pay_amount' => array('title' => ts('Next Payment Amount')), 'pledge_payment_paid_amount' => array('title' => ts('Paid Amount')), 'pledge_payment_paid_date' => array('title' => ts('Paid Date'))); $fields = array_merge($fields, $calculatedFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Pledge')); self::$_exportableFields = $fields; } return self::$_exportableFields; }
/** * Function to delete all pledge payments * * @param int $id pledge id * * @access public * @static * */ static function deletePayments($id) { require_once 'CRM/Utils/Rule.php'; if (!CRM_Utils_Rule::positiveInteger($id)) { return false; } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $payment = new CRM_Pledge_DAO_Payment(); $payment->pledge_id = $id; if ($payment->find(true)) { //also delete associated contribution. if ($payment->contribution_id) { require_once 'CRM/Contribute/BAO/Contribution.php'; CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } $transaction->commit(); return true; }
function loadObjects(&$input, &$ids, &$objects, $required) { $contribution =& $objects['contribution']; $objects['membership'] = null; $objects['contributionRecur'] = null; $objects['contributionType'] = null; $objects['event'] = null; $objects['participant'] = null; $objects['pledge_payment'] = null; require_once 'CRM/Contribute/DAO/ContributionType.php'; $contributionType = new CRM_Contribute_DAO_ContributionType(); $contributionType->id = $contribution->contribution_type_id; if (!$contributionType->find(true)) { CRM_Core_Error::debug_log_message("Could not find contribution type record: {$contributionTypeID}"); echo "Failure: Could not find contribution type record for {$contributionTypeID}<p>"; return false; } $objects['contributionType'] = $contributionType; $paymentProcessorID = null; if ($input['component'] == 'contribute') { // retrieve the other optional objects first so // stuff down the line can use this info and do things // CRM-6056 if (isset($ids['membership'])) { require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $ids['membership']; if (!$membership->find(true)) { CRM_Core_Error::debug_log_message("Could not find membership record: {$membershipID}"); echo "Failure: Could not find membership record: {$membershipID}<p>"; return false; } $membership->join_date = CRM_Utils_Date::isoToMysql($membership->join_date); $membership->start_date = CRM_Utils_Date::isoToMysql($membership->start_date); $membership->end_date = CRM_Utils_Date::isoToMysql($membership->end_date); $membership->reminder_date = CRM_Utils_Date::isoToMysql($membership->reminder_date); $objects['membership'] =& $membership; } if (isset($ids['pledge_payment'])) { require_once 'CRM/Pledge/DAO/Payment.php'; $objects['pledge_payment'] = array(); foreach ($ids['pledge_payment'] as $key => $paymentID) { $payment = new CRM_Pledge_DAO_Payment(); $payment->id = $paymentID; if (!$payment->find(true)) { CRM_Core_Error::debug_log_message("Could not find pledge payment record: {$pledge_paymentID}"); echo "Failure: Could not find pledge payment record: {$pledge_paymentID}<p>"; return false; } $objects['pledge_payment'][] = $payment; } } if (isset($ids['contributionRecur'])) { require_once 'CRM/Contribute/DAO/ContributionRecur.php'; $recur = new CRM_Contribute_DAO_ContributionRecur(); $recur->id = $ids['contributionRecur']; if (!$recur->find(true)) { CRM_Core_Error::debug_log_message("Could not find recur record: {$contributionRecurID}"); echo "Failure: Could not find recur record: {$contributionRecurID}<p>"; return false; } $objects['contributionRecur'] =& $recur; //get payment processor id from recur object. $paymentProcessorID = $recur->payment_processor_id; } //for normal contribution get the payment processor id. if (!$paymentProcessorID) { if ($contribution->contribution_page_id) { // get the payment processor id from contribution page $paymentProcessorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $contribution->contribution_page_id, 'payment_processor_id'); } //fail to load payment processor id. if (!$paymentProcessorID && !$contribution->contribution_page_id && !CRM_Utils_Array::value('pledge_payment', $ids)) { $loadObjectSuccess = true; if ($required) { $loadObjectSuccess = false; CRM_Core_Error::debug_log_message("Could not find contribution page for contribution record: {$contributionID}"); echo "Failure: Could not find contribution page for contribution record: {$contributionID}<p>"; } return $loadObjectSuccess; } } } else { // we are in event mode // make sure event exists and is valid require_once 'CRM/Event/DAO/Event.php'; $event = new CRM_Event_DAO_Event(); $event->id = $ids['event']; if ($ids['event'] && !$event->find(true)) { CRM_Core_Error::debug_log_message("Could not find event: {$eventID}"); echo "Failure: Could not find event: {$eventID}<p>"; return false; } $objects['event'] =& $event; require_once 'CRM/Event/DAO/Participant.php'; $participant = new CRM_Event_DAO_Participant(); $participant->id = $ids['participant']; if ($ids['participant'] && !$participant->find(true)) { CRM_Core_Error::debug_log_message("Could not find participant: {$participantID}"); echo "Failure: Could not find participant: {$participantID}<p>"; return false; } $participant->register_date = CRM_Utils_Date::isoToMysql($participant->register_date); $objects['participant'] =& $participant; if (!$paymentProcessorID) { $paymentProcessorID = $objects['event']->payment_processor_id; } } $loadObjectSuccess = true; if ($paymentProcessorID) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($paymentProcessorID, $contribution->is_test ? 'test' : 'live'); $ids['paymentProcessor'] = $paymentProcessorID; $objects['paymentProcessor'] =& $paymentProcessor; } else { if ($required) { $loadObjectSuccess = false; CRM_Core_Error::debug_log_message("Could not find payment processor for contribution record: {$contributionID}"); echo "Failure: Could not find payment processor for contribution record: {$contributionID}<p>"; } } return $loadObjectSuccess; }
/** * Function to delete all pledge payments * * @param int $id pledge id * * @access public * @static * */ static function deletePayments($id) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $payment = new CRM_Pledge_DAO_Payment(); $payment->pledge_id = $id; $payment->find(); while ($payment->fetch()) { //also delete associated contribution. if ($payment->contribution_id) { require_once 'CRM/Contribute/BAO/Contribution.php'; CRM_Contribute_BAO_Contribution::deleteContribution($payment->contribution_id); } $payment->delete(); } $transaction->commit(); return true; }
/** * On delete contribution record update associated pledge payment and pledge. * * @param int $contributionID contribution id * * @access public * @static */ static function resetPledgePayment($contributionID) { //get all status require_once 'CRM/Contribute/PseudoConstant.php'; $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'); require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $payment = new CRM_Pledge_DAO_Payment(); $payment->contribution_id = $contributionID; if ($payment->find(true)) { $payment->contribution_id = 'null'; $payment->status_id = array_search('Pending', $allStatus); $payment->scheduled_date = NULL; $payment->reminder_date = NULL; $payment->save(); //update pledge status. $pledgeID = $payment->pledge_id; $pledgeStatusID = self::calculatePledgeStatus($pledgeID); CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_Pledge', $pledgeID, 'status_id', $pledgeStatusID); $payment->free(); } $transaction->commit(); return true; }