Stock Control

2

I'm developing a shopping cart ...

I arrived in a party that ended up going wrong ... following the cart consists of additional product revenue and removal of ingredients

tabela produtos
id     nome      id_lanche    preço
1     X-egg       1            7.00
2     X-tudo      2            9.00

tabela receita
id     nome      id_lanche    preço     quantidade (quantiodade no caso e quanto o produto tem de cada item)
1     alface      1            1.00      1
2     bacon       1            2.00      2
3     Cheddar     1            2.00      2
4     Bife        1            3.00      1
5     alface      2            1.00      1
6     bacon       2            2.00      2
7     Ovo         2            2.00      1
8     Bife        2            3.00      1

Tabela estoque
id     nome      quantidade
1     alface      10
2     bacon       5

It happens that there is 1 lettuce with id 1 and another with id 2 ... he can not identify the item to write off ... in stock I thought by name only that not that it is 100% effective ... if the name was spelled wrong it will not work ...

could you help me to develop an effective way?

    
asked by anonymous 25.09.2014 / 10:02

1 answer

7

You have to store in the recipe table the lettuce id, as in the stock the lettuce is id = 1, so instead of the name "lettuce" in the recipe table, you save the id, your tables would look like this:

tabela produtos
id     nome      id_lanche    preço
1     X-egg       1            7.00
2     X-tudo      2            9.00

tabela receita
id    id_produto  id_lanche    preço     quantidade (quantiodade no caso e quanto o produto tem de cada item)
1     1           1            1.00      1
2     2           1            2.00      2
3     3           1            2.00      2
4     4           1            3.00      1
5     1           2            1.00      1
6     2           2            2.00      2
7     5           2            2.00      1
8     4           2            3.00      1

Tabela estoque
id     nome      quantidade
1     alface      10
2     bacon       5
3     Cheddar     6
4     Bife        8
5     Ovo         12

In this way, you can update the inventory of the item without conflicts.

    
25.09.2014 / 12:51