Loop through orders, or multiple transaction documents at once

Is is possible to loop through all orders at once. I want to do this when a ticket gets paid so I can go through each order and create account transaction documents for assign commission for each order.

I have tried using an Update Order action and placing a {CALL:custom.ShowMessage("Hello")} tag as the “Name” Order Name… Although each order ‘correctly’ had it’s name changed, the “Hello” message only appeared one, so it seems as if the script was only executed once, and it didn’t truly loop through all orders as Emre suggested it would here.

Alternatively, is possible to use the “Create Transaction Document” action to create mutliple transaction documents at a time. For example can I specify…

Account Name: 01-John;07-Steve;26-Caro
Description: Thanks;Tips;Birthday
Amount: 20.00;4.50;10.00

Yes. One of the most effective methods to do so is to change the State for the Orders, then capture the Order State Updated event. For each Order whose State was updated, the Actions in the Rule will be performed. This is essentially how the VIP/HH Tutorial works when changing the Entity, and it is also how the Kitchen Display works to Print the Orders as Task Cards.

You can also use the Tag Order Action as Emre suggested, then capture the Order Tagged event. For each Order that was Tagged, the Actions in the Rule will be performed.

The key is that you capture the Event (Order State Updated or Order Tagged), and put your Actions in that Rule.


No, you cannot do what you show in your example. However, a Document Type can fire multiple Transaction Types. That is what the Selection box is for. In general, we only ever fire a single Tx Type, but you can fire as many as you want…

Obviously, the Tx Types should be related in some way, so the above example is ridiculous. That is, each of the Tx Types in the above example should pertain to a Customer Account (the setting for Account Type in the Doc Type), because it is the Account Id of the set Account Type (Customer Accounts) that will be used in the Transaction.


There is also the Batch Create configuration in a Document Type. It might help you as well. It might not. Unfortunately, I have no idea how it works or what it is for ;). @Jesse showed it’s use here:

Perfect - This is exactly the point in the right direction I needed. This is now what I have done…

  • Create an Account called “Commissions” (I have assigned this to my “Expense Accounts” Account Type).
  • Create entity accounts for each entity that we will pay tips to
  • Create an Order Tag called commission which will hold the names of the people who should get the commission
  • Create an Account Transaction Type to move money from Commission to Entity Account
  • Create a Transaction Document to do the same (assign the transaction type to this transaction document)
  • Create a Ticket Closing rule…
    (if remaining amount = 0 and Ticket Tag “CommissionProcessed” = False)
    The purpose of assigning an order state here is to have an Order State Updated event for each order that we can hook into later
    I had to add the rule here, because if I added it when the ticket gets a state of “Paid” then at that stage the ticket number and order numbers have not been assigned. Need to add the check against CommissionProcessed because otherwise everytime the ticket is viewed later the commission would keep being reapplied!
  • Add an Update Order State action
    • State Name = Commission
    • State = CommissionToBeProcessed
  • Add a Tag Ticket action
    • Tag Name = CommissionProcessed
    • State = True
  • Create an Order State Updated rule
    (State = “CommissionToBeProcedded” and Order Tag:Commission not blank)
    This rule will be processed once for each order on the ticket, there is no reason to run this rule if the order has no commission person assigned to it
  • Add a Create Account Transaction Document
    Configure this action as appropriate, but you’ll need to calculate a value for the commission, a description and most importantly the account ID for the person who need the commission. Since this person is not the ticket entity, we need to look up this account ID. To do this, I used…
    {REPORT ENTITY DETAILS:E.AccountId:(ET=Customers) AND (EN={CALL:comm.second('{ORDER TAG LIST:Commission}')})}

You’ll see above that I have used a script to pull out the potentially second person in the list of employees who sold this item. This is the script I created to do this. There’s probably a way to do this within [= ] tags, but I think the JavaScript array brackets got confused with the SambaPOS JScript container brackets.

function first(list) {
	return (list.split(","))[0];
}
function second(list) {
	return (list.split(","))[1];
}
function third(list) {
	return (list.split(","))[2];
}
1 Like