Problem with GQL Payment closing ticket. "Ticket changed. Your latest changes not saved."

Hi!

I am currently trying to make an integration that will settle tickets automatically and had an issue where the close ticket was giving an error. I posted on the issues forum here and Jesse had kindly pointed out that my version was outdated, and it should be fixed. Tested it out and it worked perfectly, so I implemented it into the app.

And it was working fine until…it was not.
I now get an error for some tickets.

{
  "data": {
    "closeTerminalTicket": "Ticket changed. Your latest changes not saved."
  },
  "errors": null
}

loadTicket, and payTerminalTicket both work fine, but then when the ticket is closed it gives this result.

Do you guys have any idea why it would be causing this?

Thanks in advance!!

If it’s related to the one in sambapos look for any print jobs that don’t exist

Also make sure the ticket is not opened on another terminal somewhere.

Typically that means the ticket is opened at same time on other terminals and changes were made one one.

So for this do you mean as for Rules that execute actions, or all actions in general?

As for the open tickets, that’s what I originally though so I had made sure that all of terminals were logged off, and still no luck.

So I tested a bunch and I think, if a terminal had opened ticket X, closed the ticket and did NOT log out.
And then the app tried to close ticket X it will give this error. But once the terminal is logged out it has no problems.
I changed the code up so I’ll see if it changes anything.

Hey Jesse!

So I am still actually having this issue.

I tested it at home(my test system running 5.3.6) and no issues after updating. Even if I have a ticket opened on a physical terminal, it’ll still pay and close the ticket (and when I close the ticket on the physical terminal then the physical terminal will do a popup with the error: Ticket Changed. Latest changes not saved." The GQL terminal will close no problem)

Now the problem comes when I run this at the actual restaurant.

I have 8 physical terminals running, all updated to 5.3.6 (I don’t think it matters but 2 are used as actual POS terminals, 1 is a headless server, and 5 are used as Kitchen Task Displays) So 2 terminals are the only ones that constantly have open tickets.

To make sure that there’s no external factors.
I have checked the rules, I don’t think I have any print jobs that don’t exist.
I have logged out of every single terminal.

BUT I KEEP GETTING THIS ERROR!!!

So I did a database backup, and loaded it onto my home computer, and there was no issues closing the tickets.

I also made a script/message received rule: it will receive a JSON format of the tickets that need to be closed, and will execute a script for each ticket number in the array, load ticket->pay ticket->close ticket. This works fine, BUT a terminal must be running on the headless server(Which I’d like to avoid.)

I am completely stumped…
Would there be any other problem that you could think of?

(Also I’m thinking of just ignoring this route and just going the SQL route, but I’m unsure about the Accounts/Account Documents/etc.)

Also not sure if you need it but this is the code in node that I am running:

//register a GQL terminal
function openTerminal(){
	return gql(getOpenTerminalScript())
		.then(data => data.registerTerminal);
}

//load a ticket, make payments, and close ticket.
function payTicket(terminalId, ticketId, amount, paymentType){
	return loadTicket(terminalId,ticketId).then( () => {
        return payLoadedTicket(terminalId, amount, paymentType).then( resolve => {
            return closeTicket(terminalId).then( data =>{
                if(data == "Ticket changed. Your latest changes not saved.")
                    return false;
                else   
                    return true;
            }, err => false);
        }, err => false);
    });
}

//loads a ticket to the specified terminal
function loadTicket(terminalId, ticketId){
	return gql(getLoadTicketScript(terminalId,ticketId));
}
//pays a specified amount on the loaded ticket on the specified terminal.
function payLoadedTicket(terminalId, amount, paymentType){
	return gql(getPayTicketScript(terminalId, amount, paymentType));
}

//close ticket
function closeTicket(terminalId){
    return gql(getCloseTicketScript(terminalId));
}

//unregister gql terminal
function closeTerminal(terminalId){
	return gql(getCloseTerminalScript(terminalId));
}

function getOpenTicketsScript(){
	return `{getTickets(isClosed: false) {id, type, remainingAmount, states{state, stateName}, tags{tag, tagName}, entities{name}}}`;
}

function getOpenTerminalScript(){
	return `mutation register {registerTerminal(user: "Server", ticketType: "Ticket", terminal: "Server", department: "Restaurant") }`;
}

function getLoadTicketScript(terminalId, ticketId){
	return `mutation load {loadTerminalTicket(terminalId: "${terminalId}", ticketId: "${ticketId}") { id } }`;
	
}

function getPayTicketScript(terminalId, amount, paymentType){
	return `mutation pay {payTerminalTicket(terminalId:"${terminalId}", paymentTypeName:"${paymentType}", amount:${amount}){ ticketId} }`;
}

function getCloseTicketScript(terminalId){
	return `mutation close {closeTerminalTicket(terminalId:"${terminalId}") }`;
}

function getCloseTerminalScript(terminalId){
	return `mutation unregister {unregisterTerminal(terminalId: "${terminalId}")}`;
}

PS sorry for the wall of text…

Try uninstalling message server and reinstalling it since you updated to 5.3.6

That’s done by this
image
right?

I think I did do that, but I uninstalled and installed again, just to double check. I’ll see what happens in the evening!

So as I mentioned above I re-installed, and as usual it has no problems with some, but most of them I get the “Ticket Changed. Your latest changes not saved.” error. (So far it closed 1 ticket, and errored on 4 others) So I tried restarting the app, and still all of the ones that couldn’t be closed are not closing. Made a backup and tried it on my home computer, and all closed no problem…


Please somebody help how exactly do I remove this error what you explained above does not solve the problem
Everything was working fine on all computers but all over a sudden this error starts to pop
What might have caused it??
How can I remove it?

Hello @Denno,

I replied to your question on the topic that you created, please check it out.

https://forum.sambapos.com/t/ticket-changed-your-latest-changes-not-saved-exp3/25494/2