Generate price depending on months if price for each month is different

Hi there folks!
I will describe my situation: User got different prices for property booking each month(ex: may - 30$ per day, june- 40$ per day…) and customer choses dates via airdate timepicker(start date and end date)
So for example customer chose: 10 days in may and 10 days in june - how to construct the logic to solve this problem?

Someone may have a better or more detailed solution but I’ll give my thoughts in case they are helpful.

I think you probably want to solve the more general case of “what if the start date is X number of months previous to the end date?” In other words, I’m assuming you could have, say, a start date May 10 and an end date August 14.

In this case I would iterate over the months from the start date month to the end date month to add up the costs.

Here’s how that would work for any scenario where the start and end months are different:

monthDiff = endMonth - startMonth (e.g. 3)
monthInc = 0
cost = 0
Loop
thisMonth = startMonth + monthInc (June + 1 = August)
If monthInc = 0: cost = cost + $/day * (days in startMonth - startDay)
If monthInc = monthDiff: cost = cost + $/day * endDay; exit loop
If monthInc != 0 or monthDiff: cost = cost + $/day * days in thisMonth

Of course $/day will be different for each month.

Now, as far as how to implement this in Bubble, I would suggest a back end workflow where you can call that workflow recursively to iterate. Now, you (annoyingly) can’t pass a result form a backend workflow directly to the front end, so to get the result on the front end you would either have to make changes to a thing in the DB that the front end can see (easiest), or expose this back end workflow as a public API and use API connector on the front end to call your own workflow and get the result.

Best of luck.

1 Like

Thank you very much for such a detailed answer! I will digest the information, I will try :)) I will tell you the details if everything works out

This topic was automatically closed after 70 days. New replies are no longer allowed.