[interchange-cvs] interchange - heins modified 2 files

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Sun Jul 28 01:29:00 2002


User:      heins
Date:      2002-07-28 05:28:13 GMT
Modified:  lib/Vend Interpolate.pm
Modified:  code/SystemTag salestax.coretag
Log:
* Upgrade salestax() capabililty to allow multiple levels of
  tax in "multi" mode. Also allow you to present differing
  tax rate shows:

      [loop list=3D"__TAX_AREA__"]
         Tax for [loop-code]: [salestax state=3D"[loop-code]"]
      [/loop]

  Allow country passing as well, as well as tax type. So
  you can do:

      [if value country eq 'CA']
      GST: [salestax tax-type=3DGST]
      PST: [salestax tax-type=3DPST]
      Tax total: [salestax]
      [/if]

  It gets better. Combined with a few fixes to Levies, you can do:

        Subtotal: [subtotal]
    [levy-list]
        [levy-param description]: [levy-param cost]
    [/levy-list]

  and get:

        Subtotal: 10.00
        GST: 0.80
        PST (MB): 0.60

  or:

        Subtotal: 10.00
        Salestax (OH): 0.55

  Depending on country and state. This arises from the settings:

    Levies  salestax gst pst shipping handling

    Levy    salestax    description         "Sales Tax (%s)"
    Levy    salestax    label               "Tax"
    Levy    salestax    part_number         SALESTAX
    Levy    salestax    include_if          "[if value country eq US]1[/if]"
    Levy    salestax    keep_if_zero        1
    Levy    salestax    type                salestax
    Levy    salestax    sort                002

    Levy    gst         description         GST
    Levy    gst         label               GST
    Levy    gst         part_number         GST
    Levy    gst         tax_type            GST
    Levy    gst         include_if          "[if value country eq CA]1[/if]"
    Levy    gst         keep_if_zero        1
    Levy    gst         type                salestax
    Levy    gst         sort                002

    Levy    pst         description         "PST (%s)"
    Levy    pst         label               PST
    Levy    pst         part_number         PST
    Levy    pst         tax_type            PST
    Levy    pst         include_if          "[if value country eq CA]1[/if]"
    Levy    pst         keep_if_zero        1
    Levy    pst         type                salestax
    Levy    pst         sort                003

    Levy    handling    type                shipping
    Levy    handling    part_number         HANDLING
    Levy    handling    mode_from_values    mv_handling
    Levy    handling    include_if          mv_handling
    Levy    handling    check_status        mv_handling
    Levy    handling    group               handling

    Levy    shipping    label               "Shipping"
    Levy    shipping    type                shipping
    Levy    shipping    part_number         SHIPPING
    Levy    shipping    mode_from_values    mv_shipmode
    Levy    shipping    check_status        mv_shipmode
    Levy    shipping    group               shipping

Revision  Changes    Path
2.92      +85 -27    interchange/lib/Vend/Interpolate.pm


rev 2.92, prev_rev 2.91
Index: Interpolate.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.91
retrieving revision 2.92
diff -u -r2.91 -r2.92
--- Interpolate.pm	25 Jul 2002 17:14:21 -0000	2.91
+++ Interpolate.pm	28 Jul 2002 05:28:12 -0000	2.92
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 #=20
-# $Id: Interpolate.pm,v 2.91 2002/07/25 17:14:21 kwalsh Exp $
+# $Id: Interpolate.pm,v 2.92 2002/07/28 05:28:12 mheins Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -27,7 +27,7 @@
 require Exporter;
 @ISA =3D qw(Exporter);
