/** * Function to delete membership Payments * * @param int $id * @static */ static function del($id) { $dao = new CRM_Member_DAO_MembershipPayment(); $dao->id = $id; $result = FALSE; if ($dao->find(TRUE)) { $dao->delete(); $result = TRUE; } return $result; }
/** * Add or update a link between contribution and membership * * @param array $params (reference ) input parameters * * @return array (reference ) membership_payment_id of created or updated record * {@getfields MembershipPayment_create} * @example MembershipPaymentCreate.php * @access public */ function civicrm_api3_membership_payment_create($params) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $mpDAO = new CRM_Member_DAO_MembershipPayment(); $mpDAO->copyValues($params); $result = $mpDAO->save(); if (is_a($result, 'CRM_Core_Error')) { $transaction->rollback(); return civicrm_api3_create_error($result->_errors[0]['message']); } $transaction->commit(); _civicrm_api3_object_to_array($mpDAO, $mpArray[$mpDAO->id]); return civicrm_api3_create_success($mpArray, $params); }
/** * Retrieve the contribution id for the associated Membership id. * @todo we should get this off the line item * * @param int $membershipId * Membership id. * * @return int * contribution id */ public static function getMembershipContributionId($membershipId) { $membershipPayment = new CRM_Member_DAO_MembershipPayment(); $membershipPayment->membership_id = $membershipId; if ($membershipPayment->find(TRUE)) { return $membershipPayment->contribution_id; } return NULL; }
/** * Delete the record that are associated with this Membership Payment * * @param int $membershipId membsership id. * * @return boolean true if deleted false otherwise * @access public */ static function deleteMembershipPayment($membershipId) { require_once 'CRM/Member/DAO/MembershipPayment.php'; $membesrshipPayment = new CRM_Member_DAO_MembershipPayment(); $membesrshipPayment->membership_id = $membershipId; $membesrshipPayment->find(); while ($membesrshipPayment->fetch()) { require_once 'CRM/Contribute/BAO/Contribution.php'; CRM_Contribute_BAO_Contribution::deleteContribution($membesrshipPayment->contribution_id); CRM_Utils_Hook::pre('delete', 'MembershipPayment', $membesrshipPayment->id, $membesrshipPayment); $membesrshipPayment->delete(); CRM_Utils_Hook::post('delete', 'MembershipPayment', $membesrshipPayment->id, $membesrshipPayment); } return $membesrshipPayment; }
/** * Function to record contribution record associated with membership * * @param array $params array of submitted params * @param array $ids (param in process of being removed - try to use params) array of ids * * @return void * @static */ static function recordMembershipContribution(&$params, $ids = array()) { $membershipId = $params['membership_id']; $contributionParams = array(); $config = CRM_Core_Config::singleton(); $contributionParams['currency'] = $config->defaultCurrency; $contributionParams['receipt_date'] = CRM_Utils_Array::value('receipt_date', $params) ? $params['receipt_date'] : 'null'; $contributionParams['source'] = CRM_Utils_Array::value('contribution_source', $params); $contributionParams['soft_credit'] = CRM_Utils_Array::value('soft_credit', $params); $contributionParams['non_deductible_amount'] = 'null'; $recordContribution = array('contact_id', 'total_amount', 'receive_date', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'invoice_id', 'is_test', 'honor_contact_id', 'honor_type_id', 'contribution_status_id', 'check_number', 'campaign_id', 'is_pay_later'); foreach ($recordContribution as $f) { $contributionParams[$f] = CRM_Utils_Array::value($f, $params); } // make entry in batch entity batch table if (CRM_Utils_Array::value('batch_id', $params)) { $contributionParams['batch_id'] = $params['batch_id']; } if (CRM_Utils_Array::value('contribution_contact_id', $params)) { // deal with possibility of a different person paying for contribution $contributionParams['contact_id'] = $params['contribution_contact_id']; } if (CRM_Utils_Array::value('processPriceSet', $params) && !empty($params['lineItems'])) { $contributionParams['line_item'] = CRM_Utils_Array::value('lineItems', $params, NULL); } $contribution = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); // store contribution id $params['contribution_id'] = $contribution->id; //insert payment record for this membership if (!CRM_Utils_Array::value('contribution', $ids) || CRM_Utils_Array::value('is_recur', $params)) { $mpDAO = new CRM_Member_DAO_MembershipPayment(); $mpDAO->membership_id = $membershipId; $mpDAO->contribution_id = $contribution->id; if (CRM_Utils_Array::value('is_recur', $params)) { $mpDAO->find(); } CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $mpDAO); $mpDAO->save(); CRM_Utils_Hook::post('create', 'MembershipPayment', $mpDAO->id, $mpDAO); } return $contribution; }
/** * returns the list of fields that can be exported * * @access public * return array * @static */ static 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['membership_payment'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * Retrieve one / all contribution(s) / membership(s) linked to a * membership / contrbution. * * @param array $params (reference ) input parameters * * @return array (reference ) array of properties, if error an array with an error id and error message * @static void * @access public */ function &civicrm_membershipcontributionlink_get(&$params) { _civicrm_initialize(); if (empty($params)) { return civicrm_create_error(ts('No input parameters present')); } if (!is_array($params)) { return civicrm_create_error(ts('Input parameters is not an array')); } require_once 'CRM/Member/DAO/MembershipPayment.php'; $mpDAO = new CRM_Member_DAO_MembershipPayment(); $mpDAO->copyValues($params); $mpDAO->id = CRM_Utils_Array::value('membership_contribution_id', $params); $mpDAO->find(); $values = array(); while ($mpDAO->fetch()) { _civicrm_object_to_array($mpDAO, $mpArray); $mpArray['membership_contribution_id'] = $mpDAO->id; unset($mpArray['id']); $values[$mpDAO->id] = $mpArray; } return $values; }