payToPartyId = productStore.getString("payToPartyId");
}
}
// store expr
EntityCondition storeCond = null;
if (productStore != null) {
storeCond = EntityCondition.makeCondition(
EntityCondition.makeCondition("productStoreId", EntityOperator.EQUALS, productStore.get("productStoreId")),
EntityOperator.OR,
EntityCondition.makeCondition("productStoreId", EntityOperator.EQUALS, null));
} else {
storeCond = EntityCondition.makeCondition("productStoreId", EntityOperator.EQUALS, null);
}
// build the TaxAuthority expressions (taxAuthGeoId, taxAuthPartyId)
List taxAuthCondOrList = FastList.newInstance();
// start with the _NA_ TaxAuthority...
taxAuthCondOrList.add(EntityCondition.makeCondition(
EntityCondition.makeCondition("taxAuthPartyId", EntityOperator.EQUALS, "_NA_"),
EntityOperator.AND,
EntityCondition.makeCondition("taxAuthGeoId", EntityOperator.EQUALS, "_NA_")));
Iterator taxAuthorityIter = taxAuthoritySet.iterator();
while (taxAuthorityIter.hasNext()) {
GenericValue taxAuthority = (GenericValue) taxAuthorityIter.next();
EntityCondition taxAuthCond = EntityCondition.makeCondition(
EntityCondition.makeCondition("taxAuthPartyId", EntityOperator.EQUALS, taxAuthority.getString("taxAuthPartyId")),
EntityOperator.AND,
EntityCondition.makeCondition("taxAuthGeoId", EntityOperator.EQUALS, taxAuthority.getString("taxAuthGeoId")));
taxAuthCondOrList.add(taxAuthCond);
}
EntityCondition taxAuthoritiesCond = EntityCondition.makeCondition(taxAuthCondOrList, EntityOperator.OR);
try {
EntityCondition productCategoryCond = null;
if (product != null) {
// find the tax categories associated with the product and filter by those, with an IN clause or some such
// if this product is variant, find the virtual product id and consider also the categories of the virtual
// question: get all categories, or just a special type? for now let's do all categories...
String virtualProductId = null;
if ("Y".equals(product.getString("isVariant"))) {
virtualProductId = ProductWorker.getVariantVirtualId(product);
}
Set productCategoryIdSet = FastSet.newInstance();
EntityCondition productIdCond = null;
if (virtualProductId != null) {
productIdCond = EntityCondition.makeCondition(
EntityCondition.makeCondition("productId", EntityOperator.EQUALS, product.getString("productId")),
EntityOperator.OR,
EntityCondition.makeCondition("productId", EntityOperator.EQUALS, virtualProductId));
} else {
productIdCond = EntityCondition.makeCondition("productId", EntityOperator.EQUALS, product.getString("productId"));
}
List pcmList = delegator.findList("ProductCategoryMember", productIdCond, UtilMisc.toSet("productCategoryId"), null, null, true);
pcmList = EntityUtil.filterByDate(pcmList, true);
Iterator pcmIter = pcmList.iterator();
while (pcmIter.hasNext()) {
GenericValue pcm = (GenericValue) pcmIter.next();
productCategoryIdSet.add(pcm.get("productCategoryId"));
}
if (productCategoryIdSet.size() == 0) {
productCategoryCond = EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, null);
} else {
productCategoryCond = EntityCondition.makeCondition(
EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, null),
EntityOperator.OR,
EntityCondition.makeCondition("productCategoryId", EntityOperator.IN, productCategoryIdSet));
}
} else {
productCategoryCond = EntityCondition.makeCondition("productCategoryId", EntityOperator.EQUALS, null);
}
// build the main condition clause
List mainExprs = UtilMisc.toList(storeCond, taxAuthoritiesCond, productCategoryCond);
mainExprs.add(EntityCondition.makeCondition(EntityCondition.makeCondition("minItemPrice", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("minItemPrice", EntityOperator.LESS_THAN_EQUAL_TO, itemPrice)));
mainExprs.add(EntityCondition.makeCondition(EntityCondition.makeCondition("minPurchase", EntityOperator.EQUALS, null), EntityOperator.OR, EntityCondition.makeCondition("minPurchase", EntityOperator.LESS_THAN_EQUAL_TO, itemAmount)));
EntityCondition mainCondition = EntityCondition.makeCondition(mainExprs, EntityOperator.AND);
// create the orderby clause
List orderList = UtilMisc.toList("minItemPrice", "minPurchase", "fromDate");
// finally ready... do the rate query
List lookupList = delegator.findList("TaxAuthorityRateProduct", mainCondition, null, orderList, null, false);
List filteredList = EntityUtil.filterByDate(lookupList, true);
if (filteredList.size() == 0) {
Debug.logWarning("In TaxAuthority Product Rate no records were found for condition:" + mainCondition.toString(), module);
return adjustments;
}
// find the right entry(s) based on purchase amount
Iterator flIt = filteredList.iterator();