Add more descriptive comments to the invoice generation code.
Make it possible to lock and unlock the InvoiceService to prevent simultaneously running invoice generations.
Make it possible to lock and unlock the CdrService to prevent conflicting changes to the CDR database.
Lock the CDR database before inserting new CDR's.
When creating an invoice for an account, lock the InvoiceService and CdrService to prevent simultaneous generations of multiple invoices and to prevent changes to the CDR database while the generation is running.