$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) {
- if (!empty($lastFinancialTrxnId['financialTrxnId'])) {
- 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 {
- if ($params['total_amount'] < 0) {
- $params['trxnParams']['payment_instrument_id'] = $params['prevContribution']->payment_instrument_id;
+ if (!empty($lastFinancialTrxnId['financialTrxnId'])) {
+ if ($params['total_amount'] != $params['trxnParams']['total_amount']) {
$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'];
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();
+ civicrm_api3('entityFinancialTrxn', 'create', $entityFinancialTrxnParams);
}
}
}