Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-17418

Cancelling a taxable contribution writes incorrect values to the database

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.6.9
    • Fix Version/s: 4.6.11
    • Component/s: CiviContribute
    • Labels:
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code

      Description

      We've had a client lodge an issue where tax rates are removed as part of the basic amount and then re-added as a tax calculation when a contribution is cancelled, instead of being removed from their respective accounts.

      Description of the issue as it was sent to us follows:

      Scenario (steps to reproduce)

      1. Enable Sales Tax with amounts shown inclusive of tax.
      2. Create Sales Tax liability account (‘GST’) with 10% rate.
      3. Create taxable financial types (stand-alone contribution, membership fee, event fee) with GST referenced as Sales Tax account.
      4. Create a new contribution record (with or without a related membership or event record) with a manually entered or default amount (no price-set used), status of ‘Completed’, payment instrument ‘Cash’. GST will be calculated and a tax-inclusive total amount displayed and recorded correctly in the database.
      5. Cancel the contribution record by editing it, changing status to ‘Cancelled’, and saving the record.

      Result

      The contribution record is correctly displayed as cancelled in the interface with the original (tax-inclusive) amount shown.

      The amount written back to the contribution table is correct, being the total (inclusive of tax) of the contribution (i.e. -1 x original total contribution inclusive of tax).

      However, the net (income) amount and the tax amounts are incorrectly written back in the financial items table and entity financial transactions table:

      • The tax-inclusive amount is written back to the income account (i.e. -1 x original total contributions inclusive of tax), instead of the tax-exclusive amount.
      • The tax amount is written back to the tax account but with the wrong sign (i.e. 1 x original tax amount, instead of -1 x original tax amount).

      Amounts in the civicrm_contribution and civicrm_financial_trxn table are correct with only the tax-inclusive value of the total contribution written and written back.

      Amounts in the civicrm_line_item table are correct and unaffected by the cancellation.

      Tables affected, with invalid data:

      • civicrm_entity_financial_trxn
      • civicrm_financial_item Test example

      A test contribution of $90 (excluding GST) was made. GST of $9 was calculated correctly by Civi on entry of the contribution amount field, and the GST and total contribution of $99 was recorded correctly in the interface and all database tables when saved. The contribution record was immediately cancelled by clicking Edit, changing the payment status to ‘Cancelled’ and clicking Save.

      A summary of the relevant data in the affected tables before and after cancelling the contribution follows:

      Table: civicrm_entity_financial_trxn

      Before:
      Records: 3

      1. _contribution 99
      2. _financial_item (Income) 90
      3. _financial_item (GST) 9

      After:
      Records: 6

      1. _contribution 99 original – unchanged
      2. _financial_item (Income) 90 original – unchanged
      3. _financial_item (GST) 9 original – unchanged
      4. _contribution -99 new - valid
      5. _financial_item (Income) -99 new – invalid (should be -90)
      6. _financial_item (GST) 9 new – invalid (should be -9: note sign)

      Table: civicrm_financial_item

      Before:
      Records: 2

      1. Contribution Amount 90
      2. GST 9

      After:
      Records: 4

      1. Contribution Amount 90 original – unchanged
      2. GST 9 original – unchanged
      3. Contribution Amount -99 new – invalid (should be -90)
      4. GST 9 new – invalid (should be -9 note sign)

      Comments

      Note that re-testing the same example as above, but using an amount from a price-set, did not yield the same errors. All amounts appeared to be recorded and reversed correctly in all tables.

      It therefore appears that the error occurs for those contributions (stand-alone, membership or event fee) where the amount is taxable and no price-set exists.

      Testing was performed on a production database running CiviCRM 4.6.9 under Drupal 7.38 with MySQL 5.1.73 and PHP 5.3.3.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                monish.deb Monish Deb
                Reporter:
                agileware Agileware
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: