[ic] GST/PST solution?

Jud Harris interchange-users@interchange.redhat.com
Fri Oct 12 10:35:01 2001


Hi folks -

I've searched the archives extensively for this answer, and have found some
stuff.

http://interchange.redhat.com/archive/interchange-users/1999/msg06750.html
http://interchange.redhat.com/archive/interchange-users/1999/msg06751.html
http://interchange.redhat.com/archive/interchange-users/2000/msg10007.html

I'm setting up a store with a global GST tax, on all products and on all
provinces (in CA).  That's not a problem.  Only some products, however, will
need to included the PST, only in Ontario.

The msg10007 above looks like the best solution.  Has there been any further
development or integration of this?  It mentions it might be included in
4.7.x and 4.8, but I don't see it.

At any rate, I've tried it, but I'm having a problem getting the UserTag
code in the interchange.cfg (catalog.cfg, tried both..) to compile.

Here's what I've got in the interchange.cfg -

UserTag vat-calc Order table field
UserTag vat-calc addAttr
UserTag vat-calc Routine <<EOR
sub {
        my ($table, $field, $opt) = @_;

        my $error = sub {
                my $msg = shift;
                Log($msg);
                return undef;
        }

        foreach my $item (@$Vend::Items) {
                my $taxrate = tag_data($table, $field, $item->{code});
                $tax += ($taxrate * $item->{quantity});
        }
        return $tax;
}
EOR 

--- 

When I IC starts, it report this error:

UserTag 'vat_calc' subroutine failed compilation:

         syntax error at (eval 13) line 10, near "}

        my "
Global symbol "$tax" requires explicit package name at (eval 13) line 10,
<GLOBAL> line 115.
Global symbol "$tax" requires explicit package name at (eval 13) line 13,
<GLOBAL> line 115.
Global symbol "$tax" requires explicit package name at (eval 13) line 15,
<GLOBAL> line 115.

In line 115 of the configuration file 'interchange.cfg':
UserTag vat-calc Routine <<EOR

------

When the code is in the catalog.cfg, I get:

UserTag 'vat_calc' subroutine failed safe check: syntax error at (eval 136)
line 10, near "}

        my "

In line 23 of the configuration file 'catalog.cfg':
UserTag vat-calc Routine <<EOR

----

I tried changing the variable names and messed with packages, but to no
avail.  I've been out of the perl loop for a while.  It seems to always die
of the 'my $tax = 0;' line - why?

I'm confident that if I get this UserTag working, I can do the rest.  It
just needs to successfully compile first.

Anyone out there have any ideas?

thanks!
-Jud

what I'm following is below:

Quoting Rene Hertell (rene@hertell.com):
> Hi list!
> 
> I have been browsing the mail-archives for a while and trying to find an
> clear and easy solution in solving the tax-problem that probably many of the
> European minivend-users bump into. As many of you know, the tax is based on
> product-categories.
> 
> Does anyone have a simple solution (I'm a real amateur with this...) in how
> to solve this issue. It would be nice have a solution that would use the
> normal [salestax] tag. The prices are given in the productdb without tax.
> 
> 
> 
> Here a small example: The db contains a field with the tax percentage. This
> field should then be used when calculating the basket.
> 
> products.txt db
> name         price     tax
> toothbrush   10.00     0.22
> toothpaste   20.00     0.22
> a book       35.00     0.17
> 
> 
> 
> Basket:
> 
> Item         qty    price   tax   incl tax
> toothbrush   1      10.00  2.20      12.20
> toothpaste   1      20.00  4.40      24.40
> a book       1      35.00  7.70      42.70
> 

There are several ways to do it. For Interchange 4.8 (and later 4.7.x)
I will have a UI to help do this.

The thing I like best is to create a new *shipping* method and
add tax with mv_handling. I will probably be using this method.

The quick and dirty way is to write a UserTag which does it
and then include that in salestax.asc.

UserTag  vat-calc  Order  table    field
UserTag  vat-calc  addAttr
UserTag  vat-calc  Routine <<EOR
sub {
    my ($table, $field, $opt) = @_;

    my $error = sub {
        my $msg = shift;
        Log($msg);
        return undef;
    };

    my $tax = 0;
    foreach my $item (@$Vend::Items) {
        my $taxrate = tag_data($table, $field, $item->{code});
        $tax += ($taxrate * $item->{quantity});
    }
    return $tax;
}
EOR

(If you put the above in your catalog.cfg instead of interchange.cfg, you
will
have to make sure you have referenced the products table before you call
it.)

Now this in salestax.asc:

    default    [vat-calc products tax]
    UK    [vat-calc products tax]
    FR    [vat-calc products tax]
    US    0

and this in catalog.cfg:

    SalesTax   country

should do it. You can also key it on category if you want, simply by
creating a "tax" table and using:

    AutoModifier  products:category

Now use $item->{category} to key into the table for getting the tax
rate by percentage of price. (Obviously you will have to calculate the
price somehow, but that is not too difficult depending on your CommonAdjust
definition.)