
lightspd
Novice
Mar 15, 2013, 12:10 PM
Post #3 of 6
(238 views)
|
|
Re: [Kenosis] distributed amounts
[In reply to]
|
Can't Post
|
|
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.
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)
|