Custom Can Confirm Admin Pin Prompt

So working on better logs and alternate login options.
Seen it asked a couple of times but not seen a documented solution.
I plan to use this to log and set state value for void and the likes.
I like having void available for all rolls as this allows a passing manager to void mistakes without having to switch to their user.
This however will show as a void for the current user not the manager than ‘swiped’ to confirm admin pin.
So rather than use confirm admin pin I have used a script and a multi set command flow with [?prompt] for pin entry then script to check can confirm admin pin option for the user with the ‘swipped’ pin.

Since I would prefer to use less rules for easier managment I will pass all the automation command through my own can confirm admin pin rule before triggering the actual command for say void.

My example is for Void but will extend this to refund and gift etc.

Fisrt step is to change the VOID automation command button.
Rather than going straight to the void command rule it will now go to my new processing rule;

You will see I have added - ConfirmAdminPin to the command name and set Void as the only value in the values field. I will use this command value to separate the end command back to the original void rule once pin is and can confirm roll checked.

Next I make a ‘Custom Confirm Admin Pin’ rule;

So the automation command name is constrained to the ‘Void - ConfirmAdminPin’ command now triggered by the Void button.
I then use an execute automation command action to trigger the original void rule.
Using [:CommandValue] passed from the button the triggered rule after this will now be the origional Void rule.
Now for the command value I use a {CALL:xx} function with a [?Prompt]. The prompt will ask for user to enter a pin like confirm admin pin. The entered value is passed to the acript to validate and will pass the value returned as the command value into the void rule.

I have used this script;

 function canConfirmAdminPin(inputPin){
	qry = 	"SELECT u.Name as UserName ,max(case when p.[Name] = 'CanConfirmAdminPin' then p.value end) as CanConfirmAdminPin	";
	qry +=	"FROM [Users] u JOIN [UserRoles] r on r.Id = u.UserRole_Id JOIN [Permissions] p on r.id = p.UserRoleId				";
	qry +=	"WHERE u.PinCode = '"+inputPin+"'";
	qry +=	"GROUP BY u.Name";
	var userQry = sql.Query(qry).Delimit('~').First;
	if(!userQry){
		return false
	}
	var userQryArray = userQry.split('~');
	var userName = userQryArray[0];
	var canConfirmAdminPin = userQryArray[1];
	if (canConfirmAdminPin==0){
		return userName
	} else {
		return false
	}
}

This script will lookup the entered pin and return false if pin is not valid or if correct but user does not have a role set which allows can confirm admin pin.
If the pin is correct and has permission to confirm admin pin it will return the user name for the pin.

Then all that is left is to add an extra constraint to the original void rule for command value not equals False.
This way if the script cannot find pin or doesn’t have permission and returns/passes False as command value the rule will not fire.
Anything else - ie the user name the rule triggers.
Then if not already set, adding command value to the gift state void value the user who swiped will be named as the state value;

image

Now even with default work period report Voids will be listed per user;

image

2 Likes

I really envy your Scripting skills >.<

This is great!

2 Likes

JScript part is simple, but am chuffed with the SQl as after half an hour tring to find the permissions table LOL I managd to JOIN which was a worry at first as it is stored wordpress meta style with permission name 'key and 1/0 value. As usual google showed the way.

1 Like

Ive followed many of the tutorials regarding Jscript within SambaPOS and honestly I still have a hard time getting grips with it.

SQL is really fun but also can be a bit of a pain to deal with. I only understood SQL because I studied it a lot at Uni(And yet I still suck at putting something together haha)

JScript is 95% the same as JavaScript which in all honesty is more valuable to understand but luckily they are very similar.
Its synchronous like PHP which makes like simpler, line by line in order, very logical. Its all just about handling variables. Google shows and explains functions and there parameters and being so similar to java there is huge amounts of info on web.

Before doing that PMS integration I have never touched JScript, Java or SQL beyond very simple tweeks to existing scripts. Luckily q and kendash helped allot and took interest in my project and offered allot of guidance in early days.

I need to go back to like a coding bootcamp lol

Only took me a few months to get the basics and build that integration from 0 experience other than light HTML and CSS. No pro but think I can hold my weight.
A logic mindset helps which I am fortunate to have.

A change to contains ConfirmAdminPin simplifies the process, already propagated out to void, change price, gift and refund;

image

2 Likes

Can I do it in Samba POS 3 ?

No, you need scripting for SQL and scripts. Not available before v5

1 Like

how can I do ADMIN cinfirmation for Void items in Version 3

Oh thought you meant custom method of tutorial, normal confirm admin pin is an automation command button option, that is available in V4 but not sure about v3. Most on forum have not used V4 yet alone v3, I haven’t looked at v3 for at least 5 years.

It is not possible in V3. There is no support for Confirmation of Automation Commands

It is however available in V4

2 Likes

Wow! Fantastic! Just in time!

Great code, I tweaked it to add the reason for voiding.