1

I am working on a pricing algorithm where I want to generalize the calculation of certain components/charges. There are 3 components to the charges.

1 - a basic/core charge, 2- a handling charge (may have many number of these), 3- tax components (may have many varieties of these as well).

I am wondering if I can store an algorithm like below in a database and use this for calculating the charges every time.. Or is there a better way of handling such pricing in a flexible way?

  • Step 1: Step1Result = Sum(value of component1, value of component2, value of component4) (Let us say the freight charges are the sum of a few core charges)
  • Step 2: Step2Result = Step1Result * .01 (let us say some handling charge is about 1 percent on the step 1 result)
  • Step 3: Step3Result = Step1Result * .103 (let us say some tax on step 1 result is 10.3 percent)
  • Step 4: Step4Result = Step3Result * .0203 (let us say some special tax surcharge as 2.03 percent)
  • Total: TotalResult = step1result + step2result + step3result + step4result

[Edit] Adding a sample of a logistics freight service which is what we are working on now.

  • A Parcel booked may get transported from location A to Location E via C,D and E.
  • So the base freight charge is calculated as the cost of transportation between A to B, B to C, C to E.
  • The parcel may be unloaded from one vehicle at location D and loaded to another vehicle for which loading/unloading charges may have to be added. This may be a percentage of the transportation charge or an absolute value. There may be additional charges which may be added in the future as well
  • Then we may have some other premium facility charges
  • We have taxes which will have to be computed not on the entire cost but one tax may go to basic freight charge and the other may go to the other charges and another set will be on the total cost. Now I need a flexible logic so that the calculation is configurable pricing logic for the user. If someone has worked on such a generic algorithm, pls give an idea. Please note that I have searched for such stuff in SO as well as google and unable to come up with a concrete one yet. If I missed something, please feel free to point out.

Basically I would like to store the formula and workout the price with it. This logic is going to be implemented in C# and Sql Server.

5
  • What benefit are you expecting to get by storing the formulas in a database? Commented Feb 6, 2014 at 11:12
  • Storing the intermediate results in the database is not going you give you much benefit. However, you state twice "may have many number of these", and those are the interesting parts. How do these relate to your components or to external influences? You are not giving us enough information, I'm afraid. Please edit your question; actual examples help. Commented Feb 6, 2014 at 11:29
  • @JeffO, Flexibility.. The problem is I have 3 types of charges to be calculated and this will be changing atleast once a month. Commented Feb 6, 2014 at 11:45
  • @Jan Doggen, I added one of the actual calculation. Commented Feb 6, 2014 at 11:53
  • @Muthu Thanks for the update. Generally you have to store in the database "the steps that will apply", thier parameters, but not the formula. So the transportation route, a 'transfer' flag for each waypoint with parameters percentage/fixed cost, tax percentage on goods, tax percentage on freight etc. etc. Do you have all that already? If yes, show and describe your entities. If not, you should work on that first. It does not sound as is there a generic algorithm taking all the variable factors into account. Commented Feb 6, 2014 at 12:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.