svn commit: r450569 - in /incubator/ofbiz/trunk/applications: order/entitydef/ order/src/org/ofbiz/order/order/ order/src/org/ofbiz/order/shoppingcart/ product/entitydef/

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

svn commit: r450569 - in /incubator/ofbiz/trunk/applications: order/entitydef/ order/src/org/ofbiz/order/order/ order/src/org/ofbiz/order/shoppingcart/ product/entitydef/

jonesde
Author: jonesde
Date: Wed Sep 27 13:46:34 2006
New Revision: 450569

URL: http://svn.apache.org/viewvc?view=rev&rev=450569
Log:
Added more support for recurring prices, in this case recurringAmount on adjustments including adjustments based on selection of optional features, this gets us pretty close to complete functionality for initially showing and tracking recurring prices; note that there is no follow up like auto-orders automatically for these prices, just display and store them to pass on to other systems for now; if someone needs it that functionality could certainly be added later on

Modified:
    incubator/ofbiz/trunk/applications/order/entitydef/entitymodel.xml
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
    incubator/ofbiz/trunk/applications/product/entitydef/entitymodel.xml

Modified: incubator/ofbiz/trunk/applications/order/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/entitydef/entitymodel.xml?view=diff&rev=450569&r1=450568&r2=450569
==============================================================================
--- incubator/ofbiz/trunk/applications/order/entitydef/entitymodel.xml (original)
+++ incubator/ofbiz/trunk/applications/order/entitydef/entitymodel.xml Wed Sep 27 13:46:34 2006
@@ -57,6 +57,7 @@
       <field name="comments" type="comment"></field>
       <field name="description" type="description"></field>
       <field name="amount" type="currency-precise"></field>
+      <field name="recurringAmount" type="currency-precise"></field>
       <field name="productPromoId" type="id"></field>
       <field name="productPromoRuleId" type="id"></field>
       <field name="productPromoActionSeqId" type="id"></field>

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?view=diff&rev=450569&r1=450568&r2=450569
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Wed Sep 27 13:46:34 2006
@@ -21,17 +21,16 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashSet;
 
-import org.apache.commons.collections.set.ListOrderedSet;
+import javolution.util.FastList;
+import javolution.util.FastMap;
 
+import org.apache.commons.collections.set.ListOrderedSet;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilFormatOut;
 import org.ofbiz.base.util.UtilMisc;
@@ -43,9 +42,9 @@
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.condition.EntityExpr;
 import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.condition.EntityConditionList;
 import org.ofbiz.entity.util.EntityUtil;
 import org.ofbiz.product.product.ProductWorker;
 import org.ofbiz.security.Security;
