svn commit: r518369 - in /ofbiz/trunk/applications/order: servicedef/ src/org/ofbiz/order/requirement/ webapp/ordermgr/WEB-INF/actions/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: r518369 - in /ofbiz/trunk/applications/order: servicedef/ src/org/ofbiz/order/requirement/ webapp/ordermgr/WEB-INF/actions/requirement/ webapp/ordermgr/requirement/

sichen
Author: sichen
Date: Wed Mar 14 15:56:51 2007
New Revision: 518369

URL: http://svn.apache.org/viewvc?view=rev&rev=518369
Log:
Add an amount total to the list of approved product requirements.

Modified:
    ofbiz/trunk/applications/order/servicedef/services_requirement.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java
    ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/requirement/ApprovedProductRequirements.bsh
    ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml

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=518369&r1=518368&r2=518369
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services_requirement.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services_requirement.xml Wed Mar 14 15:56:51 2007
@@ -102,6 +102,7 @@
         <attribute mode="OUT" name="requirementsForSupplier" type="java.util.List" optional="true"/>
         <attribute mode="OUT" name="distinctProductCount" type="Integer" optional="true"/>
         <attribute mode="OUT" name="quantityTotal" type="Double" optional="true"/>
+        <attribute mode="OUT" name="amountTotal" type="Double" optional="true"/>
     </service>
     <service name="createOrderRequirementCommitment" engine="simple" auth="true"
         location="org/ofbiz/order/order/OrderServices.xml" invoke="createOrderRequirementCommitment">

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=518369&r1=518368&r2=518369
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/requirement/RequirementServices.java Wed Mar 14 15:56:51 2007
@@ -79,8 +79,9 @@
             Map inventories = FastMap.newInstance();
             Map productsSold = FastMap.newInstance();
 
-            // to count quantity and distinct products in list
+            // to count quantity, running total, and distinct products in list
             double quantity = 0.0;
+            double amountTotal = 0.0;
             Set products = new HashSet();
 
             // time period to count products ordered from, six months ago and the 1st of that month
@@ -94,20 +95,28 @@
                 String productId = requirement.getString("productId");
                 partyId = requirement.getString("partyId");
                 String facilityId = requirement.getString("facilityId");
+                double requiredQuantity = requirement.getDouble("quantity").doubleValue();
 
-                // get an available supplier product
+                // get an available supplier product, preferably the one with the smallest minimum quantity to order, followed by price
                 String supplierKey =  partyId + "^" + productId;
                 GenericValue supplierProduct = (GenericValue) suppliers.get(supplierKey);
                 if (supplierProduct == null) {
                     conditions = UtilMisc.toList(
+                            // TODO: it is possible to restrict to quantity > minimumOrderQuantity, but then the entire requirement must be skipped
                             new EntityExpr("partyId", EntityOperator.EQUALS, partyId),
                             new EntityExpr("productId", EntityOperator.EQUALS, productId),
                             EntityUtil.getFilterByDateExpr("availableFromDate", "availableThruDate")
                             );
-                    supplierProduct = EntityUtil.getFirst( delegator.findByAnd("SupplierProduct", conditions) );
+                    supplierProduct = EntityUtil.getFirst( delegator.findByAnd("SupplierProduct", conditions, UtilMisc.toList("minimumOrderQuantity", "lastPrice")) );
                     suppliers.put(supplierKey, supplierProduct);
                 }
-                if (supplierProduct != null) union.putAll(supplierProduct.getAllFields());
+
+                // add our supplier product and cost of this line to the data
+                if (supplierProduct != null) {
+                    union.putAll(supplierProduct.getAllFields());
+                    double lastPrice = supplierProduct.getDouble("lastPrice").doubleValue();
+                    amountTotal += lastPrice * requiredQuantity;
+                }
 
                 // for good identification, get the UPCA type (UPC code)
                 GenericValue gid = (GenericValue) gids.get(productId);
@@ -156,7 +165,7 @@
 
                 // keep a running total of distinct products and quantity to order
                 if (requirement.getDouble("quantity") == null) requirement.put("quantity", new Double("1")); // default quantity = 1
-                quantity += requirement.getDouble("quantity").doubleValue();
+                quantity += requiredQuantity;
                 products.add(productId);
 
                 // add all the requirement fields last, to overwrite any conflicting fields
@@ -168,6 +177,7 @@
             results.put("requirementsForSupplier", requirements);
             results.put("distinctProductCount", new Integer(products.size()));
             results.put("quantityTotal", new Double(quantity));
+            results.put("amountTotal", new Double(amountTotal));
             return results;
         } catch (GenericServiceException e) {
             Debug.logError(e, module);

Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/requirement/ApprovedProductRequirements.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/requirement/ApprovedProductRequirements.bsh?view=diff&rev=518369&r1=518368&r2=518369
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/requirement/ApprovedProductRequirements.bsh (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/actions/requirement/ApprovedProductRequirements.bsh Wed Mar 14 15:56:51 2007
@@ -23,5 +23,5 @@
 if (prepare.get("entityConditionList") != null) {
  results = dispatcher.runSync("getRequirementsForSupplier", UtilMisc.toMap("requirementConditions", prepare.get("entityConditionList"), "partyId", parameters.get("partyId")));
  context.put("requirementsForSupplier", results.get("requirementsForSupplier"));
- context.put("quantityReport", UtilMisc.toMap("distinctProductCount", results.get("distinctProductCount"), "quantityTotal", results.get("quantityTotal")));
+ context.put("quantityReport", UtilMisc.toMap("distinctProductCount", results.get("distinctProductCount"), "quantityTotal", results.get("quantityTotal"), "amountTotal", results.get("amountTotal")));
 }

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=518369&r1=518368&r2=518369
==============================================================================
--- ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml (original)
+++ ofbiz/trunk/applications/order/webapp/ordermgr/requirement/RequirementForms.xml Wed Mar 14 15:56:51 2007
@@ -326,8 +326,9 @@
     </form>
     <form name="ApprovedProductRequirementsSummary" type="single" default-map-name="quantityReport" target="ApprovedProductRequirements"
         default-title-style="tableheadtext" default-widget-style="tabletext" default-tooltip-style="tabletext">
-        <field name="distinctProductCount"><display/></field>
+        <field name="distinctProductCount" title="Number of Products"><display/></field>
         <field name="quantityTotal"><display/></field>
+        <field name="amountTotal"><display type="currency" currency="${currencyUomId}"/></field>
     </form>
     <form name="ApprovedProductRequirementsByVendor" type="list" use-row-submit="true" list-name="requirements" target="ApprovedProductRequirements" separate-columns="true"
         default-title-style="tableheadtext" default-widget-style="tabletext" default-tooltip-style="tabletext"