use of org.apache.ofbiz.entity.condition.EntityExpr in project ofbiz-framework by apache.
the class OrderReadHelper method getOrderReturnedQuantity.
/**
* Get the total quantity of returned items for an order. This will count
* only the ReturnItems that are directly correlated to an OrderItem.
*/
public BigDecimal getOrderReturnedQuantity() {
List<GenericValue> returnedItemsBase = getOrderReturnItems();
List<GenericValue> returnedItems = new ArrayList<>(returnedItemsBase.size());
// filter just order items
List<EntityExpr> orderItemExprs = UtilMisc.toList(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_PROD_ITEM"));
orderItemExprs.add(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_FPROD_ITEM"));
orderItemExprs.add(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_DPROD_ITEM"));
orderItemExprs.add(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_FDPROD_ITEM"));
orderItemExprs.add(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_PROD_FEATR_ITEM"));
orderItemExprs.add(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_SPROD_ITEM"));
orderItemExprs.add(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_WE_ITEM"));
orderItemExprs.add(EntityCondition.makeCondition("returnItemTypeId", EntityOperator.EQUALS, "RET_TE_ITEM"));
returnedItemsBase = EntityUtil.filterByOr(returnedItemsBase, orderItemExprs);
// get only the RETURN_RECEIVED and RETURN_COMPLETED statusIds
returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_RECEIVED")));
returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_COMPLETED")));
BigDecimal returnedQuantity = ZERO;
for (GenericValue returnedItem : returnedItems) {
if (returnedItem.get("returnQuantity") != null) {
returnedQuantity = returnedQuantity.add(returnedItem.getBigDecimal("returnQuantity")).setScale(scale, rounding);
}
}
return returnedQuantity.setScale(scale, rounding);
}
use of org.apache.ofbiz.entity.condition.EntityExpr in project ofbiz-framework by apache.
the class OrderReadHelper method getOrderPaymentReceivedTotalByType.
/**
* Get the total payment received amount by payment type. Specify null to get amount
* over all types. This method works by going through all the PaymentAndApplications
* for all order Invoices that have status PMNT_RECEIVED.
*/
public BigDecimal getOrderPaymentReceivedTotalByType(String paymentMethodTypeId) {
BigDecimal total = ZERO;
try {
// get a set of invoice IDs that belong to the order
List<GenericValue> orderItemBillings = orderHeader.getRelated("OrderItemBilling", null, null, false);
Set<String> invoiceIds = new HashSet<>();
for (GenericValue orderItemBilling : orderItemBillings) {
invoiceIds.add(orderItemBilling.getString("invoiceId"));
}
// get the payments of the desired type for these invoices TODO: in models where invoices can have many orders, this needs to be refined
List<EntityExpr> conditions = UtilMisc.toList(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_RECEIVED"), EntityCondition.makeCondition("invoiceId", EntityOperator.IN, invoiceIds));
if (paymentMethodTypeId != null) {
conditions.add(EntityCondition.makeCondition("paymentMethodTypeId", EntityOperator.EQUALS, paymentMethodTypeId));
}
EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(conditions, EntityOperator.AND);
List<GenericValue> payments = orderHeader.getDelegator().findList("PaymentAndApplication", ecl, null, null, null, true);
for (GenericValue payment : payments) {
if (payment.get("amountApplied") == null) {
continue;
}
total = total.add(payment.getBigDecimal("amountApplied")).setScale(scale, rounding);
}
} catch (GenericEntityException e) {
Debug.logError(e, e.getMessage(), module);
}
return total;
}
use of org.apache.ofbiz.entity.condition.EntityExpr in project ofbiz-framework by apache.
the class OrderReadHelper method getValidDigitalItems.
public List<GenericValue> getValidDigitalItems() {
List<GenericValue> digitalItems = new LinkedList<>();
// only approved or complete items apply
List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_APPROVED"), EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_COMPLETED"));
List<GenericValue> items = EntityUtil.filterByOr(getOrderItems(), exprs);
for (GenericValue item : items) {
if (item.get("productId") != null) {
GenericValue product = null;
try {
product = item.getRelatedOne("Product", false);
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get Product from OrderItem", module);
}
if (product != null) {
GenericValue productType = null;
try {
productType = product.getRelatedOne("ProductType", false);
} catch (GenericEntityException e) {
Debug.logError(e, "ERROR: Unable to get ProductType from Product", module);
}
if (productType != null) {
String isDigital = productType.getString("isDigital");
if (isDigital != null && "Y".equalsIgnoreCase(isDigital)) {
// make sure we have an OrderItemBilling record
List<GenericValue> orderItemBillings = null;
try {
orderItemBillings = item.getRelated("OrderItemBilling", null, null, false);
} catch (GenericEntityException e) {
Debug.logError(e, "Unable to get OrderItemBilling from OrderItem");
}
if (UtilValidate.isNotEmpty(orderItemBillings)) {
// get the ProductContent records
List<GenericValue> productContents = null;
try {
productContents = product.getRelated("ProductContent", null, null, false);
} catch (GenericEntityException e) {
Debug.logError("Unable to get ProductContent from Product", module);
}
List<EntityExpr> cExprs = UtilMisc.toList(EntityCondition.makeCondition("productContentTypeId", EntityOperator.EQUALS, "DIGITAL_DOWNLOAD"), EntityCondition.makeCondition("productContentTypeId", EntityOperator.EQUALS, "FULFILLMENT_EMAIL"), EntityCondition.makeCondition("productContentTypeId", EntityOperator.EQUALS, "FULFILLMENT_EXTERNAL"));
// add more as needed
productContents = EntityUtil.filterByDate(productContents);
productContents = EntityUtil.filterByOr(productContents, cExprs);
if (UtilValidate.isNotEmpty(productContents)) {
// make sure we are still within the allowed timeframe and use limits
for (GenericValue productContent : productContents) {
Timestamp fromDate = productContent.getTimestamp("purchaseFromDate");
Timestamp thruDate = productContent.getTimestamp("purchaseThruDate");
if (fromDate == null || item.getTimestamp("orderDate").after(fromDate)) {
if (thruDate == null || item.getTimestamp("orderDate").before(thruDate)) {
// TODO: Implement use count and days
digitalItems.add(item);
}
}
}
}
}
}
}
}
}
}
return digitalItems;
}
use of org.apache.ofbiz.entity.condition.EntityExpr in project ofbiz-framework by apache.
the class OrderReadHelper method getItemPickedQuantityBd.
public BigDecimal getItemPickedQuantityBd(GenericValue orderItem) {
BigDecimal quantityPicked = ZERO;
EntityConditionList<EntityExpr> pickedConditions = EntityCondition.makeCondition(UtilMisc.toList(EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderItem.get("orderId")), EntityCondition.makeCondition("orderItemSeqId", EntityOperator.EQUALS, orderItem.getString("orderItemSeqId")), EntityCondition.makeCondition("statusId", EntityOperator.NOT_EQUAL, "PICKLIST_CANCELLED")), EntityOperator.AND);
List<GenericValue> picked = null;
try {
picked = orderHeader.getDelegator().findList("PicklistAndBinAndItem", pickedConditions, null, null, null, false);
} catch (GenericEntityException e) {
Debug.logError(e, module);
this.orderHeader = null;
}
if (picked != null) {
for (GenericValue pickedItem : picked) {
BigDecimal issueQty = pickedItem.getBigDecimal("quantity");
if (issueQty != null) {
quantityPicked = quantityPicked.add(issueQty).setScale(scale, rounding);
}
}
}
return quantityPicked.setScale(scale, rounding);
}
use of org.apache.ofbiz.entity.condition.EntityExpr in project ofbiz-framework by apache.
the class OrderReadHelper method getReceivedPaymentTotalsByPaymentMethod.
/**
* Returns a Map of paymentMethodId -> amount charged (BigDecimal) based on PaymentGatewayResponse.
* @return returns a Map of paymentMethodId -> amount charged (BigDecimal) based on PaymentGatewayResponse.
*/
public Map<String, BigDecimal> getReceivedPaymentTotalsByPaymentMethod() {
Map<String, BigDecimal> paymentMethodAmounts = new HashMap<>();
List<GenericValue> paymentPrefs = getPaymentPreferences();
for (GenericValue paymentPref : paymentPrefs) {
List<GenericValue> payments = new LinkedList<>();
try {
List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_RECEIVED"), EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "PMNT_CONFIRMED"));
payments = paymentPref.getRelated("Payment", null, null, false);
payments = EntityUtil.filterByOr(payments, exprs);
List<EntityExpr> conds = UtilMisc.toList(EntityCondition.makeCondition("paymentTypeId", EntityOperator.EQUALS, "CUSTOMER_PAYMENT"), EntityCondition.makeCondition("paymentTypeId", EntityOperator.EQUALS, "CUSTOMER_DEPOSIT"), EntityCondition.makeCondition("paymentTypeId", EntityOperator.EQUALS, "INTEREST_RECEIPT"), EntityCondition.makeCondition("paymentTypeId", EntityOperator.EQUALS, "GC_DEPOSIT"), EntityCondition.makeCondition("paymentTypeId", EntityOperator.EQUALS, "POS_PAID_IN"));
payments = EntityUtil.filterByOr(payments, conds);
} catch (GenericEntityException e) {
Debug.logError(e, module);
}
BigDecimal chargedToPaymentPref = ZERO;
for (GenericValue payment : payments) {
if (payment.get("amount") != null) {
chargedToPaymentPref = chargedToPaymentPref.add(payment.getBigDecimal("amount")).setScale(scale + 1, rounding);
}
}
if (chargedToPaymentPref.compareTo(ZERO) > 0) {
// key of the resulting map is paymentMethodId or paymentMethodTypeId if the paymentMethodId is not available
String paymentMethodKey = paymentPref.getString("paymentMethodId") != null ? paymentPref.getString("paymentMethodId") : paymentPref.getString("paymentMethodTypeId");
if (paymentMethodAmounts.containsKey(paymentMethodKey)) {
BigDecimal value = paymentMethodAmounts.get(paymentMethodKey);
if (value != null) {
chargedToPaymentPref = chargedToPaymentPref.add(value);
}
}
paymentMethodAmounts.put(paymentMethodKey, chargedToPaymentPref.setScale(scale, rounding));
}
}
return paymentMethodAmounts;
}
Aggregations