Author: jacopoc
Date: Sat Mar 10 14:24:01 2007
New Revision: 516798

URL: http://svn.apache.org/viewvc?view=rev&rev=516798
Log:
Added support for facility groups in MRP: if a facility group is specified 
(instead of a facility id) the MRP will use the facilities in the group as 
warehouse facility (WAREHOUSE) and manufacturing facility (PLANT).

Modified:
    ofbiz/trunk/applications/manufacturing/servicedef/services_mrp.xml
    
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java
    
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java
    ofbiz/trunk/applications/manufacturing/webapp/manufacturing/mrp/MrpForms.xml

Modified: ofbiz/trunk/applications/manufacturing/servicedef/services_mrp.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/servicedef/services_mrp.xml?view=diff&rev=516798&r1=516797&r2=516798
==============================================================================
--- ofbiz/trunk/applications/manufacturing/servicedef/services_mrp.xml 
(original)
+++ ofbiz/trunk/applications/manufacturing/servicedef/services_mrp.xml Sat Mar 
10 14:24:01 2007
@@ -28,8 +28,9 @@
     <service name="executeMrp" engine="java"
             location="org.ofbiz.manufacturing.mrp.MrpServices" 
invoke="executeMrp" auth="true" use-transaction="false">
         <description>Performs a run of Mrp</description>
-        <attribute name="facilityId" type="String" form-display="true" 
form-label="Facility" mode="IN" optional="false"/>
-        <attribute name="mrpName" type="String" form-display="true" 
form-label="Mrp Name" mode="IN" optional="true"/>
+        <attribute name="facilityGroupId" type="String" mode="IN" 
optional="true"/>
+        <attribute name="facilityId" type="String" mode="IN" optional="true"/>
+        <attribute name="mrpName" type="String" mode="IN" optional="true"/>
         <attribute name="msgResult" type="List" mode="OUT" optional="false"/>
     </service>
     <service name="initInventoryEventPlanned" engine="java"

Modified: 
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java?view=diff&rev=516798&r1=516797&r2=516798
==============================================================================
--- 
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java
 (original)
+++ 
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/MrpServices.java
 Sat Mar 10 14:24:01 2007
