Help with SQL to create a price check button

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

They are “aliases” for the Table (or a subquery). Like an abbreviation. They can be whatever you want.

Without aliases, in your SELECT portion, you would do this to distinguish the [Name] column of one Table from another Table:

SELECT
 [MenuItems].[Name]
,[MenuItemPortions].[Name]
,[MenuItemPrices].[Name]

But the alias lets you do this instead:

SELECT
 m.[Name] -- MenuItems.Name
,s.[Name] -- MenuItemPortions.Name
,p.[Name] -- MenuItemPrices.name

Mine is not working :frowning:
I did exactly what you showed us here.
Its asking me for the barcode but when I scan nothing appears.

Show what you have done.
It definatly works, I have not photoshopped the screenshots


1 Like


And the automation script?

https://forum.sambapos.com/uploads/default/original/3X/3/0/3006407fb468288a5f1486fb1c37743d9c20252a.png

And you get the Scan Barcode prompt?

Yes Its showing Barcode prompt.

So first tesct the script using checkPrice(‘BARCODEHERE’) in the test box in bottom right on script screen.