How to use Views to calculate final balance based on custom content entity?

by gbmapo   Last Updated June 12, 2019 15:07 PM

In a custom module (SEL), I have a custom Content Entity (Transaction) with these fields:

$fields['dateoftransaction'] = BaseFieldDefinition::create('datetime')
$fields['transaction'] = BaseFieldDefinition::create('string')
$fields['from_person_id'] = BaseFieldDefinition::create('entity_reference')
$fields['to_person_id'] = BaseFieldDefinition::create('entity_reference')
$fields['valueoftransaction'] = BaseFieldDefinition::create('integer')

from_person_id and to_person_id are references to another Content Entity (basically, a Person with FirstName, Lastname, Cellphone number).

At the end of the transaction, from_person_id has a credit of valueoftransaction while to_person_id has a debit of the same amount.

I'd like to use Views to list all the persons with their final balance (Sum of valueoftransaction where person is 'from' minus Sum of valueoftransaction where person is 'to') considering all the transactions they are involved in.
How can I do that?

Tags : views 8

Related Questions

Updated February 28, 2018 21:07 PM

Updated May 26, 2016 09:03 AM

Updated July 20, 2015 13:03 PM

Updated January 12, 2017 08:03 AM

Updated May 02, 2015 23:03 PM