How to handle price fluctuations in an invoice application?

自闭症网瘾萝莉.ら 提交于 2019-12-04 08:51:13

I would always store the actual name, quantity and price at the time of purchase against each order item, effectively de-normalising the data. An order is a snap-shot in time and shouldn't be related back to something that can change. Not only can prices fluctuate, but what happens if you delete or rename the original product and your invoice relates back to it?

Add a price field to the invoice line.

I would echo your suggestion: Breaking out Prices into a separate table with these columns:

PriceId, ProductId, Price, StartDate, EndDate.

This way you can also plan ahead for future price changes. Current data could be gotten using (Sql Server syntax):

SELECT *
FROM Products
   Inner Join Prices ON Products.ProductId = Prices.ProductId 
      And GetDate() Between StartDate and EndDate
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!