You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by si...@apache.org on 2007/04/16 23:57:35 UTC

svn commit: r529416 - in /ofbiz/trunk/applications/order: config/OrderErrorUiLabels.properties servicedef/services.xml src/org/ofbiz/order/order/OrderServices.java

Author: sichen
Date: Mon Apr 16 14:57:34 2007
New Revision: 529416

URL: http://svn.apache.org/viewvc?view=rev&rev=529416
Log:
Adding the getOrderItemValue service, which calculates the value of a given orderItem by totalling the item subtotal, any adjustments for that item, and the item's share of any order-level adjustments. The last is calculated by applying the percentage of the items total that the item represents to the order-level adjustments total - EG if the item subtotal is $10, the total value of all items and item-level adjustments is $50, and the total of order-level adjustments is $5, the service will claim that the orderItem's value is $11.

Modified:
    ofbiz/trunk/applications/order/config/OrderErrorUiLabels.properties
    ofbiz/trunk/applications/order/servicedef/services.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java

Modified: ofbiz/trunk/applications/order/config/OrderErrorUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/OrderErrorUiLabels.properties?view=diff&rev=529416&r1=529415&r2=529416
==============================================================================
--- ofbiz/trunk/applications/order/config/OrderErrorUiLabels.properties (original)
+++ ofbiz/trunk/applications/order/config/OrderErrorUiLabels.properties Mon Apr 16 14:57:34 2007
@@ -105,6 +105,7 @@
 OrderErrorOrderItemAndOrOrderHeaderDontExist=ERROR : OrderItem and/or OrderHeader don't exist
 OrderErrorOrderItemCantBeModified=ERROR : OrderItem can't be modified
 OrderErrorOrderIdNotFound=ERROR: Order with ID [${orderId}] not found
+OrderErrorOrderItemNotFound=ERROR: Order item with ID [${orderId}] and orderItemSeqId [${orderItemSeqId}] not found
 OrderErrorOrderNotPurchaseOrder=Order ${orderId} is not a Purchase Order
 OrderErrorOrderTypeLookupFailed=ERROR : OrderType lookup failed : 
 OrderErrorProcessingOfflinePayments=<li>Error processing offline payments. 

Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?view=diff&rev=529416&r1=529415&r2=529416
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Mon Apr 16 14:57:34 2007
@@ -662,4 +662,14 @@
         <attribute name="facilityId" type="String" mode="IN" optional="false"/>
     </service>
 
+    <service name="getOrderItemValue" engine="java"
+            location="org.ofbiz.order.order.OrderServices" invoke="getOrderItemValue" auth="true">
+        <description>Calculates the value of a given orderItem by totalling the item subtotal, any adjustments for that item, and
+            the item's share of any order-level adjustments (which is calculated by applying the percentage of the items total that the
+            item represents to the order-level adjustments total.</description>
+        <attribute name="orderId" type="String" mode="IN" optional="false"/>
+        <attribute name="orderItemSeqId" type="String" mode="IN" optional="false"/>
+        <attribute name="orderItemValue" type="BigDecimal" mode="OUT" optional="true"/>
+    </service>
+
 </services>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?view=diff&rev=529416&r1=529415&r2=529416
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon Apr 16 14:57:34 2007
@@ -88,6 +88,8 @@
     }
     public static final int taxDecimals = UtilNumber.getBigDecimalScale("salestax.calc.decimals");
     public static final int taxRounding = UtilNumber.getBigDecimalRoundingMode("salestax.rounding");
+    public static final int orderDecimals = UtilNumber.getBigDecimalScale("order.decimals");
+    public static final int orderRounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");
     public static final BigDecimal ZERO = (new BigDecimal("0")).setScale(taxDecimals, taxRounding);    
 
     /** Service for creating a new order */
@@ -4148,5 +4150,64 @@
                 Debug.logWarning(e, e.getMessage(), module);
             }
         }
+    }
+
+    /**
+     * Calculates the value of a given orderItem by totalling the item subtotal, any adjustments for that item, and
+     *  the item's share of any order-level adjustments (that calculated by applying the percentage of the items total that the
+     *  item represents to the order-level adjustments total.
+     * @param dctx DispatchContext
+     * @param context Map
+     * @return Map
+     */
+    public static Map getOrderItemValue(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+        Locale locale = (Locale) context.get("locale");
+        
+        String orderId = (String) context.get("orderId");
+        String orderItemSeqId = (String) context.get("orderItemSeqId");
+
+        GenericValue orderHeader = null;
+        GenericValue orderItem = null;
+        try {
+
+            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+            if (UtilValidate.isEmpty(orderHeader)) {
+                String errorMessage = UtilProperties.getMessage(resource_error, "OrderErrorOrderIdNotFound", context, locale);
+                Debug.logError(errorMessage, module);
+                return ServiceUtil.returnError(errorMessage);
+            }
+            
+            orderItem = delegator.findByPrimaryKey("OrderItem", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));
+            if (UtilValidate.isEmpty(orderItem)) {
+                String errorMessage = UtilProperties.getMessage(resource_error, "OrderErrorOrderItemNotFound", context, locale);
+                Debug.logError(errorMessage, module);
+                return ServiceUtil.returnError(errorMessage);
+            }
+            
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        OrderReadHelper orh = new OrderReadHelper(orderHeader);
+        
+        // How much of the order items total does this orderItem represent? (Includes item-level adjustments but not order-level adjustments)
+        BigDecimal orderItemTotal = orh.getOrderItemTotalBd(orderItem);
+        BigDecimal orderItemsTotal = orh.getOrderItemsTotalBd();
+        BigDecimal proportionOfOrderItemsTotal = orderItemTotal.divide(orderItemsTotal, orderRounding);
+        BigDecimal portionOfOrderItemsTotal = proportionOfOrderItemsTotal.multiply(orderItemsTotal).setScale(orderDecimals, orderRounding);
+        
+        // How much of the order-level adjustments total does this orderItem represent? The assumption is: the same
+        //  proportion of the adjustments as of the item to the items total
+        BigDecimal orderAdjustmentsTotal = orh.getOrderAdjustmentsTotalBd();
+        BigDecimal portionOfOrderAdjustmentsTotal = proportionOfOrderItemsTotal.multiply(orderAdjustmentsTotal).setScale(orderDecimals, orderRounding);
+        
+        // The total value of the item is the value of the item itself plus its adjustments, and the item's share of the order-level adjustments
+        BigDecimal orderItemTotalValue = portionOfOrderItemsTotal.add(portionOfOrderAdjustmentsTotal);
+
+        Map result = ServiceUtil.returnSuccess();
+        result.put("orderItemValue", orderItemTotalValue);
+        return result;
     }
 }