// CRM-16189
CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID);
- if (!isset($params['tax_amount']) && $setPrevContribution && (isset($params['total_amount']) || isset
- ($params['financial_type_id']))) {
+ if (!isset($params['tax_amount']) && $setPrevContribution && (isset($params['total_amount']) ||
+ isset($params['financial_type_id']))) {
$params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params);
}
$itemAmount = $params['trxnParams']['total_amount'] + $cancelledTaxAmount;
}
elseif ($context == 'changePaymentInstrument') {
+ $deferredFinancialAccount = CRM_Utils_Array::value('deferred_financial_account_id', $params);
+ if (empty($deferredFinancialAccount)) {
+ $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Deferred Revenue Account is' "));
+ $deferredFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $relationTypeId);
+ }
+ $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC', FALSE, NULL, $deferredFinancialAccount);
if ($params['trxnParams']['total_amount'] < 0) {
- $deferredFinancialAccount = CRM_Utils_Array::value('deferred_financial_account_id', $params);
- if (empty($deferredFinancialAccount)) {
- $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Deferred Revenue Account is' "));
- $deferredFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($params['prevContribution']->financial_type_id, $relationTypeId);
- }
- $lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($params['prevContribution']->id, 'DESC', FALSE, NULL, $deferredFinancialAccount);
if (!empty($lastFinancialTrxnId['financialTrxnId'])) {
- $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
if ($params['total_amount'] > 0) {
+ $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
$params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
}
else {
+ $params['trxnParams']['to_financial_account_id'] = $params['to_financial_account_id'];
$params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
}
}
}
else {
- $params['trxnParams']['to_financial_account_id'] = $params['to_financial_account_id'];
if ($params['total_amount'] < 0) {
+ $params['trxnParams']['net_amount'] = $params['trxnParams']['total_amount'];
$params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
+ $params['trxnParams']['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $lastFinancialTrxnId['financialTrxnId'], 'to_financial_account_id');
}
else {
+ $params['trxnParams']['to_financial_account_id'] = $params['to_financial_account_id'];
$params['trxnParams']['payment_instrument_id'] = $params['contribution']->payment_instrument_id;
}
}
return;
}
}
-
$trxn = CRM_Core_BAO_FinancialTrxn::create($params['trxnParams']);
$params['entity_id'] = $trxn->id;
if ($context != 'changePaymentInstrument') {
}
}
}
+ if ($context == 'changePaymentInstrument') {
+ foreach ($params['line_item'] as $lineitems) {
+ foreach ($lineitems as $fieldValueId => $fieldValues) {
+ $prevFinancialItem = CRM_Financial_BAO_FinancialItem::getPreviousFinancialItem($fieldValues['id']);
+ if (!CRM_Utils_Rule::currencyCode($trxn->currency)) {
+ $trxn->currency = CRM_Core_Config::singleton()->defaultCurrency;
+ }
+
+ // save to entity_financial_trxn table
+ $entityFinancialTrxnParams = array(
+ 'entity_table' => "civicrm_financial_item",
+ 'entity_id' => $prevFinancialItem->id,
+ 'financial_trxn_id' => $trxn->id,
+ 'amount' => $trxn->total_amount,
+ 'currency' => $trxn->currency,
+ );
+ $entityTrxn = new CRM_Financial_DAO_EntityFinancialTrxn();
+ $entityTrxn->copyValues($entityFinancialTrxnParams);
+ $entityTrxn->save();
+ }
+ }
+ }
CRM_Core_BAO_FinancialTrxn::createDeferredTrxn(CRM_Utils_Array::value('line_item', $params), $params['contribution'], TRUE, $context);
}
WHERE con.id = %1 AND ft.to_financial_account_id <> %3
GROUP BY ft.id";
-
$queryParams = array(
1 => array($contributionId, 'Integer'),
2 => array($feeFinancialAccount, 'Integer'),
3 => array($arAccount, 'Integer'),
);
$resultDAO = CRM_Core_DAO::executeQuery($sql, $queryParams);
-
$statuses = CRM_Contribute_PseudoConstant::contributionStatus();
while ($resultDAO->fetch()) {