From: Pradeep Nayak Date: Wed, 25 Mar 2015 15:33:35 +0000 (+0530) Subject: -- CRM-15848, removed code to update financial_trxn table and create a new entry X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=18fdfcc3d52d25833467d834f25471f1ae5b80ec;p=civicrm-core.git -- CRM-15848, removed code to update financial_trxn table and create a new entry ---------------------------------------- * CRM-15848: Civiaccounts inconsistent with spec when adding partial event payment https://issues.civicrm.org/jira/browse/CRM-15848 --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 3144f84bc2..7e1568ebfb 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3504,7 +3504,7 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) $baseTrxnId = $baseTrxnId['financialTrxnId']; $isBalance = FALSE; } - if (empty($total) || $usingLineTotal) { + if (!CRM_Utils_Array::value('total_amount', $total) || $usingLineTotal) { // for additional participants if ($entityTable == 'civicrm_participant') { $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId); diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index de77175ebd..f6cfc85918 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -108,9 +108,12 @@ class CRM_Core_BAO_FinancialTrxn extends CRM_Financial_DAO_FinancialTrxn { $balanceAmtDAO = CRM_Core_DAO::executeQuery($q, $p); $ret = array(); + if ($balanceAmtDAO->N) { + $ret['total_amount'] = 0; + } while ($balanceAmtDAO->fetch()) { $ret['trxn_id'] = $balanceAmtDAO->id; - $ret['total_amount'] = $balanceAmtDAO->total_amount; + $ret['total_amount'] += $balanceAmtDAO->total_amount; } return $ret; diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 694b9773c7..5f5afaf801 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -2053,7 +2053,8 @@ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantI * @param int $contributionId */ public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL) { - $balanceAmt = $updatedAmount - $paidAmount; + $pendingAmount = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); + $balanceAmt = $updatedAmount - $paidAmount - CRM_Utils_Array::value('total_amount', $pendingAmount, 0); $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses); $pendingRefundStatusId = array_search('Pending refund', $contributionStatuses); @@ -2083,36 +2084,26 @@ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantI $updatedContributionDAO->total_amount = $updatedAmount; $updatedContributionDAO->tax_amount = $taxAmount; $updatedContributionDAO->save(); - - $ftDetail = CRM_Core_BAO_FinancialTrxn::getBalanceTrxnAmt($contributionId); + // adjusted amount financial_trxn creation - if (empty($ftDetail['trxn_id'])) { - $updatedContribution = CRM_Contribute_BAO_Contribution::getValues( - array('id' => $contributionId), - CRM_Core_DAO::$_nullArray, - CRM_Core_DAO::$_nullArray - ); - $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); - $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($updatedContribution->financial_type_id, $relationTypeId); - - $adjustedTrxnValues = array( - 'from_financial_account_id' => NULL, - 'to_financial_account_id' => $toFinancialAccount, - 'total_amount' => $balanceAmt, - 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'), - 'payment_instrument_id' => $updatedContribution->payment_instrument_id, - 'contribution_id' => $updatedContribution->id, - 'trxn_date' => date('YmdHis'), - 'currency' => $updatedContribution->currency, - ); - $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues); - } - else { - // update the financial trxn amount as well, as the fee selections has been updated - if ($balanceAmt != $ftDetail['total_amount']) { - CRM_Core_DAO::setFieldValue('CRM_Core_BAO_FinancialTrxn', $ftDetail['trxn_id'], 'total_amount', $balanceAmt); - } - } + $updatedContribution = CRM_Contribute_BAO_Contribution::getValues( + array('id' => $contributionId), + CRM_Core_DAO::$_nullArray, + CRM_Core_DAO::$_nullArray + ); + $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); + $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($updatedContribution->financial_type_id, $relationTypeId); + $adjustedTrxnValues = array( + 'from_financial_account_id' => NULL, + 'to_financial_account_id' => $toFinancialAccount, + 'total_amount' => $balanceAmt, + 'status_id' => CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name'), + 'payment_instrument_id' => $updatedContribution->payment_instrument_id, + 'contribution_id' => $updatedContribution->id, + 'trxn_date' => date('YmdHis'), + 'currency' => $updatedContribution->currency, + ); + $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues); } }