@@ -205,7 +204,7 @@
      * @return
      */
     public Map getReceivedPaymentTotalsByPaymentMethod() {
-        Map paymentMethodAmounts = new HashMap();
+        Map paymentMethodAmounts = FastMap.newInstance();
         List paymentPrefs = getPaymentPreferences();
         Iterator ppit = paymentPrefs.iterator();
         while (ppit.hasNext()) {
@@ -241,7 +240,7 @@
      * @return
      */
     public Map getReturnedTotalsByPaymentMethod() {
-        Map paymentMethodAmounts = new HashMap();
+        Map paymentMethodAmounts = FastMap.newInstance();
         List paymentPrefs = getPaymentPreferences();
         Iterator ppit = paymentPrefs.iterator();
         while (ppit.hasNext()) {
@@ -413,7 +412,7 @@
     }
 
     public List getShippingLocations() {
-        List shippingLocations = new LinkedList();
+        List shippingLocations = FastList.newInstance();
         List shippingCms = this.getOrderContactMechs("SHIPPING_LOCATION");
         if (shippingCms != null) {
             Iterator i = shippingCms.iterator();
@@ -470,7 +469,7 @@
     }
 
     public List getBillingLocations() {
-        List billingLocations = new LinkedList();
+        List billingLocations = FastList.newInstance();
         List billingCms = this.getOrderContactMechs("BILLING_LOCATION");
         if (billingCms != null) {
             Iterator i = billingCms.iterator();
@@ -815,7 +814,7 @@
     }
 
     public Map getFeatureIdQtyMap(String shipGroupSeqId) {
-        Map featureMap = new HashMap();
+        Map featureMap = FastMap.newInstance();
         List validItems = getValidOrderItems(shipGroupSeqId);
         if (validItems != null) {
             Iterator i = validItems.iterator();
@@ -1043,7 +1042,7 @@
     }
 
     public List getShippableSizes() {
-        List shippableSizes = new LinkedList();
+        List shippableSizes = FastList.newInstance();
 
         List validItems = getValidOrderItems();
         if (validItems != null) {
@@ -1215,7 +1214,7 @@
     }
 
    public List getShippableItemInfo(String shipGroupSeqId) {
-        List shippableInfo = new LinkedList();
+        List shippableInfo = FastList.newInstance();
 
         List validItems = getValidOrderItems(shipGroupSeqId);
         if (validItems != null) {
@@ -1230,7 +1229,7 @@
     }
 
     public Map getItemInfoMap(GenericValue item) {
-        Map itemInfo = new HashMap();
+        Map itemInfo = FastMap.newInstance();
         itemInfo.put("productId", item.getString("productId"));
         itemInfo.put("quantity", getOrderItemQuantity(item));
         itemInfo.put("weight", new Double(this.getItemWeight(item)));
@@ -1592,7 +1591,7 @@
        List returnItems = getOrderReturnItems();
 
        // since we don't have a handy grouped view entity, we'll have to group the return items by hand
-       Map returnMap = new HashMap();
+       Map returnMap = FastMap.newInstance();
        for (Iterator iter = this.getValidOrderItems().iterator(); iter.hasNext(); ) {
            GenericValue orderItem = (GenericValue) iter.next();
            List group = EntityUtil.filterByAnd(returnItems,
@@ -1743,7 +1742,7 @@
         returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_RECEIVED")));
         returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_COMPLETED")));
 
-        Map itemReturnedQuantities = new HashMap();
+        Map itemReturnedQuantities = FastMap.newInstance();
         Iterator i = returnedItems.iterator();
         while (i.hasNext()) {
             GenericValue returnedItem = (GenericValue) i.next();
@@ -2245,12 +2244,12 @@
         List contraints1 = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, null));
         List contraints2 = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, DataModelConstants.SEQ_ID_NA));
         List contraints3 = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, ""));
-        List contraints4 = new LinkedList();
+        List contraints4 = FastList.newInstance();
         if (shipGroupSeqId != null) {
             contraints4.add(new EntityExpr("shipGroupSeqId", EntityOperator.EQUALS, shipGroupSeqId));
         }
         List toFilter = null;
-        List adj = new LinkedList();
+        List adj = FastList.newInstance();
 
         if (shipGroupSeqId != null) {
             toFilter = EntityUtil.filterByAnd(adjustments, contraints4);
@@ -2268,7 +2267,7 @@
         List contraints1 = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, null));
         List contraints2 = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, DataModelConstants.SEQ_ID_NA));
         List contraints3 = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, ""));
-        List newOrderStatuses = new LinkedList();
+        List newOrderStatuses = FastList.newInstance();
 
         newOrderStatuses.addAll(EntityUtil.filterByAnd(orderStatuses, contraints1));
         newOrderStatuses.addAll(EntityUtil.filterByAnd(orderStatuses, contraints2));
@@ -2297,7 +2296,7 @@
         }
 
         if (responses == null) {
-            responses = new LinkedList();
+            responses = FastList.newInstance();
         }
         return responses;
     }
@@ -2314,7 +2313,7 @@
         }
 
         if (responses == null) {
-            responses = new LinkedList();
+            responses = FastList.newInstance();
         }
         return responses;
     }
@@ -2576,6 +2575,22 @@
         return adjTotal;
     }
 
