Skip to content

Instantly share code, notes, and snippets.

@JoeMurray
Last active May 21, 2020 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoeMurray/6db6a82ff6c9e593ca5301b5f8708f52 to your computer and use it in GitHub Desktop.
Save JoeMurray/6db6a82ff6c9e593ca5301b5f8708f52 to your computer and use it in GitHub Desktop.
issue with 2020-04-16 financial transactions on contributions with other dates
Background: A 2014-10-04 contribution with bank fee was imported 2020-04-01. A change in its financial type that changed the revenue financial account was made on 2020-04-16.
Bug 1: the value in civicrm_financial_trxn.fee_amount for reversal transaction 193392 should be the negative of the original amount, ie -0.39 rather than 0.39. This would result in the net_amount value for that record being -9.61 (correct) rather than -10.39 (incorrect).
Bug 2: on import via api, the civicrm_financial_item.transaction_date for the banking fee record is incorrectly set to the import date rather than the transaction date (ie for record 41350 below, the date should be 2014-10-04 13:55:26).
MariaDB [mydb]> select * from civicrm_financial_trxn where id in (143964,143965,193392,193393);
+--------+---------------------------+-------------------------+---------------------+--------------+------------+------------+----------+------------+---------------+------------------+-----------+----------------------+-----------------------+--------------+--------------+----------------+-----------------+
| id | from_financial_account_id | to_financial_account_id | trxn_date | total_amount | fee_amount | net_amount | currency | is_payment | trxn_id | trxn_result_code | status_id | payment_processor_id | payment_instrument_id | card_type_id | check_number | pan_truncation | order_reference |
+--------+---------------------------+-------------------------+---------------------+--------------+------------+------------+----------+------------+---------------+------------------+-----------+----------------------+-----------------------+--------------+--------------+----------------+-----------------+
| 143964 | NULL | 6 | 2014-10-04 13:55:26 | 10.00 | 0.39 | 9.61 | CAD | 1 | CH+0003533766 | NULL | 1 | NULL | 10 | NULL | NULL | NULL | NULL |
| 143965 | 6 | 5 | 2014-10-04 13:55:26 | 0.39 | 0.00 | 0.39 | CAD | 0 | CH+0003533766 | NULL | 1 | NULL | 10 | NULL | NULL | NULL | NULL |
| 193392 | NULL | 6 | 2020-04-16 17:41:56 | -10.00 | 0.39 | -10.39 | CAD | 1 | CH+0003533766 | NULL | 1 | NULL | 10 | NULL | NULL | NULL | NULL |
| 193393 | NULL | 6 | 2020-04-16 17:41:56 | 10.00 | 0.39 | 9.61 | CAD | 1 | CH+0003533766 | NULL | 1 | NULL | 10 | NULL | NULL | NULL | NULL |
+--------+---------------------------+-------------------------+---------------------+--------------+------------+------------+----------+------------+---------------+------------------+-----------+----------------------+-----------------------+--------------+--------------+----------------+-----------------+
4 rows in set (0.001 sec)
MariaDB [mydb]> select * from civicrm_financial_item fi inner join civicrm_entity_financial_trxn eft on fi.id=eft.entity_id AND eft.entity_table='civicrm_financial_item' and eft.financial_trxn_id in (143964,143965,193392,193393);
+-------+---------------------+---------------------+------------+---------------------+--------+----------+----------------------+-----------+------------------------+-----------+--------+------------------------+-----------+-------------------+--------+
| id | created_date | transaction_date | contact_id | description | amount | currency | financial_account_id | status_id | entity_table | entity_id | id | entity_table | entity_id | financial_trxn_id | amount |
+-------+---------------------+---------------------+------------+---------------------+--------+----------+----------------------+-----------+------------------------+-----------+--------+------------------------+-----------+-------------------+--------+
| 41349 | 2020-04-01 13:50:11 | 2014-10-04 13:55:26 | 15864 | Contribution Amount | 10.00 | CAD | 1 | 1 | civicrm_line_item | 475 | 82698 | civicrm_financial_item | 41349 | 143964 | 10.00 |
| 41350 | 2020-04-01 13:50:11 | 2020-04-01 13:50:11 | 1 | Fee | 0.39 | CAD | 5 | 1 | civicrm_financial_trxn | 143964 | 82700 | civicrm_financial_item | 41350 | 143965 | 0.39 |
| 90777 | 2020-04-16 17:41:56 | 2014-10-04 13:55:26 | 15864 | Contribution Amount | -10.00 | CAD | 1 | 1 | civicrm_line_item | 475 | 181554 | civicrm_financial_item | 90777 | 193392 | -10.00 |
| 90778 | 2020-04-16 17:41:56 | 2014-10-04 13:55:26 | 15864 | Contribution Amount | 10.00 | CAD | 117 | 1 | civicrm_line_item | 475 | 181556 | civicrm_financial_item | 90778 | 193393 | 10.00 |
+-------+---------------------+---------------------+------------+---------------------+--------+----------+----------------------+-----------+------------------------+-----------+--------+------------------------+-----------+-------------------+--------+
4 rows in set (0.001 sec)
@JoeMurray
Copy link
Author

Making public in order to report to core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment