unit converter for product I have a question regarding to unit converter for product. I stored the following data as shown below
1 PCS = 1 PCS
1 BOX = 10 PCS
1 CARTON = 40 PCS
database design
id | fromUnit | ratio | toUnit
I am converting every fromUnit to a base unit (PCS).
How should i design my database so that i know 1 BOX = ? CARTON? E.g 2 BOX = 0.5 CARTON. (Formula : 20/40 = 0.5)
Any linkage need to make based on this situation?
I would probably calculate it on the fly instead. I don't see the need to have pcs since one pcs is always 1 pcs.
Something like this
id | product_id |box_qty | carton_qty
SELECT 2 * box_qty / carton_qty as cartons
FROM packings
WHERE product_id = 1
is it easier to think the other way around?
640 pcs per pallet
40 pcs per carton
10 pcs per box
1 pcs per pcs
I assume if someone wants 20 of something, this should convert to 2 boxes?, 50 is 1 carton and 1 box? 12 is 1 box and 2 pcs
Do you need to convert between units or just know how many of each to most efficiently make up an order?
@SNAPEY - For example, pcs is always my base unit for conversion. But during display, will show 1carton = 10box = 100pcs
Not sure where the problem is then?
You need two columns, 'container' and 'pcs'
@SNAPEY - Because i am storing only conversion rate to base. But i didnt store conversion between box and carton. I only know carton = how many pcs and box = how many pcs, but not 1 carton = how many box
you can calculate box/carton ratio at any time
@SNAPEY - ya, right. Do i need attribute like parent id to know which is the biggest and smallest unit? E.g. Carton -> Box -> pcs
I don't know your use case, but if you have more than product being converted you might need to store what this set of conversions relate to, otherwise no, why would you need to store the order when they are in the database with a column stating the number of pcs?
Please sign in or create an account to participate in this conversation.