getPreviousOrder function implemented with Session variables