Action Constraint Help

That explains a lot I’ll look at it and try to see what we can do.

But your rate was being called from an entity field? I dont see staff entity on the screenshot?

shouldnt be too hard with my favourite SETTING action :smiley:

entity type for employees (same name as user)

Field: Pay Level

ask question with numbpad “how many employees” result goes in setting:empNo

Select employee (im sure entities can be listed in a ask question action?) with question

then a popup comes up with formula (in simple terms) Daily Sales/empNo/100*{name of employee selected :ENTITY DATA:Pay Level}

or so

1 Like

it is called when creating a transaction
in order not to create many transactions, one is created when closing shift (entity PunchOut)
X and Y:
OS.cou is count
OS.empl1 (or empl2 etc.) is entity name employee
{REPORT ORDER DETAILS:([O.Total]/[OS.cou]).Sum:(OS.empl1={ENTITY NAME}) AND O.Total > 0}
Z:
{REPORT ENTITY DETAILS:EC.Pay Rate percent of sale:(EN={ENTITY NAME})}

so youll need to know all the time how many employees are working? which can be updated with either a timeclock scriipt change or having a manual button where you can edit the number of employees on shift at the time

I explained it above
created a rule that goes through the options and sets the correct

so it looks like in Sambapos

1 Like

sorry, i misread i thought you were still asking for help. Doing too many things at once here lol

Am pretty sure this could be simplified but if it works for you then go with it i guess.
If nothing else could just feed the 4 states into a script as 4 vairables and have it return the count in a single action.

Wouldn’t it be easier to calculate salary with scripts?

PS: I’m just guessing this is about calculating salary of employees. Sorry if it is something else.

1 Like

you’re right.
but I don’t know jscript so much to create a working script

How percentage salary action works? Can I see the screen shot?

OK nevermind it seems to update the order state… Let me think about it.

I think cou is same for all actions and only state value changes. Is it correct?

As a starting point you can use this function to count number of non-empty items.

I’ll show how you can call it.

function count(v){
    var r = 0;
	for (i=0;i<arguments.length;i++){
		if(arguments[i]) r++;
	}
	return r;
}
1 Like

I added a Show Message action to test the function result.

I added 2 hardcoded items, one tag item and an empty item. As the result of the tag will be empty it shows 2.

Whis is how we can call the script’s count function. We’ll use handler name, function name and parameters.

{CALL:emp.count('emre','asdf','{TICKET STATE:X}','')}

Probably you’ll use it like…

{CALL:emp.count('{ORDER STATE:empl1}','{ORDER STATE:empl2}','{ORDER STATE:empl3}','{ORDER STATE:empl4}')}

So a single action will be enough. As the count() function does the calculation you’ll not need constraints.

If you need I can also help creating a script for calculating employee salary…

I added the salary function.

Let me figure out how we should call this.

function salary(order_price, employee_count, percent){
	return order_price / employee_count / 100 * percent;
}

works through {SETTING:X}

First, at the entrance to the shift, each one is assigned his {SETTING:}


set according to its position indicated in entity custom field:

further when adding an order
rule checks compliance
{menu item custom tag} = {entity custom field:Position}

and adds order state

and another rule runs which sets count

in the ticket looks like this:

at Punchout setting is reset and create transaction document is amount in transaction calculate formula which I quoted above (“big monstrues formula”)

PS.while writing the message, you added some scripts, now I will try to optimize the process with their help

OK I guess you can simplify employee count calculation as I’ve showed above. I’ll be glad if you can try it and let me know if it works fine or not.

I’ll try to understand what can we do to simplify it further.

OK so I’m adding an example for how to update settings inside script. You don’t need to call update setting action. It updates settings inside script.

You can call updateSushiEmployee function like

{CALL:emp.updateSushiEmployee('{ENTITY NAME}')} 

… or you can use Execute Script action depending on your need.

This is the final state of the function. I hope it gives an idea about how you can use scripts. The script will also test if employee already assigned. As you’re using it with the time clock you’ll probably won’t assign a single employee multiple times but that might be a good example for how scripts can be used.

function count(v){
    var r = 0;
	for (i=0;i<arguments.length;i++){
		if(arguments[i]) r++;
	}
	return r;
}

function salary(order_price, employee_count, percent){
	return order_price / employee_count / 100 * percent;
}

function readSetting(setting_name){
   var qry = '{setting:getGlobalSetting(name:"'+ setting_name + '"){name,value}}';
   var res = gql.Exec(qry);
   var res = JSON.parse(res);
   return res.data.setting.value;
}

function setSetting(setting_name,setting_value){
    var qry = 'mutation m {setting:updateGlobalSetting(name:"'+ setting_name + '",value:"' + setting_value + '"){name,value}}';
    gql.Exec(qry);
}


function updateSushiEmployee(employee_name){
	var sushi1 = readSetting('sushi1') || '';
	var sushi2 = readSetting('sushi2') || '';
	var sushi3 = readSetting('sushi3') || '';
	var sushi4 = readSetting('sushi4') || '';
	var target= '';
	
	if(sushi1 == '' || sushi1 == employee_name) target = 'sushi1';
	else if(sushi2 == '' || sushi2 == employee_name) target = 'sushi2';
	else if(sushi3 == '' || sushi3 == employee_name) target = 'sushi3';
	else if(sushi4 == '' || sushi4 == employee_name) target = 'sushi4';
	
	setSetting(target,employee_name);
	
	return target;
}
2 Likes

Also if you need to read more about updating settings inside a script you can read Q’s great example…

2 Likes