[ic] Calculating saletax for individual items

Jamie Neil interchange-users@icdevgroup.org
Fri May 2 18:10:01 2003


> -----Original Message-----
> From: interchange-users-admin@icdevgroup.org
> [mailto:interchange-users-admin@icdevgroup.org]On Behalf Of Andy Mayer
> Sent: 02 May 2003 22:25
> To: Interchange Users
> Subject: [ic] Calculating saletax for individual items
>
>
> Hi,
>
> I have setup 4.9.6 to use UK VAT. My country tax setup and item's
> tax_category are been correctly used when the cart calculates the total
> salestax for all items in the cart.
>
> But I would like to know what the salestax value is for each
> *individual* item rather than just for the whole cart (as displayed by
> [salestax]). Basically, I want to modify the flypage and search results
> to display the full price including tax. So my question is: Is there a
> built-in way to access the applicable tax for an individual item? Or do
> I have to write a UserTag [price-with-tax] that does the lookup using
> tax_category and parse the tax field from the country table?

Andy,

I wanted to do the same thing, but found no built in mechanism for
displaying prices with tax. So I wrote a usertag.

This is probably not the best or most efficient way of doing this (as
several better coders will no doubt point out soon enough). The function of
the tag is to add tax at the correct rate to any supplied figure. This means
it can be wrapped around the price, subtotal and other tags as required. It
is only designed to work with tax type "multi" where tax categories are
stored in the country table, but could be adapted to support the other
systems.

Syntax: [addtax amount tax_category nontaxable noformat] [addtax
amount="amount" cat="tax_category" notax="nontaxable" noformat="noformat"]

amount - unformatted price
cat - tax category (from country table)
notax - whether the amount should be taxed or not (0|1)
noformat - returns unformated figure (0|1)

Example usage:

[addtax [item-price noformat=1][item-field tax_category][item-field
nontaxable]]

addtax.tag
----------

UserTag addtax              Order        amount cat notax
UserTag addtax              addAttr
UserTag addtax              Routine   <<EOR
sub {
        my ($amount, $cat, $notax, $ref) = @_;
::logDebug("amount=$amount, cat=$cat, notax=$notax, ref=$ref");
        return currency( $amount, $ref->{noformat} ) if $notax;
        my $cfield = $::Variable->{MV_COUNTRY_FIELD} || 'country';
        my $country = $ref->{country} || $::Values->{$cfield};
        return 0 if ! $country;
        my $ctable   = $ref->{country_table}
                                || $::Variable->{MV_COUNTRY_TABLE}
                                || 'country';
        my $c_taxfield   = $ref->{country_tax_field}
                                || $::Variable->{MV_COUNTRY_TAX_FIELD}
                                || 'tax';
#::logDebug("ctable=$ctable c_taxfield=$c_taxfield country=$country");
        my $type ||= $Tag->data($ctable, $c_taxfield, $country);
        return currency( $amount, $ref->{noformat} ) if ! $type;
#::logDebug("tax type=$type");
        $type =~ s/^\s+//;
        $type =~ s/\s+$//;
        my $tax = Vend::Util::get_option_hash($type);
#::logDebug("tax hash=" . uneval($tax));
        my $taxrate = defined $tax->{$cat} ? $tax->{$cat} : $tax->{default};
#::logDebug("cat=$cat rate=$taxrate");
        $taxrate =~ s/\s*%\s*$// and $taxrate /= 100;
        $amount += $amount * $taxrate;
#::logDebug("amount=$amount");
        return currency( $amount, $ref->{noformat} );
}
EOR

Hope it's of some use (it works for me anyway)

Jamie Neil

>
> Thanks again for a first class product!
>
> Andy
>
>
>
> _______________________________________________
> interchange-users mailing list
> interchange-users@icdevgroup.org
> http://www.icdevgroup.org/mailman/listinfo/interchange-users
>