+    public static BigDecimal calcItemAdjustmentsRecurringBd(BigDecimal quantity, BigDecimal unitPrice, List adjustments, boolean includeOther, boolean includeTax, boolean includeShipping, boolean forTax, boolean forShipping) {
+        BigDecimal adjTotal = ZERO;
+
+        if (adjustments != null && adjustments.size() > 0) {
+            List filteredAdjs = filterOrderAdjustments(adjustments, includeOther, includeTax, includeShipping, forTax, forShipping);
+            Iterator adjIt = filteredAdjs.iterator();
+
+            while (adjIt.hasNext()) {
+                GenericValue orderAdjustment = (GenericValue) adjIt.next();
+
+                adjTotal = adjTotal.add(OrderReadHelper.calcItemAdjustmentRecurringBd(orderAdjustment, quantity, unitPrice)).setScale(scale, rounding);
+            }
+        }
+        return adjTotal;
+    }
+
     /** @deprecated */
     public static double calcItemAdjustments(Double quantity, Double unitPrice, List adjustments, boolean includeOther, boolean includeTax, boolean includeShipping, boolean forTax, boolean forShipping) {
         return calcItemAdjustmentsBd(new BigDecimal(quantity.doubleValue()), new BigDecimal(unitPrice.doubleValue()), adjustments, includeOther, includeTax, includeShipping, forTax, forShipping).doubleValue();
@@ -2599,13 +2614,22 @@
         return adjustment.setScale(scale, rounding);
     }
 
+    public static BigDecimal calcItemAdjustmentRecurringBd(GenericValue itemAdjustment, BigDecimal quantity, BigDecimal unitPrice) {
+        BigDecimal adjustmentRecurring = ZERO;
+        if (itemAdjustment.get("recurringAmount") != null) {
+            adjustmentRecurring = adjustmentRecurring.add(setScaleByType("SALES_TAX".equals(itemAdjustment.get("orderAdjustmentTypeId")), itemAdjustment.getBigDecimal("recurringAmount")));
+        }
+        if (Debug.verboseOn()) Debug.logVerbose("calcItemAdjustmentRecurring: " + itemAdjustment + ", quantity=" + quantity + ", unitPrice=" + unitPrice + ", adjustmentRecurring=" + adjustmentRecurring, module);
+        return adjustmentRecurring.setScale(scale, rounding);
+    }
+
     /** @deprecated */
     public static double calcItemAdjustment(GenericValue itemAdjustment, Double quantity, Double unitPrice) {
         return calcItemAdjustmentBd(itemAdjustment, new BigDecimal(quantity.doubleValue()), new BigDecimal(unitPrice.doubleValue())).doubleValue();
     }
 
     public static List filterOrderAdjustments(List adjustments, boolean includeOther, boolean includeTax, boolean includeShipping, boolean forTax, boolean forShipping) {
-        List newOrderAdjustmentsList = new LinkedList();
+        List newOrderAdjustmentsList = FastList.newInstance();
 
         if (adjustments != null && adjustments.size() > 0) {
             Iterator adjIt = adjustments.iterator();

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?view=diff&rev=450569&r1=450568&r2=450569
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Wed Sep 27 13:46:34 2006
@@ -2315,7 +2315,7 @@
         double itemsTotal = 0.00;
         Iterator i = iterator();
         while (i.hasNext()) {
-            itemsTotal += ((ShoppingCartItem) i.next()).getDisplayItemRecurringSubTotalNoAdj();
+            itemsTotal += ((ShoppingCartItem) i.next()).getDisplayItemRecurringSubTotal();
         }
         return itemsTotal;
     }

Modified: incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java?view=diff&rev=450569&r1=450568&r2=450569
==============================================================================
--- incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java (original)
+++ incubator/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartItem.java Wed Sep 27 13:46:34 2006
@@ -1,5 +1,4 @@
 /*
- *
  * Copyright 2001-2006 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
@@ -16,6 +15,7 @@
  */
 package org.ofbiz.order.shoppingcart;
 
+import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1741,7 +1741,12 @@
 
     /** Returns the "other" adjustments. */
     public double getOtherAdjustments() {
-        return OrderReadHelper.calcItemAdjustments(new Double(quantity), new Double(getBasePrice()), this.getAdjustments(), true, false, false, false, false);
+        return OrderReadHelper.calcItemAdjustmentsBd(new BigDecimal(quantity), new BigDecimal(getBasePrice()), this.getAdjustments(), true, false, false, false, false).doubleValue();
+    }
+
+    /** Returns the "other" adjustments. */
+    public double getOtherAdjustmentsRecurring() {
+        return OrderReadHelper.calcItemAdjustmentsRecurringBd(new BigDecimal(quantity), new BigDecimal(getRecurringBasePrice() == null ? 0.0 : getRecurringBasePrice().doubleValue()), this.getAdjustments(), true, false, false, false, false).doubleValue();
     }
 
     /** calculates for a reservation the percentage/100 extra for more than 1 person. */
@@ -1783,13 +1788,23 @@
     }
 
     public double getDisplayItemSubTotal() {
-        return (this.getDisplayPrice() * this.getQuantity() * getRentalAdjustment()) + getOtherAdjustments();
+        return (this.getDisplayPrice() * this.getQuantity() * this.getRentalAdjustment()) + this.getOtherAdjustments();
     }
     
     public double getDisplayItemSubTotalNoAdj() {
         return this.getDisplayPrice() * this.getQuantity();
     }
 
