progressivetech / net.ourpowerbase.sumfields

The Summary Fields extension creates read-only custom data fields that extend Contact and are automatically populated with up-to-date totals such as total lifetime contributions, last contribution amount, last attended event, etc.
Other
8 stars 29 forks source link

use of civicrm_line_items table misses updated transactions #66

Open jmcclelland opened 5 years ago

jmcclelland commented 5 years ago

If you create a contribution for $1000.00, then a record is entered in:

If you realize you made a mistake and edit the amount of the contribution, changing it to $100, then:

Since we recently changed summary fields to calculate the totals from the civicrm_line_item table (to properly capture contributions made that are split between different financial types), we are now getting inaccurate results for contributions that have been updated since the civicrm_line_item table is not updated when a change is made.

To get the accurate results, we should be totalling the civicrm_financial_item's amount field instead of qty * unit_price in civicrm_line_item.

Here's an example query that would get a more accurate result: SELECT SUM(fi.amount) FROM civicrm_financial_item fi JOIN civicrm_line_item li ON li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item' AND contact_id = 54708;