Jump to content

(Advice) - Storing price break points in database


Adamhumbug
Go to solution Solved by Barand,

Recommended Posts

I have a system that creates quotes.

Most items are simple, order 2 its 2 times the price, order 10, 10 times the price ect.

I have some items that break at certain intervals (the intervals are all different.)

Item A - price is each appart from under 500 where it is a flat £500.

1 - 499 £500
500 -999 £1.00
1,000 - 1,999 £0.90
2,000 - 2,999 £0.80
3,000 - 5,999 £0.70
6,000 - 9,999 £0.60
10,000 +£0.50

 

Item B has a similar plan but the breaks are different.

I have no idea where to start with this and am struggling to come up with a reasonable database structure that doesnt seem overkill.

Also, i have shown the price in GBP but we also have a price for USD, CAD and EUR which follows the same break points.

Link to comment
Share on other sites

I would have a table that shows the max quantity for a certain price value.  Then query looking for records with their quantities > than your current order, in quantity order and limit to 1.  Now you have your price value.  Then have a table or function that converts your currency amount to what you need  

Link to comment
Share on other sites

  • Solution

Something like this...

+---------------+ 
| invoice_item  |
+---------------+ 
| id            |
| prod_id       |------+
| quantity      |      |      +----------+
|---------------+      |      | price    |
                       |      +----------+
                       +-----<| prod_id  |
                              | minqty   |
                              | maxqty   |
                              | usd      |
                              | cad      |
                              | eur      |
                              +----------+

SELECT i.prod_id
     , p.product_name
     , pr.usd
     , pr.cadd
     , pr.eur
FROM invoice_item i
     JOIN product p ON i.prod_id = p.id
     JOIN price pr ON i.prod_id = pr.prod_id 
                      AND i.quantity BETWEEN pr.minqty AND pr.maxqty

 

Link to comment
Share on other sites

1 minute ago, Barand said:

Something like this...

+---------------+ 
| invoice_item  |
+---------------+ 
| id            |
| prod_id       |------+
| quantity      |      |      +----------+
|---------------+      |      | price    |
                       |      +----------+
                       +-----<| prod_id  |
                              | minqty   |
                              | maxqty   |
                              | usd      |
                              | cad      |
                              | eur      |
                              +----------+

SELECT i.prod_id
     , p.product_name
     , pr.usd
     , pr.cadd
     , pr.eur
FROM invoice_item i
     JOIN product p ON i.prod_id = p.id
     JOIN price pr ON i.prod_id = pr.prod_id 
                      AND i.quantity BETWEEN pr.minqty AND pr.maxqty

 

That could be a winner - let me have a play with that and i will report back

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.