Waiter Screen / Ready Orders

Just curious, but why “green”? If the screen only contains complete Kitchen Orders that are ready to go, what is the point of making them “green”?

Anyway …


##Task Type

##Actions

We will use this Action to Execute some JScript Functions.

##KD ExecScript [Execute Script] (Action)##

Action Name: KD ExecScript
Action Type: Execute Script
###Parameters:###
Function: [:handler.func]
Command: [:cmd]
Run In Background: [:runBG]

We will use this Action to execute other Automation Commands.

##KD ExecAMC [Execute Automation Command] (Action)##

Action Name: KD ExecAMC
Action Type: Execute Automation Command
###Parameters:###
Automation Command Name: [:AMCname]
Command Value: [:AMCvalue]
Background: [:runBG]
Delay: [:delay]

We will use this Action to Duplicate a Task.

##KD Set Widget Value [Set Widget Value] (Action)##

Action Name: KD Set Widget Value
Action Type: Set Widget Value
###Parameters:###
Widget Name: [:widgetName]
Value: [:value]

##Script

:warning: This Script uses new GraphQL functions available only in v5.1.60 or higher. Be sure to upgrade to 5.1.60 or this will not work.

##TSK Task Type Functions [tasks] (Script)##

Script Name: TSK Task Type Functions
Script Handler: tasks

Script:

function getTaskbyIdentifier(taskType,ident,field) {
  // getTaskbyIdentifier('KD Task GUI - Food','27751-Qure Burger.Burger-12837-j9tXI2XMRkq7Q446SFfroQ')
  taskType = typeof taskType==='undefined' ? '' : taskType;
  ident    = typeof ident==='undefined' ? '' : ident;
  field    = typeof field==='undefined' ? 'name' : field;

  if (taskType=='' || ident=='') {
   return false;
  }
  
  var qry = '{task:getTask(taskType:"'+taskType+'",identifier:"'+ident+'"){id,name,identifier,content}}';
  var r = gql.Exec(qry);
  r = JSON.parse(r);
  var task = r.data.task;
  
  //dlg.ShowMessage("tt:"+taskType+"\rid:"+ident+"\rname:"+task.name);

  return task[field];
}

