Details
-
Type: Sub-task
-
Status: Open
-
Priority: Minor
-
Resolution: Unresolved
-
Affects Version/s: 4.7.16
-
Fix Version/s: Unscheduled
-
Component/s: CiviContribute
-
Labels:None
-
Versioning Impact:Patch (backwards-compatible bug fixes)
-
Documentation Required?:User and Admin Doc
-
Funding Source:Contributed Code
-
Verified?:No
Description
Wherever contribution view is provided, instead of displaying label for contribution.financial_type_id, display the names of the revenue financial accounts of each of the financial line items associated with the contribution, ie the result of
SELECT GROUP_CONCAT(fa.name ORDER BY fa.name SEPARATOR ', ') FROM civicrm_contribution c INNER JOIN civicrm_entity_financial_trxn eft1 ON c.id=eft1.entity_id AND eft1.entity_table='civicrm_contribution' INNER JOIN civicrm_entity_financial_trxn eft2 ON eft1.financial_trxn_id=eft2.financial_trxn_id AND eft2.entity_table='civicrm_financial_item' INNER JOIN civicrm_financial_item fi ON eft2.entity_id=fi.id INNER JOIN civicrm_financial_account fa ON fi.financial_account_id=fa.id WHERE c.id=%1
I'm sure that a less efficient but more maintainable API and PHP based approach is possible, eg find all financial items for a contribution, returning their financial_account, then do array_unique() on results.
An alternative could be to display the civicrm_financial_type.name of each line item. We should for various reasons of reporting require line items as well as financial_items from extensions and modules writing into the CiviCRM db. However, the connection between a financial type and its revenue financial account record in the financial_item.financial_account_id field is not guaranteed after the financial_item is recorded. If we display the financial type for the line item, the display may vary from what has been or will be exported to the accounting software, which would be problematic. So I don't think this is a workable or good idea.
Wherever payment view is provided with financial type column eg on contribution view for quick config price set, display the names of the revenue financial accounts associated with the payment. In this case, the query should be based on the financial_trxn of the payments, rather than the contribution. The following draft query gets the line items for just one payment, and would need to be changed to get them for all the appropriate financial trxn for a contributions that has gone through edits and partial payments and refunds etc.
SELECT GROUP_CONCAT(fa.name ORDER BY fa.name SEPARATOR ', ') FROM civicrm_financial_trxn ft INNER JOIN civicrm_entity_financial_trxn eft ON ft.id=eft.financial_trxn_id AND eft.entity_table='civicrm_financial_item' INNER JOIN civicrm_financial_item fi ON eft.entity_id=fi.id INNER JOIN civicrm_financial_account fa ON fi.financial_account_id=fa.id WHERE ft.id=%1
Again, a more appropriate approach would be to use API to find all current, uncancelled line items for a contribution, returning their financial type, and then do array_unique() on that.
Note: this issue does not deal with editing contributions. It also is a single step towards a full solution that replaces contribution.financial_type_id with line item financial types in reports and searches and any other places it is used in the codebase.