[ic] PricePictures and Calculations with Perl
Kevin Walsh
kevin at cursor.biz
Tue Sep 23 18:01:27 EDT 2003
Xenia Diaz Orejarena [diaz at peppermind.de] wrote:
>
> the problem is, that I can't calculate with Perl with values like
> [subtotal]. After the execution of calculating the Results are always
> missing there decimal places like:
>
> 13.40 + 10 = 23.00
>
> I have no idea, what's going on there. What ist the problem between Perl and
> interchange in this case.
>
> The Price-Picture-Definitions in catalog.cfg are as follows:
>
> Locale eur_EUR mon_decimal_point .
> Locale eur_EUR price_picture "######.##"
>
>
> [calc]
>
> my $mwst = ( $Tag->subtotal() * 16 ) / 116 ;
> $mwst = sprintf("%.2f",$mwst);
> $Tag->set("mwst", $mwst);
>
> my $flgs = sprintf("%.2f",$Tag->scratch("flaschen_ges"));
>
> if ($flgs > 6 && [subtotal] < 250){
>
> $Tag->set("vpp", "10.00");
> $gesamt = '[subtotal]' + '10.00';
>
> }elsif($flgs <= 6 && [subtotal] > 250){
>
> $Tag->set("vpp", "6.50");
> $gesamt = '[subtotal]' + '6.50';
>
> }
> $gesamt = sprintf("%.2f",$gesamt);
> $Tag->seti("ges_preis", $gesamt);
>
> return;
>
> [/calc]
>
If I understand the intended use of the above code correctly then
it could probably be re-written as follows (untested):
[calcn]
my $subtotal = $Tag->subtotal({ noformat => 1 });
my $adjust = 0;
if ($Scratch->{flaschen_ges} > 6 && $subtotal < 250) {
$adjust = 10;
}
elsif ($Scratch->{flaschen_ges} <= 6 && $subtotal > 250) {
$adjust = 6.5;
}
$Scratch->{mwst} = $Tag->currency(($subtotal * 16) / 116);
$Scratch->{vpp} = $Tag->currency($adjust);
$Scratch->{ges_preis} = $Tag->currency($subtotal + $adjust);
undef;
[/calcn]
That should leave you with three currency-formatted scratch variables
called mwst, vpp and ges_preis.
It seems to me that you should really be using the existing sales tax
and handling/shipping facilities instead of the above.
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin at cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
More information about the interchange-users
mailing list