Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
breakoutModewide
languagejava
Filter getCustomerProductFilter(String typeCode, Collection customerIds, Collection skus, List contractStatus,
                                String dateFrom, String dateTo) {

    def filters = Filter.and()

    if (customerIds != null) {
        Filter filterCustomers = Filter.or()

        if (customerIds) {
            customerIds.each { customerId ->
                filterCustomers.add(api.customerToRelatedObjectsFilter(typeCode, customerId))
            }
        } else {
            filterCustomers.add(
                    Filter.equal("customerId", null)
            )
        }

        filters.add(
                Filter.or(filterCustomers, Filter.isNull("customerGroup"))
        )
    }

    if (skus != null) {
        Filter filterProducts = Filter.or()

        if (skus) {
            skus.each { sku ->
                filterProducts.add(api.productToRelatedObjectsFilter(typeCode, sku))
            }
        } else {
            filterProducts.add(
                    Filter.equal("sku", null)
            )
        }
        filters.add(
                Filter.or(filterProducts, Filter.isNull("productGroup"))
        )
    }

    if (contractStatus) {
        filters.add(
                Filter.in("contractStatus", contractStatus)
        )
    }

    if (dateFrom) {
        filters.add(
                Filter.greaterOrEqual("startDate", dateFrom),
        )
    }

    if (dateTo) {
        filters.add(
                Filter.lessOrEqual("endDate", dateTo),
        )
    }

    return filters
}
Code Block
breakoutModewide
languagejava
def customerIds = out.Customers?.customerId
def skus = out.Products?.sku
def contractStatus = out.Status
def productList = out.Products
def tradeLeverCategory = out.TradeLevers?.TradeLeverCategory
def tradeLeverType = out.TradeLevers?.TradeLeverType
def contractTermTypes = out.ContractTermTypes

def filter = Library.getCustomerProductFilter("CT", customerIds, skus, contractStatus, out.DateFrom, out.DateTo)

def contracts = api.find("CT", 0, api.maxFindResultsLimit, "startDate", ["id"], filter)
        .collect { contract ->
            api.getCalculableLineItemCollection(contract.id + ".CT")
        }