简体   繁体   中英

How to handle quantity/stock monitoring in an inventory system?

I'm creating a simple inventory/pos system for a hardware store as a school project.

I'm wondering how to properly implement monitoring of stocks/quantity on hand and sales of items. As of now i have a field 'QuantityOnHand' in my products table. This is where the total number of stocks is stored. Whenever a sale is made, i subtract the quantity of item(s) sold on the 'QuantityOnHand' field and save the items in two related tables, 'Sales' for the recording of the transaction and 'SalesItems' for the items sold.

This design was ok for the most part but i cannot create a report that compares the remaining quantity of items of the past day/week against the remaining balance of the current minus the sales/defective items because the quantity of items was not properly tracked and is only saved in a single field.

How do i design the database in such a way that i can properly monitor the quantity of items?

You must carefully analyze all of your reporting requirements and design your tables in such a way as to make it straightforward to achieve your goals.

However, it's generally a good idea to create a table to store stock events that might look something like this:

  • eventid - a unique identifier for this event.
  • productid - the product / item id
  • eventtype - identifies the type of event (eg receive, sale, loss, restock, count, transferin, transferout, etc...)
  • timestamp - when event occurred.
  • stockinglocationid - identifies the warehouse/store/...
  • . . .

stock events are only created, they are never updated. That's the key to being able to get the kind of analysis you want.

From this, you should be able to reconstitute the qoh for any product at a prior time.

For sales, you would certainly want all sorts of other data points in addition to quantity, price, product - customer type, customer country/region/state/city, sales location, salesperson, . . . Treat this table as immutable, just like stock event.

I'd encourge you to google 'inventory star schema' and 'sales star schema'. This should give you some food for thought on how best to organize your data for reporting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM