svn commit: r778565 - in /ofbiz/trunk/applications: manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java product/script/org/ofbiz/product/cost/CostServices.xml product/servicedef/services_cost.xml

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

svn commit: r778565 - in /ofbiz/trunk/applications: manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java product/script/org/ofbiz/product/cost/CostServices.xml product/servicedef/services_cost.xml

jacopoc
Author: jacopoc
Date: Tue May 26 05:32:04 2009
New Revision: 778565

URL: http://svn.apache.org/viewvc?rev=778565&view=rev
Log:
Misc fixes and enhancements for the costing routines: there is still room for improvements but at least now the standard costing and actual costing are based on the same rules.

Modified:
    ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
    ofbiz/trunk/applications/product/script/org/ofbiz/product/cost/CostServices.xml
    ofbiz/trunk/applications/product/servicedef/services_cost.xml

Modified: ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=778565&r1=778564&r2=778565&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ ofbiz/trunk/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Tue May 26 05:32:04 2009
@@ -1012,6 +1012,28 @@
                     dispatcher.runSync(customMethod.getString("customMethodName"), inMap);
                 }
             }
+            // Now get the cost information associated to the fixed asset and compute the costs
+            GenericValue fixedAsset = workEffort.getRelatedOne("FixedAsset");
+            if (UtilValidate.isEmpty(fixedAsset) && UtilValidate.isNotEmpty(routingTask)) {
+                fixedAsset = routingTask.getRelatedOne("FixedAsset");
+            }
+            if (UtilValidate.isNotEmpty(fixedAsset)) {
+                List setupCosts = fixedAsset.getRelatedByAnd("FixedAssetStdCost", UtilMisc.toMap("fixedAssetStdCostTypeId", "SETUP_COST"));
+                GenericValue setupCost = EntityUtil.getFirst(EntityUtil.filterByDate(setupCosts));
+                List usageCosts = fixedAsset.getRelatedByAnd("FixedAssetStdCost", UtilMisc.toMap("fixedAssetStdCostTypeId", "USAGE_COST"));
+                GenericValue usageCost = EntityUtil.getFirst(EntityUtil.filterByDate(usageCosts));
+                if (UtilValidate.isNotEmpty(setupCost) || UtilValidate.isNotEmpty(usageCost)) {
+                    String currencyUomId = (setupCost != null? setupCost.getString("amountUomId"): usageCost.getString("amountUomId"));
+                    BigDecimal fixedAssetCost = (setupCost.getBigDecimal("amount").multiply(BigDecimal.valueOf(actualSetupMillis.doubleValue()))).add(usageCost.getBigDecimal("amount").multiply(BigDecimal.valueOf(actualMilliSeconds.doubleValue()))).setScale(decimals, rounding);
+                    fixedAssetCost = fixedAssetCost.divide(BigDecimal.valueOf(3600000)).setScale(decimals, rounding);
+                    // store the cost
+                    Map inMap = UtilMisc.toMap("userLogin", userLogin, "workEffortId", productionRunTaskId);
+                    inMap.put("costComponentTypeId", "ACTUAL_ROUTE_COST");
+                    inMap.put("costUomId", currencyUomId);
+                    inMap.put("cost", fixedAssetCost);
+                    dispatcher.runSync("createCostComponent", inMap);
+                }
+            }
         } catch (Exception e) {
             return ServiceUtil.returnError("Unable to create routing costs for the production run task [" + productionRunTaskId + "]: " + e.getMessage());
         }
@@ -1876,8 +1898,8 @@
         Timestamp toDate = (Timestamp)context.get("toDate");
         BigDecimal addQuantityProduced = (BigDecimal)context.get("addQuantityProduced");
         BigDecimal addQuantityRejected = (BigDecimal)context.get("addQuantityRejected");
-        Double addSetupTime = (Double)context.get("addSetupTime");
-        Double addTaskTime = (Double)context.get("addTaskTime");
+        BigDecimal addSetupTime = (BigDecimal)context.get("addSetupTime");
+        BigDecimal addTaskTime = (BigDecimal)context.get("addTaskTime");
         String comments = (String)context.get("comments");
         Boolean issueRequiredComponents = (Boolean)context.get("issueRequiredComponents");
         Map componentsLocationMap = (Map)context.get("componentsLocationMap");
