MT#5879 Make email invoices query simplier.

Remove redundant link through contract_balances to contracts.
Process customer email template and add month and year into invoice data.