How to change order state automatically when it meet a special requirement?

i am now changing the order status of ea ordered item individually from submmited to delivered.
but i wanna the whole ticket change the state from waiting to unpaid (in order to show different colour) when all the individual item in the ticket has been changed to delivered.

anyway to do it?