Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

in which there is a reduction in food stocks 1

Status
Not open for further replies.

jezky82

MIS
Jul 7, 2012
39
0
0
ID
I make food sales program. in which there is a reduction in food stocks. such a sale spaghetti require:


250 gr Spaghetti
200 gr chicken meat
100 g carrots
100 g baby kailan
6 pieces of red chilli
3 tablespoons soy sauce
5 cloves of garlic minced
1 tablespoon instant chicken broth
1 tablespoon fried shallots
1 tsp fine salt
3 tablespoons cooking oil
1 tablespoon cornstarch
then when selling a spaghetti reduce stock as above.
so I created two databases. The first database is the data is the key ingredient of spaghetti and a negative value. The second data is a database of food stocks. so when selling spaghet the first data with the key into the spaghetti will continue my second database based on the total food ingredients will automatically be reduced. is there a shorter way than the way I mentioned please help with sample programs. thank you
 
No, that is the shortest way.

You essentially have a BOM (Bill of Materials, or BOQ Bill of Quantities) and use that to reduce the stock of raw materials by the right amount
when you sell a product.

Code:
FUNCTION SELLPRODUCT
  Parameter m.ProductCode, m.Quantity
  Private m.ProductCode, m.Quantity, m.Success
  m.Success = .f.
  Select tblBOM
  Set order to ProductCode
  Seek (m.ProductCode)
  If Found()
    Success = .t.
    Do While .NOT. EOF() .and. tblBOM.ProductCode = M.ProductCode
      Select tblIngrediants
      Set Order to Ingrediants
      Seek (tblBOM.IngrediantCode)
      if found()
         if tblIngrediants.Quantity >= tblBOM.Quantity * m.Quantity
            replace tblIngrediants.Quantity with tblIngrediants.Quantity -(tblBOM.Quantity * m.Quantity)
         else
            replace tblIngrediants.Quantity with 0
             m.success = .f.
         endif
      else
         m.success= .f.
      endif
      Select fblBOM
      Skip
    EndDo
  EndIF
Return(m.Success)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Sorry, couple of typos in my example!

B-)

Thank you for the star though

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.
 
Well, if you have a table with inventory data and another with BOM as Griff called it, you could do one UPDATE-SQL, too.

assumed ingredients have a stock in an inventorytable and an ingredientID to identify them uniquely, and your bill of material data has a quantity to subtract from stock:

Update inventorytable set stock = stock - bom.quantity from inventorytable inner join bom on inventorytable.ingredientID = bom.ingredientID

This gives you less control about not matched ingredients and what to do about such errors. You can check if _TALLY, the number of updated records, matches the number of bom ingredients as a simple check. But if that doesn't match you have to see what data is wrong or missing.

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top