Re: svn commit: r501633 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/order/OrderServices.xml src/org/ofbiz/order/requirement/RequirementServices.java webapp/ordermgr/requirement/RequirementForms.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r501633 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/order/OrderServices.xml src/org/ofbiz/order/requirement/RequirementServices.java webapp/ordermgr/requirement/RequirementForms.xml

Guido Amarilla
Excellent feature! Just what I needed today!!!


Guido Amarilla

2007/1/30, [hidden email] <[hidden email]>:

> Author: sichen
> Date: Tue Jan 30 15:11:32 2007
> New Revision: 501633
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501633
> Log:
> Added QOH and ATP for the approved product requirements list.  The idea is to be able to see what the inventory is before creating POs based on requirements.
>
> Modified:
>     ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
>     ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
>     ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml
>
> Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml?view=diff&rev=501633&r1=501632&r2=501633
> ==============================================================================
> --- ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml (original)
> +++ ofbiz/trunk/applications/order/script/org/ofbiz/order/order/OrderServices.xml Tue Jan 30 15:11:32 2007
> @@ -127,6 +127,14 @@
>
>      <simple-method method-name="createRequirementAndCommitment" short-description="create a requirement and commitment for it">
>          <set value="PRODUCT_REQUIREMENT" field="inputMap.requirementTypeId"/>
> +
> +        <!-- Include the facilityId corresponding to this order by looking up the ProductStore -->
> +        <entity-one entity-name="OrderHeader" value-name="orderHeader" auto-field-map="true"/>
> +        <get-related-one value-name="orderHeader" relation-name="ProductStore" to-value-name="productStore" use-cache="true"/>
> +        <if-not-empty field-name="productStore.inventoryFacilityId">
> +            <set from-field="productStore.inventoryFacilityId" field="inputMap.facilityId"/>
> +        </if-not-empty>
> +
>          <call-service service-name="createRequirement" in-map-name="inputMap">
>              <result-to-field field-name="parameters.requirementId" result-name="requirementId"/>
>          </call-service>
>
> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java?view=diff&rev=501633&r1=501632&r2=501633
> ==============================================================================
> --- ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java (original)
> +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java Tue Jan 30 15:11:32 2007
> @@ -24,13 +24,14 @@
>  import javolution.util.FastMap;
>
>  import org.ofbiz.base.util.*;
> +import org.ofbiz.entity.*;
> +import org.ofbiz.entity.condition.*;
>  import org.ofbiz.entity.GenericDelegator;
>  import org.ofbiz.entity.GenericEntityException;
>  import org.ofbiz.entity.GenericValue;
> -import org.ofbiz.entity.*;
> -import org.ofbiz.entity.condition.*;
>  import org.ofbiz.entity.util.EntityUtil;
>  import org.ofbiz.service.DispatchContext;
> +import org.ofbiz.service.GenericServiceException;
>  import org.ofbiz.service.LocalDispatcher;
>  import org.ofbiz.service.ServiceUtil;
>
> @@ -45,6 +46,7 @@
>
>      public static final Map getRequirementsForSupplier(DispatchContext ctx, Map context) {
>          GenericDelegator delegator = ctx.getDelegator();
> +        LocalDispatcher dispatcher = ctx.getDispatcher();
>          Locale locale = (Locale) context.get("locale");
>
>          EntityCondition requirementConditions = (EntityCondition) context.get("requirementConditions");
> @@ -71,27 +73,59 @@
>              }
>              List requirementAndRoles = delegator.findByAnd("RequirementAndRole", conditions, orderBy);
>
> +            // maps to cache the associated suppliers and products data
> +            Map suppliers = FastMap.newInstance();
> +            Map gids = FastMap.newInstance();
> +            Map inventories = FastMap.newInstance();
> +
>              // join in fields with extra data about the suppliers and products
>              List requirements = FastList.newInstance();
>              for (Iterator iter = requirementAndRoles.iterator(); iter.hasNext(); ) {
>                  GenericValue requirement = (GenericValue) iter.next();
> +                String productId = requirement.getString("productId");
> +                partyId = requirement.getString("partyId");
> +                String facilityId = requirement.getString("facilityId");
>                  Map union = FastMap.newInstance();
>
>                  // get an available supplier product
> -                conditions = UtilMisc.toList(
> -                        new EntityExpr("partyId", EntityOperator.EQUALS, requirement.get("partyId")),
> -                        new EntityExpr("productId", EntityOperator.EQUALS, requirement.get("productId")),
> -                        EntityUtil.getFilterByDateExpr("availableFromDate", "availableThruDate")
> -                        );
> -                GenericValue supplierProduct = EntityUtil.getFirst( delegator.findByAnd("SupplierProduct", conditions) );
> -                if (supplierProduct != null) {
> -                    union.putAll(supplierProduct.getAllFields());
> +                String supplierKey =  partyId + "^" + productId;
> +                GenericValue supplierProduct = (GenericValue) suppliers.get(supplierKey);
> +                if (supplierProduct == null) {
> +                    conditions = UtilMisc.toList(
> +                            new EntityExpr("partyId", EntityOperator.EQUALS, partyId),
> +                            new EntityExpr("productId", EntityOperator.EQUALS, productId),
> +                            EntityUtil.getFilterByDateExpr("availableFromDate", "availableThruDate")
> +                            );
> +                    supplierProduct = EntityUtil.getFirst( delegator.findByAnd("SupplierProduct", conditions) );
> +                    suppliers.put(supplierKey, supplierProduct);
>                  }
> +                if (supplierProduct != null) union.putAll(supplierProduct.getAllFields());
>
>                  // for good identification, get the UPCA type (UPC code)
> -                GenericValue gid = delegator.findByPrimaryKey("GoodIdentification", UtilMisc.toMap("goodIdentificationTypeId", "UPCA", "productId", requirement.get("productId")));
> +                GenericValue gid = (GenericValue) gids.get(productId);
> +                if (gid == null) {
> +                    gid = delegator.findByPrimaryKey("GoodIdentification", UtilMisc.toMap("goodIdentificationTypeId", "UPCA", "productId", requirement.get("productId")));
> +                    gids.put(productId, gid);
> +                }
>                  if (gid != null) union.put("idValue", gid.get("idValue"));
>
> +                // the ATP and QOH quantities
> +                if (UtilValidate.isNotEmpty(facilityId)) {
> +                    String inventoryKey = facilityId + "^" + productId;
> +                    Map inventory = (Map) inventories.get(inventoryKey);
> +                    if (inventory == null) {
> +                        inventory = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.toMap("productId", productId, "facilityId", facilityId));
> +                        if (ServiceUtil.isError(inventory)) {
> +                            return inventory;
> +                        }
> +                        inventories.put(inventoryKey, inventory);
> +                    }
> +                    if (inventory != null) {
> +                        union.put("qoh", inventory.get("quantityOnHandTotal"));
> +                        union.put("atp", inventory.get("availableToPromiseTotal"));
> +                    }
> +                }
> +
>                  // add all the requirement fields last, to overwrite any conflicting fields
>                  union.putAll(requirement.getAllFields());
>                  requirements.add(union);
> @@ -100,6 +134,9 @@
>              Map results = ServiceUtil.returnSuccess();
>              results.put("requirementsForSupplier", requirements);
>              return results;
> +        } catch (GenericServiceException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderServiceExceptionSeeLogs", locale));
>          } catch (GenericEntityException e) {
>              Debug.logError(e, module);
>              return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderEntityExceptionSeeLogs", locale));
>
> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml?view=diff&rev=501633&r1=501632&r2=501633
> ==============================================================================
> --- ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml (original)
> +++ ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml Tue Jan 30 15:11:32 2007
> @@ -320,6 +320,8 @@
>          <field name="minimumOrderQuantity" widget-area-style="tabletextright"><display/></field>
>          <field name="lastPrice" widget-area-style="tabletextright"><display type="currency" currency="${currencyUomId}"/></field>
>          <field name="requiredByDate"><display/></field>
> +        <field name="atp" title="${uiLabelMap.ProductAtp}" widget-area-style="tabletextright"><display/></field>
> +        <field name="qoh" title="${uiLabelMap.ProductQoh}" widget-area-style="tabletextright"><display/></field>
>          <field name="quantity"><text size="4"/></field>
>          <field name="comments"><display/></field>
>          <field name="_rowSubmit" title="${uiLabelMap.CommonSelect}"><check/></field>
>
>
>


--
Guido Amarilla
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r501633 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/order/OrderServices.xml src/org/ofbiz/order/requirement/RequirementServices.java webapp/ordermgr/requirement/RequirementForms.xml

David E Jones

Just a quick note: this might have been easier using the "row-
actions" stuff in the form widget.

-David


2007/1/30, [hidden email] <[hidden email]>:

> Author: sichen
> Date: Tue Jan 30 15:11:32 2007
> New Revision: 501633
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=501633
> Log:
> Added QOH and ATP for the approved product requirements list.  The  
> idea is to be able to see what the inventory is before creating POs  
> based on requirements.
>
> Modified:
>     ofbiz/trunk/applications/order/script/org/ofbiz/order/order/
> OrderServices.xml
>     ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/
> RequirementServices.java
>     ofbiz/trunk/applications/order/webapp/ordermgr/requirement/
> RequirementForms.xml
>
> Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/
> order/OrderServices.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/ 
> script/org/ofbiz/order/order/OrderServices.xml?
> view=diff&rev=501633&r1=501632&r2=501633
> ======================================================================
> ========
> --- ofbiz/trunk/applications/order/script/org/ofbiz/order/order/
> OrderServices.xml (original)
> +++ ofbiz/trunk/applications/order/script/org/ofbiz/order/order/
> OrderServices.xml Tue Jan 30 15:11:32 2007
> @@ -127,6 +127,14 @@
>
>      <simple-method method-name="createRequirementAndCommitment"  
> short-description="create a requirement and commitment for it">
>          <set value="PRODUCT_REQUIREMENT"  
> field="inputMap.requirementTypeId"/>
> +
> +        <!-- Include the facilityId corresponding to this order by  
> looking up the ProductStore -->
> +        <entity-one entity-name="OrderHeader" value-
> name="orderHeader" auto-field-map="true"/>
> +        <get-related-one value-name="orderHeader" relation-
> name="ProductStore" to-value-name="productStore" use-cache="true"/>
> +        <if-not-empty field-name="productStore.inventoryFacilityId">
> +            <set from-field="productStore.inventoryFacilityId"  
> field="inputMap.facilityId"/>
> +        </if-not-empty>
> +
>          <call-service service-name="createRequirement" in-map-
> name="inputMap">
>              <result-to-field field-name="parameters.requirementId"  
> result-name="requirementId"/>
>          </call-service>
>
> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/
> requirement/RequirementServices.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/ 
> src/org/ofbiz/order/requirement/RequirementServices.java?
> view=diff&rev=501633&r1=501632&r2=501633
> ======================================================================
> ========
> --- ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/
> RequirementServices.java (original)
> +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/
> RequirementServices.java Tue Jan 30 15:11:32 2007
> @@ -24,13 +24,14 @@
>  import javolution.util.FastMap;
>
>  import org.ofbiz.base.util.*;
> +import org.ofbiz.entity.*;
> +import org.ofbiz.entity.condition.*;
>  import org.ofbiz.entity.GenericDelegator;
>  import org.ofbiz.entity.GenericEntityException;
>  import org.ofbiz.entity.GenericValue;
> -import org.ofbiz.entity.*;
> -import org.ofbiz.entity.condition.*;
>  import org.ofbiz.entity.util.EntityUtil;
>  import org.ofbiz.service.DispatchContext;
> +import org.ofbiz.service.GenericServiceException;
>  import org.ofbiz.service.LocalDispatcher;
>  import org.ofbiz.service.ServiceUtil;
>
> @@ -45,6 +46,7 @@
>
>      public static final Map getRequirementsForSupplier
> (DispatchContext ctx, Map context) {
>          GenericDelegator delegator = ctx.getDelegator();
> +        LocalDispatcher dispatcher = ctx.getDispatcher();
>          Locale locale = (Locale) context.get("locale");
>
>          EntityCondition requirementConditions = (EntityCondition)  
> context.get("requirementConditions");
> @@ -71,27 +73,59 @@
>              }
>              List requirementAndRoles = delegator.findByAnd
> ("RequirementAndRole", conditions, orderBy);
>
> +            // maps to cache the associated suppliers and products  
> data
> +            Map suppliers = FastMap.newInstance();
> +            Map gids = FastMap.newInstance();
> +            Map inventories = FastMap.newInstance();
> +
>              // join in fields with extra data about the suppliers  
> and products
>              List requirements = FastList.newInstance();
>              for (Iterator iter = requirementAndRoles.iterator();  
> iter.hasNext(); ) {
>                  GenericValue requirement = (GenericValue) iter.next
> ();
> +                String productId = requirement.getString
> ("productId");
> +                partyId = requirement.getString("partyId");
> +                String facilityId = requirement.getString
> ("facilityId");
>                  Map union = FastMap.newInstance();
>
>                  // get an available supplier product
> -                conditions = UtilMisc.toList(
> -                        new EntityExpr("partyId",  
> EntityOperator.EQUALS, requirement.get("partyId")),
> -                        new EntityExpr("productId",  
> EntityOperator.EQUALS, requirement.get("productId")),
> -                        EntityUtil.getFilterByDateExpr
> ("availableFromDate", "availableThruDate")
> -                        );
> -                GenericValue supplierProduct = EntityUtil.getFirst
> ( delegator.findByAnd("SupplierProduct", conditions) );
> -                if (supplierProduct != null) {
> -                    union.putAll(supplierProduct.getAllFields());
> +                String supplierKey =  partyId + "^" + productId;
> +                GenericValue supplierProduct = (GenericValue)  
> suppliers.get(supplierKey);
> +                if (supplierProduct == null) {
> +                    conditions = UtilMisc.toList(
> +                            new EntityExpr("partyId",  
> EntityOperator.EQUALS, partyId),
> +                            new EntityExpr("productId",  
> EntityOperator.EQUALS, productId),
> +                            EntityUtil.getFilterByDateExpr
> ("availableFromDate", "availableThruDate")
> +                            );
> +                    supplierProduct = EntityUtil.getFirst
> ( delegator.findByAnd("SupplierProduct", conditions) );
> +                    suppliers.put(supplierKey, supplierProduct);
>                  }
> +                if (supplierProduct != null) union.putAll
> (supplierProduct.getAllFields());
>
>                  // for good identification, get the UPCA type (UPC  
> code)
> -                GenericValue gid = delegator.findByPrimaryKey
> ("GoodIdentification", UtilMisc.toMap("goodIdentificationTypeId",  
> "UPCA", "productId", requirement.get("productId")));
> +                GenericValue gid = (GenericValue) gids.get
> (productId);
> +                if (gid == null) {
> +                    gid = delegator.findByPrimaryKey
> ("GoodIdentification", UtilMisc.toMap("goodIdentificationTypeId",  
> "UPCA", "productId", requirement.get("productId")));
> +                    gids.put(productId, gid);
> +                }
>                  if (gid != null) union.put("idValue", gid.get
> ("idValue"));
>
> +                // the ATP and QOH quantities
> +                if (UtilValidate.isNotEmpty(facilityId)) {
> +                    String inventoryKey = facilityId + "^" +  
> productId;
> +                    Map inventory = (Map) inventories.get
> (inventoryKey);
> +                    if (inventory == null) {
> +                        inventory = dispatcher.runSync
> ("getInventoryAvailableByFacility", UtilMisc.toMap("productId",  
> productId, "facilityId", facilityId));
> +                        if (ServiceUtil.isError(inventory)) {
> +                            return inventory;
> +                        }
> +                        inventories.put(inventoryKey, inventory);
> +                    }
> +                    if (inventory != null) {
> +                        union.put("qoh", inventory.get
> ("quantityOnHandTotal"));
> +                        union.put("atp", inventory.get
> ("availableToPromiseTotal"));
> +                    }
> +                }
> +
>                  // add all the requirement fields last, to  
> overwrite any conflicting fields
>                  union.putAll(requirement.getAllFields());
>                  requirements.add(union);
> @@ -100,6 +134,9 @@
>              Map results = ServiceUtil.returnSuccess();
>              results.put("requirementsForSupplier", requirements);
>              return results;
> +        } catch (GenericServiceException e) {
> +            Debug.logError(e, module);
> +            return ServiceUtil.returnError
> (UtilProperties.getMessage(resource_error,  
> "OrderServiceExceptionSeeLogs", locale));
>          } catch (GenericEntityException e) {
>              Debug.logError(e, module);
>              return ServiceUtil.returnError
> (UtilProperties.getMessage(resource_error,  
> "OrderEntityExceptionSeeLogs", locale));
>
> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/
> requirement/RequirementForms.xml
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/ 
> webapp/ordermgr/requirement/RequirementForms.xml?
> view=diff&rev=501633&r1=501632&r2=501633
> ======================================================================
> ========
> --- ofbiz/trunk/applications/order/webapp/ordermgr/requirement/
> RequirementForms.xml (original)
> +++ ofbiz/trunk/applications/order/webapp/ordermgr/requirement/
> RequirementForms.xml Tue Jan 30 15:11:32 2007
> @@ -320,6 +320,8 @@
>          <field name="minimumOrderQuantity" widget-area-
> style="tabletextright"><display/></field>
>          <field name="lastPrice" widget-area-
> style="tabletextright"><display type="currency" currency="$
> {currencyUomId}"/></field>
>          <field name="requiredByDate"><display/></field>
> +        <field name="atp" title="${uiLabelMap.ProductAtp}" widget-
> area-style="tabletextright"><display/></field>
> +        <field name="qoh" title="${uiLabelMap.ProductQoh}" widget-
> area-style="tabletextright"><display/></field>
>          <field name="quantity"><text size="4"/></field>
>          <field name="comments"><display/></field>
>          <field name="_rowSubmit" title="$
> {uiLabelMap.CommonSelect}"><check/></field>
>
>


smime.p7s (3K) Download Attachment