python - Items movement daily collection database design system issue -


i doing simple database in mysql track movement of items. current paper form looks this:

date     totalfrompreviousday  newtoday   lefttoday  remainatendofday 1.1.2017    5                     5           2          8 (5+5-2) 2.1.2017    8                     3           0         11  ( 8+ 3 -0) 3.1.2017    11                    0           5         6   (11+0-5) 

and forth. in table, want make totalfrompreviousday , remainatendofday calculated fields show in front end only. cos tend erase on paper due errors. want them reflected based on changes other 2 fields. such, did table this:

id date newtoday lefttoday 

now problem facing is, want select date , able "there 5 items @ start of day or previous day, 5 added, 0 left , day ended 10 items"

so far, can't think of way going it. theoretically, want try this: if requested day feb. 1, 2017, start @ 0 cos that's day started collecting data. if not, loop thru records @ 0 , doing math until requested date found.

but inefficient cos have start form first date until last every time.

is approach ok or should include columns in table? if first, way in python/mysql?

i think have step little bit , define business needs first (it worthwhile talk somebody, worked stocks before) because these determine table structure.

a system tracks current level of stocks , movement. business decision how save historical stock level , influences how store data.

you may save current stock level along transactions. in case store stock level in transactions table. not have sum transactions per day because last transaction per day have daily closing stock level anyway.

you may choose save historic stock levels regularly (on daily / weekly / monthly, etc. basis). in case have separate historic stock levels table stock id, stock name (name may change on time, may idea save it), date , level. if know historic stock level point of time falls between saved points, need take latest saved stock level before period looking for, , sum transactions saved period.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -