public void update(Integer entityId, NewInvoiceDTO addition) { // add the lines to the invoice first createLines(addition); // update the inoice record considering the new lines invoice.setTotal(calculateTotal()); // new total // adjust the balance addition.calculateTotal(); BigDecimal balance = invoice.getBalance(); balance = balance.add(addition.getTotal()); invoice.setBalance(balance); if (invoice.getBalance().compareTo(BigDecimal.ZERO) == 0) { invoice.setToProcess(Integer.valueOf(0)); } if (addition.getMetaFields() != null && !addition.getMetaFields().isEmpty()) { invoice.updateMetaFieldsWithValidation(entityId, addition); } }