CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [Kenosis] distributed amounts: Edit Log



lightspd
Novice

Mar 15, 2013, 12:10 PM


Views: 949
Re: [Kenosis] distributed amounts

EDIT: I'll also add, that I'm limited to perl version 5.8.8, I really really wish I wasn't but that's what I got.

No my apologies, I wasn't very clear.

I'm writing a new discount function for an already existing code base. I get passed the amt or percentage to be discounted, then distribute them over all items that meet X conditions. Initially the spec said evenly distributed over all items, then I got the complaint that the item becomes neg and accounting people didn't like that. ( I probably should have thought of it myself.)

To clarify, I just insert the discount below the discounted item and the math is done else where. The discAmt is used to keep track the item price minus any discounts that have been applied to it, the field is also used on percentage discounts. The amt field is the amt of the item itself, never gets changed.

Here is an example of the basic structure.


Code
 
my @AOH = (
{ plu => "coke",
amt => "299",
discAmt => "299",
void => "f",
},
{ plu => "pepsi",
amt => "199",
discAmt => "199",
void => "f",
},
);

foreach my $hash ( @AOH ){
#process $1.00 off discount for example.
$hash->{'discAmt'} -= 50;
splice in discount hashref below item.
}


Now my issue comes in because they can enter as many discounts as they like and do, as long as it doesn't take the total below zero.

Using the example above, they apply a $4.00 off discount, so $2.00 off each item. The pepsi is $1.99 so I should take $1.99 off that and $2.01 off the coke.

I hope this clarifies the issue I'm having.

Cheers.


(This post was edited by lightspd on Mar 15, 2013, 12:38 PM)


Edit Log:
Post edited by lightspd (Novice) on Mar 15, 2013, 12:38 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives