In a production system, this actually takes place twice--the first time it's when scheduling/planning a production run and the data represents the predicted production of new inventory and the consumption of ingredients. The second time around, it's the actual reported production and consumption--where wastage, shortfalls and overruns have to be accounted for instead of the original "ideal" quantities specified in the recipe.
Typical production systems have 3 different subsystems: Specs--the recipe for producing one unit of product, Scheduling--the predicted production/consumption figures and Inventory Management--the actual changes produced by the production run.
So using your Potato Chips example, your Recipe might specify the ingredients and Quantities for a 1 ounce quantity of finished product. In the specifications subsystem, you might then have records for both a 16 ounce bag and a 32 ounce bag of potato chips. In the scheduling system, you might setup a 3 shift production run of 30,000 32 ounce bags of potato chips and the Inventory Management subsystem might then record the production of 32,000 32 ounce bags with actual amounts produced and consumed that will vary to some degree from that scheduled due to either more or less wastage than specified in the "recipe" and the 2,000 bag overrun.
For both "spec" and "scheduling" sub systems, I can think of two different approaches that can be used. One is to set up yet another Join table that is populated by a script that loops through the current recipe's list of ingredients and quantities to produce a set of join table records with adjusted quantities. The other is a more sophisticated relationship supported by a script and a global field to enable calculation field in the existing join table to access data in the current finished product record in order to show correctly adjusted quantities:
FinishedProduct----<Recipe-------<RecipeIngredient>----FinishedProduct|Selected
RecipeIngredient::gfkFinishedProductID = FinishedProduct|Selected::__pkFinishedProductID
FinishedProduct|Selected is another table occurrence of FinishedProduct.
gfkFinishedProductID is a number field with global storage.
You would keep it updated with the correct value by using the OnRecordLoad trigger to perform this script:
Set Field [RecipeIngredient::gfkFinishedProductID ; FinishedProduct::__pkFinishedProductID ]
Commit Records
This enables the following calculation field in RecipeIngredient to return the correct quantity:
Qty * FinishedProduct|Selected::SizeFactor
to adjust the quantities for each ingredient. In our Potato chip example, with a recipe for an ounce of potato chips, the sizefactor for a 16 oz. bag will be 16 and 32 for the 32 ounce size.
And I strongly recommend that you not use Name field as the match fields in your relationship like you have set up here. Consider the problems that might occur if you have to change the name of a product, recipe or ingredient--perhaps to correct a data entry error. That name change will break links to other related tables for the record where you change the name. Using auto-entered serial numbers instead of names as the match fields makes for a much safer system.
Your new post is loading...