I know making account transaction is quite complicated for me too. I think using ticket tag is easier than reverse account transaction and cleaner transaction too. You can ticket tag to track pool/cigarette cash out item added or cancelled and when click close ticket then do account transaction.
It might be even better to do it when ticket gets fully paid. Not to deal with cancellations, voids, etc prefer this method. Handle payment processed rule and add a constraint to check if remaining amount is zero. When it is zero you can assume this is the final state of the ticket and you can make related account transactions.
To be able to find transaction amount you need to know total of these items. We have {ORDER STATE TOTAL:X}
tag to determine total for orders that have a specific state. Alternatively you can use {TICKET ORDER TOTAL EXP:X}
tag to find total of orders that matches X expression. Expression compatible with custom reports expressions so you can use these expressions.
OT.<tag name> Order Tagged With
OS.<state name> Order is in State
OU Order User Name Equals
MT.<tag name> Order Menu Item Custom tag Equals
MG Order Menu Item Group Equals
So for example {TICKET ORDER TOTAL EXP:(MG=Beverages)}
tag will return total amount for orders these menu item group equals beverages.
It will be better to experiment that with a show message action that shows tag value when payment processed. When you start seeing desired amounts you can implement action that decreases that amount from cash.
Oh God! sorry you asked for V4. Expression tags is a V5 feature but {ORDER STATE TOTAL:X}
will probably work for V4 so you can mark orders with a state change and use this tag to read total.
I suggest ticket close because I think customer in this case tend to stay very very long times (few hours at least). It remind me when I was young, I stayed there for 4-8 hours lol. He might want to check cash in the till before customer paid for the bill.