final double taxRate = 0.20d; invoiceRegistry.addInvoice().withId(new Id("" + nextId++)) .withDate(lastDate) .withDueDate(lastDate.plusMonths(2)) .withEarnings(new Money(new BigDecimal(earnings), "EUR")) .withJobEvents(eventsSubList) .withNumber(prefix + (i + 1)) .withProject(project) .withTax(new Money(new BigDecimal(earnings * taxRate), "EUR")) .create();
final Money earnings = configuration.getMoney("invoiceAmount"); invoiceRegistry.addInvoice().withId(configuration.getId("uniqueIdentifier")) .withNumber(configuration.getString("invoiceNumber")) .withDate(configuration.getDate("date")) .withDueDate(configuration.getDate("dueDate")) .withEarnings(earnings.subtract(tax)) .withTax(tax) .withProject(project) .withJobEvents(events) .create();
@Nonnull public Invoice.Builder toBuilder (final @Nonnull Accounting accounting) { try { final Project customer = accounting.getProjectRegistry().findProjects().withId(projectXml.getId()).result(); return new Invoice.Builder().withId(id) .withNumber(number) .withProject(customer) .withDate(date) .withDueDate(dueDate) .withEarnings(earnings) .withTax(tax) .withJobEvents(JobEventXml.toJobEvents(jobEventsXml)); } catch (NotFoundException e) { throw new RuntimeException(e); } } }
public void fill (final @Nonnull Accounting accounting) { final CustomerRegistry customerRegistry = accounting.getCustomerRegistry(); final ProjectRegistry projectRegistry = accounting.getProjectRegistry(); final InvoiceRegistry invoiceRegistry = accounting.getInvoiceRegistry(); customersXml.forEach(customer -> customerRegistry.addCustomer().with(customer.toBuilder()).create()); projectsXml.forEach(project -> projectRegistry.addProject().with(project.toBuilder(accounting)).create()); invoicesxml.forEach(invoice -> invoiceRegistry.addInvoice().with(invoice.toBuilder(accounting)).create()); } }