diff --git a/applications/order/entitydef/entitymodel_view.xml b/applications/order/entitydef/entitymodel_view.xml index 028b20c440..687ee595ba 100644 --- a/applications/order/entitydef/entitymodel_view.xml +++ b/applications/order/entitydef/entitymodel_view.xml @@ -766,6 +766,7 @@ under the License. + diff --git a/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java b/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java index ea97407df6..080f22c46b 100644 --- a/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java +++ b/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java @@ -19,6 +19,7 @@ package org.ofbiz.order.requirement; import java.util.*; +import java.sql.Timestamp; import javolution.util.FastList; import javolution.util.FastMap; @@ -77,11 +78,15 @@ public class RequirementServices { Map suppliers = FastMap.newInstance(); Map gids = FastMap.newInstance(); Map inventories = FastMap.newInstance(); + Map productsSold = FastMap.newInstance(); // to count quantity and distinct products in list double quantity = 0.0; Set products = new HashSet(); + // time period to count products ordered from, six months ago and the 1st of that month + Timestamp timePeriodStart = UtilDateTime.getMonthStart(UtilDateTime.nowTimestamp(), 0, -6); + // join in fields with extra data about the suppliers and products List requirements = FastList.newInstance(); for (Iterator iter = requirementAndRoles.iterator(); iter.hasNext(); ) { @@ -130,6 +135,26 @@ public class RequirementServices { } } + // how many of the products were sold (note this is for a fixed time period across all product stores) + Double sold = (Double) productsSold.get(productId); + if (sold == null) { + EntityCondition prodConditions = new EntityConditionList( UtilMisc.toList( + new EntityExpr("productId", EntityOperator.EQUALS, productId), + new EntityExpr("orderTypeId", EntityOperator.EQUALS, "SALES_ORDER"), + new EntityExpr("orderStatusId", EntityOperator.NOT_IN, UtilMisc.toList("ORDER_REJECTED", "ORDER_CANCELLED")), + new EntityExpr("orderItemStatusId", EntityOperator.NOT_IN, UtilMisc.toList("ITEM_REJECTED", "ITEM_CANCELLED")), + new EntityExpr("orderDate", EntityOperator.GREATER_THAN_EQUAL_TO, timePeriodStart) + ), EntityOperator.AND); + GenericValue count = EntityUtil.getFirst( delegator.findByCondition("OrderItemQuantityReportGroupByProduct", prodConditions, UtilMisc.toList("quantityOrdered"), null) ); + if (count != null) { + sold = count.getDouble("quantityOrdered"); + if (sold != null) productsSold.put(productId, sold); + } + } + if (sold != null) { + union.put("qtySold", sold); + } + // keep a running total of distinct products and quantity to order quantity += requirement.getDouble("quantity").doubleValue(); products.add(productId); diff --git a/applications/order/webapp/ordermgr/requirement/RequirementForms.xml b/applications/order/webapp/ordermgr/requirement/RequirementForms.xml index 5458918e03..1e3f96ce87 100644 --- a/applications/order/webapp/ordermgr/requirement/RequirementForms.xml +++ b/applications/order/webapp/ordermgr/requirement/RequirementForms.xml @@ -306,11 +306,12 @@ under the License. - + +