Unlink "Advances payment" after canceling "Sales Invoice"

I have been facing a problem which is Unlink “Advances payment” after canceling “Sales Invoice” so when I cancel sales invoice system directly unlink advance payment that linked to that invoice and “total advance field” changes to “0” amount
Can anyone explain to me the logic behind that?