Help with SQL to create a price check button

You should be able to do that without JScript.

The Function field is the HandlerName, in your case @@PriceCheck.

In the case of executing JScript, Function field needs the JScript HandlerName and the FunctionName within the JScript handler.

The Parameters field in the case of SQL is a comma-separated list, so you should make that a [:variable] that you will populate from the Rule to feed in the BarCode.

In the @@PriceCheck script, you access the Parameters via an @indexNumber, so the SQL script would become the following (notice the @1 which is the first value of the Parameters list):

SELECT p.[Price]
FROM [MenuItemPrices] p
LEFT JOIN [MenuItemPortions] s ON s.[Id] = p.[MenuItemPortionId]
LEFT JOIN [MenuItems] m ON m.[Id] = s.[MenuItemId]
WHERE m.[Barcode]='@1'AND s.[Name]="Normal"
2 Likes

@QMcKay can you show example of calling the script when doing direct SQL script?

Feed barcode into variable via program setting?

OK so i updated the script to be:
image

and i have three rules:

  1. creates the program setting where a keypad appears to enter the barcode, this then starts an auto command to run the script
    image

  2. Executes the script using the details provided above Function = @@PriceCheck and Parameter = {SETTING:Price Check} which is the store value of the barcode from the first rule. This rule then generates another auto command to fire another rule with a display message action to display the price
    image

  3. This rule should display the price in a display message action, I dont think this rule is correct but i dont know if the previous two are correctly setup. this 3rd rule doesnt generate the show message box, nothing happens
    image

The SQL script wont update the program setting if thats what your thinking is happening.

Using a script and {CALL:xxx} you only need one rule and one action;

Script;

function checkPrice(inputBarcode) {
	qry =  "SELECT p.[Price] FROM [MenuItemPrices] p LEFT JOIN [MenuItemPortions] s ON s.[Id] = p.[MenuItemPortionId] LEFT JOIN [MenuItems] m ON m.[Id] = s.[MenuItemId] WHERE m.[Barcode]="+inputBarcode+"AND s.[Name]='Normal'";
	var salesTicketCount = sql.Query(qry).First;
	return salesTicketCount;
}

Rule;

CALL expression;
{CALL:toolScripts.checkPrice('[?Scan Barcode;;;OCN]')}

No Settings.
One script,
One rule,
One action.

2 Likes

perfect thanks!!

Dont suppose theres a way to display all portion prices, with an addtion to the script?

so the script just uses the portion Normal, is there anyway to change it from saying Normal to a value that displays all portiona, or can i just add my different portions as a comma separated list after Normal?

I tried that but doesnt seem to work lol

Youll need to process the list returned…
1 sec

Something like this would do it;

function checkPrice(inputBarcode) {																	
	qry =  "SELECT s.[Name], p.[Price] FROM [MenuItemPrices] p LEFT JOIN [MenuItemPortions] s ON s.[Id] = p.[MenuItemPortionId] LEFT JOIN [MenuItems] m ON m.[Id] = s.[MenuItemId] WHERE m.[Barcode]="+inputBarcode;
	var priceList = sql.Query(qry).Delimit(' ').All;
	var priceCount = priceList.Length;
	var responce = '';
	for (t = 0; t < priceCount ; t++) {
		responce += priceList[t]+'<linebreak/>';
		}
	return responce
}

Mine are doubled up because I have 2 price lists and query doesnt specify a price list.

3 Likes

Cheers ill update this tomorrow thanks!! :grinning:

I would never have worked that out!

I take it if there arent any portions and its just ‘Normal’ it wont display the word normal as before and just the price

And it will only show the portion name if its anything other than normal/more than 1 portion?

Scripts are awesome, well worth learning. Plus as its JScript which is pretty much the same as JavaScript its a good code to understand the basics of.
I often end up doing things in scripts which could be done with reports or other ‘easier ways’ as especially with the helper functions from samba there isnt much you cant do.
You can even trigger some automation actions like messages/dialoges etc.

SQL to is a good language to have basic understanding of. SELECT for sure and basic JOIN understanding will get youmore ways to get data out of samba where report expressions miss bits.

This is the PMS Intergration topic, which at the begining of I had minimal knolage of SQL or JScript but Q and Kendash thankfully offered me directions and as with many things, once you get the basics google becomes so much more usefull for expanding your skills.

1 Like

I have 2 questions for you Jtrtech:
1- Is there any possibility that we can show name of the item as well with price? Do I have to add [MenuItemName] in the script with [Price]?
2- The price its showing is it the price for the items which we have in the menu only or all the products we have in the product list?

One more thing is there a possibility to add this item in the ticket which we scanned for the price check?
Take a scenario if a customer comes to cashier with a item and ask for the price, so when cashier press price check button scan item tell the customer price and then customer say that he want this item.
Could we add two buttons like ok and cancel if customer say that he want it so cashier press ok and the item would be added to order, if customer say no so cashier will press cancel and the item would not be added to order.

You would add [Name] in the script to show the name and also update the response accordingly.

All products in your Product List. It is not related to Menus

Possibly. You could amend the buttons on the Ask Question and set the OK button to execute an Automation Command that in turn triggers the Add Order action to add the item to a new / existing ticket, however it won’t be that straightforward as you need to pass the product name to the Add Order action and you currently don’t have that from the barcode.

I would suggest just to scan the item again if someone wants to buy it, it is probably easier and I have seen in many shops when I ask a price for something then buy, they have to scan the item again to sell it, so I think any staff you have wouldn’t find it too much of a hassle.

p.[Name] or s.[Name]?
He used s.[Name] to call the price by portions.

m.[Name] is what you need

Why go thru the problem? just add item to ticket as usual, he don’t want it just click cancel dont need to do all this.:man_facepalming: Why we always want to make thing more complicate than it should be? :stuck_out_tongue_closed_eyes:

2 Likes

I was also going to ask this but not sure what the m’s and s’s are or what and where i need to add to the script

the letters are identifiers for the tables set as part of the join.

m = menu items table
p = price table
s = portions (p already used so thought s for size LOL)

1 Like