@@ -463,15 +463,51 @@
      */
     public static Map executeMrp(DispatchContext ctx, Map context) {
         Debug.logInfo("executeMrp called", module);
-        //Context
+
         GenericDelegator delegator = ctx.getDelegator();
         LocalDispatcher dispatcher = ctx.getDispatcher();
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         Timestamp now = UtilDateTime.nowTimestamp();
         
         String mrpName = (String)context.get("mrpName");
+        String facilityGroupId = (String)context.get("facilityGroupId");
         String facilityId = (String)context.get("facilityId");
-        // Variable declaration
+        String manufacturingFacilityId = null;
+        if (UtilValidate.isEmpty(facilityId) && 
UtilValidate.isEmpty(facilityGroupId)) {
+            return ServiceUtil.returnError("facilityId and facilityGroupId 
cannot be both null");
+        }
+        if (UtilValidate.isEmpty(facilityId)) {
+            try {
+                GenericValue facilityGroup = 
delegator.findByPrimaryKey("FacilityGroup", UtilMisc.toMap("facilityGroupId", 
facilityGroupId));
+                if (UtilValidate.isEmpty(facilityGroup)) {
+                    return ServiceUtil.returnError("facilityGroupId [" + 
facilityGroupId + "] is not valid");
+                }
+                List facilities = 
facilityGroup.getRelated("FacilityGroupMember", UtilMisc.toList("sequenceNum"));
+                if (UtilValidate.isEmpty(facilities)) {
+                    return ServiceUtil.returnError("No facility associated to 
facilityGroupId [" + facilityGroupId + "]");
+                }
+                Iterator facilitiesIt = facilities.iterator();
+                while (facilitiesIt.hasNext()) {
+                    GenericValue facilityMember = 
(GenericValue)facilitiesIt.next();
+                    GenericValue facility = 
facilityMember.getRelatedOne("Facility");
+                    if 
("WAREHOUSE".equals(facility.getString("facilityTypeId")) && 
UtilValidate.isEmpty(facilityId)) {
+                        facilityId = facility.getString("facilityId");
+                    }
+                    if ("PLANT".equals(facility.getString("facilityTypeId")) 
&& UtilValidate.isEmpty(manufacturingFacilityId)) {
+                        manufacturingFacilityId = 
facility.getString("facilityId");
+                    }
+                }
+            } catch (GenericEntityException e) {
+                return ServiceUtil.returnError("Problem loading facility group 
information: " + e.getMessage());
+            }
+        } else {
+            manufacturingFacilityId = facilityId;
+        }
+
+        if (UtilValidate.isEmpty(facilityId) || 
UtilValidate.isEmpty(manufacturingFacilityId)) {
+            return ServiceUtil.returnError("facilityId and 
manufacturingFacilityId cannot be both null");
+        }
+        
         int bomLevelWithNoEvent = 0;
         double stockTmp = 0;
         String oldProductId = null;
@@ -486,7 +522,7 @@
         double minimumStock = 0;
         int daysToShip = 0;
         List components = null;
-        boolean isbuild = false;
+        boolean isBuilt = false;
         GenericValue routing = null;
         
         Map result = null;
@@ -565,9 +601,9 @@
                         components = (List)serviceResponse.get("components");
                         if (components != null && components.size() > 0) {
                             BOMNode node = 
((BOMNode)components.get(0)).getParentNode();
-                            isbuild = node.isManufactured();
+                            isBuilt = node.isManufactured();
                         } else {
-                            isbuild = false;
+                            isBuilt = false;
                         }
                         // 
#####################################################
 
@@ -581,7 +617,7 @@
                         eventDate = 
inventoryEventForMRP.getTimestamp("eventDate");
                         // to be just before the requirement
                         eventDate.setTime(eventDate.getTime()-1);
-                        ProposedOrder proposedOrder = new 
ProposedOrder(product, facilityId, isbuild, eventDate, qtyToStock);
+                        ProposedOrder proposedOrder = new 
ProposedOrder(product, facilityId, manufacturingFacilityId, isBuilt, eventDate, 
qtyToStock);
                         proposedOrder.setMrpName(mrpName);
                         // calculate the ProposedOrder quantity and update the 
quantity object property.
                         
proposedOrder.calculateQuantityToSupply(reorderQuantity, minimumStock, 
iteratorListInventoryEventForMRP);
@@ -607,15 +643,15 @@
                         }
                         if (components != null && components.size() > 0) {
                             BOMNode node = 
((BOMNode)components.get(0)).getParentNode();
-                            isbuild = node.isManufactured();
+                            isBuilt = node.isManufactured();
                         } else {
-                            isbuild = false;
+                            isBuilt = false;
                         }
                         // 
#####################################################
                         
                         // calculate the ProposedOrder requirementStartDate 
and update the requirementStartDate object property.
                         Map routingTaskStartDate = 
proposedOrder.calculateStartDate(daysToShip, routing, delegator, dispatcher, 
userLogin);
-                        if (isbuild) {
+                        if (isBuilt) {
                             // process the product components
                             processBomComponent(product, 
proposedOrder.getQuantity(), proposedOrder.getRequirementStartDate(), 
routingTaskStartDate, components);
                         }
@@ -625,7 +661,7 @@
                         }
                         Map eventMap = UtilMisc.toMap("productId", 
product.getString("productId"),
                                                       "eventDate", eventDate,
-                                                      
"inventoryEventPlanTypeId", (isbuild? "PROP_MANUF_O_RECP" : "PROP_PUR_O_RECP"));
+                                                      
"inventoryEventPlanTypeId", (isBuilt? "PROP_MANUF_O_RECP" : "PROP_PUR_O_RECP"));
                         try {
                             
InventoryEventPlannedServices.createOrUpdateInventoryEventPlanned(eventMap, new 
Double(proposedOrder.getQuantity()), null, delegator);
                         } catch (GenericEntityException e) {

Modified: 
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java?view=diff&rev=516798&r1=516797&r2=516798
==============================================================================
--- 
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java
 (original)
+++ 
ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/ProposedOrder.java
 Sat Mar 10 14:24:01 2007
@@ -50,20 +50,22 @@
     public static final String resource = "ManufacturingUiLabels";
     
     protected GenericValue product;
-    protected boolean isbuild;
+    protected boolean isBuilt;
     protected String productId;
     protected String facilityId;
+    protected String manufacturingFacilityId;
     protected String mrpName;
     protected Timestamp requiredByDate;
     protected Timestamp requirementStartDate;
     protected double quantity;
     
     
-    public ProposedOrder(GenericValue product, String facilityId, boolean 
isbuild, Timestamp requiredByDate, double quantity) {
+    public ProposedOrder(GenericValue product, String facilityId, String 
manufacturingFacilityId, boolean isBuilt, Timestamp requiredByDate, double 
quantity) {
         this.product = product;
         this.productId = product.getString("productId");
         this.facilityId = facilityId;
-        this.isbuild = isbuild;
+        this.manufacturingFacilityId = manufacturingFacilityId;
+        this.isBuilt = isBuilt;
         this.requiredByDate = requiredByDate;
         this.quantity = quantity;
         this.requirementStartDate = null;
@@ -97,7 +99,7 @@
         Map result = null;
         Timestamp endDate = (Timestamp) requiredByDate.clone();
         Timestamp startDate = endDate;
-        if (isbuild) {
+        if (isBuilt) {
             List listRoutingTaskAssoc = null;
             if (routing == null) {
                 try {
@@ -211,11 +213,11 @@
         Map parameters = UtilMisc.toMap("userLogin", userLogin);
         
         parameters.put("productId", productId);
-        parameters.put("facilityId", facilityId);
+        parameters.put("facilityId", (isBuilt? manufacturingFacilityId: 
facilityId));
         parameters.put("requiredByDate", requiredByDate);
         parameters.put("requirementStartDate", requirementStartDate);
         parameters.put("quantity", new Double(quantity));
-        parameters.put("requirementTypeId", (isbuild? "INTERNAL_REQUIREMENT" : 
"PRODUCT_REQUIREMENT"));
+        parameters.put("requirementTypeId", (isBuilt? "INTERNAL_REQUIREMENT" : 
"PRODUCT_REQUIREMENT"));
         if (mrpName != null) {
             parameters.put("description", "MRP_" + mrpName);
         } else {

Modified: 
ofbiz/trunk/applications/manufacturing/webapp/manufacturing/mrp/MrpForms.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/webapp/manufacturing/mrp/MrpForms.xml?view=diff&rev=516798&r1=516797&r2=516798
==============================================================================
--- 
ofbiz/trunk/applications/manufacturing/webapp/manufacturing/mrp/MrpForms.xml 
(original)
+++ 
ofbiz/trunk/applications/manufacturing/webapp/manufacturing/mrp/MrpForms.xml 
Sat Mar 10 14:24:01 2007
@@ -20,10 +20,16 @@
 
 <forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
         
xsi:noNamespaceSchemaLocation="http://www.ofbiz.org/dtds/widget-form.xsd";>
+
     <form name="RunMrp" type="single" target="runMrpGo" title="">
         <field name="mrpName"  
title="${uiLabelMap.ManufacturingMrpName}"><text size="20"/></field>
+        <field name="facilityGroupId" 
title="${uiLabelMap.ProductFacilityGroup}">
+            <drop-down allow-empty="true">
+                <entity-options entity-name="FacilityGroup" 
description="${facilityGroupName} [${facilityGroupId}]"/>
+            </drop-down>
+        </field>
         <field name="facilityId" title="${uiLabelMap.ProductFacility}">
-            <drop-down allow-empty="false">
+            <drop-down allow-empty="true">
                 <entity-options entity-name="Facility" 
description="${facilityName} [${facilityId}]"/>
             </drop-down>
         </field>


Reply via email to