*
* @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;
}
]
);
}
- $typeField = CRM_Financial_DAO_FinancialType::export();
+
$financialAccount = CRM_Financial_DAO_FinancialAccount::export();
$contributionPage = array(
),
);
- $fields = array_merge($fields, $typeField, $contributionPage,
+ $fields = array_merge($fields, $contributionPage,
$contributionNote, $extraFields, $softCreditFields, $financialAccount, $campaignTitle,
CRM_Core_BAO_CustomField::getFieldsForImport('Contribution', FALSE, FALSE, FALSE, $checkPermission)
);
}
}
+ /**
+ * Get memberships realted to the contribution.
+ *
+ * @param int $contributionID
+ *
+ * @return array
+ */
+ protected static function getRelatedMemberships($contributionID) {
+ $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'];
+ }
+
/**
* @inheritDoc
*/
}
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
*/
* @throws \CiviCRM_API3_Exception
*/
public static function updateMembershipBasedOnCompletionOfContribution($contribution, $primaryContributionID, $changeDate) {
- $contribution->loadRelatedMembershipObjects();
- if (empty($contribution->_relatedObjects['membership'])) {
- return;
- }
- $memberships = $contribution->_relatedObjects['membership'];
- foreach ($memberships as $membershipTypeIdKey => $membership) {
- if ($membership) {
- $membershipParams = array(
- 'id' => $membership->id,
- 'contact_id' => $membership->contact_id,
- 'is_test' => $membership->is_test,
- 'membership_type_id' => $membership->membership_type_id,
- 'membership_activity_status' => 'Completed',
- );
+ $memberships = self::getRelatedMemberships($contribution->id);
+ foreach ($memberships as $membership) {
+ $membershipParams = array(
+ 'id' => $membership['id'],
+ 'contact_id' => $membership['contact_id'],
+ 'is_test' => $membership['is_test'],
+ 'membership_type_id' => $membership['membership_type_id'],
+ 'membership_activity_status' => 'Completed',
+ );
- $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'],
- $membershipParams['membership_type_id'],
- $membershipParams['is_test'],
- $membershipParams['id']
- );
+ $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'],
+ $membershipParams['membership_type_id'],
+ $membershipParams['is_test'],
+ $membershipParams['id']
+ );
- // CRM-8141 update the membership type with the value recorded in log when membership created/renewed
- // this picks up membership type changes during renewals
- // @todo this is almost certainly an obsolete sql call, the pre-change
- // membership is accessible via $this->_relatedObjects
- $sql = "
+ // CRM-8141 update the membership type with the value recorded in log when membership created/renewed
+ // this picks up membership type changes during renewals
+ // @todo this is almost certainly an obsolete sql call, the pre-change
+ // membership is accessible via $this->_relatedObjects
+ $sql = "
SELECT membership_type_id
FROM civicrm_membership_log
WHERE membership_id={$membershipParams['id']}
ORDER BY id DESC
LIMIT 1;";
- $dao = CRM_Core_DAO::executeQuery($sql);
- if ($dao->fetch()) {
- if (!empty($dao->membership_type_id)) {
- $membershipParams['membership_type_id'] = $dao->membership_type_id;
- }
+ $dao = CRM_Core_DAO::executeQuery($sql);
+ if ($dao->fetch()) {
+ if (!empty($dao->membership_type_id)) {
+ $membershipParams['membership_type_id'] = $dao->membership_type_id;
}
- $dao->free();
+ }
- $membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType(
- $membershipParams['membership_type_id'],
- $primaryContributionID
+ $membershipParams['num_terms'] = $contribution->getNumTermsByContributionAndMembershipType(
+ $membershipParams['membership_type_id'],
+ $primaryContributionID
+ );
+ // @todo remove all this stuff in favour of letting the api call further down handle in
+ // (it is a duplication of what the api does).
+ $dates = array_fill_keys(array(
+ 'join_date',
+ 'start_date',
+ 'end_date',
+ ), NULL);
+ if ($currentMembership) {
+ /*
+ * Fixed FOR CRM-4433
+ * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
+ * when Contribution mode is notify and membership is for renewal )
+ */
+ CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);
+
+ // @todo - we should pass membership_type_id instead of null here but not
+ // adding as not sure of testing
+ $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'],
+ $changeDate, NULL, $membershipParams['num_terms']
);
- // @todo remove all this stuff in favour of letting the api call further down handle in
- // (it is a duplication of what the api does).
- $dates = array_fill_keys(array(
- 'join_date',
- 'start_date',
- 'end_date',
- ), NULL);
- if ($currentMembership) {
- /*
- * Fixed FOR CRM-4433
- * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
- * when Contribution mode is notify and membership is for renewal )
- */
- CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);
-
- // @todo - we should pass membership_type_id instead of null here but not
- // adding as not sure of testing
- $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membershipParams['id'],
- $changeDate, NULL, $membershipParams['num_terms']
- );
- $dates['join_date'] = $currentMembership['join_date'];
- }
+ $dates['join_date'] = $currentMembership['join_date'];
+ }
- //get the status for membership.
- $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
- $dates['end_date'],
- $dates['join_date'],
- 'today',
- TRUE,
- $membershipParams['membership_type_id'],
- $membershipParams
- );
+ //get the status for membership.
+ $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'],
+ $dates['end_date'],
+ $dates['join_date'],
+ 'today',
+ TRUE,
+ $membershipParams['membership_type_id'],
+ $membershipParams
+ );
- unset($dates['end_date']);
- $membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
- //we might be renewing membership,
- //so make status override false.
- $membershipParams['is_override'] = FALSE;
- $membershipParams['status_override_end_date'] = 'null';
+ unset($dates['end_date']);
+ $membershipParams['status_id'] = CRM_Utils_Array::value('id', $calcStatus, 'New');
+ //we might be renewing membership,
+ //so make status override false.
+ $membershipParams['is_override'] = FALSE;
+ $membershipParams['status_override_end_date'] = 'null';
- //CRM-17723 - reset static $relatedContactIds array()
- // @todo move it to Civi Statics.
- $var = TRUE;
- CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
- civicrm_api3('Membership', 'create', $membershipParams);
- }
+ //CRM-17723 - reset static $relatedContactIds array()
+ // @todo move it to Civi Statics.
+ $var = TRUE;
+ CRM_Member_BAO_Membership::createRelatedMemberships($var, $var, TRUE);
+ civicrm_api3('Membership', 'create', $membershipParams);
}
}
* @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);