+    public double getDisplayItemRecurringSubTotal() {
+        Double curRecurringDisplayPrice = this.getRecurringDisplayPrice();
+        
+        if (curRecurringDisplayPrice == null) {
+            return this.getOtherAdjustmentsRecurring();
+        }
+        
+        return (curRecurringDisplayPrice.doubleValue() * this.getQuantity()) + this.getOtherAdjustmentsRecurring();
+    }
+
     public double getDisplayItemRecurringSubTotalNoAdj() {
         Double curRecurringDisplayPrice = this.getRecurringDisplayPrice();
         if (curRecurringDisplayPrice == null) return 0.0;
@@ -1820,6 +1835,7 @@
         orderAdjustment.set("orderAdjustmentTypeId", "ADDITIONAL_FEATURE");
         orderAdjustment.set("description", additionalProductFeatureAndAppl.get("description"));
         orderAdjustment.set("productFeatureId", additionalProductFeatureAndAppl.get("productFeatureId"));
+
         // NOTE: this is a VERY simple pricing scheme for additional features and will likely need to be extended for most real applications
         double amount = 0;
         Double amountDbl = (Double) additionalProductFeatureAndAppl.get("amount");
@@ -1827,6 +1843,13 @@
             amount = amountDbl.doubleValue() * this.getQuantity();
         }
         orderAdjustment.set("amount", new Double(amount));
+
+        Double recurringAmountDbl = (Double) additionalProductFeatureAndAppl.get("recurringAmount");
+        if (recurringAmountDbl != null) {
+            double recurringAmount = recurringAmountDbl.doubleValue() * this.getQuantity();
+            orderAdjustment.set("recurringAmount", new Double(recurringAmount));
+            //Debug.logInfo("Setting recurringAmount " + recurringAmount + " for " + orderAdjustment, module);
+        }
 
         this.addAdjustment(orderAdjustment);
     }

Modified: incubator/ofbiz/trunk/applications/product/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?view=diff&rev=450569&r1=450568&r2=450569
==============================================================================
--- incubator/ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original)
+++ incubator/ofbiz/trunk/applications/product/entitydef/entitymodel.xml Wed Sep 27 13:46:34 2006
@@ -778,6 +778,7 @@
       <alias entity-alias="PFA" name="thruDate"/>
       <alias entity-alias="PFA" name="sequenceNum"/>
       <alias entity-alias="PFA" name="amount"/>
+      <alias entity-alias="PFA" name="recurringAmount"/>
       <view-link entity-alias="PF" rel-entity-alias="PFA">
         <key-map field-name="productFeatureId"/>
       </view-link>