[ic] Calculating saletax for individual items
Mike Heins
interchange-users@icdevgroup.org
Sat May 3 14:14:02 2003
Quoting Jamie Neil (jamie@versado.net):
> Quoting mike:
> > > UserTag addtax Order amount cat notax
> > > UserTag addtax addAttr
> > > UserTag addtax Routine <<EOR
> > > sub {
> > > my ($amount, $cat, $notax, $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';
> > > my $type ||= $Tag->data($ctable, $c_taxfield, $country);
> > > return currency( $amount, $ref->{noformat} ) if ! $type;
> > > $type =~ s/^\s+//;
> > > $type =~ s/\s+$//;
> > > my $tax = Vend::Util::get_option_hash($type);
> > > my $taxrate = defined $tax->{$cat} ? $tax->{$cat} : $tax->{default};
> > > $taxrate =~ s/\s*%\s*$// and $taxrate /= 100;
> > > $amount += $amount * $taxrate;
> > > return currency( $amount, $ref->{noformat} );
> > > }
> > > EOR
> > >
> >
> > Looks perfect to me. I like your coding style! 8-)
>
> Guess I should have mentioned that it's basically a stripped down
> version of the tax_vat sub in Interpolate.pm. _My_ coding style
> sucks ;).
But you picked up on the way to translate it to a UserTag, with the
addAttr causing the $ref, and the noformat option of the tag being
available to pass to currency().
A lot of people miss that; it is a powerful technique but seems
lost on many.
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.513.523.7621 <mike@perusion.com>
I don't want to get to the end of my life and find I have just
lived the length of it. I want to have lived the width of it as
well. -- Diane Ackerman