0

I'm developing a tourist web app with node.js and microservics.

I need to develop a pricing service which will do all the calculation for the guest (price for night, taxes, VAT, discounts etc).

Moreover, I need those calculation will be easy to dynamically change and control.

From my past experience, doing those calcs in common web programming languages and/or storing math formulas in the db end with a mess.

Are there any alternative solutions for this? From what I read so far language like python, R or Java can fit to the job. However, is there any specific library within those which aimed for pricing?

wizard
  • 583
  • 2
  • 9
  • 26

2 Answers2

0

On can do calulations in (datamodel / class) in javascript

1 : you can create a javascript class

   function sales(){
    let self = this
    this.address = '';
    this.personname = '';
    this.totalVat = 0
    this.items = [];
    this.calculateTax = function(){
       let tax = ...compute items array and set 
       self.totalVat = tax
     }   
   }

Note :

you can use this data model if you are going to use it only on ui

else if

you want to use it on server then you can use same datamodel on server

esle if

you want to use on both server and ui then

(you can maintain only 1 copy of this model shared by server and ui , here you can use require.js bundling to take help of sharing one datamodel , also there are nice articles that show how to share js datamodels)

in Case Of (you want to use on both server and ui then)

You mentioned database , you create mechanism to store formula in database and you can generate sales_datamodel.js on server whenever any changes are done in datamodel in db

vijay
  • 10,276
  • 11
  • 64
  • 79
  • reply when stuck – vijay Nov 13 '17 at 06:46
  • I'm looking for more complete solution like using framework or dedicated programming language like R for example. – wizard Nov 13 '17 at 14:51
  • you questionnaire information is very limited , i answered according to that question..can you be more specific with question and update question , Like you said You want to use R language - mention this in question ,also mention what you were trying earlier with some sudo code snippet – vijay Nov 13 '17 at 15:16
  • Updated the question. – wizard Nov 14 '17 at 06:52
0

@wizard I would share here something .

If you have complex calculation or any type of calculation do it in db end if feasible.

The best approach postgres

to do this type of process is to make function (PL\SQL) block . If you are using postgres create all calculation in postgres .

This is why node.js was design , no calculation in node.js end .

mongodb

if you are working with mongodb with this approach then i will recommend you to go with

Stored JavaScript in MongoDB

Himanshu sharma
  • 7,487
  • 4
  • 42
  • 75