svn commit: r501216 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/requirement/ servicedef/ src/org/ofbiz/order/requirement/ webapp/ordermgr/requirement/

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

svn commit: r501216 - in /ofbiz/trunk/applications/order: script/org/ofbiz/order/requirement/ servicedef/ src/org/ofbiz/order/requirement/ webapp/ordermgr/requirement/

sichen
Author: sichen
Date: Mon Jan 29 14:51:57 2007
New Revision: 501216

URL: http://svn.apache.org/viewvc?view=rev&rev=501216
Log:
Improve the getRequirementsForSupplier service to include useful data about the supplier and product.  Required replacing the simple method with a java service due to the complexity.  Improved requirement forms as well.

Added:
    ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/
    ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
Modified:
    ofbiz/trunk/applications/order/script/org/ofbiz/order/requirement/RequirementServices.xml
    ofbiz/trunk/applications/order/servicedef/services_requirement.xml
    ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml

Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/requirement/RequirementServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/requirement/RequirementServices.xml?view=diff&rev=501216&r1=501215&r2=501216
==============================================================================
--- ofbiz/trunk/applications/order/script/org/ofbiz/order/requirement/RequirementServices.xml (original)
+++ ofbiz/trunk/applications/order/script/org/ofbiz/order/requirement/RequirementServices.xml Mon Jan 29 14:51:57 2007
@@ -64,52 +64,6 @@
         <set-pk-fields map-name="parameters" value-name="newEntity"/>
         <create-value value-name="newEntity"/>
     </simple-method>
-    
-    <simple-method method-name="getRequirementsForSupplier" short-description="Get the requirements applicable to a given supplier">
-        <make-value value-name="newEntity" entity-name="Requirement"/>
-        <if-not-empty field-name="parameters.partyId">
-            <!-- all the product requirements that are assigned to the given supplier are shown -->
-            <entity-condition entity-name="RequirementAndRole" list-name="requirementsForSupplier">
-                <condition-list>
-                    <condition-object field-name="parameters.requirementConditions"/>
-                    <condition-expr field-name="statusId" value="REQ_APPROVED"/>
-                    <condition-expr field-name="roleTypeId" value="SUPPLIER"/>
-                    <condition-expr field-name="requirementTypeId" value="PRODUCT_REQUIREMENT"/>
-                    <condition-expr field-name="partyId" env-name="parameters.partyId"/>
-                </condition-list>
-            </entity-condition>
-        <else>
-            <if-not-empty field-name="parameters.unassignedRequirements">
-                <!-- only the product requirements that are not assigned to a supplier are shown -->
-                <entity-condition entity-name="RequirementAndRole" list-name="requirementsForSupplier">
-                    <condition-list>
-                        <condition-object field-name="parameters.requirementConditions"/>
-                        <condition-expr field-name="statusId" value="REQ_APPROVED"/>
-                        <condition-expr field-name="requirementTypeId" value="PRODUCT_REQUIREMENT"/>
-                        <condition-expr field-name="partyId" env-name="null"/>
-                    </condition-list>
-                </entity-condition>
-            <else>
-                <!-- all the product requirements that are assigned to suppliers are shown -->
-                <entity-condition entity-name="RequirementAndRole" list-name="requirementsForSupplier">
-                    <condition-list>
-                        <condition-object field-name="parameters.requirementConditions"/>
-                        <condition-expr field-name="statusId" value="REQ_APPROVED"/>
-                        <condition-expr field-name="requirementTypeId" value="PRODUCT_REQUIREMENT"/>
-                        <condition-expr field-name="roleTypeId" value="SUPPLIER"/>
-                    </condition-list>
-                    <order-by field-name="partyId"/>
-                </entity-condition>
-            </else>
-            </if-not-empty>
-        </else>
-        </if-not-empty>
-        <if-not-empty field-name="parameters.assignedRequirements">
-        <else>
-        </else>
-        </if-not-empty>
-        <field-to-result field-name="requirementsForSupplier" result-name="requirementsForSupplier"/>
-    </simple-method>
 
     <simple-method method-name="autoAssignRequirementToSupplier" short-description="If the requirement is a product requirement (purchasing) try to assign it to the primary supplier">
         <entity-one entity-name="Requirement" value-name="requirement" auto-field-map="true"/>
@@ -124,7 +78,6 @@
                     </condition-list>
                     <order-by field-name="supplierPrefOrderId"/>
                 </entity-condition>
-                <filter-list-by-date list-name="supplierProducts" from-field-name="availableFromDate" thru-field-name="availableThruDate"/>
                 <first-from-list list-name="supplierProducts" entry-name="supplierProduct"/>
                 <if-not-empty field-name="supplierProduct.partyId">
                     <make-value value-name="requirementSupplier" entity-name="RequirementRole"/>

Modified: ofbiz/trunk/applications/order/servicedef/services_requirement.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_requirement.xml?view=diff&rev=501216&r1=501215&r2=501216
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_requirement.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_requirement.xml Mon Jan 29 14:51:57 2007
@@ -92,8 +92,8 @@
         <attribute name="workReqFulfTypeId" type="String" mode="IN" optional="true"/>
     </service>
 
-    <service name="getRequirementsForSupplier" engine="simple"
-            location="org/ofbiz/order/requirement/RequirementServices.xml" invoke="getRequirementsForSupplier">
+    <service name="getRequirementsForSupplier" engine="java"
+            location="org.ofbiz.order.requirement.RequirementServices" invoke="getRequirementsForSupplier">
         <description>Retrieves requirements information for suppliers</description>
         <attribute mode="IN" name="requirementConditions" type="org.ofbiz.entity.condition.EntityCondition" optional="true"/>
         <attribute mode="IN" name="partyId" type="String" optional="true"/>

