omfgppc - 2009-03-10

You have subscribed to a wiki page or wiki category on "xTuple" for change =

The "EnhancedTaxInternationalization" page has been changed by jrogelstad:

=

* It should be possible to define tax calculations that are calculated a=
gainst the result of another tax calculation (i.e. taxes on taxes).
=

-  * It should be possible to define tax assignments that calculate tax the=
cumulative sum of the base price item and an multiple other taxes.
+  * It should be possible to define tax assignments that calculate tax the=
cumulative sum of the base price item and multiple other taxes.
=

* Tax rates should have effective and expiration dates.
=

@@ -124, +124 @@

=

. {{attachment:taxClass.png}}
=

+ The group sequence is used for calculating cumulative taxes as described =
below.
=3D=3D=3D Tax Registration =3D=3D=3D
Tax registration will be altered as pictured to include both tax zone and=
tax authority.  The tax zone may be ~Any~ or a selected zone.  Notes will =
be added to the tax registration for reporting.
=

@@ -139, +140 @@

=

. {{attachment:taxAssignments.png}}
=

+ The tax assignments window also allows users to have a visual cue of the =
relationship of group sequences.  These numbers designate cumulative tax gr=
oupings.  Cumulative taxes are calculated in order of group sequence.  As t=
ax codes in each sequence are processed all the taxes are cumulatively adde=
d to a running total.   The running total of a sequence is added to the bas=
e price number in the next sequence so that tax codes in subsequent sequenc=
es consider the base price and all the taxes calculated in the previous seq=
uence as the basis for their tax calculation.
=3D=3D=3D Tax Assignment =3D=3D=3D
The Tax Selection window will be renamed "Tax Assignment" as pictured, an=
d reference tax zone in lieu of tax authority.
=

@@ -285, +287 @@

=

=3D=3D Basic Algorithms =3D=3D
. '''Deriving Subordinate Taxes'''
+ =

Because taxes may be nested by having one tax based on the results of ano=
ther, we will need a utility table function that returns a row set of all t=
he taxes that are subordinate to another.  This function will take argument=
s of a tax code and a current tax level, and run recursively to return all =
tax codes and their respective levels subordinate to the tax code id passed=
in the argument.
=

First our function requires a new composite type called '''subtax'''.
+ =

{{{
- CREATE TYPE subtax AS =

+ CREATE TYPE subtax AS
(
subtax_taxcode_id integer,
subtax_taxcode_code text,
@@ -298, +302 @@

)
}}}
Then we can build our '''getSubTax''' function
+ =

{{{
CREATE OR REPLACE FUNCTION getSubTax(INTEGER, INTEGER) RETURNS SET OF  su=
btax AS \$\$
DECLARE
pTaxCodeId ALIAS FOR \$1;
pLevel ALIAS FOR \$2;
-   _row subtax%ROWTYPE
+   _row subtax%ROWTYPE;
+   _x RECORD;
+   _y RECORD;
BEGIN
+   FOR _x IN Select all tax codes whose calculation basis is pTaxCodeId
+   LOOP
+     Map result to _row.  Level is pLevel + 1.
+     RETURN NEXT _row
+ =

+     FOR _y IN  Select getSubTax(_x tax id, pLevel + 1).  This is the recu=
rsive part.
+     LOOP
+       Map result to _row.
+       RETURN NEXT _row
+ =

+ ... close loops and function
+ =

}}}
+ The results should look something like this:
+ select * from getSubTax(7,1);  -- Where 7 is system assigned tax code id =
for  "ED-10 - Education Tax".
+ ||<tablewidth=3D"200px" tablealign=3D"">subtax_taxcode_id||subtax_taxcode=
_code||subtax_taxcode_descrip||subtax_taxcode_level||
+ ||12||EC||Eduction Cess||2||
+ ||17||HEC||Higher Education Cess||3||
+ =

=

. '''taxassignments'''
=

@@ -326, +351 @@

);
}}}
Then we can build our function
+ =

{{{
CREATE OR REPLACE FUNCTION taxAssignments(INTEGER, INTEGER) RETURNS SETOF=
taxassign AS \$\$
DECLARE
@@ -544, +570 @@

ALTER TABLE tax ADD COLUMN tax_basis_tax_id integer REFERENCES tax (tax_i=