if (customer == null) {
// no customer => no invoices
return null;
}
BillingEngineContext billingEngineContext = new BillingEngineContext();
billingEngineContext.setCustomer(customer);
billingEngineViewer.generateBill(billingEngineContext);
// reloading the customer with new updates
customer = billingEngineContext.getCustomer();
Invoice invoice = customer.getActiveInvoice();
// convert it and return
if (invoice == null) {
return null;