Shopping Cart Tax Exempt Feature Broken



Hello All,

Please forgive me for jumping in like this, but I could really use your help. First off, I have to confess that I am NOT a perl programmer. I do want to learn, but I need to get this problem fixed as soon as possible. Hopefully someone here will be willing to help me.

The tax exempt feature in my shopping cart is broken. Even when a customer is flagged as tax exempt, they are still charged tax in their orders. I've included what I think is the relevant section to the cart in hopes that someone could see where the problem lies.

Thank you for any help you can give me. If you need more information, please let me know.

Regards,
Ted

--------------------------------

sub TotalCart
{
my ($shipamt,$calculation,$from_page,$domains,$line, $page_string,@payloads,$payload,$add,@adds,$inclusive, $repl,$field,$tokenvalue,$type,$search_tag,$tag,$replace_tag, $uid_string,$hidden,$name,$calc,$key,
        $bsktstring,%item,$count,$cat_field,$counter,
        $this_item,$thisloop,$cartitem, @newcalcs) = ();

($main::global->{form}->{chargetotal}, $main::global->{form}-> {subtotal},$main::global->{form}->{taxtotal},$main::global->{form}-> {'subtotal'}, $main::global->{form}->{'shipcost'}, $main::global-> {form}->{'totalweight'}, $main::global->{form}->{'totalqty'}, $main::global->{form}->{'totalother'}, $main::global->{form}->{'key'},$main::global->{form}->{dllink}, $main::global->{form}->{dllinkmail},$main::global->{form}-> {chargetotal},$main::global->{form}->{'totalvolume'},$main::global-> {form}->{totalshipping}, $main::global->{form}->{'totalcalcs'}, % {$main::global->{key}}) = ();
    $counter = 0;
    my (%hazardous, $hazardous,$shiptotals);
    %{$shiptotals} = ();
    foreach $cartitem (sort keys (%{$main::global->{cart}}))
    {
        next if (! $cartitem || $cartitem eq 'formdata');
        $counter++;
        chomp($main::global->{cart}->{$cartitem});
my @cartparts = split (/\t/,$main::global->{cart}-> {$cartitem});
        next if ($cartparts[1] <= 0);
my $item = &ModifyCartItem('modify',$cartparts[1], $main::global->{cart}->{$cartitem}); $item->{'shipping'} = &CalculateItemShipping($main::global-> {form}->{'shiptype'},$item->{'quantity'},$item->{'shipping'}, $shiptotals);# if ($item->{'shipping'} =~ /, */);
        $item->{'unitprice'}   += $item->{'optionprice'};
$item->{'netprice'} = ($item->{'quantity'} * $item-> {'unitprice'}) + $item->{'other'}; $item->{'netweight'} = $item->{'quantity'} * $item-> {'weight'}; $item->{'netvolume'} = $item->{'quantity'} * $item-> {'volume'};
        $item->{'itemcount'}    = $counter;
        $hazardous .= "|$item->{'hazardous'}";
$main::global->{key}->{$item->{'itemid'}} += $item-> {'quantity'}; $main::global->{form}->{'subtotal'} += $item-> {'netprice'}; $main::global->{form}->{'taxtotal'} += $item-> {'netprice'} unless ($item->{taxable} || $main::global->{userinfo}-> {'taxexempt'}); $main::global->{form}->{'totalqty'} += $item-> {'quantity'}; $main::global->{form}->{'totalship'} += $item-> {'quantity'} unless ($item->{itemid} =~ /(pld|gft)$/); #ignore gift certs and payloads $main::global->{form}->{'totalweight'} += $item-> {'netweight'};
        $main::global->{form}->{'totalother'}    += $item->{'other'};
$main::global->{form}->{'totalvolume'} += $item-> {'netvolume'};

    }


    foreach my $hazard (split (/\|/,$hazardous))
    {
        next unless ($hazard =~ /\w/);
        $hazardous{$hazard}++;
    }
    $hazardous = join ("|", keys %hazardous);
$main::global->{form}->{key} = join ("|", keys %{$main::global-> {key}});
    if ($main::global->{cartcounter}) {

        $main::global->{form}->{newcalcinput} = [];
        $main::global->{form}->{newcalc}      = [];
        $main::global->{form}->{hide}         = {};




        #validate coupon

        $main::global->{form}->{authamt} = 0;
($main::global->{form}->{authamt},$main::global->{form}-> {'coupontype'}) = &VerifyCoupon if ($main::global->{form}-> {'couponid'} && $main::global->{form}->{'couponpass'});
        if ($main::global->{form}->{'authamt'} eq 'error') {
($main::global->{userinfo}->{'couponid'},$main::global-> {userinfo}->{'couponpass'}) = ();
            &Trap('refer','',$main::global->{form}->{'coupontype'});
        }
if ($main::global->{form}->{'coupontype'} =~ /coupon/i) { #coupon: apply discount before taxes $main::global->{form}->{'authamt'} = $main::global-> {form}->{'subtotal'} if ($main::global->{form}->{authamt} > $main::global->{form}->{'subtotal'}); $main::global->{form}->{'authamt'} = - $main::global-> {form}->{'authamt'} if ($main::global->{form}->{'authamt'}); $main::global->{form}->{'ordercalcs'} += $main::global-> {form}->{'authamt'} if ($main::global->{form}->{'subtotal'} > 0);
        }


        $main::global->{form}->{calccounter} = 0;
        $main::global->{form}->{recalculate} = 1;
        $main::global->{form}->{newcalcs}    = [];
        #do  calculations
        &OpenDB('calculations');

        &parse_calc_file();

        foreach my $calctype (qw (ordercalcs precalcs addcalcs noadd))
        {
foreach $calc (@{$main::global->{open}->{calculations}-> {$calctype}})
            {
                $main::global->{form}->{calccounter}++;
do_calculation($calctype, $calc, $shiptotals, $main::global->{'form'});
            }
        }
$main::global->{form}->{'taxexempt'} = $main::global-> {userinfo}->{'taxexempt'}; $main::global->{form}->{'totalsalestax'} = &moneyfy ($main::global->{form}->{'precalcs'}, $main::global->{config}-> {'precision'}); $main::global->{form}->{'totalcalcs'} = join ("\r", @ {$main::global->{form}->{newcalcs}});

        #calculate after-tax total
$main::global->{form}->{'chargetotal'} = $main::global-> {form}->{'subtotal'} + $main::global->{form}->{'ordercalcs'} + $main::global->{form}->{'precalcs'} + $main::global->{form}-> {'addcalcs'};

        #now subtract gift certs
        if ($main::global->{form}->{'coupontype'} =~ /ship/i) {
$main::global->{form}->{'authamt'} = $main::global-> {form}->{'shipcost'}; $main::global->{form}->{'authamt'} = - $main::global-> {form}->{'authamt'} if ($main::global->{form}->{'authamt'}); $main::global->{form}->{'chargetotal'} += $main::global-> {form}->{'authamt'} ; $main::global->{form}->{'chargetotal'} = 0 unless ($main::global->{form}->{'chargetotal'} > 0);

        }
        elsif ($main::global->{form}->{'coupontype'} =~ /gift/i) {
$main::global->{form}->{'authamt'} = $main::global-> {form}->{'chargetotal'} if ($main::global->{form}->{authamt} > $main::global->{form}->{'chargetotal'}); $main::global->{form}->{'authamt'} = - $main::global-> {form}->{'authamt'} if ($main::global->{form}->{'authamt'}); $main::global->{form}->{'chargetotal'} += $main::global-> {form}->{'authamt'} ; $main::global->{form}->{'chargetotal'} = 0 unless ($main::global->{form}->{'chargetotal'} > 0);
        }

$main::global->{form}->{'authamt'} = &moneyfy ($main::global->{form}->{'authamt'}, $main::global->{config}-> {'precision'});
        &getCredit;
$main::global->{'form'}->{'Credit'} = &moneyfy ($main::global->{'form'}->{'Credit'},$main::global->{config}-> {'precision'}); $main::global->{form}->{'chargetotal'} = &moneyfy ($main::global->{form}->{'chargetotal'}, $main::global->{config}-> {'precision'});

        #replace shipmethod tag with popup menu
        my @methods = ();
        my $shipamt = 0;
foreach $type (sort @{$main::global->{open}->{calculations}-> {shiptype}})
        {
            my ($sort, $cname) = split (/%%/, $type);
next if ($hazardous && $cname =~ /^$hazardous$/); #prevents air shipments of hazardous cargo
            $shipamt = $main::global->{form}->{$cname};
            unless ($shipamt =~ /free/i) {
                next if (! $shipamt || $shipamt eq '--');
$shipamt = &moneyfy($shipamt,$main::global->{config}- >{'precision'},1);
            }
            my $methods = "<option value=\"$cname\"";
            if ($main::global->{form}->{shiptype} eq $cname) {
                $methods .= " selected";
            }
            $methods.= ">$cname-$shipamt</option>\n";
$main::global->{form}->{shiptype} = $cname unless ($main::global->{form}->{shiptype}); #get first shipping type as default
            push @methods, $methods;
        }
        if (@methods == 1) {
$main::global->{form}->{shipmethod} = "<input type= \"hidden\" name=\"shiptype\" value=\"$main::global->{form}->{shiptype} \">$main::global->{form}->{shiptype}: $shipamt";
        }
        elsif (@methods > 1) {
$main::global->{form}->{shipmethod} = "<select name= \"shiptype\">\n".join("\n", @methods) . "\n</select>\n";
        }
        else {
            $main::global->{form}->{shipmethod} = '';
        }
$main::global->{form}->{shipmethodjs} = $main::global-> {form}->{'shipmethod'}; $main::global->{form}->{shipmethodjs} =~ s/<select name="shiptype">/<select name="shiptype" onChange="this.form.submit\ (\)">/s;


        &CloseDB('calculations');


    }
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]