Fixed next_invoice_date calculation on groups.

The calculation now takes only contracts in active states (waiting + active)
and is recalculated if contracts change state or next_invoice_date.