[interchange-cvs] interchange - heins modified lib/Vend/Interpolate.pm
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Tue Feb 18 18:11:01 2003
User: heins
Date: 2003-02-18 23:10:42 GMT
Modified: lib/Vend Interpolate.pm
Log:
* Add ability to tax shipping and handling on a per-country or state basis
in VAT mode. Add mv_shipping=NN% key to tax hash, likewise with mv_handling=NN.N%.
Change conceived and coded by Jonathon Clark with minimal change from me.
Revision Changes Path
2.148 +45 -26 interchange/lib/Vend/Interpolate.pm
rev 2.148, prev_rev 2.147
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.147
retrieving revision 2.148
diff -u -r2.147 -r2.148
--- Interpolate.pm 12 Feb 2003 03:59:12 -0000 2.147
+++ Interpolate.pm 18 Feb 2003 23:10:42 -0000 2.148
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.147 2003/02/12 03:59:12 mheins Exp $
+# $Id: Interpolate.pm,v 2.148 2003/02/18 23:10:42 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.147 $, 10);
+$VERSION = substr(q$Revision: 2.148 $, 10);
@EXPORT = qw (
@@ -6288,42 +6288,61 @@
next;
}
elsif ($t =~ /handling:(.*)/) {
- my @modes = grep /\S/, split /[\s,]+/, $1;
-
- my $cost = 0;
- $cost += tag_handling($_) for @modes;
+ my @modes = grep /\S/, split /[\s,]+/, $1;
+
+ my $cost = 0;
+ $cost += tag_handling($_) for @modes;
$total += $cost;
next;
- }
- my $tax;
+ }
+ my $tax;
#::logDebug("tax type=$t");
if($t =~ /^(\d+(?:\.\d+)?)\s*(\%)$/) {
- my $rate = $1;
- $rate /= 100 if $2;
- my $amount = Vend::Interpolate::taxable_amount();
+ my $rate = $1;
+ $rate /= 100 if $2;
+ my $amount = Vend::Interpolate::taxable_amount();
$total += ($rate * $amount);
- }
- else {
+ }
+ else {
$tax = Vend::Util::get_option_hash($t);
- }
+ }
#::logDebug("tax hash=" . uneval($tax));
- my $pfield = $opt->{tax_category_field}
- || $::Variable->{MV_TAX_CATEGORY_FIELD}
- || 'tax_category';
- my @pfield = split /:+/, $pfield;
+ my $pfield = $opt->{tax_category_field}
+ || $::Variable->{MV_TAX_CATEGORY_FIELD}
+ || 'tax_category';
+ my @pfield = split /:+/, $pfield;
- for my $item (@$Vend::Items) {
+ for my $item (@$Vend::Items) {
my $rhash = tag_data($item->{mv_ib}, undef, $item->{code}, { hash => 1});
- my $cat = join ":", @{$rhash}{@pfield};
- my $rate = defined $tax->{$cat} ? $tax->{$cat} : $tax->{default};
+ my $cat = join ":", @{$rhash}{@pfield};
+ my $rate = defined $tax->{$cat} ? $tax->{$cat} : $tax->{default};
#::logDebug("item $item->{code} cat=$cat rate=$rate");
- $rate =~ s/\s*%\s*$// and $rate /= 100;
- next if $rate <= 0;
- my $sub = Vend::Data::item_subtotal($item);
+ $rate =~ s/\s*%\s*$// and $rate /= 100;
+ next if $rate <= 0;
+ my $sub = Vend::Data::item_subtotal($item);
#::logDebug("item $item->{code} subtotal=$sub");
- $total += $sub * $rate;
+ $total += $sub * $rate;
#::logDebug("tax total=$total");
- }
+ }
+
+ ## Add some tax on shipping if rate for mv_shipping category is set
+ if ($tax->{mv_shipping} > 0) {
+ my $rate = $tax->{mv_shipping};
+ $rate =~ s/\s*%\s*$// and $rate /= 100;
+ my $sub = tag_shipping() * $rate;
+#::logDebug("applying shipping tax rate of $rate, tax of $sub");
+ $total += $sub;
+ }
+
+ ## Add some tax on handling if rate for mv_handling category is set
+ if ($tax->{mv_handling} > 0) {
+ my $rate = $tax->{mv_handling};
+ $rate =~ s/\s*%\s*$// and $rate /= 100;
+ my $sub = tag_handling() * $rate;
+#::logDebug("applying handling tax rate of $rate, tax of $sub");
+ $total += $sub;
+ }
+
}
return $total;
}