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
} |