I've got a few database tables set up as a test scenario to be able to find total inventory by company, by location, shelf, bin, etc..
Very simply the data structure is like this:
inv_location
inv_location_id
location_name
parent_inv_location_id
Then inventory counts go here
inv_stocktage
inv_stocktake_id
part_id
quantity
inv_location_id (FK to inv_location)
stocktake_date
Ok, so database stuff aside, I'm trying to figure out a decent way to recursively go through each inventory location and see what is listed under it in the stocktake table, group them appropriately and store in an inventory object (seems the most beneficial way to recursively loop through and store the results).
I don't need code written, just some help getting the flow setup.
So far, I have something that goes like this (just pseudo code)
Expand|Select|Wrap|Line Numbers
- function find_inv($loc_id)
- {
- // grab an array of all other inv_locations that have current loc_id as a parent_id
- $array = select items from inv_location table
- if $array has records
- {
- foreach(value fround in above-mentioned array as $id)
- {
- // begin recursive loop here
- find_inv($id);
- }
- }
- $values = select items from inv_stocktake table and store in some class variable
- return this;
- }
I get a bit lost on how I will be storing the found $values but I am sure I could work something out.
Any ideas to get me going in the right direction?
Thanks!!