Дело в шляпе (concern is in the hat or has we say in English the trick is done). This is what you can say or hear when you or your another speaker is sure about the issue of a business or when something has been completed safely.
One of the theories about the origin of this idiom связывает его с взяточничеством (is associated with bribery). Indeed, if какое-либо дело попадало в суд (a case came to the court), then каждый старался подкупить судью (each side would try to bribe the judge) to make sure to win the case. But no one dared to give or take a bribe openly, so they had to come up with different ways to do it quickly and discreetly.
And one of the methods was the hat: судья клал свою шляпу (the judge would place his hat) in a way it was clearly visible to the applicant, если проситель сумел незаметно для других положить в неё деньги (and if the petitioner was able to discretely put money in it), he could count on a decision in his favour.