Skip to content

AutoCalculation Engine

Because invoices can come in a very wide variety of formats and specifically where the line level information may not have all of the values required to balance the invoice, we provide our auto calculation engine which will attempt to balance the transaction in the Unit4 system.

The engine will use the available information to calculate row data but in some cases it must make assumptions about the Tax rates etc.

The typical scenario is Net, Tax and Gross on the header but all lines are Net with no Tax or Tax rates.

We can work out the tax rate from the header, but we then have to assume this rate on all lines because we have no information to tell us otherwise.

You should also have some default tax codes defined for non-po invoices as the EI02 will require valid tax codes where possible. These are defined in the system setup value ERPOCR_TAX_CODES

Parameters

This is controlled with three parameters (but also takes account of ERPOCR_EI02_NOTAX and ERPOCR_TAX_CODES)

ERPOCR_CALC_AMOUNTS

This is the on/off switch for the autocalculation engine but it is not a simple on or off as it can take different values in the text2 field

If text2 is set to 1 the system will calculate when a PO is downloaded, added or changed or a tax code is added or changed (original behaviour)

If set to 2, the system will calculate on the above and every time the data is downloaded from Rossum regardless of PO.

ERPOCR_CALC_ALLOW_RATES

This contains a comma separated list of tax rates that the system is allowed to assume when calculating the line amounts. For example in the UK we would have 0,5,20

ERPOCR_CALC_AUTOFIX

This allows the engine to autofix small rounding differences on to the largest line. For example if text2 is set to 0.1 then it will be allowed to put a maximum of £0.1 extra on the largest line.

Logic

The system will run through the following logic:

Header Level Processing

  1. First check Does the document already balance

    1. I.e. line net tax and gross equal header amounts
    2. OR ei02_no_tax is in use and the header balances
      1. If so then no further action
  2. Second check Do the net lines = gross head and the invoice doesn't balance on gross OR do the gross lines = the net head and the net doesn't balance

    1. If so then update the line net to gross or gross to net
  3. We then generate an assumed rate based on the header amounts and check if it is in the list of allowable rates.

Per Line Processing

4. If both the net and gross on the line are zero then we exit as we can't calculate

5. Third check Do we have a tax code from the line coding or the PO

6. NO Tax Code

The system will recalculate the amounts on the lines

7. Tax Code is ZERO OR the vat percent OR factor vat on the code are zero.

The system will recalculate the amounts on the lines using this set of checks in order

If(netAmount !=0 and the net balances to the header then set newGrossAmount = netAmount; and set newNetAmount = netAmount;

Otherwise set newGrossAmount = grossAmount; newNetAmount = grossAmount;

8. Tax Code is NOT ZERO AND have a valid percentage.

The system will recalculate the amounts on the lines based on the tax percentage