简体   繁体   中英

How to properly handle rental inventory via database

I am building a rental inventory app that handles the tracking of rental reservations. I think I might be over thinking it but I am getting stuck on trying to figure out the model or schema of inventory scheduling part. In the attached image, I have 4 copies of one movie. On the first only one copy is scheduled to be out; on the 5th, 3 copies are out; on the 6th and 10th all copies are out. Now, I would like to design the database in a way in which I can look up a date OR date-range to see how much inventory is available that day(s). The challenge is that there might NOT be individual sku's or tracking for each individual rental item. So I can't treat Movie_1 as if it has movie_1_a,movie_1_b,movie_1_c,movie_1_d. Instead I have to treat it like Movie_1 has 4 copies and on the 5th, 3 copies are out but we don't know which ones.

Can anyone give any suggestions on how to write the schema. How would a sample query look like to search for availability?

出租库存进/出图

There are two, (three if you include sales/delivery) aspects to this.

Something like

Originals (StockId etc)

CopySchedule(CopyId, StockID, DeliveryDate, NumberOfCopiesRequired, NumberOFCopiesAchieved, Status, etc)

Copies (CopyId, Quantity, etc)

So when you set a CopyScheduleStatus to Done, you add a record to Copies.

Then your projected stock level would be from Now? To Whenever would be

NumberInStock - NumberScheduledtoDeliver( between now and whenever) + NumberScheduledToCopy(between now and whenever)

Don't try to do all of your needs in one model.

In your movie table you shoud have movie_copies field, then create a table for [Movie_flow] with this schema:

[PK]movement_id (could be an identity or an pair year/movement number if you wanna reset  movements counter every year)
movie_id
movement_datetime
movement_type (I-in/O-out)
quantity

When you want to know movie availability at a specific date you can simply read al movements by movie_id, adding quantity value for movement_type "I" and decreasing quantity for movement_type "O" until the given date: movie_copies - this count gives you the movie copies available.

Keep clean that table to optimize performance, you can archive older movements if you want to keep an history

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