When doing an eConnect integration, it is common to get data from a web site that includes only the header level taxes.
eConnect requires that we provide taxes on a detail level, so the technique is to back into the line item taxes and tax details. Since we'll be dividing and rounding to do that, there will be rounding errors at the end; we'll make a final 'adjustment' in the tax amounts to deal with the errant pennies.
The web site sends you 'MyTaxSchedule' and the header level tax of $xx.xx, the tax rate is 8.5%
We know that MyTaxSchedule is made up of:
- MyStateDetail (6%)
- MyCountyDetail (1%)
- MyCityDetail (.5%)
For each line in the order, we have to figure what the tax should be for each of the three tax details (so, for a two line order, we have six tax detail lines).
Then, at the end, we sum up our work and make a correction to deal with the pennies.
The code below is straight out of production; the data source that was used was an XML file that was serialized into a Class (a very cool technique); the main class is called oGreatPlainsIntegration. The GreatPlainsIntegration class contains a Batch class. That class has a Customer class, the Customer class has the DocumentHeader class; the DocumentHeader class contains the DocumentLines class. I didn't invent that; that's the way the web site sends it.