how calculate items in different discount
plz help

Recommended Answers

All 6 Replies

example is
hotdog quantity > 20 then discount is 10%
ham quantity > 10 then discount is 5%
cheese quantity > 30 then discount 15%

plz help :)

You need to show your code. We can't help you if we don't know where you are holding the food type or the quantity or where you want the results. Also you need to show that you've tried.

Show your form and explain a bit better what you are trying to accomplish (ie. is the discount for the particular line or for the whole order?)

If ListView1.SelectedItems.Count = 0 Then
            MsgBox("Plese Select a Product")
        Else
            Dim price As Double
            Dim quantity As Integer
            Dim total As Double
 
            price = ListView1.FocusedItem.SubItems(3).Text
            quantity = ListView1.FocusedItem.SubItems(2).Text
 
            If txtProductName.Text = "Happy" Then
                If txtQuantity2.Text > 20 Then
                    total = price * Val(txtQuantity2.Text) * 0.95
                    total = Format(total, "0.00")
                    execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
                    FillListview(execute("select * from tblOrder"), ListView2)
                    MsgBox("success")
                ElseIf txtQuantity2.Text < 20 Then
                    total = price * Val(txtQuantity2.Text)
                    total = Format(total, "0.00")
                    execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
                    FillListview(execute("select * from tblOrder"), ListView2)
                    MsgBox("success")
                    If txtProductName.Text = "Moby" Then
                        If txtQuantity2.Text > 15 Then
                            total = price * Val(txtQuantity2.Text) * 0.97
                            total = Format(total, "0.00")
                            execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
                            FillListview(execute("select * from tblOrder"), ListView2)
                            MsgBox("success")
                        ElseIf txtQuantity.Text < 15 Then
                            total = price * Val(txtQuantity2.Text)
                            total = Format(total, "0.00")
                            execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
                            FillListview(execute("select * from tblOrder"), ListView2)
                            MsgBox("success")
                            If txtProductName.Text = "Honey" Then
                                If txtQuantity2.Text > 25 Then
                                    total = price * Val(txtQuantity2.Text) * 0.97
                                    total = Format(total, "0.00")
                                    execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
                                    FillListview(execute("select * from tblOrder"), ListView2)
                                    MsgBox("success")
                                ElseIf txtQuantity.Text < 25 Then
                                    total = price * Val(txtQuantity2.Text)
                                    total = Format(total, "0.00")
                                    execute("insert into tblOrder Values('" & txtProductName.Text & "', '" & txtQuantity2.Text & "', '" & total & "')")
                                    FillListview(execute("select * from tblOrder"), ListView2)
                                    MsgBox("success")

here sir the moby and honey is not working

Of course they won't work.
What you are doing wrong is nesting all the If's. So you are practically running this:

If txtProductName.Text = "Happy" Then
  If txtProductName.Text = "Moby" Then
    If txtProductName.Text = "Honey" Then

This translates to if txtproductname is Happy and txtproductname is Moby (which can never be true because you have already checked that txtproductname is Happy in order to get to the second if).
What you need to do in order to fix this is either add

End If
End If

(two End If - one for the quantity check and one for the product) before If txtProductName.Text = "Moby" Then and before If txtProductName.Text = "Honey" Then
or add

End If 
ElseIf

in the same places (replacing the If each time).

If the quantity for discount varies from item to item then I suggest you add it as well as the discount to your listview as a subitem. That way you wouldn't have to hardcode a test for each type of item. Also, your insert query is independent of the item type and discount so you can remove all the inserts from inside the selects and just do one insert after you have determined the discount.

'get item price and minimum limit needed for discount

price = CDbl(ListView1.FocusedItem.SubItems(3).Text)
limit = CInt(ListView1.FocusedItem.SubItems(?).Text)
quantity = CInt(ListView1.FocusedItem.SubItems(2).Text)
discount = CDbl(ListView1.FocusedItem.SubItems(?).Text

'determine price with possible discount

If quantity > limit Then
    total = FormatCurrency(quantity * price * discount,2)
Else
    total = FormatCurrency(quantity * price,2)
End If

'update database

execute("insert...")
FillListview(execute("select * from tblOrder"), ListView2)

Since Reverend Jim opened the issue of design, may I ask if this is a school assignment, an effort to learn or a true application you are building?

The reasons for asking are:
1) I don't see any real life application that would force the user to insert an order line by line (the user needs to select a row in order to insert it into the db). What happens if the network connection goes down during an order entry? Or if the user decides to cancel?
2) I find it to be a good practise to store all the data that resulted in the total value. That would mean that you would have to store the unit price and the discount offered. The reasons for this are too many to go into details, but it is a life saver.
3) Use the database to give the total value to the customer. Insert the item and quantity in the db and have the db calculate discounts and total. The reason behind this is that the db is - or should be - much more secure than the client. If you use this approach you might want to save yourself some nag by informing your users that the prices shown may not be the final ones.
4)You are inserting into tblOrder product, quantity and total. Where does customer, date, (status) and stuff like that go? Don't you need a key if they are stored in a different table? If they are stored in the same table, what happens if the user changes the customer (back in #1) halfway through the order?
5)Reverend Jim is right about hardcoding discounts and limits into your app.

My intention is not to disapoint you, but show you that you need to think of several scenarios other than the "happy path".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.