@@ -1898,10 +1920,10 @@
             addQuantityRejected = BigDecimal.ZERO;
         }
         if (addSetupTime == null) {
-            addSetupTime = Double.valueOf(0);
+            addSetupTime = BigDecimal.ZERO;
         }
         if (addTaskTime == null) {
-            addTaskTime = Double.valueOf(0);
+            addTaskTime = BigDecimal.ZERO;
         }
         if (comments == null) {
             comments = "";

Modified: ofbiz/trunk/applications/product/script/org/ofbiz/product/cost/CostServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/product/cost/CostServices.xml?rev=778565&r1=778564&r2=778565&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/script/org/ofbiz/product/cost/CostServices.xml (original)
+++ ofbiz/trunk/applications/product/script/org/ofbiz/product/cost/CostServices.xml Tue May 26 05:32:04 2009
@@ -180,12 +180,12 @@
         <set-service-fields service-name="getEstimatedTaskTime" map="parameters" to-map="inputMap"/>
         <set from-field="parameters.workEffortId" field="inputMap.taskId"/>
         <call-service service-name="getEstimatedTaskTime" in-map-name="inputMap">
-            <result-to-field result-name="estimatedTaskTime"/>
+            <result-to-field result-name="estimatedTaskTime" field="totalEstimatedTaskTime"/>
             <result-to-field result-name="setupTime"/>
         </call-service>
 
         <calculate field="estimatedTaskTime" decimal-scale="6">
-            <calcop field="estimatedTaskTime" operator="subtract">
+            <calcop field="totalEstimatedTaskTime" operator="subtract">
                 <calcop field="setupTime" operator="get"/>
             </calcop>
         </calculate>
@@ -222,7 +222,42 @@
             </calcop>
         </calculate>
 
+        <!-- Now compute the costs derived from CostComponentCalc records associated with the task -->
+        <get-related relation-name="WorkEffortCostCalc" list="weccs" value-field="task"/>
+        <filter-list-by-date list="weccs"/>
+        <iterate entry="wecc" list="weccs">
+            <clear-field field="totalCostComponentCost"/>
+            <clear-field field="totalCostComponentTime"/>
+            <get-related-one relation-name="CostComponentCalc" to-value-field="costComponentCalc" value-field="wecc"/>
+            <get-related-one relation-name="CustomMethod" to-value-field="customMethod" value-field="costComponentCalc"/>
+            <if-empty field="customMethod">
+                <if-not-empty field="costComponentCalc.perMilliSecond">
+                    <if-compare operator="not-equals" value="0" field="costComponentCalc.perMilliSecond" type="BigDecimal">
+                        <calculate field="totalCostComponentTime" decimal-scale="6">
+                            <calcop field="totalEstimatedTaskTime" operator="divide">
+                                <calcop field="costComponentCalc.perMilliSecond" operator="get"/>
+                            </calcop>
+                        </calculate>
+                        <calculate field="totalCostComponentCost" decimal-scale="6">
+                            <calcop field="totalCostComponentTime" operator="multiply">
+                                <calcop field="costComponentCalc.variableCost" operator="get"/>
+                            </calcop>
+                        </calculate>
+                        <calculate field="totalCostComponentCost" decimal-scale="6">
+                            <calcop field="totalCostComponentCost" operator="add">
+                                <calcop field="costComponentCalc.fixedCost" operator="get"/>
+                            </calcop>
+                        </calculate>
+                        <set field="costsByType.${wecc.costComponentTypeId}" from-field="totalCostComponentCost"/>
+                    </if-compare>
+                </if-not-empty>
+            <else>
+                <!-- FIXME: formulas are still not supported for standard costs -->
+            </else>
+            </if-empty>
+        </iterate>
         <field-to-result field="taskCost"/>
+        <field-to-result field="costsByType"/>
     </simple-method>
 
     <!-- services to automatically generate cost information -->
@@ -296,12 +331,25 @@
             <set from-field="routing.workEffortId" field="callSvcMap.routingId"/>
             <call-service service-name="getTaskCost" in-map-name="callSvcMap">
                 <result-to-field result-name="taskCost" field="taskCost"/>
+                <result-to-field result-name="costsByType" field="costsByType"/>
             </call-service>
             <calculate field="totalTaskCost" decimal-scale="6">
                 <calcop field="totalTaskCost" operator="add">
                     <calcop field="taskCost" operator="get"/>
                 </calcop>
             </calculate>
+            <iterate-map map="costsByType" key="costType" value="costAmount">
+                <if-not-empty field="totalCostsByType.${costType}">
+                    <calculate field="totalCostsByType.${costType}" decimal-scale="6">
+                        <calcop field="costAmount" operator="add">
+                            <calcop field="totalCostsByType.${costType}" operator="get"/>
+                        </calcop>
+                    </calculate>
+                <else>
+                    <set field="totalCostsByType.${costType}" from-field="costAmount"/>
+                </else>
+                </if-not-empty>
+            </iterate-map>
         </iterate>
 
         <calculate field="totalCost" decimal-scale="6">
@@ -331,7 +379,15 @@
                 <call-service service-name="recreateCostComponent" in-map-name="callSvcMap"/>
             </if-compare>
         </if-not-empty>
-
+        <iterate-map map="totalCostsByType" key="costType" value="totalCostAmount">
+            <clear-field field="callSvcMap"/>
+            <set value="${parameters.costComponentTypePrefix}_${costType}" field="callSvcMap.costComponentTypeId"/>
+            <set from-field="parameters.productId" field="callSvcMap.productId"/>
+            <set from-field="parameters.currencyUomId" field="callSvcMap.costUomId"/>
+            <set from-field="totalCostAmount" field="callSvcMap.cost"/>
+            <call-service service-name="recreateCostComponent" in-map-name="callSvcMap"/>
+        </iterate-map>
+        
         <field-to-result field="totalCost"/>
     </simple-method>
     <simple-method method-name="calculateProductAverageCost" short-description="Calculate inventory average cost for a product">

Modified: ofbiz/trunk/applications/product/servicedef/services_cost.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_cost.xml?rev=778565&r1=778564&r2=778565&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services_cost.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services_cost.xml Tue May 26 05:32:04 2009
@@ -72,6 +72,7 @@
         <attribute mode="IN" name="productId" optional="true" type="String"/>
         <attribute mode="IN" name="routingId" optional="true" type="String"/>
         <attribute mode="OUT" name="taskCost" type="BigDecimal" optional="false"/>
+        <attribute mode="OUT" name="costsByType" type="Map" optional="true"/>
     </service>
     <service name="calculateProductCosts" engine="simple" auth="true"
                 location="component://product/script/org/ofbiz/product/cost/CostServices.xml" invoke="calculateProductCosts">