Need help With Discount Calculation!!

G

Guest

Hi everybody

Need a formula to calculate the discount base on the quantity
(Buy certain quantity and get certain quantity free)?

Any help will be appreciated
 
S

S. Justin Gengo

Simo,

A good equation will depend on exactly what you want to do. Do you need to
enter discounts often? Then you should database it. If the discounts won't
change then a select case statement would work quite well. And what type of
discount a certain fixed amount off? Or percentage off? All these things
will need to be answered before anyone can help you.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

Thanks much Justin for your replay!
All the discounts will be fixed amount.
but the one that i am having problem with is related to quntities like buy
(1) get (1) free or buy 4 get 2 free.
i figureout a dumy equation but it's not working proberly

((FLOOR(bi.qty/(@DiscountBuy + @DiscountGet))* @DiscountBuy)*
p.variant_price)+(((bi.qty-(FLOOR(bi.qty/(@DiscountBuy +
@DiscountGet))*(@DiscountBuy + @DiscountGet)))/@DiscountBuy)* p.variant_price)

bi = alias to basket_item table
p = alias to product table


I appreciated your help
 
S

S. Justin Gengo

Simo,

I think you can do this simply by using a select case statement. In the
example you gave both discounts (buy 1 get 1 free, buy 4 get 2 free) are 50%
off. But assuming there will be other percentages off you'd do something
like this:

E.g.

Dim PercentOff As Decimal

Select Case QuantityPurchased
Case 1, 4
PercentOff = .5
Case 3
PercentOff = .25
End Select

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

I can not have swich statement because the quantities of (buy / get) are
variable
but base on what did you get the percentage value?

Thanks again
 
G

Guest

Does this make sense for you Justin?

Simo said:
I can not have swich statement because the quantities of (buy / get) are
variable
but base on what did you get the percentage value?

Thanks again
 
S

S. Justin Gengo

Simo,

I based that on your sample of: buy 1 get 1 free buy 4 get 2 free. In both
cases that's 50% off...

Now, I would still try to do this programatically if I were you.

Here's how I'd go about it:

In your database create a table that stores two values for each product,
quantity and discount. It would look like this:

tblDiscounts

productId Quantity Discount
1 2 20%
1 3 25%
1 6 50%
2 3 25%

Then there are two different scenarious for looking up the data depending on
how you are giving out the discounts:

1) If you're only giving the discount for the exact quantity purchased look
up the discount based on productId and Quantity

SELECT Discount FROM tblDiscounts WHERE productId = 1 And Quantity = 3

2) More likely you are giving a discount for a certain number of items
purchased or greater. So you'll need to get all the discounts for the
quantity purchased and then figure out which one is the correct one. I'd use
a datareader for that:

SELECT Discount FROM tblDiscounts WHERE productId = 1 ORDER By Quantity (you
could limit this via AND Quantity >= if appropriate.)

Dim Discount As Decimal

While DataReader.Read
If DataReader.Item("Quantity") >= CustomerQuantity Then
Discount = DataReader.Item("Discount")
Else
'---The customer quantity is less than the rest of the discounts
found it's safe to exit the loop
Exit While
End While

DataReader.Close

'---Discount now has the correct discount in it.


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
G

Guest

Thanks Justin.
I will try this approche even it's out of the scope and hope the client (as
well as my manager) will not mind to put the percentage himself.

Again I appreciated your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top