Handle changes in calculation logic for order system

22 views Asked by At

I am currently dealing with a problem I can't find a answer to.

Imagin a software which holds information about Orders and OrderItems. Something like this:

OrderItem {
 ...
 price,
 amount
}

Order {
 ...
 total,
 vatTotal,
}

OrderDiscounts {
 ...
 percentage,
 targetGroup
}

**OrderItems can be subtotal as well holding no price and amount

All those information have to be taken into account for calculating the vat and the total.

As the order is finalized, the tables are getting locked via triggers to prevent changes on the finished order. The total and vat total of the order is saved on calculation time which happens while displaying the order information.

First Problem: Time passes and there is a decision (or a bug) so that the logic for the calculation has to be updated. Let's be friendly and say it's a decision to adjust the logic how the system does the rounding.

Now the following problem occurs: If you want to show an old order with it's total and subtotals it would have to recalculate everything with the new logic and obviously you run into a small difference.

How can you solve this problem in a elegant way?

Second problem: You generate a PDF out of the order on the time of finalizing. Again time passes and the software gets updated/adjusted. For example a table header for the order is changed. If you would reprint the order again it wouldn't be the same anymore.

Possible solution first problem One solution which comes to my mind is to save all information visible to the user in database fields. This would require to add fields like lineTotal for almost everything.

Are there other possible solutions which I'm not able to see?

Second problem Is there any other way than just saving the PDF somewhere and reference the once generated pdf? Is this even an issue?

0

There are 0 answers