Added: 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=auto&rev=501216
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java (added)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java Mon Jan 29 14:51:57 2007
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *******************************************************************************/
+package org.ofbiz.order.requirement;
+
+import java.util.*;
+
+import javolution.util.FastList;
+import javolution.util.FastMap;
+
+import org.ofbiz.base.util.*;
+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.LocalDispatcher;
+import org.ofbiz.service.ServiceUtil;
+
+/**
+ * Requirement Services
+ */
+
+public class RequirementServices {
+
+    public static final String module = RequirementServices.class.getName();
+    public static final String resource_error = "OrderErrorUiLabels";
+
+    public static final Map getRequirementsForSupplier(DispatchContext ctx, Map context) {
+        GenericDelegator delegator = ctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+
+        EntityCondition requirementConditions = (EntityCondition) context.get("requirementConditions");
+        String partyId = (String) context.get("partyId");
+        String unassignedRequirements = (String) context.get("unassignedRequirements");
+        String currencyUomId = (String) context.get("currencyUomId");
+        try {
+            List orderBy = UtilMisc.toList("partyId", "requirementId");
+            List conditions = UtilMisc.toList(
+                    new EntityExpr("requirementTypeId", EntityOperator.EQUALS, "PRODUCT_REQUIREMENT"),
+                    new EntityExpr("statusId", EntityOperator.EQUALS, "REQ_APPROVED"),
+                    EntityUtil.getFilterByDateExpr()
+                    );
+            if (requirementConditions != null) conditions.add(requirementConditions);
+
+            // we're either getting the requirements for a given supplier, unassigned requirements, or requirements for all suppliers
+            if (UtilValidate.isNotEmpty(partyId)) {
+                conditions.add( new EntityExpr("partyId", EntityOperator.EQUALS, partyId) );
+                conditions.add( new EntityExpr("roleTypeId", EntityOperator.EQUALS, "SUPPLIER") );
+            } else if (UtilValidate.isNotEmpty(unassignedRequirements)) {
+                conditions.add( new EntityExpr("partyId", EntityOperator.EQUALS, null) );
+            } else {
+                conditions.add( new EntityExpr("roleTypeId", EntityOperator.EQUALS, "SUPPLIER") );
+            }
+            List requirementAndRoles = delegator.findByAnd("RequirementAndRole", conditions, orderBy);
+
+            // 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();
+                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());
+                }
+
+                // for good identification, get the UPCA type (UPC code)
+                GenericValue gid = delegator.findByPrimaryKey("GoodIdentification", UtilMisc.toMap("goodIdentificationTypeId", "UPCA", "productId", requirement.get("productId")));
+                if (gid != null) union.put("idValue", gid.get("idValue"));
+
+                // add all the requirement fields last, to overwrite any conflicting fields
+                union.putAll(requirement.getAllFields());
+                requirements.add(union);
+            }
+
+            Map results = ServiceUtil.returnSuccess();
+            results.put("requirementsForSupplier", requirements);
+            return results;
+        } 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=501216&r1=501215&r2=501216
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml Mon Jan 29 14:51:57 2007
@@ -275,15 +275,20 @@
             <hyperlink also-hidden="true" description="${requirementId}" target="EditRequirement?requirementId=${requirementId}"/>
         </field>
         <field name="productId" widget-style="buttontext">
-            <hyperlink also-hidden="true" target-type="inter-app" description="${productId}" target="/catalog/control/EditProductInventoryItems?productId=${productId}"/>
+            <hyperlink also-hidden="true" target-type="inter-app" description="${productId}" target="/catalog/control/EditProductInventoryItems?productId=${productId}" target-window="top"/>
         </field>
         <field name="internalName" entry-name="productId">
             <display-entity entity-name="Product" key-field-name="productId" description="${internalName}"/>
         </field>
         <field name="facilityId"><display/></field>
-        <field name="partyId"><display/></field>
+        <field name="partyId" title="${uiLabelMap.ProductSupplier}"><display/></field>
+        <field name="supplierProductId" title="${uiLabelMap.ProductSupplierProductId}"><display/></field>
+        <field name="idValue" title="UPCA"><display/></field>
+        <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="quantity" widget-area-style="tabletextright"><display/></field>
+        <field name="comments"><display/></field>
     </form>
     <form name="ApprovedProductRequirements" type="multi" use-row-submit="true" target="quickPurchaseOrderEntry" title="" list-name="requirementsForSupplier"
         paginate-target="RequirementsForSupplier" default-title-style="tableheadtext" default-widget-style="tabletext" default-tooltip-style="tabletext">
@@ -303,9 +308,11 @@
         <field name="requirementId" widget-style="buttontext">
             <hyperlink also-hidden="true" description="${requirementId}" target="EditRequirement?requirementId=${requirementId}"/>
         </field>
-        <field name="productId"><hidden value="${productId}"/></field>
-        <field name="productId">
-            <display-entity entity-name="Product" key-field-name="productId" description="${productId} - ${internalName}"/>
+        <field name="productId" widget-style="buttontext">
+            <hyperlink also-hidden="true" target-type="inter-app" description="${productId}" target="/catalog/control/EditProductInventoryItems?productId=${productId}" target-window="top"/>
+        </field>
+        <field name="internalName" entry-name="productId">
+            <display-entity entity-name="Product" key-field-name="productId" description="${internalName}"/>
         </field>
         <field name="requiredByDate"><display/></field>
         <field name="quantity"><text/></field>