Hi @Rapturecamps_Elisa_P - welcome to the forum.
You're in luck. This month we launched some new time/date related functions that are just perfect for your use case.
Here's my take on how you can do it.
I've made some pretty significant changes to really take advantage of everything Text Blaze has to offer.
For instance:
- I used a couple {note} commands to insert notes for the agent, which will not be inserted in the final snippet.
- I created a keyed list with the time brackets and associated refund amounts, and used it in a number of ways, such as generating the refund policy data for the agent, checking the number of days against the values in the list, and referencing the refund amount accordingly.
- I used the {if} command to insert text based on conditional logic
- I used the {error} command to prevent the agent from inserting the snippet unless they've filled in the booking amount.
Have a look and let me know what you think. You can copy the snippet directly to your dashboard by clicking on the "Copy to Text Blaze" button in the top right corner.
{note: trim=right; preview=no}
{days=datetimediff(datetimeparse(booking, "DD.MM.YYYY"), datetimeparse(cancellation, "DD.MM.YYYY"), "D")}
List with cancellation periods (in days) and corresponding refund percentages:
{periods=["60":90, "45":80, "30":60, "20":30, "12":0]}
{bracket=min(filter(keys(periods), item -> days <= item))}
{refund=catch(periods[bracket], "0")}
{endnote: trim=right}
{note: trim=right}
For agent:
Booking date:
{formdate: DD.MM.YYYY; name=booking} ({=datetimeformat(datetimeparse(booking, "DD.MM.YYYY"), "dddd, MMMM Do, YYYY")})
Cancellation date:
{formdate: DD.MM.YYYY; name=cancellation} ({=datetimeformat(datetimeparse(cancellation, "DD.MM.YYYY"), "dddd, MMMM Do, YYYY")})
Difference in days: {=days}
Cancellation refund policy:
{repeat: for period in periods; trim=right}
{=period} days in advance: {if: periods[period] == 0}No{else}{=periods[period]}%{endif} refund.
{endrepeat}
================ END OF NOTES ================
{endnote: trim=right}
Total booking amount: ${formtext: name=total} {if: total <= 0}{error: Fill in booking amount; block=yes}{endif}
Booking date: {=booking}
Cancellation date: {=cancellation}
{if: days > 12; trim=right}
Since you are cancelling {=days} prior to your booking date, we can refund you {=refund}% of the booking amount, which comes to ${=(total/100)*refund}.
{else: trim=right}
Unfortunately, we are unable to refund any part of your booking since your cancellation is less than 12 days prior to your booking date.
{endif: trim=right}