docs: public InvoiceItemModelDao computeCBAComplexity(final InvoiceModelDao invoice,
                                                      @Nullable final BigDecimal accountCBAOrNull,
                                                      @Nullable final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory,
                                                      final InternalCallContext context) throws EntityPersistenceException, InvoiceApiException {
          final BigDecimal balance = getInvoiceBalance(invoice);
  
          if (balance.compareTo(BigDecimal.ZERO) < 0) {
              // Current balance is negative, we need to generate a credit (positive CBA amount)
              return buildCBAItem(invoice, balance, context);
          } else if (balance.compareTo(BigDecimal.ZERO) > 0 && invoice.getStatus() == InvoiceStatus.COMMITTED && !invoice.isWrittenOff()) {
              // Current balance is positive and the invoice is COMMITTED, we need to use some of the existing if available (negative CBA amount)
              // PERF: in some codepaths, the CBA maybe have already been computed
              BigDecimal accountCBA = accountCBAOrNull;
              if (accountCBAOrNull == null) {
                  accountCBA = getAccountCBAFromTransaction(entitySqlDaoWrapperFactory, context);
              }
  
              if (accountCBA.compareTo(BigDecimal.ZERO) <= 0) {
                  return null;
              }
              final BigDecimal positiveCreditAmount = accountCBA.compareTo(balance) > 0 ? balance : accountCBA;
              return buildCBAItem(invoice, positiveCreditAmount, context);
          } else {
              // 0 balance, nothing to do.
              return null;
          }
      }