Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle price fluctuations in an invoice application?

In an invoicing application, consider following:

I have a products table that also contains the price of the product. And then I have an invoice and invoice_lines table and in each invoice line, I refer to the product id along with quantity. In this case, I am not storing the price of the product with the invoice line.

Now few months later, if the price of the product changes, any report would show the volume of the sales based on current price instead of the price on which the product was actually sold.

One solution that comes to my mind is that we keep a separate table named prices that links to each product and whenever the price of the product is changed a record is inserted into this prices table. The latest record in this table always is considered as the current price for new invoices. Each invoice line indicates its price by indicating the id of the price so that it shows correctly later in reports.

What are the best practices for handling such situations?

like image 987
Mohsin Shafique Avatar asked Aug 12 '10 16:08

Mohsin Shafique


People also ask

What are price fluctuations?

Price fluctuation relates to an economic metric that is used to determine the rate of increase or decrease in the price of goods and services within a market. Price fluctuation is expected in the market because of the growth and decline in market demand.


2 Answers

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?

like image 173
Dan Diplo Avatar answered Oct 02 '22 15:10

Dan Diplo


Add a price field to the invoice line.

like image 36
Vebjorn Ljosa Avatar answered Oct 02 '22 16:10

Vebjorn Ljosa