I'm building a small-scale MRP system for an electronics manufacturing business. There are assemblies that are built, and parts that go into those assemblies. The individual component parts that go into each assembly have their own component part numbers, and since many manufacturers make those basic components, often times alternative part numbers (and quantities) exist in the inventory system for a given component part.
Fortunately, we assign internal part numbers, so there's a one-to-many relationship between the internal part numbers that we use to build assemblies by and the actual manufacturer's part numbers that we've purchased to maintain inventory for that internal part number.
So, we could have more than one MfgPN for any given internal PN (for example):
Internal PN | Manufacturer PN | Quantity
RES-000293-R | CRCW0603330RJNE A | 150
RES-000293-R | RM06J301CT-ND-TR | 5000
So, in other words, either of those MfgPN's is completely appropriate to use wherever the assembly calls out RES-000293-R.
And our operators will use up existing, opened reels of parts before mounting new reels. So, in this example, we'll use up the stock of 150 CRCW0603330RJNE A before mounting the unopened reel of RM06J301CT-ND-TR.
Parts don't have expiration dates, so we use up small quantities before moving on to larger ones.
The dillema this creates is in creating SQL code to decrement inventory appropriately. Consider building 500 assemblies where this part is used once per assembly:
In reality, we'd use up the 150 first, then use 350 of the RM06J301CT-ND-TR.
So, after running, I'd have this:
Internal PN | Manufacturer PN | Quantity
RES-000293-R | CRCW0603330RJNE A | 0
RES-000293-R | RM06J301CT-ND-TR | 4650
From a SQL standpoint, I have:
Inventory table has MfgPN and Qty.
Parts table has IntPN and MfgPN.
Assemblies table has data on each assembly location, including IntPN.
I created a stored query (used as a view) to provide IntPN, count(*) for any given assembly, so I know how many IntPN's I need to decrement from inventory.
How could I then process that against [functionally] potentially multiple instances of that IntPN in inventory, so that it subtracts from the smallest inventory item first, then the next smallest, and so on until the full decrement quantity has been reached?
I'd like to stay within SQL if possible to do this in a query.
Fortunately, we assign internal part numbers, so there's a one-to-many relationship between the internal part numbers that we use to build assemblies by and the actual manufacturer's part numbers that we've purchased to maintain inventory for that internal part number.
So, we could have more than one MfgPN for any given internal PN (for example):
Internal PN | Manufacturer PN | Quantity
RES-000293-R | CRCW0603330RJNE A | 150
RES-000293-R | RM06J301CT-ND-TR | 5000
So, in other words, either of those MfgPN's is completely appropriate to use wherever the assembly calls out RES-000293-R.
And our operators will use up existing, opened reels of parts before mounting new reels. So, in this example, we'll use up the stock of 150 CRCW0603330RJNE A before mounting the unopened reel of RM06J301CT-ND-TR.
Parts don't have expiration dates, so we use up small quantities before moving on to larger ones.
The dillema this creates is in creating SQL code to decrement inventory appropriately. Consider building 500 assemblies where this part is used once per assembly:
In reality, we'd use up the 150 first, then use 350 of the RM06J301CT-ND-TR.
So, after running, I'd have this:
Internal PN | Manufacturer PN | Quantity
RES-000293-R | CRCW0603330RJNE A | 0
RES-000293-R | RM06J301CT-ND-TR | 4650
From a SQL standpoint, I have:
Inventory table has MfgPN and Qty.
Parts table has IntPN and MfgPN.
Assemblies table has data on each assembly location, including IntPN.
I created a stored query (used as a view) to provide IntPN, count(*) for any given assembly, so I know how many IntPN's I need to decrement from inventory.
How could I then process that against [functionally] potentially multiple instances of that IntPN in inventory, so that it subtracts from the smallest inventory item first, then the next smallest, and so on until the full decrement quantity has been reached?
I'd like to stay within SQL if possible to do this in a query.
Comment