Auto Surcharge Query

Hey guys,

I’ve gone through a few topics to see if there was anything I can find relating to auto surcharges on specific days(Such as weekends) but could not find much.

Only thing I found close was the use of triggers.

I will share my progress here, but I just wanted to know, what would be the easiest way to deal with auto surcharge applications?

For example I’d like to apply a surcharge of 10% on weekends or special holidays such as valentines day etc.

Would the use of triggers be an easier way, or use of order tags with custom constraint rules, maybe a button that triggers a price change for the day upon press, which I can create an auto command to switch on & off type of thing.

Just would like to get some ideas to figure out the best way to go about this.

Lately it’s been a hot topic among a few of our clients so I figured I’d ask.

Any input is highly appreciated.

I do a lot of things with order tags.

I imagine you could set-up an JavaScript array of dates in a script and then use a {CALL:} in a contrainst to have some JS logic to return “ChargeTheBuggers” or “BeNice” depending on if today’s date is either in the array or if the day of the current week equals a certain value.

If the contraint returns true, then use an action to add an Order Tag with a rate specified.

Interestingly I had a feeling you were going to say that, as I saw some previous posts mentioning you were doing this haha.

Unfortunately I’m really not good at Jscript and how it calls upon in an action or rule. I’ve attempted it in the past, struggled hard!

Hmmm

Build it up in stages…

1) Create a script and test it

image

// The various functions here will be used
// in rules to handle surchaging on certain days
function whatDayIsToday(){
var d = new Date();
var n = d.getDay();
return n
}

This script will output the day of the week as a number 0-6 (Sunday is 0)
https://www.w3schools.com/jsref/jsref_getday.asp

2) See your script result in a rule

image
{CALL:date.whatDayIsToday()}

3) Use your script result as a constraint instead

image
[=TN('{CALL:date.whatDayIsToday()}')] == 3

1 Like

Thank you for providing an example.

I will attempt to work with this and see how I go. Will post status here in case its useful for anyone else.

You are welcome… That should get you started…

Ultimately you probably want all the logic inside your script… This should mean that the script will either give a return value of “ChargeThem” or “DontChargeThem”… You will need to look at various generic JS tutorials (wider than just here within SambaPOS) to see how you would build out this logic.

I am thinking (psuedo code)…

today = new date = today
day = day from today
set ReturnVal = DontChargeThem
set arrats
set array BadDays [Sat, Sun]
set array BadDateMonths [25/12, 14/02, 01/01]
set array BadDateMonthYears [04/03/2019, 06/03/2020, 10/03/2021]

If day is in BayDays then ReturnVal = ChargeThem
If datemonth(today) is in BadDateMonths then ReturnVal = ChargeThem
If today is in BadDateMonthYears then ReturnVal = ChargeThem

return ReturnVal

The reason I have used two different arrays to hold the dates is that some dates are chargable every year (valentines day)… But others might move year-by-year (easter - or even Friday and Saturday nights near valentines day).

Also even if you don’t go down the order tag route, this script idea is probably going to be pretty important to actually build out the underlying logic of whether or not the surcharge should be applied.

4 Likes

Hello, the documents I shared below may be useful

5.1.4.a. How to Add Service Charge to Ticket?

2.3.13.a. How to Add Service Charge Manually by Using a Button?

1 Like

Thanks for sharing those links.

I have looked at them but didnt realize the second one was there.

I’m used to creating a calculation type, but that second method got me thinking we may be able to automate after all.

I’m going to use a mix of script and the second method to see if I can get it to work.

Thanks for your inputs!

1 Like

You shouldn’t need a script, even simpler than that.
You can just use constraint with date based constraints.
Look for happy hour tutorial without triggers, think it was one of Qs.
Along the lines of
{DATE:ddd} = Mon|Tue|Wed etc
Or {DATE:ddMM} = 1302

1 Like

Q did that auto happy hour trigger didnt he?
Hmm

This is a cleaner approach for sure! I just do a lot of my complicated calculations in a script, so I jumped a little quickly to that.

He did one without scripts, have refered to it many times for the date based part for other constraints. Will find it in a sec.

Here it is.
His setup was a little more complicated than any happy hours I have done which just used price list and update price list on order added with time and date constraints.

The key part I refer to is like in this screenshot. Just the constraints not the rest.

4f242e556a73ea01d03125434d44d2446e74388b

Hmmm Im more confident with rules and constraints, i may take Q’s approach, but I think for the sake of learning too, I may try scripts too. I’ll try to put something together in next few days, see what I can come up with.
Would triggers not be a good method to use?

Triggers wont execute if you have a ticket open on a terminal.

1 Like

Ohh Good point. I didn’t know that. Thanks for pointing that out

That’s true but they will execute as soon as ticket gets closed. It only defers the execution if it triggers while editing a ticket.

However we’re not using triggers for date / time based automatons anymore. Q’s method will work better.

1 Like