>I have a client that is moving a VFP6 app from a local to a regional level, and now requires an extension to handle an additional level of tax calculation. Any pointers to a better solution I am more than willing to consider. Table structure changes and rules are allowed :>)
>
>As of now, I have (3) numerics holding state, county, and local tax rates. To deal with clothing sales, we also have (3) logicals to determine the exempt status, .T. indicating that clothing is exempt in this jurisdiction. To add to my grief, NYS does not exempt any one item >$110. Up to this point, I have been handling it similar to the below pseudocode:
>
>IF saleitem >$110
> totaltaxrate = statetax+countytax
> do_the_calc_and_storeit()
>ELSE
> DO CASE
> CASE state_exempt AND county_exempt
> totaltaxrate = 0
> do_the_calc_and_storeit()
> CASE state_exempt AND !county_exempt
> totaltaxrate = countytaxrate
> do_the_calc_and_storeit()
> CASE !state_exempt AND !county_exempt
> totaltaxrate = statetaxrate + countytaxrate
> do_the_calc_and_storeit()
> ENDCASE
>ENDIF
>
I'd just make it as general as possible, and as table-driven as possible. Having worked in two countries where the rules changed few times a year (at some point Yugoslav sales' tax had about 40 categories with as many different rates), I've learned a few rules:
- each item sold has to have all the rates and indicators copied into its record for historical reasons; if later you need to recalculate or revert anything, you can't rely on the lookups anymore, as the values and conditions there have probably changed already
- the item record has to have the date on it, so if there's some change somewhere in the rules, you can apply them starting with the date the rule is effective
- round each value before you add; don't calculate the total tax rate and multiply by it, calculate the amout of each tax then round them to cents and add them. That's the way the accountants calculate, and if they ever want to check, they'll check the adding and not the total roundoff error. They don't care about the roundoff, they want it added precisely to the cent.
As to table-driven, you can have a memo with the expression in your rules table, and eval() the expression as needed, so your "saleitem >$110" can be such an expression; you can fire the rules one by one until you get the rule with no expression or an expression which returns .t.
Also, why not
totaltaxrate=iif(state_exempt, 0, staterate)+iif(county_exempt,0,countyrate)+...
That's the one which will surely fire and you don't have to have all the combinations in separate case statements.