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')
- INNER JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id AND ft.to_financial_account_id != {$feeFinancialAccount}
-WHERE con.id = {$contributionId}
-";
+ SELECT GROUP_CONCAT(fa.`name`) as financial_account,
+ ft.total_amount,
+ 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')
+ INNER JOIN civicrm_financial_trxn ft ON ft.id = eft.financial_trxn_id
+ AND ft.to_financial_account_id != {$feeFinancialAccount}
+ INNER JOIN civicrm_entity_financial_trxn ef ON (ef.financial_trxn_id = ft.id AND ef.entity_table = 'civicrm_financial_item')
+ LEFT JOIN civicrm_financial_item fi ON fi.id = ef.entity_id
+ INNER JOIN civicrm_financial_account fa ON fa.id = fi.financial_account_id
+
+ WHERE con.id = {$contributionId}
+ GROUP BY ft.id
+ ";
// conditioned WHERE clause
if ($isBalance) {
$resultDAO = CRM_Core_DAO::executeQuery($sql);
$statuses = CRM_Contribute_PseudoConstant::contributionStatus();
- $financialTypes = CRM_Contribute_PseudoConstant::financialType();
+
while ($resultDAO->fetch()) {
$paidByLabel = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$paidByName = CRM_Core_PseudoConstant::getName('CRM_Core_BAO_FinancialTrxn', 'payment_instrument_id', $resultDAO->payment_instrument_id);
$val = array(
'total_amount' => $resultDAO->total_amount,
- 'financial_type' => $financialTypes[$resultDAO->financial_type_id],
+ 'financial_type' => $resultDAO->financial_account,
'payment_instrument' => $paidByLabel,
'receive_date' => $resultDAO->trxn_date,
'trxn_id' => $resultDAO->trxn_id,