From 8cf01b22ec5c8a58c2837e0ce8355d9cad715cc1 Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Thu, 2 Oct 2014 17:47:38 -0700 Subject: [PATCH] CRM-15374 - exclude fee-related financial_trxn rows from balance calculations and view payments page. ---------------------------------------- * CRM-15374: https://issues.civicrm.org/jira/browse/CRM-15374 --- CRM/Contribute/BAO/Contribution.php | 10 +++++++++- CRM/Core/BAO/FinancialTrxn.php | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 98a802b755..fde8e741e6 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3334,6 +3334,8 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) } /** + * function to get list of payments displayed by Contribute_Page_PaymentInfo + * * @param $id * @param $component * @param bool $getTrxnInfo @@ -3385,6 +3387,11 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) $paymentBalance = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($id, $entity, FALSE, $total); $contributionIsPayLater = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'is_pay_later'); + + $feeRelationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' ")); + $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionId, 'financial_type_id'); + $feeFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $feeRelationTypeId); + if ($paymentBalance == 0 && $contributionIsPayLater) { $paymentBalance = $total; } @@ -3397,11 +3404,12 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) $info['payLater'] = $contributionIsPayLater; $rows = array(); if ($getTrxnInfo && $baseTrxnId) { + // Need to exclude fee trxn rows so filter out rows where TO FINANCIAL ACCOUNT is expense account $sql = " SELECT ft.total_amount, con.financial_type_id, ft.payment_instrument_id, ft.trxn_date, ft.trxn_id, ft.status_id, ft.check_number FROM civicrm_contribution con LEFT JOIN civicrm_entity_financial_trxn eft ON (eft.entity_id = con.id AND eft.entity_table = 'civicrm_contribution') - LEFT JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id + LEFT JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id AND ft.to_financial_account_id != {$feeFinancialAccount} WHERE con.id = {$contributionId} "; diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index 7008bf9607..c6afcd61b6 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -459,6 +459,8 @@ WHERE ceft.entity_id = %1"; $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' ")); $toFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $relationTypeId); + $feeRelationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Expense Account is' ")); + $feeFinancialAccount = CRM_Contribute_PseudoConstant::financialAccountType($financialTypeId, $feeRelationTypeId); if (empty($lineItemTotal)) { $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId); @@ -479,7 +481,7 @@ FROM civicrm_financial_trxn ft LEFT JOIN civicrm_entity_financial_trxn eft ON (ft.id = eft.financial_trxn_id AND eft.entity_table = 'civicrm_contribution') LEFT JOIN civicrm_contribution c ON (eft.entity_id = c.id) LEFT JOIN civicrm_participant_payment pp ON (pp.contribution_id = c.id) -WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFinancialAccount} +WHERE pp.participant_id = {$entityId} AND ft.to_financial_account_id != {$toFinancialAccount} AND ft.to_financial_account_id != {$feeFinancialAccount} AND ft.status_id IN ({$statusId}, {$refundStatusId}) "; $ftTotalAmt = CRM_Core_DAO::singleValueQuery($sqlFtTotalAmt); -- 2.25.1