[interchange-cvs] interchange - heins modified lib/Vend/Interpolate.pm
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Sat Mar 1 10:48:00 2003
User: heins
Date: 2003-03-01 15:47:15 GMT
Modified: lib/Vend Interpolate.pm
Log:
* Fixes and a new feature (suggested by Ton) for Levies.
-- New Levy add_to key allows consolidation of levies under one
heading.
Levies salestax foo
Levy salestax description "Sales Tax (%s)"
Levy salestax keep_if_zero 1
Levy salestax type salestax
Levy salestax sort 002
Levy salestax label_value state
Levy foo keep_if_zero 0
Levy foo add_to salestax
Levy foo type shipping
Levy foo mode PERD
This will calculate the foo levy, but add its cost to the salestax
levy for display purposes.
-- Remove sprintf() function and replace with round_to_frac_digits,
prevent worries about rounding errors.
-- Allow label_value for all levy types, means you can do
something like:
Levy shipping description Shipping (%s)
Levy shipping keep_if_zero 0
Levy shipping type shipping
Levy shipping mode_from_values mv_shipmode
Levy shipping label_value zip
which will display
Shipping (45056)
Revision Changes Path
2.150 +32 -14 interchange/lib/Vend/Interpolate.pm
rev 2.150, prev_rev 2.149
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.149
retrieving revision 2.150
diff -u -r2.149 -r2.150
--- Interpolate.pm 27 Feb 2003 10:12:15 -0000 2.149
+++ Interpolate.pm 1 Mar 2003 15:47:15 -0000 2.150
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.149 2003/02/27 10:12:15 ton Exp $
+# $Id: Interpolate.pm,v 2.150 2003/03/01 15:47:15 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.149 $, 10);
+$VERSION = substr(q$Revision: 2.150 $, 10);
@EXPORT = qw (
@@ -6724,10 +6724,11 @@
my $cost = 0;
my $sort;
my $desc;
+ my $lab_field = $l->{label_value};
if($type eq 'salestax') {
my $save;
$sort = $l->{sort} || '010';
- my $lab_field = $l->{label_value} || $Vend::Cfg->{SalesTax};
+ $lab_field ||= $Vend::Cfg->{SalesTax};
if($l->{tax_fields}) {
$save = $Vend::Cfg->{SalesTax};
$Vend::Cfg->{SalesTax} = $l->{tax_fields};
@@ -6737,10 +6738,7 @@
$Vend::Cfg->{SalesTax} = 'multi';
}
$cost = salestax(undef, { tax_type => $l->{tax_type} } );
- $desc = errmsg(
- $l->{description} || 'Sales Tax',
- $::Values->{$lab_field},
- );
+ $l->{description} ||= 'Sales Tax';
$Vend::Cfg->{SalesTax} = $save if defined $save;
}
elsif ($type eq 'shipping' or $type eq 'handling') {
@@ -6748,7 +6746,7 @@
$sort = $type eq 'handling' ? 100 : 500;
}
$cost = shipping($mode);
- $desc = $l->{description} || tag_shipping_desc($mode);
+ $l->{description} ||= tag_shipping_desc($mode);
}
elsif($type eq 'custom') {
my $sub;
@@ -6771,16 +6769,18 @@
}
}
+ $desc = errmsg(
+ $l->{description},
+ $::Values->{$lab_field},
+ );
+
my $cost_format;
- unless ($cost_format = $l->{cost_format}) {
- my $digits = errmsg('frac_digits') || 2;
- $cost_format = "%.${digits}f";
- }
+
my $item = {
code => $name,
mode => $mode,
sort => $sort,
- cost => sprintf($cost_format,$cost),
+ cost => round_to_frac_digits($cost),
currency => currency($cost),
group => $group,
label => $l->{label} || $desc,
@@ -6792,8 +6792,26 @@
$item->{free} = 1;
$item->{free_message} = $l->{free_message} || $cost;
}
- push @$lcart, $item;
+
+ if(my $target = $l->{add_to}) {
+ my $found;
+ foreach my $lev (@$lcart) {
+ next unless $lev->{code} eq $target;
+ $lev->{cost} += $item->{cost};
+ $lev->{cost} = round_to_frac_digits($lev->{cost});
+ $lev->{currency} = currency($lev->{cost});
+ $found = 1;
+ last;
+ }
+ unless($found) {
+ push @$lcart, $item;
+ }
+ }
+ else {
+ push @$lcart, $item;
+ }
}
+
@$lcart = sort { $a->{sort} cmp $b->{sort} } @$lcart;
for(@$lcart) {