This script checks that items in the defined categories have attributes assigned and if not, prompts the user to choose one from drop down list.
This will only work if all items in the category use the same attributes!
It will also work if EVERY item uses that same attributes set.
You will need an open blank text document in the background to copy and paste values to/from.
Getting the Category ID String[]
The first script tells you the ID numbers of each category.
They will appear in an Input box ready to be cut/copied into the text file.
**If all your items use the same attribute set - skip this step**
Copy this code into the script.event.total (or receipt consolidate whichever you are using)
Preferably rename the old one and make a new blank one.
// script.Event.Total.GetCategoryID // This script gets the Product Category ID for all products in sales window one by one // ************************************************************************** for (int number= 0; number < ticket.getLinesCount(); number++) { line = ticket.getLine(number); value1 = JOptionPane.showInputDialog( null, line.getProductName() + " is in Category ID:", line.getProductName() + " category", JOptionPane.PLAIN_MESSAGE, null, null, line.getProductCategoryID()); } return "Cancel";
Then add 1 product from each category you want to use to the sales pane
Press =
Copy the value in the input box the the text file making sure to make a note of which category it is associated with.
Press OK to bring up the next value.
Repeat for all categories
It then returns you to the sales screen to delete/cancel the items
Getting the Attribute ID String[]
This script is similar the the last one, but tells you the ID associated with an Attribute instead
So delete the last script and replace it with this:
// script.Event.Total.GetAttributeID // This script gets the Product Category ID for all products in sales window one by one // ************************************************************************** for (int number= 0; number < ticket.getLinesCount(); number++) { line = ticket.getLine(number); value1 = JOptionPane.showInputDialog( null, "This is the ID for " + line.getProductAttSetInstDesc(), line.getProductAttSetInstDesc() + "ID", JOptionPane.PLAIN_MESSAGE, null, null, line.getProductAttSetInstId()); } return "Cancel";
Add items and use EVERY attribute you want to have available
(I.E. for steak cooking add 5 steaks 1 Rare, 1 Medium Rare and so on).
If multiple items use the same attribute you only need to add it once.
Press =
Copy the value in the input box the the text file making sure to make a note of which Attribute it is associated with.
Press OK to bring up the next value.
Repeat for all Attributes
It then returns you to the sales screen to delete/cancel the items
The script.Event.Total[]
Now delete the last script and replace it with this:
// script.Event.Total.Category // This script requires ALL Attribute items to have Attributes before Payment // Also allows different attributes for different product categories // ************************************************************************** //Enter Your Category ID's Here var Category1 = "178ab803-cb91-4da7-b8fc-3574ac3902fe"; var Category2 = "9ac06f86-8295-4c63-9cfd-4fe6d84f81eb"; //Add new categories by using the var Category# = ""; form //Enter your Attribute Names Here - EXACTLY as they appear in the attributes pane var attr1 = "Rare"; var attr2 = "Medium Rare"; var attr3 = "Medium"; var attr4 = "Medium Well"; var attr5 = "Well"; //Add new Attributes using - var attr# = ""; //Enter YOUR Attribute ID's Here - making sure the numbers match up (attr1 for attr1a etc) var attr1a = "b6b476c8-8b00-4580-954f-5baa5aa56588"; var attr2a = "74324ead-c8d6-44d5-b865-1c9f736d692a"; var attr3a = "5bae43fd-9c6d-4ce4-bc43-6bea33266af0"; var attr4a = "84ad4e9d-b602-4460-ad03-867020902ba4"; var attr5a = "7798b0ba-082a-4cb5-ba40-5b844a88747b"; //Add new IDs using - var attr#a = ""; for(int i= 0; i < ticket.getLinesCount(); i++){ line = ticket.getLine(i); if (line.getProductAttSetId() != null && line.getProductAttSetInstDesc().equals("")) { java.awt.Toolkit.getDefaultToolkit().beep(); //Enter the variable name for the first category here: if(line.getProductCategoryID().equals(Category1)) { //Enter you attribute variables here Object[] possibleValues = {attr1, attr2, attr3, attr4, attr5}; String s = (String)JOptionPane.showInputDialog( null, "Please select Attribute for " + line.getProductName(), line.getProductName() + "requires an attribute", JOptionPane.PLAIN_MESSAGE, null, possibleValues, possibleValues[0]); if ((s != null) && (s.length() > 0)) { if (s == attr1){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr1a); } if (s == attr2){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr2a); } if (s == attr3){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr3a); } if (s == attr4){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr4a); } if (s == attr5){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr5a); } //If you need more than 5 attributes //copy one of these and change the attr number. If less delete unused } } ////////////////////////////////////////////////////////////////// //Enter the variable name for the second category here: if(line.getProductCategoryID().equals(Category2)) { //Enter you attribute variables here Object[] possibleValues = {attr1, attr2, attr3, attr4, attr5}; String s = (String)JOptionPane.showInputDialog( null, "Please select Attribute for " + line.getProductName(), line.getProductName() + "requires an attribute", JOptionPane.PLAIN_MESSAGE, null, possibleValues, possibleValues[0]); if ((s != null) && (s.length() > 0)) { if (s == attr1){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr1a); } if (s == attr2){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr2a); } if (s == attr3){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr3a); } if (s == attr4){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr4a); } if (s == attr5){ line.setProductAttSetInstDesc(s); line.setProductAttSetInstId(attr5a); } //If you needs more than 5 attributes //copy one of these and change the attr number. If less delete unused. } } //2 // Copy this section and paste below to add another category /////////////////////////////////////////////////////////// } //Make sure these 2 } stay at the bottom } //or you will get <EOF> errors
Finish[]
Make sure to save the changes!
Try it out by adding a few items without attributes and see what happens!
Kael2001 (talk) 22:15, February 8, 2013 (UTC)