Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ramniksingh's avatar

Inventory Management System

Hi Everyone, I had earlier developed an inventory management system in MS Access for the below :

Multiple Products (Approx 1000's) , Multiple Departments (Approx 10's) - Dynamic , Products are issued / received between departments with quantity.

Existing Design :-

Table: DailyIssues , Table: DailyReceipts , Table: ItemStockTake ,

In existing system, Queries are being used in calculation of inventory like below:-

Present Stock for any item in any section = (Recent Date StockTake) + (Item Receipts) - (Item Issued).

Problem: For such a huge data calculating stock is a time consuming task.

Now I want to develop this system in Laravel and want to know whether this design is all right?

1- How about having each item stock stored in table rather than always calculating from query?

2- How to manage such complexity in an easy way with complete stock history?

3- Any recommendations for multi level inventory management system design !!!

4- Any resources!

Thanks

0 likes
2 replies
martinbean's avatar

@ramniksingh You first need to pick out the entities involved in the domain. Based on your overview, there are products and departments.

For tracking the history, you should probably go for a transaction-based approach, where you record the stock movements rather than just have a table with integer values. As if you see a stock level of “50”, then you have no way of knowing when stock was transferred in, out, how many units, etc.

So, have a table that records any stock coming in and out of a department. You can then get the stock level for any particular product in any given department by sum-ing the quantity column:

Schema::create('stock_movements', function (Blueprint $table) {
    $table->id();
    $table->foreignId('product_id')->constraint();
    $table->foreignId('department')->constraint();
    $table->integer('quantity');
});
// Get stock level for product 123 in department 45:
$stockLevel = StockMovement::where('product_id', '=', 123)->where('department_id', '=', 45)->sum('quantity');

You could create local scopes to simplify the query:

$stockLevel = StockMovement::forProduct($product)->inDepartment($department)->sum('quantity');

Or create some other method that encapsulates the query entirely:

$stockLevel = $product->stockLevelIn($department);

Obviously it would be a good idea to index the columns in this query for performance.

If you find querying becomes slow, then you could create “snapshots” of stock levels that are built from your movements table (where the stock level at that time is stored in the database as a simple integer value) and query that table. This way you have stock levels (but at the cost of being out of date until the next snapshot is generated), but still have the entire history of movement of stock between departments.

1 like
ramniksingh's avatar

Thanks @martinbean for the suggestions.

What you suggested is again a query solution. Which can be optimized using snapshots.

For the existing system one year data has around 200000 records for items issued and it will be going to increase. I hope this won't be making any issues in performance. But the potential issue might be to fetch records by filtering out the section & item and getting history records, then summing them to get balance stock. Which becomes complex for multiple products and multiple sections.

  1. How about having a present stock table and updating this table alongside our history table in case of any transactions happened each time.?

  2. How about the inventory management practices in some high level applications? Are they using only simple queries like this or there is any specific approach to follow for a large multi level inventory?

Thanks

Please or to participate in this conversation.