=20
-$VERSION =3D substr(q$Revision: 2.91 $, 10);
+$VERSION =3D substr(q$Revision: 2.92 $, 10);
=20
 @EXPORT =3D qw (
=20
@@ -2550,7 +2550,7 @@
 sub tag_counter {
     my $file =3D shift || 'etc/counter';
 	my $opt =3D shift;
-#::logDebug("counter: file=3D$file start=3D$opt->{start}");
+#::logDebug("counter: file=3D$file start=3D$opt->{start} sql=3D$opt->{sql}=
 caller=3D" . scalar(caller()) );
 	if($opt->{sql}) {
 		my ($tab, $seq) =3D split /:+/, $opt->{sql}, 2;
 		my $db =3D database_exists_ref($tab);
@@ -5831,9 +5831,9 @@
 	    my $use_modifier;
=20
 	    if ($::Variable->{MV_SHIP_MODIFIERS}){
-		my @pieces =3D grep {$_ =3D quotemeta $_} split(/[\s,|]+/,$::Variable->{=
MV_SHIP_MODIFIERS});
-		my $regex =3D join('|',@pieces);
-		$use_modifier =3D 1 if ($regex && $field =3D~ /^($regex)$/);
+			my @pieces =3D grep {$_ =3D quotemeta $_} split(/[\s,|]+/,$::Variable->=
{MV_SHIP_MODIFIERS});
+			my $regex =3D join('|',@pieces);
+			$use_modifier =3D 1 if ($regex && $field =3D~ /^($regex)$/);
 	    }
=20
 	    my $col_checked =3D 0;
@@ -6181,6 +6181,12 @@
=20
 sub fly_tax {
 	my ($area) =3D @_;
+
+	if(my $country_check =3D $::Variable->{TAXCOUNTRY}) {
+		$country_check =3D~ /\b$::Values->{country}\b/
+			or return 0;
+	}
+
 	if(! $area) {
 		my $zone =3D $Vend::Cfg->{SalesTax};
 		while($zone =3D~ m/(\w+)/g) {
@@ -6219,7 +6225,7 @@
=20
 sub tax_vat {
 	my($type, $opt) =3D @_;
-#::logDebug("entering VAT");
+#::logDebug("entering VAT, opts=3D" . ::uneval($opt));
 	my $cfield =3D $::Variable->{MV_COUNTRY_FIELD} || 'country';
 	my $country =3D $opt->{country} || $::Values->{$cfield};
=20
@@ -6230,15 +6236,18 @@
 	my $c_taxfield   =3D $opt->{country_tax_field}
 				|| $::Variable->{MV_COUNTRY_TAX_FIELD}
 				|| 'tax';
-#::logDebug("ctable=3D$ctable c_taxfield=3D$c_taxfield");
-	$type =3D tag_data($ctable, $c_taxfield, $country)
+#::logDebug("ctable=3D$ctable c_taxfield=3D$c_taxfield country=3D$country"=
);
+	$type ||=3D tag_data($ctable, $c_taxfield, $country)
 		or return 0;
 #::logDebug("tax type=3D$type");
 	$type =3D~ s/^\s+//;
 	$type =3D~ s/\s+$//;
+
+	my @taxes;
+
 	if($type =3D~ /^(\w+)$/) {
 		my $sfield =3D $1;
-		my $state  =3D $::Values->{$sfield};
+		my $state  =3D $opt->{state} || $::Values->{$sfield};
 		return 0 if ! $state;
 		my $stable   =3D $opt->{state_table}
 					|| $::Variable->{MV_STATE_TABLE}
@@ -6246,12 +6255,21 @@
 		my $s_taxfield   =3D $opt->{state_tax_field}
 					|| $::Variable->{MV_STATE_TAX_FIELD}
 					|| 'tax';
+		my $s_taxtype   =3D $opt->{tax_type_field}=20
+					|| $::Variable->{MV_TAX_TYPE_FIELD}
+					|| 'tax_name';
 		my $db =3D database_exists_ref($stable)
 			or return 0;
+		my $addl =3D '';
+		if($opt->{tax_type}) {
+			$addl =3D " AND $s_taxtype =3D " .
+					$db->quote($opt->{tax_type}, $s_taxtype);
+		}
 		my $q =3D qq{
 						SELECT $s_taxfield FROM $stable
 						WHERE  $cfield =3D '$country'
 						AND    $sfield =3D '$state'
+						$addl
 					};
 #::logDebug("tax state query=3D$q");
 		my $ary;
@@ -6261,32 +6279,43 @@
 		if($@) {
 			::logError("error on state tax query %s", $q);
 		}
-#::logDebug("query returns " . ::uneval($q));
+#::logDebug("query returns " . ::uneval($ary));
 		return 0 unless ref $ary;
-		return 0 unless $type =3D $ary->[0][0];
+		for(@$ary) {
+			next unless $_->[0];
+			push @taxes, $_->[0];
 	}
-	$type =3D~ s/^\s+//;
-	$type =3D~ s/\s+$//;
-	if ($type =3D~ /simple:(.*)/) {
-		return fly_tax($::Values->{$1});
 	}
-	elsif ($type =3D~ /handling:(.*)/) {
+	else {
+		@taxes =3D $type;
+	}
+
+	my $total =3D 0;
+	foreach my $t (@taxes) {
+		$t =3D~ s/^\s+//;
+		$t =3D~ s/\s+$//;
+		if ($t =3D~ /simple:(.*)/) {
+			$total +=3D fly_tax($::Values->{$1});
+			next;
+		}
+		elsif ($t =3D~ /handling:(.*)/) {
 		my @modes =3D grep /\S/, split /[\s,]+/, $1;
=20=09=09
 		my $cost =3D 0;
 		$cost +=3D tag_handling($_) for @modes;
-		return $cost;
+			$total +=3D $cost;
+			next;
 	}
 	my $tax;
-#::logDebug("tax type=3D$type");
-	if($type =3D~ /^(\d+(?:\.\d+)?)\s*(\%)$/) {
+#::logDebug("tax type=3D$t");
+		if($t =3D~ /^(\d+(?:\.\d+)?)\s*(\%)$/) {
 		my $rate =3D $1;
 		$rate /=3D 100 if $2;
 		my $amount =3D Vend::Interpolate::taxable_amount();
-		return $rate * $amount;
+			$total +=3D ($rate * $amount);
 	}
 	else {
-		$tax =3D Vend::Util::get_option_hash($type);
+			$tax =3D Vend::Util::get_option_hash($t);
 	}
 #::logDebug("tax hash=3D" . ::uneval($tax));
 	my $pfield   =3D $opt->{tax_category_field}
@@ -6294,9 +6323,8 @@
 				|| 'tax_category';
 	my @pfield =3D split /:+/, $pfield;
=20
-	my $total =3D 0;
 	for my $item (@$Vend::Items) {
-		my $rhash =3D tag_data($item->{mv_ib}, undef, $item->{code}, { hash =3D>=
 1} );
+			my $rhash =3D tag_data($item->{mv_ib}, undef, $item->{code}, { hash =3D=
> 1});
 		my $cat =3D join ":", @{$rhash}{@pfield};
 		my $rate =3D defined $tax->{$cat} ? $tax->{$cat} : $tax->{default};
 #::logDebug("item $item->{code} cat=3D$cat rate=3D$rate");
@@ -6307,12 +6335,16 @@
 		$total +=3D $sub * $rate;
 #::logDebug("tax total=3D$total");
 	}
+	}
 	return $total;
 }
=20
 # Calculate the sales tax
 sub salestax {
-	my($cart) =3D @_;
+	my($cart, $opt) =3D @_;
+
+	$opt ||=3D {};
+
 	my($save);
 	### If the user has assigned to salestax,
 	### we use their value come what may, no rounding
@@ -6331,7 +6363,7 @@
 	my $tax_hash;
 	my $cost;
 	if($Vend::Cfg->{SalesTax} eq 'multi') {
-		$cost =3D tax_vat();
+		$cost =3D tax_vat($opt->{type}, $opt);
 	}
 	elsif($Vend::Cfg->{SalesTax} =3D~ /\[/) {
 		$cost =3D interpolate_html($Vend::Cfg->{SalesTax});
@@ -6648,6 +6680,28 @@
 			logOnce('error', "Levy '%s' called but not defined. Skipping.", $name);
 			next;
 		}
+		if(my $if =3D $l->{include_if}) {
+			if($if =3D~ /^\w+$/) {
+				next unless $::Values->{$if};
+			}
+			elsif($if =3D~ /__[A-Z]\w+__|[[a-zA-Z]/) {
+				next unless interpolate_html($if);
+			}
+			else {
+				next unless tag_calc($if);
+			}
+		}
+		if(my $if =3D $l->{exclude_if}) {
+			if($if =3D~ /^\w+$/) {
+				next if $::Values->{$if};
+			}
+			elsif($if =3D~ /__[A-Z]\w+__|[[a-zA-Z]/) {
+				next if interpolate_html($if);
+			}
+			else {
+				next if tag_calc($if);
+			}
+		}
 		my $type =3D $l->{type} || ($name eq 'salestax' ? 'salestax' : 'shipping=
');
 		my $mode;
=20
@@ -6670,7 +6724,11 @@
 				$save =3D $Vend::Cfg->{SalesTax};
 				$Vend::Cfg->{SalesTax} =3D $l->{tax_fields};
 			}
-			$cost =3D salestax();
+			elsif ($l->{multi}) {
+				$save =3D $Vend::Cfg->{SalesTax};
+				$Vend::Cfg->{SalesTax} =3D 'multi';
+			}
+			$cost =3D salestax(undef, { tax_type =3D> $l->{tax_type} } );
 			$desc =3D errmsg(
 						$l->{description} || 'Sales Tax',
 						$::Values->{$Vend::Cfg->{SalesTax}},



1.2       +3 -2      interchange/code/SystemTag/salestax.coretag


rev 1.2, prev_rev 1.1
Index: salestax.coretag
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /anon_cvs/repository/interchange/code/SystemTag/salestax.coretag,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- salestax.coretag	29 Jan 2002 05:52:38 -0000	1.1
+++ salestax.coretag	28 Jul 2002 05:28:13 -0000	1.2
@@ -1,10 +1,11 @@
 UserTag salestax            Order        name noformat
 UserTag salestax            attrAlias    cart name
+UserTag salestax            addAttr
 UserTag salestax            InvalidateCache
 UserTag salestax            PosNumber    2
 UserTag salestax            Routine <<EOR
 sub {
-	my($cart, $noformat) =3D @_;
-	return currency( salestax($cart), $noformat);
+	my($cart, $noformat, $opt) =3D @_;
+	return currency( salestax($cart, $opt), $noformat);
 }
 EOR