$contributionStatus = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', (int) $params['contribution_status_id']);
if (!$contributionID
- && CRM_Utils_Array::value('membership_id', $params)
+ && !empty($params['membership_id'])
&& Civi::settings()->get('deferred_revenue_enabled')
) {
$memberStartDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $params['membership_id'], 'start_date');
CRM_Core_BAO_Note::add($noteParams);
}
- // make entry in batch entity batch table
- if (!empty($params['batch_id'])) {
- // in some update cases we need to get extra fields - ie an update that doesn't pass in all these params
- $titleFields = [
- 'contact_id',
- 'total_amount',
- 'currency',
- 'financial_type_id',
- ];
- $retrieveRequired = 0;
- foreach ($titleFields as $titleField) {
- if (!isset($contribution->$titleField)) {
- $retrieveRequired = 1;
- break;
- }
- }
- if ($retrieveRequired == 1) {
- $contribution->find(TRUE);
- }
- }
-
CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution);
$transaction->commit();
CRM_Core_BAO_CustomField::getFieldsForImport('Contribution', FALSE, FALSE, FALSE, $checkPermission)
);
+ $fields['financial_type_id']['title'] = ts('Financial Type ID');
+
self::$_exportableFields = $fields;
}
if (empty($resultDAO->payment_processor_id) && CRM_Core_Permission::check('edit contributions')) {
$links = [
CRM_Core_Action::UPDATE => [
- 'name' => "<i class='crm-i fa-pencil'></i>",
+ 'name' => ts('Edit Payment'),
+ 'icon' => 'fa-pencil',
'url' => 'civicrm/payment/edit',
'class' => 'medium-popup',
'qs' => "reset=1&id=%%id%%&contribution_id=%%contribution_id%%",
* @return bool
* @throws Exception
*/
- public function loadRelatedObjects(&$input, &$ids, $loadAll = FALSE) {
+ 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
*/
public static function recordFinancialAccounts(&$params, $financialTrxnValues = NULL) {
$skipRecords = $update = $return = $isRelatedId = FALSE;
+ $isUpdate = !empty($params['prevContribution']);
$additionalParticipantId = [];
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
if (empty($params['prevContribution'])) {
$entityID = NULL;
}
- else {
- $update = TRUE;
- }
$statusId = $params['contribution']->contribution_status_id;
// CRM-13964 partial payment
$params['trxnParams'] = $trxnParams;
- if (!empty($params['prevContribution'])) {
+ if ($isUpdate) {
$updated = FALSE;
$params['trxnParams']['total_amount'] = $trxnParams['total_amount'] = $params['total_amount'] = $params['prevContribution']->total_amount;
$params['trxnParams']['fee_amount'] = $params['prevContribution']->fee_amount;
$newFinancialAccount = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship($params['financial_type_id'], $accountRelationship);
if ($oldFinancialAccount != $newFinancialAccount) {
$params['total_amount'] = 0;
+ // If we have a fee amount set reverse this as well.
+ if (isset($params['fee_amount'])) {
+ $params['trxnParams']['fee_amount'] = 0 - $params['fee_amount'];
+ }
if (in_array($params['contribution']->contribution_status_id, $pendingStatus)) {
$params['trxnParams']['to_financial_account_id'] = CRM_Financial_BAO_FinancialAccount::getFinancialAccountForFinancialTypeByRelationship(
$params['prevContribution']->financial_type_id, $accountRelationship);
/* $params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id']; */
$params['financial_account_id'] = $newFinancialAccount;
$params['total_amount'] = $params['trxnParams']['total_amount'] = $params['trxnParams']['net_amount'] = $trxnParams['total_amount'];
+ // Set the transaction fee amount back to the original value for creating the new positive financial trxn.
+ if (isset($params['fee_amount'])) {
+ $params['trxnParams']['fee_amount'] = $params['fee_amount'];
+ }
self::updateFinancialAccounts($params);
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE);
$params['trxnParams']['to_financial_account_id'] = $trxnParams['to_financial_account_id'];
}
}
- if (!$update) {
+ else {
// records finanical trxn and entity financial trxn
// also make it available as return value
self::recordAlwaysAccountsReceivable($trxnParams, $params);
}
// record line items and financial items
if (empty($params['skipLineItem'])) {
- CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $update);
+ CRM_Price_BAO_LineItem::processPriceSet($entityId, CRM_Utils_Array::value('line_item', $params), $params['contribution'], $entityTable, $isUpdate);
}
// create batch entry if batch_id is passed and
public static function checkTaxAmount($params, $isLineItem = FALSE) {
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
- // This function should be only called after standardisation (removal of
- // thousand separator & using a decimal point for cents separator.
- // However, we don't know if that is always true :-(
- // There is a deprecation notice tho :-)
- $unknownIfMoneyIsClean = empty($params['skipCleanMoney']) && !$isLineItem;
// Update contribution.
if (!empty($params['id'])) {
// CRM-19126 and CRM-19152 If neither total or financial_type_id are set on an update
empty($params['skipLineItem']) && !$isLineItem
) {
$taxRateParams = $taxRates[$params['financial_type_id']];
- $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount(CRM_Utils_Array::value('total_amount', $params), $taxRateParams, $unknownIfMoneyIsClean);
+ $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount(CRM_Utils_Array::value('total_amount', $params), $taxRateParams);
$params['tax_amount'] = round($taxAmount['tax_amount'], 2);
// Get Line Item on update of contribution
// update line item of contrbution
if (isset($params['financial_type_id']) && array_key_exists($params['financial_type_id'], $taxRates) && $isLineItem) {
$taxRate = $taxRates[$params['financial_type_id']];
- $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['line_total'], $taxRate, $unknownIfMoneyIsClean);
+ $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($params['line_total'], $taxRate);
$params['tax_amount'] = round($taxAmount['tax_amount'], 2);
}
}
* @param array $ids
* @param array $objects
* @param CRM_Core_Transaction $transaction
- * @param CRM_Contribute_BAO_Contribution $contribution
+ * It is not recommended to pass this in. The calling function handle it's own roll back if it wants it.
* @param bool $isPostPaymentCreate
* Is this being called from the payment.create api. If so the api has taken care of financial entities.
* Note that our goal is that this would only ever be called from payment.create and never handle financials (only
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public static function completeOrder($input, &$ids, $objects, $transaction, $contribution, $isPostPaymentCreate = FALSE) {
+ public static function completeOrder($input, &$ids, $objects, $transaction = NULL, $isPostPaymentCreate = FALSE) {
+ if (!$transaction) {
+ $transaction = new CRM_Core_Transaction();
+ }
+ $contribution = $objects['contribution'];
$primaryContributionID = $contribution->id ?? $objects['first_contribution']->id;
// The previous details are used when calculating line items so keep it before any code that 'does something'
if (!empty($contribution->id)) {