For registrars that have automatic renewal enabled, the deregistration must occur before the domain's expiration date.
If automatic renewal is not enabled, the timing of the deregistration submission does not affect the invoice, as the invoice is sent only after the registrar has specifically renewed the domain using the EPP command "renew".