Skip to content

POS Yes No Recipe

Andy Theuninck edited this page Feb 20, 2015 · 2 revisions

One common pattern is to provide the cashier with a yes/no prompt. In many cases it's asking them to simply confirm the action. Under the hood, this is implemented by repeating the same command twice in a row. The first time results in a prompt and if there is a second time that means the cashier pressed enter and the action should occur.

Let's extend the Hello World example to ask a question. Again we need a Parser. The command can once again be "Hello". The beginning of the definition is identical:

class HelloWorldParser extends Parser
{
    public function check($str)
    {
        if ($str == 'HELLO') {
            return true;
        } else {
            return false;
        }
    }
}

The parse() method will be different though. We're going to use a status flag in the session named msgrepeat to check whether the input has been repeated. If it has, we'll add "Hello World" to the transaction as a comment; otherwise we'll prompt for confirmation.

public function parse($str)
{
    $json = $this->default_json();

    if (CoreLocal::get('msgrepeat')) {
        TransRecord::addComment('Hello World');
        $json['output'] = DisplayLib::lastpage();
    } else {
        CoreLocal::set('boxMsg', 'Add Hello to Transaction?');
        $json['main_frame'] = MiscLib::baseURL() . 'gui-modules/boxMsg2.php';
    }

    return $json;
}

Let's look at the conditional first. "CoreLocal" is a class with static methods to access the session. The session is persistent state that exists across requests. Normally HTTP is a stateless protocol. Storing values in the session means they can be defined and one page and accessed on a different page. The particular session variable here, "msgrepeat", indicates whether the input value ("msg") has been repeated.

If the message has been repeated, TransRecord::addComment() adds a comment line to the transaction. To display the comment, output is set to DisplayLib::lastpage() which returns HTML for the last X lines of the transaction where X is the number of lines that fit on the screen.

If the message was not repeated, we're going to set a session variable and redirect to the boxMsg2.php page. This page is specifically designed to handle these yes/no questions. It will automatically set appropriate session values to repeat the last command based on whether the cashier presses enter (yes) or clear (no). The session variable we're setting, "boxMsg", is displayed on the yes/no prompt.

In some circumstances, these repeated commands can get a little more complicated. If a command triggers more than one confirmation prompt, it's not sufficient to know whether the command repeated but rather whether it was the repeat we requested. An example might be a check tender that prompts to confirm the amount then prompts to confirm the check has been placed in the endorser. This is were the "lastRepeat" session value comes in.

public function parse($str)
{
    $json = $this->default_json();

    if (CoreLocal::get('msgrepeat') && CoreLocal::get('lastRepeat') == 'HelloWorld') {
        TransRecord::addComment('Hello World');
        CoreLocal::set('lastRepeat', '');
        $json['output'] = DisplayLib::lastpage();
    } else {
        CoreLocal::set('boxMsg', 'Add Hello to Transaction?');
        CoreLocal::set('lastRepeat', 'HelloWorld');
        $json['main_frame'] = MiscLib::baseURL() . 'gui-modules/boxMsg2.php';
    }

    return $json;
}

If the cashier presses clear, boxMsg2.php will take care of clearing the "lastRepeat" value.

Clone this wiki locally
You can’t perform that action at this time.