*
* @var array
*/
- static $_importableFields = NULL;
+ public static $_importableFields = NULL;
/**
* Static field for all the contribution information that we can potentially export
*
* @var array
*/
- static $_exportableFields = NULL;
+ public static $_exportableFields = NULL;
/**
* Static field to hold financial trxn id's.
*
* @var array
*/
- static $_trxnIDs = NULL;
+ public static $_trxnIDs = NULL;
/**
* Field for all the objects related to this contribution
);
}
- CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
+ // reset the group contact cache for this group
+ // HACK: dave hack - these caches are murder!!!
+ // CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
if ($contributionID) {
CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution);
return $contribution;
}
- $null = NULL; // return by reference
+ // return by reference
+ $null = NULL;
return $null;
}
* @return array
*/
protected static function getRelatedMemberships($contributionID) {
- $contribution = new CRM_Contribute_BAO_Contribution();
- $contribution->id = $contributionID;
- $contribution->fetch(TRUE);
- $contribution->loadRelatedMembershipObjects();
- $result = CRM_Utils_Array::value('membership', $contribution->_relatedObjects, []);
- $memberships = [];
- foreach ($result as $membership) {
- if (empty($membership)) {
- continue;
- }
- // @todo - remove this again & just call api in the first place.
- _civicrm_api3_object_to_array($membership, $memberships[$membership->id]);
- }
- return $memberships;
+ $membershipPayments = civicrm_api3('MembershipPayment', 'get', [
+ 'return' => 'membership_id',
+ 'contribution_id' => (int) $contributionID,
+ ])['values'];
+ $membershipIDs = [];
+ foreach ($membershipPayments as $membershipPayment) {
+ $membershipIDs[] = $membershipPayment['membership_id'];
+ }
+ if (empty($membershipIDs)) {
+ return [];
+ }
+ // We could combine this with the MembershipPayment.get - we'd
+ // need to re-wrangle the params (here or in the calling function)
+ // as they would then me membership.contact_id, membership.is_test etc
+ return civicrm_api3('Membership', 'get', [
+ 'id' => ['IN' => $membershipIDs],
+ 'return' => ['id', 'contact_id', 'membership_type_id', 'is_test'],
+ ])['values'];
}
/**
}
else {
$whereClauses['financial_type_id'] = [
- 'IN (' . implode(',', array_keys($types)) . ')'
+ 'IN (' . implode(',', array_keys($types)) . ')',
];
}
return $whereClauses;
'subject' => ts('Payment failed at payment processor'),
'source_record_id' => $contributionID,
'source_contact_id' => CRM_Core_Session::getLoggedInContactID() ? CRM_Core_Session::getLoggedInContactID() :
- $contactID,
+ $contactID,
));
// CRM-20336 Make sure that the contribution status is Failed, not Pending.
strpos($dao->source, $source) !== FALSE
) {
$contributionId = $dao->contribution_id;
- $dao->free();
}
}
}
}
// else fall back to using current membership type
- $dao->free();
-
// Figure out number of terms
$numterms = 1;
$lineitems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contributionId);
);
}
- $updateResult['membership_end_date'] = CRM_Utils_Date::customFormat($dates['end_date'],
- '%B %E%f, %Y'
- );
$updateResult['updatedComponents']['CiviMember'] = $membership->status_id;
if ($processContributionObject) {
$processContribution = TRUE;
* @throws Exception
*/
public function loadRelatedObjects(&$input, &$ids, $loadAll = FALSE) {
+ // @todo deprecate this function - the steps should be
+ // 1) add additional functions like 'getRelatedMemberships'
+ // 2) switch all calls that refer to ->_relatedObjects to
+ // using the helper functions
+ // 3) make ->_relatedObjects noisy in some way (deprecation won't work for properties - hmm
+ // 4) make ->_relatedObjects protected
+ // 5) hone up the individual functions to not use rely on this having been called
+ // 6) deprecate like mad
if ($loadAll) {
$ids = array_merge($this->getComponentDetails($this->id), $ids);
if (empty($ids['contact']) && isset($this->contact_id)) {
}
}
+ // These are probably no longer accessed from anywhere
+ // @todo remove this line, after ensuring not used.
$ids = $this->loadRelatedMembershipObjects($ids);
if ($this->_component != 'contribute') {
'amount' => $additional->fee_amount,
);
$additional->save();
- $additional->free();
$template->assign('amount', $amount);
CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText);
}
return FALSE;
}
-
/**
* Function to record additional payment for partial and refund contributions.
*
$input['participant_id'] = $contribution->_relatedObjects['participant']->id;
}
elseif (!empty($contribution->_relatedObjects['membership'])) {
+ // @todo - use getRelatedMemberships instead
$input['contribution_mode'] = 'membership';
$contribution->contribution_status_id = $contributionParams['contribution_status_id'];
$contribution->trxn_id = CRM_Utils_Array::value('trxn_id', $input);
/**
* Load related memberships.
*
+ * @deprecated
+ *
* Note that in theory it should be possible to retrieve these from the line_item table
* with the membership_payment table being deprecated. Attempting to do this here causes tests to fail
* as it seems the api is not correctly linking the line items when the contribution is created in the flow
$membership->start_date = CRM_Utils_Date::isoToMysql($membership->start_date);
$membership->end_date = CRM_Utils_Date::isoToMysql($membership->end_date);
$this->_relatedObjects['membership'][$membership->membership_type_id] = $membership;
- $membership->free();
}
}
}
public static function recordPartialPayment($contribution, $params) {
$balanceTrxnParams['to_financial_account_id'] = self::getToFinancialAccount($contribution, $params);
- $fromFinancialAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contribution['financial_type_id'], 'Accounts Receivable Account is');
- $balanceTrxnParams['from_financial_account_id'] = $fromFinancialAccountId;
+ $balanceTrxnParams['from_financial_account_id'] = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship($contribution['financial_type_id'], 'Accounts Receivable Account is');
$balanceTrxnParams['total_amount'] = $params['total_amount'];
$balanceTrxnParams['contribution_id'] = $params['contribution_id'];
$balanceTrxnParams['trxn_date'] = CRM_Utils_Array::value('trxn_date', $params, CRM_Utils_Array::value('contribution_receive_date', $params, date('YmdHis')));
$balanceTrxnParams['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_FinancialTrxn', 'status_id', 'Completed');
$balanceTrxnParams['payment_instrument_id'] = CRM_Utils_Array::value('payment_instrument_id', $params, $contribution['payment_instrument_id']);
$balanceTrxnParams['check_number'] = CRM_Utils_Array::value('check_number', $params);
-
- // @todo the logic of this section seems very wrong. This code is ONLY reached from the Payment.create
- // routine so is_payment should ALWAYS be true
- $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
- $statusId = array_search('Completed', $contributionStatuses);
- if ($fromFinancialAccountId != NULL &&
- ($statusId == array_search('Completed', $contributionStatuses) || $statusId == array_search('Partially paid', $contributionStatuses))
- ) {
- $balanceTrxnParams['is_payment'] = 1;
- }
+ $balanceTrxnParams['is_payment'] = 1;
if (!empty($params['payment_processor'])) {
+ // I can't find evidence this is passed in - I was gonna just remove it but decided to deprecate as I see self::getToFinancialAccount
+ // also anticipates it.
+ CRM_Core_Error::deprecatedFunctionWarning('passing payment_processor is deprecated - use payment_processor_id');
$balanceTrxnParams['payment_processor_id'] = $params['payment_processor'];
}
return CRM_Core_BAO_FinancialTrxn::create($balanceTrxnParams);
$updatedStatusName = CRM_Utils_Array::value($updatedStatusId,
CRM_Member_PseudoConstant::membershipStatus()
);
- if ($updatedStatusName == 'Cancelled') {
- $statusMsg .= "<br />" . ts("Membership for %1 has been Cancelled.", array(1 => $userDisplayName));
- }
- elseif ($updatedStatusName == 'Expired') {
- $statusMsg .= "<br />" . ts("Membership for %1 has been Expired.", array(1 => $userDisplayName));
- }
- else {
- $endDate = CRM_Utils_Array::value('membership_end_date', $updateResult);
- if ($endDate) {
- $statusMsg .= "<br />" . ts("Membership for %1 has been updated. The membership End Date is %2.",
- array(
- 1 => $userDisplayName,
- 2 => $endDate,
- )
- );
- }
+
+ $statusNameMsgPart = 'updated';
+ switch ($updatedStatusName) {
+ case 'Cancelled':
+ case 'Expired':
+ $statusNameMsgPart = $updatedStatusName;
+ break;
}
+
+ $statusMsg .= "<br />" . ts("Membership for %1 has been %2.", array(1 => $userDisplayName, 2 => $statusNameMsgPart));
}
if ($componentName == 'CiviEvent') {
* Line items.
* @param bool $isARefund
* Is this a refund / negative transaction.
+ * @param int $previousLineItemTotal
*
* @return float
*/
$membershipParams['membership_type_id'] = $dao->membership_type_id;
}
}
- $dao->free();
$membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType(
$membershipParams['membership_type_id'],
* @param float $balance
* @param string $contributionStatus
*
- * @return array $actionLinks Links array containing:
- * -url
- * -title
+ * @return array
+ * $actionLinks Links array containing:
+ * -url
+ * -title
*/
protected static function getContributionPaymentLinks($id, $balance, $contributionStatus) {
if ($contributionStatus === 'Failed' || !CRM_Core_Permission::check('edit contributions')) {
$clauses = [];
foreach ($whereClauses as $key => $clause) {
- $clauses[] = 'b.' . $key . " " . implode(' AND b.' . $key, (array) $clause);
+ $clauses[] = 'b.' . $key . " " . implode(' AND b.' . $key, (array) $clause);
}
$whereClauseString = implode(' AND ', $clauses);