function addTask(taskType,name,content,ident,color,taskTypeOld) {
  // addTask('KD Waiter - Food','','blah','27751-Qure Burger.Burger-12837-j9tXI2XMRkq7Q446SFfroQ','#FFFFFF00')
  taskType  = typeof taskType==='undefined' ? '' : taskType;
  taskTypeOld = typeof taskTypeOld==='undefined' ? '' : taskTypeOld;
  taskTypeOld = taskTypeOld=='' ? 'KD Task GUI - Food' : taskTypeOld;
  ident    = typeof ident==='undefined' ? '' : ident;
  name     = typeof name==='undefined' || name=='' ? getTaskbyIdentifier(taskTypeOld,ident,'name') : name;
  color    = typeof color==='undefined' ? '' : color;

  var oldContent = getTaskbyIdentifier(taskTypeOld,ident,'content');
  oldContent = oldContent.replace(/"/g,"'");
  oldContent = oldContent.replace(/\r\n/g,'<!rn>');
  content = oldContent + '<!rn>' + content;

  //dlg.ShowMessage("tt:"+taskType+"\rid:"+ident+"\rname:"+name+"\rcontent:"+content);
  
  if (taskType=='' || name=='') {
    return false;
  }
  
  var qry='mutation m {addTask (task:{taskType:"'+taskType+'",name:"'+name+'",content:"'+content+'",isCompleted:false,identifier:"'+ident+'",customData:[{name:"Color",value:"'+color+'"}]}){id,name,isCompleted,content,identifier,customData{name,value}}}';
  var r = gql.Exec(qry);
  r = JSON.parse(r);
  var task = r.data.addTask;
  
  return task.name;
}

function updateTask(taskType,name,ident,color,content) {
  // updateTask('KD Waiter - Food','','27755-Poutine-12841-swifCxkYVk6UDrmcd0JUmg','#FFFFFF00')
  taskType = typeof taskType==='undefined' ? '' : taskType;
  ident    = typeof ident==='undefined' ? '' : ident;
  name     = typeof name==='undefined' || name=='' ? getTaskbyIdentifier(taskType,ident,'name') : name;
  color    = typeof color==='undefined' ? '' : color;
  content  = typeof content==='undefined' ? '' : content;

  //dlg.ShowMessage("tt:"+taskType+"\rid:"+ident+"\rname:"+name+"\rcontent:"+content);
  
  if (taskType=='' || name=='') {
    return false;
  }
  
  var qry='mutation m {updateTask (taskType:"'+taskType+'",identifier:"'+ident+'",task:{taskType:"'+taskType+'",isCompleted:false,identifier:"'+ident+'",customData:[{name:"Color",value:"'+color+'"}]}){id,name,isCompleted,content,identifier,customData{name,value}}}';
  var r = gql.Exec(qry);
  r = JSON.parse(r);
  var task = r.data.updateTask;
  
  return task.name;
}

##Rule

This Rule will be fired when you complete a KD Food Task.

##KD Ready - Food [Automation Command Executed] (Rule)##

Rule Name: KD Ready - Food
Event Name: Automation Command Executed
Rule Tags:
Custom Constraint List (1):
Execute Rule if: Matches
Automation Command NameEqualsKD Ready - Food

##Actions (2):##

KD Set Widget Value

Constraint: (none)

widgetName: KD Task Editor - Food
value: Duplicate>KD Waiter - Food
KD ExecAMC

Constraint: (none)

AMCname: KD Waiter Color - Food
AMCvalue: [:CommandValue]
runBG: True
delay: 1

##Mappings##

Mappings
Terminal User Role Department Ticket Type
****

This Rule will be fired after the first Rule, to update the Task Card Color.

##KD Waiter Color - Food [Automation Command Executed] (Rule)##

Rule Name: KD Waiter Color - Food
Event Name: Automation Command Executed
Rule Tags:
Custom Constraint List (1):
Execute Rule if: Matches
Automation Command NameEqualsKD Waiter Color - Food

##Actions (1):##

KD ExecScript

Constraint: (none)

handler.func: tasks.updateTask('KD Waiter - Food','','[:CommandValue]','#55007700')
cmd:
runBG:

##Mappings##

Mappings
Terminal User Role Department Ticket Type
****

##Some things to note:

The Food Task Widget needs to have this in Task Complete Commands:

KD Ready - Food:[Id]

So when a Food Task is marked as complete on the KD, an Automation Command will be fired named KD Ready - Food and it will pass along with it, then Id (identifier) of the Task as the [:CommandValue].

The Rule named KD Ready - Food handles the Automation Command, and it uses the Set Widget Value Action to Duplicate the KD Food Task to become a KD Waiter Task Type (Duplicate>KD Waiter - Food). The Widget Name in this case is the Name of the Task Editor Widget for your KD Food Display:

KD Task Editor - Food

The Rule then:executes another Automation Command named KD Waiter Color - Food.

The Rule named KD Waiter Color - Food handles the above Automation Command, and executes a JScript Function:

tasks.updateTask('KD Waiter - Food','','[:CommandValue]','#55007700')

There are 4 parameters to the updateTask function:

tasks.updateTask(taskType, name(optional/blank), identifier, color)

Mapped out:

taskType       = 'KD Waiter - Food' // our new "Waiter" Task Type for Food
name           = '' // when left blank, the Task Name will not change
identifier     = '[:CommandValue]'
color          = '#55007700' // Green - really, this is the only thing we are updating

I named the new Waiter Task as “KD Waiter - Food”. Adjust those parameters as necessary for your setup.

Obviously, you will need to create a new custom Entity Screen for the Waiter Display, and add a Task Editor Widget to it for the new Task Type “KD Waiter - Food”.

1 Like