[OFBiz] SVN: r5620 - in trunk/applications/order: config entitydef script/org/ofbiz/order/quote servicedef src/org/ofbiz/order/shoppingcart webapp/ordermgr/WEB-INF webapp/ordermgr/quote widget/ordermgr

jacopo at svn.ofbiz.org jacopo at svn.ofbiz.org
Thu Sep 1 09:11:34 EDT 2005


Author: jacopo
Date: 2005-09-01 08:11:00 -0500 (Thu, 01 Sep 2005)
New Revision: 5620

Modified:
   trunk/applications/order/config/OrderUiLabels.properties
   trunk/applications/order/entitydef/entitygroup.xml
   trunk/applications/order/entitydef/entitymodel.xml
   trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml
   trunk/applications/order/servicedef/services_cart.xml
   trunk/applications/order/servicedef/services_quote.xml
   trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
   trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
   trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
   trunk/applications/order/webapp/ordermgr/quote/QuoteForms.xml
   trunk/applications/order/webapp/ordermgr/quote/QuoteTabBar.ftl
   trunk/applications/order/widget/ordermgr/QuoteScreens.xml
Log:
First draft of the quote adjustment stuff (OFBIZ-468): it is now possible to run (from the new adjustment screen) the auto adjustment calc and see the results without (evident) errors: both header and lines adjustments are created and also promo quote items.
Manual adjustments and the ability to apply cart adjustments from quote adjustments are still not implemented.


Modified: trunk/applications/order/config/OrderUiLabels.properties
===================================================================
--- trunk/applications/order/config/OrderUiLabels.properties	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/config/OrderUiLabels.properties	2005-09-01 13:11:00 UTC (rev 5620)
@@ -120,6 +120,7 @@
 OrderOrderOptionSettings = Order Option Settings
 OrderOrderPurchaseToBeScheduled = Order Purchase To Be Scheluded
 OrderOrderQuote = Quote
+OrderOrderQuoteAdjustments=Adjustments
 OrderOrderQuoteAttributeName = Attribute Name
 OrderOrderQuoteAttributeValue = Attribute Value
 OrderOrderQuoteAttributes = Quote Attributes

Modified: trunk/applications/order/entitydef/entitygroup.xml
===================================================================
--- trunk/applications/order/entitydef/entitygroup.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/entitydef/entitygroup.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -97,6 +97,7 @@
     <entity-group group="org.ofbiz" entity="QuoteType" />
     <entity-group group="org.ofbiz" entity="QuoteTypeAttr" />
     <entity-group group="org.ofbiz" entity="QuoteWorkEffort" />
+    <entity-group group="org.ofbiz" entity="QuoteAdjustment" />
 
     <!-- ========================================================= -->
     <!-- org.ofbiz.order.request -->

Modified: trunk/applications/order/entitydef/entitymodel.xml
===================================================================
--- trunk/applications/order/entitydef/entitymodel.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/entitydef/entitymodel.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -1073,6 +1073,7 @@
       <field name="issueDate" type="date-time"></field>
       <field name="statusId" type="id"></field>
       <field name="currencyUomId" type="id"></field>
+      <field name="productStoreId" type="id"></field>
       <field name="validFromDate" type="date-time"></field>
       <field name="validThruDate" type="date-time"></field>
       <field name="quoteName" type="name"></field>
@@ -1093,6 +1094,9 @@
       <relation type="one" fk-name="QUOTE_CUOM" rel-entity-name="Uom">
         <key-map field-name="currencyUomId" rel-field-name="uomId"/>
       </relation>
+      <relation type="one" fk-name="QUOTE_PRDS" rel-entity-name="ProductStore">
+        <key-map field-name="productStoreId"/>
+      </relation>
     </entity>
     <entity entity-name="QuoteAttribute"
             package-name="org.ofbiz.order.quote"
@@ -1135,9 +1139,11 @@
       <field name="custRequestId" type="id"></field>
       <field name="custRequestItemSeqId" type="id"></field>
       <field name="quantity" type="floating-point"></field>
+      <field name="selectedAmount" type="floating-point"></field>
       <field name="quoteUnitPrice" type="currency-amount"></field>
       <field name="estimatedDeliveryDate" type="date-time"></field>
       <field name="comments" type="comment"></field>
+      <field name="isPromo" type="indicator"></field>
       <prim-key field="quoteId"/>
       <prim-key field="quoteItemSeqId"/>
       <relation type="one" fk-name="QUOTE_ITM_QTE" rel-entity-name="Quote">
@@ -1275,6 +1281,76 @@
             <key-map field-name="workEffortId"/>
         </relation>
     </entity>
+    <entity entity-name="QuoteAdjustment"
+            package-name="org.ofbiz.order.quote"
+            never-cache="true"
+            title="Quote Adjustment Entity">
+      <description>Note that both includeInTax and includeInShipping should default to true, except in the case where this adjustment is a tax or shipping adjustment then should be ignored.</description>
+      <field name="quoteAdjustmentId" type="id-ne"></field>
+      <field name="quoteAdjustmentTypeId" type="id"></field>
+      <field name="quoteId" type="id"></field>
+      <field name="quoteItemSeqId" type="id"></field>
+      <field name="comments" type="comment"></field>
+      <field name="description" type="description"></field>
+      <field name="amount" type="currency-amount"></field>
+      <field name="productPromoId" type="id"></field>
+      <field name="productPromoRuleId" type="id"></field>
+      <field name="productPromoActionSeqId" type="id"></field>
+      <field name="productFeatureId" type="id"></field>
+      <field name="correspondingProductId" type="id"></field>
+      <field name="sourceReferenceId" type="id-long"></field>
+      <field name="sourcePercentage" type="floating-point"><!-- for tax entries this is the tax percentage --></field>
+      <field name="customerReferenceId" type="id-long"><!-- for tax entries this is partyTaxId --></field>
+      <field name="primaryGeoId" type="id"><!-- for tax entries this is the primary jurisdiction Geo (the smallest or most local Geo that this tax is for, usually a state/province, perhaps a county or a city) --></field>
+      <field name="secondaryGeoId" type="id"><!-- for tax entries this is the secondary jurisdiction Geo (usually a country, or other Geo that the primary is within) --></field>
+      <field name="exemptAmount" type="currency-amount"><!-- an amount that would normally apply, but not to this order; for tax exemption represents the what the tax would have been --></field>
+      <field name="taxAuthGeoId" type="id"></field><!-- these taxAuth fields deprecate the primaryGeoId and secondaryGeoId fields and will be used with the newer tax calc stuff -->
+      <field name="taxAuthPartyId" type="id"></field>
+      <field name="overrideGlAccountId" type="id"><!-- used to specify the override or actual glAccountId used for the adjustment, avoids problems if configuration changes after initial posting, etc --></field>
+      <field name="includeInTax" type="indicator"></field>
+      <field name="includeInShipping" type="indicator"></field>
+      <field name="createdDate" type="date-time"></field>
+      <field name="createdByUserLogin" type="id-vlong"></field>
+      <prim-key field="quoteAdjustmentId"/>
+      <relation type="one" fk-name="QUOTE_ADJ_TYPE" rel-entity-name="OrderAdjustmentType">
+        <key-map field-name="quoteAdjustmentTypeId" rel-field-name="orderAdjustmentTypeId"/>
+      </relation>
+      <relation type="one" fk-name="QUOTE_ADJ_OHEAD" rel-entity-name="Quote">
+        <key-map field-name="quoteId"/>
+      </relation>
+      <relation type="one" fk-name="QUOTE_ADJ_USERL" rel-entity-name="UserLogin">
+        <key-map field-name="createdByUserLogin" rel-field-name="userLoginId"/>
+      </relation>
+      <relation type="one-nofk" rel-entity-name="QuoteItem">
+        <key-map field-name="quoteId"/>
+        <key-map field-name="quoteItemSeqId"/>
+      </relation>
+      <relation type="one" fk-name="QUOTE_ADJ_PROMO" rel-entity-name="ProductPromo">
+        <key-map field-name="productPromoId"/>
+      </relation>
+      <relation type="one-nofk" rel-entity-name="ProductPromoRule">
+        <key-map field-name="productPromoId"/>
+        <key-map field-name="productPromoRuleId"/>
+      </relation>
+      <relation type="one-nofk" rel-entity-name="ProductPromoAction">
+        <key-map field-name="productPromoId"/>
+        <key-map field-name="productPromoRuleId"/>
+        <key-map field-name="productPromoActionSeqId"/>
+      </relation>
+      <relation type="one" fk-name="QUOTE_ADJ_PRGEO" title="Primary" rel-entity-name="Geo">
+        <key-map field-name="primaryGeoId" rel-field-name="geoId"/>
+      </relation>
+      <relation type="one" fk-name="QUOTE_ADJ_SCGEO" title="Secondary" rel-entity-name="Geo">
+        <key-map field-name="secondaryGeoId" rel-field-name="geoId"/>
+      </relation>
+      <relation type="one" fk-name="QUOTE_ADJ_TXA" rel-entity-name="TaxAuthority">
+        <key-map field-name="taxAuthGeoId"/>
+        <key-map field-name="taxAuthPartyId"/>
+      </relation>
+      <relation type="one" fk-name="QUOTE_ADJ_OGLA" title="Override" rel-entity-name="GlAccount">
+        <key-map field-name="overrideGlAccountId" rel-field-name="glAccountId"/>
+      </relation>
+    </entity>
 
   <!-- ========================================================= -->
   <!-- org.ofbiz.order.request -->

Modified: trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml
===================================================================
--- trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -114,7 +114,7 @@
         <field-to-field field-name="parameters.quoteId" to-field-name="newEntity.quoteId"/>
         <env-to-field env-name="quoteItemSeqId" map-name="newEntity"/>
         <field-to-result field-name="quoteId" result-name="quoteId"/>
-        <field-to-result field-name="quoteItemSeqId" result-name="quoteItemSeqId"/>
+        <field-to-result field-name="newEntity.quoteItemSeqId" result-name="quoteItemSeqId"/>
 
         <!-- finally create the record (should not exist already)-->
         <create-value value-name="newEntity"/>
@@ -141,6 +141,7 @@
         </check-permission>
         <check-errors/>
         <entity-one entity-name="QuoteItem" value-name="quoteItem" auto-field-map="true"/>
+        <remove-related value-name="quoteItem" relation-name="QuoteAdjustment"/>
         <check-errors/>
         <remove-value value-name="quoteItem"/>
     </simple-method>
@@ -316,5 +317,59 @@
         <check-errors/>
         <field-to-request field-name="quoteItem.quoteId" request-name="quoteId"/>
     </simple-method>
+    <simple-method method-name="autoCreateQuoteAdjustments" short-description="Auto create QuoteAdjustments">
+        <check-permission permission="ORDERMGR" action="_CREATE">
+            <fail-property resource="OrderErrorUiLabels" property="OrderSecurityErrorToRunAutoUpdateQuotePrice"/>
+        </check-permission>
+        <check-errors/>
+        <entity-one entity-name="Quote" value-name="quote" auto-field-map="true"/>
+        <!-- all existing quote adjustments are removed -->
+        <!-- TODO: how to manage manual adjustments? -->
+        <remove-related value-name="quote" relation-name="QuoteAdjustment"/>
+        <get-related value-name="quote" relation-name="QuoteItem" list-name="quoteItems"/>
+        <iterate list-name="quoteItems" entry-name="quoteItem">
+            <if-compare field-name="quoteItem.isPromo" value="Y" operator="equals">
+                <clear-field field-name="removeQuoteItemInMap"/>
+                <set-service-fields service-name="removeQuoteItem" to-map-name="removeQuoteItemInMap" map-name="parameters"/>
+                <field-to-field field-name="quoteItem.quoteItemSeqId" to-field-name="removeQuoteItemInMap.quoteItemSeqId"/>
+                <call-service service-name="removeQuoteItem" in-map-name="removeQuoteItemInMap"/>
+            </if-compare>
+        </iterate>
+        <set-service-fields service-name="loadCartFromQuote" to-map-name="loadCartFromQuoteInMap" map-name="parameters"/>
+        <string-to-field string="false" field-name="loadCartFromQuoteInMap.applyQuoteAdjustments"/>
+        <call-service service-name="loadCartFromQuote" in-map-name="loadCartFromQuoteInMap">
+            <result-to-field result-name="shoppingCart" field-name="cart"/>
+        </call-service>
 
+        <call-object-method obj-field-name="cart" method-name="items" ret-field-name="items"/>
+        <iterate list-name="items" entry-name="item">
+            <call-object-method obj-field-name="item" method-name="getOrderItemSeqId" ret-field-name="orderItemSeqId"/>
+            <if-empty field-name="orderItemSeqId">
+                <!-- this is a new (promo) item -->
+                <!-- a new quote item is created -->
+                <clear-field field-name="createQuoteItemInMap"/>
+                <set-service-fields service-name="createQuoteItem" to-map-name="createQuoteItemInMap" map-name="parameters"/>
+                <call-object-method obj-field-name="item" method-name="getProductId" ret-field-name="createQuoteItemInMap.productId"/>
+                <call-object-method obj-field-name="item" method-name="getQuantity" ret-field-name="createQuoteItemInMap.quantity"/>
+                <string-to-field string="Y" field-name="createQuoteItemInMap.isPromo"/>
+                <call-service service-name="createQuoteItem" in-map-name="createQuoteItemInMap">
+                    <result-to-field result-name="quoteItemSeqId" field-name="quoteItemSeqId"/>
+                </call-service>
+                <!-- and the quoteItemSeqId is assigned to the shopping cart item (as orderItemSeqId) -->
+                <call-object-method obj-field-name="item" method-name="setOrderItemSeqId">
+                    <field field-name="quoteItemSeqId" type="String"/>
+                </call-object-method>
+            <call-object-method obj-field-name="item" method-name="getOrderItemSeqId" ret-field-name="newOrderItemSeqId"/>
+            </if-empty>
+        </iterate>
+        <call-object-method obj-field-name="cart" method-name="makeAllQuoteAdjustments" ret-field-name="adjustments"/>
+
+        <iterate list-name="adjustments" entry-name="adjustment">
+            <field-to-field field-name="parameters.quoteId" to-field-name="adjustment.quoteId"/>
+            <sequenced-id-to-env sequence-name="QuoteAdjustment" env-name="quoteAdjustmentId"/>
+            <field-to-field field-name="quoteAdjustmentId" to-field-name="adjustment.quoteAdjustmentId"/>
+            <create-value value-name="adjustment"/>
+        </iterate>
+    </simple-method>
+
 </simple-methods>
\ No newline at end of file

Modified: trunk/applications/order/servicedef/services_cart.xml
===================================================================
--- trunk/applications/order/servicedef/services_cart.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/servicedef/services_cart.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -101,4 +101,12 @@
         <attribute name="orderId" type="String" mode="IN" optional="false"/>
         <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/>
     </service>
+
+    <service name="loadCartFromQuote" engine="java" auth="true"
+            location="org.ofbiz.order.shoppingcart.ShoppingCartServices" invoke="loadCartFromQuote">
+        <description>Create a ShoppingCart Object based on an existing quote. If applyQuoteAdjustments is set to false then standard cart adjustments are generated.</description>
+        <attribute name="quoteId" type="String" mode="IN" optional="false"/>
+        <attribute name="applyQuoteAdjustments" type="String" mode="IN" optional="true"/>
+        <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/>
+    </service>
 </services>
\ No newline at end of file

Modified: trunk/applications/order/servicedef/services_quote.xml
===================================================================
--- trunk/applications/order/servicedef/services_quote.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/servicedef/services_quote.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -128,4 +128,9 @@
         <!--<attribute name="averageCost" type="Double" mode="IN" optional="true"/>
         <attribute name="costToPriceMult" type="Double" mode="IN" optional="true"/>-->
     </service>
+    <service name="autoCreateQuoteAdjustments" engine="simple" auth="true"
+            location="org/ofbiz/order/quote/QuoteServices.xml" invoke="autoCreateQuoteAdjustments">
+        <description>Remove all existing quote adjustments, recalc them and persist in QuoteAdjustment.</description>
+        <attribute name="quoteId" type="String" mode="IN" optional="false"/>
+    </service>
 </services>

Modified: trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
===================================================================
--- trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java	2005-09-01 13:11:00 UTC (rev 5620)
@@ -2584,6 +2584,19 @@
         }
     }
 
+    public void clearAllAdjustments() {
+        // remove all the promotion information (including adjustments)
+        clearAllPromotionInformation();
+        // remove all cart adjustments
+        this.adjustments.clear();
+        // remove all cart item adjustments
+        Iterator cartItemIter = this.iterator();
+        while (cartItemIter.hasNext()) {
+            ShoppingCartItem checkItem = (ShoppingCartItem) cartItemIter.next();
+            checkItem.getAdjustments().clear();
+        }
+    }
+
     /** Adds a promotion code to the cart, checking if it is valid. If it is valid this will return null, otherwise it will return a message stating why it was not valid
      * @param productPromoCodeId The promotion code to check and add
      * @return String that is null if valid, and added to cart, or an error message of the code was not valid and not added to the cart.
@@ -2883,6 +2896,48 @@
         return allAdjs;
     }
 
+    /** make a list of all quote adjustments including header adjustments, line adjustments, and special adjustments (shipping and tax if applicable).
+     *  Internally, the quote adjustments are created from the order adjustments.
+     */
+    public List makeAllQuoteAdjustments() {
+        List quoteAdjs = new LinkedList();
+
+        List orderAdjs = makeAllAdjustments();
+        Iterator orderAdjsIter = orderAdjs.iterator();
+
+        while (orderAdjsIter.hasNext()) {
+            GenericValue orderAdj = (GenericValue) orderAdjsIter.next();
+            GenericValue quoteAdj = this.getDelegator().makeValue("QuoteAdjustment", null);
+            quoteAdj.put("quoteAdjustmentId", orderAdj.get("orderAdjustmentId"));
+            quoteAdj.put("quoteAdjustmentTypeId", orderAdj.get("orderAdjustmentTypeId"));
+            quoteAdj.put("quoteItemSeqId", orderAdj.get("orderItemSeqId"));
+            quoteAdj.put("comments", orderAdj.get("comments"));
+            quoteAdj.put("description", orderAdj.get("description"));
+            quoteAdj.put("amount", orderAdj.get("amount"));
+            quoteAdj.put("productPromoId", orderAdj.get("productPromoId"));
+            quoteAdj.put("productPromoRuleId", orderAdj.get("productPromoRuleId"));
+            quoteAdj.put("productPromoActionSeqId", orderAdj.get("productPromoActionSeqId"));
+            quoteAdj.put("productFeatureId", orderAdj.get("productFeatureId"));
+            quoteAdj.put("correspondingProductId", orderAdj.get("correspondingProductId"));
+            quoteAdj.put("sourceReferenceId", orderAdj.get("sourceReferenceId"));
+            quoteAdj.put("sourcePercentage", orderAdj.get("sourcePercentage"));
+            quoteAdj.put("customerReferenceId", orderAdj.get("customerReferenceId"));
+            quoteAdj.put("primaryGeoId", orderAdj.get("primaryGeoId"));
+            quoteAdj.put("secondaryGeoId", orderAdj.get("secondaryGeoId"));
+            quoteAdj.put("exemptAmount", orderAdj.get("exemptAmount"));
+            quoteAdj.put("taxAuthGeoId", orderAdj.get("taxAuthGeoId"));
+            quoteAdj.put("taxAuthPartyId", orderAdj.get("taxAuthPartyId"));
+            quoteAdj.put("overrideGlAccountId", orderAdj.get("overrideGlAccountId"));
+            quoteAdj.put("includeInTax", orderAdj.get("includeInTax"));
+            quoteAdj.put("includeInShipping", orderAdj.get("includeInShipping"));
+            quoteAdj.put("createdDate", orderAdj.get("createdDate"));
+            quoteAdj.put("createdByUserLogin", orderAdj.get("createdByUserLogin"));
+            quoteAdjs.add(quoteAdj);
+        }
+
+        return quoteAdjs;
+    }
+
     /** make a list of all OrderPaymentPreferences and Billing info including all payment methods and types */
     public List makeAllOrderPaymentInfos() {
         List allOpPrefs = new LinkedList();

Modified: trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
===================================================================
--- trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java	2005-09-01 13:11:00 UTC (rev 5620)
@@ -28,6 +28,8 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.HashMap;
+import java.util.LinkedList;
 
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
@@ -356,4 +358,211 @@
         result.put("shoppingCart", cart);
         return result;
     }
+    
+    public static Map loadCartFromQuote(DispatchContext dctx, Map context) {
+        LocalDispatcher dispatcher = dctx.getDispatcher();
+        GenericDelegator delegator = dctx.getDelegator();
+
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        String quoteId = (String) context.get("quoteId");
+        String applyQuoteAdjustmentsString = (String) context.get("applyQuoteAdjustments");
+        Locale locale = (Locale) context.get("locale");
+
+        boolean applyQuoteAdjustments = applyQuoteAdjustmentsString == null || "true".equals(applyQuoteAdjustmentsString);
+        
+        // get the quote header
+        GenericValue quote = null;
+        try {
+            quote = delegator.findByPrimaryKey("Quote", UtilMisc.toMap("quoteId", quoteId));
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        // initial require cart info
+        String productStoreId = quote.getString("productStoreId");
+        String currency = quote.getString("currencyUomId");
+
+        // create the cart
+        ShoppingCart cart = new ShoppingCart(delegator, productStoreId, locale, currency);
+
+        try {
+            cart.setUserLogin(userLogin, dispatcher);
+        } catch (CartItemModifyException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+
+        // set the role information
+        cart.setOrderPartyId(quote.getString("partyId"));
+
+        cart.setQuoteId(quoteId);
+        
+        List quoteItems = null;
+        List quoteAdjs = null;
+        try {
+            quoteItems = quote.getRelated("QuoteItem");
+            quoteAdjs = quote.getRelated("QuoteAdjustment");
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        // Convert the quote adjustment to order header adjustments and
+        // put them in a map: the key/values pairs are quoteItemSeqId/List of adjs
+        Map orderAdjsMap = new HashMap();
+        Iterator quoteAdjsIter = quoteAdjs.iterator();
+        while (quoteAdjsIter.hasNext()) {
+            GenericValue quoteAdj = (GenericValue)quoteAdjsIter.next();
+            List orderAdjs = (List)orderAdjsMap.get(quoteAdj.get("quoteItemSeqId"));
+            if (orderAdjs == null) {
+                orderAdjs = new LinkedList();
+                orderAdjsMap.put(quoteAdj.get("quoteItemSeqId"), orderAdjs);
+            }
+            // convert quote adjustments to order adjustments
+            GenericValue orderAdj = delegator.makeValue("OrderAdjustment", null);
+            orderAdj.put("orderAdjustmentId", quoteAdj.get("quoteAdjustmentId"));
+            orderAdj.put("orderAdjustmentTypeId", quoteAdj.get("quoteAdjustmentTypeId"));
+            orderAdj.put("orderItemSeqId", quoteAdj.get("quoteItemSeqId"));
+            orderAdj.put("comments", quoteAdj.get("comments"));
+            orderAdj.put("description", quoteAdj.get("description"));
+            orderAdj.put("amount", quoteAdj.get("amount"));
+            orderAdj.put("productPromoId", quoteAdj.get("productPromoId"));
+            orderAdj.put("productPromoRuleId", quoteAdj.get("productPromoRuleId"));
+            orderAdj.put("productPromoActionSeqId", quoteAdj.get("productPromoActionSeqId"));
+            orderAdj.put("productFeatureId", quoteAdj.get("productFeatureId"));
+            orderAdj.put("correspondingProductId", quoteAdj.get("correspondingProductId"));
+            orderAdj.put("sourceReferenceId", quoteAdj.get("sourceReferenceId"));
+            orderAdj.put("sourcePercentage", quoteAdj.get("sourcePercentage"));
+            orderAdj.put("customerReferenceId", quoteAdj.get("customerReferenceId"));
+            orderAdj.put("primaryGeoId", quoteAdj.get("primaryGeoId"));
+            orderAdj.put("secondaryGeoId", quoteAdj.get("secondaryGeoId"));
+            orderAdj.put("exemptAmount", quoteAdj.get("exemptAmount"));
+            orderAdj.put("taxAuthGeoId", quoteAdj.get("taxAuthGeoId"));
+            orderAdj.put("taxAuthPartyId", quoteAdj.get("taxAuthPartyId"));
+            orderAdj.put("overrideGlAccountId", quoteAdj.get("overrideGlAccountId"));
+            orderAdj.put("includeInTax", quoteAdj.get("includeInTax"));
+            orderAdj.put("includeInShipping", quoteAdj.get("includeInShipping"));
+            orderAdj.put("createdDate", quoteAdj.get("createdDate"));
+            orderAdj.put("createdByUserLogin", quoteAdj.get("createdByUserLogin"));
+            orderAdjs.add(orderAdj);
+        }
+
+        long nextItemSeq = 0;
+        if (quoteItems != null) {
+            Iterator i = quoteItems.iterator();
+            while (i.hasNext()) {
+                GenericValue item = (GenericValue) i.next();
+
+                // get the next item sequence id
+                String orderItemSeqId = item.getString("quoteItemSeqId");
+                try {
+                    long seq = Long.parseLong(orderItemSeqId);
+                    if (seq > nextItemSeq) {
+                        nextItemSeq = seq;
+                    }
+                } catch (NumberFormatException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
+
+                boolean isPromo = item.get("isPromo") != null && "Y".equals(item.getString("isPromo"));
+                if (isPromo && applyQuoteAdjustments) {
+                    // do not include PROMO items
+                    continue;
+                }
+
+                // not a promo item; go ahead and add it in
+                Double amount = item.getDouble("selectedAmount");
+                if (amount == null) {
+                    amount = new Double(0);
+                }
+                //Double quantity = OrderReadHelper.getOrderItemQuantity(item);
+                Double quantity = item.getDouble("quantity");
+                if (quantity == null) {
+                    quantity = new Double(0);
+                }
+                int itemIndex = -1;
+                if (item.get("productId") == null) {
+                    // non-product item
+                    //String itemType = item.getString("orderItemTypeId");
+                    String desc = item.getString("description");
+                    try {
+                        //itemIndex = cart.addNonProductItem(itemType, desc, null, 0.00, quantity.doubleValue(), null, null, dispatcher);
+                        itemIndex = cart.addNonProductItem(null, desc, null, 0.00, quantity.doubleValue(), null, null, dispatcher);
+                    } catch (CartItemModifyException e) {
+                        Debug.logError(e, module);
+                        return ServiceUtil.returnError(e.getMessage());
+                    }
+                } else {
+                    // product item
+                    //String prodCatalogId = item.getString("prodCatalogId");
+                    String productId = item.getString("productId");
+                    try {
+                        //itemIndex = cart.addItemToEnd(productId, amount.doubleValue(), quantity.doubleValue(), null, null, prodCatalogId, dispatcher);
+                        itemIndex = cart.addItemToEnd(productId, amount.doubleValue(), quantity.doubleValue(), null, null, null, dispatcher);
+                    } catch (ItemNotFoundException e) {
+                        Debug.logError(e, module);
+                        return ServiceUtil.returnError(e.getMessage());
+                    } catch (CartItemModifyException e) {
+                        Debug.logError(e, module);
+                        return ServiceUtil.returnError(e.getMessage());
+                    }
+                }
+
+                // flag the item w/ the orderItemSeqId so we can reference it
+                ShoppingCartItem cartItem = cart.findCartItem(itemIndex);
+                cartItem.setOrderItemSeqId(orderItemSeqId);
+                // attach addition item information
+                //cartItem.setStatusId(item.getString("statusId"));
+                //cartItem.setItemType(item.getString("orderItemTypeId"));
+                cartItem.setItemComment(item.getString("comments"));
+                cartItem.setQuoteId(item.getString("quoteId"));
+                cartItem.setQuoteItemSeqId(item.getString("quoteItemSeqId"));
+                cartItem.setIsPromo(isPromo);
+                //cartItem.setProductCategoryId(item.getString("productCategoryId"));
+                // TODO: impostare una data?
+                //cartItem.setDesiredDeliveryDate(item.getTimestamp("estimatedDeliveryDate"));
+                //cartItem.setShoppingList(item.getString("shoppingListId"), item.getString("shoppingListItemSeqId"));
+
+            }
+
+        }
+
+        // If applyQuoteAdjustments is set to false then standard cart adjustments are used.
+        if (applyQuoteAdjustments) {
+            // The auto adjustments are removed
+            cart.clearAllAdjustments();
+            // TODO: we should also remove promo item generated in the cart
+            // HINT: this items are the ones with a null orderItemSeqId...
+            // The cart adjustments, derived from quote adjustments, are added to the cart
+            List adjs = (List)orderAdjsMap.get(null);
+            if (adjs != null) {
+                cart.getAdjustments().addAll(adjs);
+            }
+            // The cart item adjustments, derived from quote item adjustments, are added to the cart
+            if (quoteItems != null) {
+                Iterator i = cart.iterator();
+                while (i.hasNext()) {
+                    ShoppingCartItem item = (ShoppingCartItem) i.next();
+                    adjs = (List)orderAdjsMap.get(item.getOrderItemSeqId());
+                    if (adjs != null) {
+                        item.getAdjustments().addAll(adjs);
+                    }
+                }
+            }
+        }
+        // set the item seq in the cart
+        if (nextItemSeq > 0) {
+            try {
+                cart.setNextItemSeq(nextItemSeq);
+            } catch (GeneralException e) {
+                Debug.logError(e, module);
+                return ServiceUtil.returnError(e.getMessage());
+            }
+        }
+
+        Map result = ServiceUtil.returnSuccess();
+        result.put("shoppingCart", cart);
+        return result;
+    }
 }

Modified: trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml
===================================================================
--- trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -916,6 +916,10 @@
         <security https="true" auth="true"/>
         <response name="success" type="view" value="ManageQuotePrices"/>
     </request-map>
+    <request-map uri="ListQuoteAdjustments">
+        <security https="true" auth="true"/>
+        <response name="success" type="view" value="ListQuoteAdjustments"/>
+    </request-map>
 
     <request-map uri="createQuote">
         <security https="true" auth="true"/>
@@ -988,6 +992,11 @@
         <response name="success" type="view" value="ManageQuotePrices"/>
         <response name="error" type="view" value="ManageQuotePrices"/>
     </request-map>
+    <request-map uri="autoCreateQuoteAdjustments">
+        <security https="true" auth="true"/>
+        <event type="service" path="" invoke="autoCreateQuoteAdjustments"/>
+        <response name="success" type="view" value="ListQuoteAdjustments"/>
+    </request-map>
 
     <!-- Lookup request mappings -->
     <request-map uri="LookupPerson">
@@ -1102,6 +1111,7 @@
     <view-map name="ListQuoteCoefficients" type="screen" page="component://order/widget/ordermgr/QuoteScreens.xml#ListQuoteCoefficients"/>
     <view-map name="EditQuoteCoefficient" type="screen" page="component://order/widget/ordermgr/QuoteScreens.xml#EditQuoteCoefficient"/>
     <view-map name="ManageQuotePrices" type="screen" page="component://order/widget/ordermgr/QuoteScreens.xml#ManageQuotePrices"/>
+    <view-map name="ListQuoteAdjustments" type="screen" page="component://order/widget/ordermgr/QuoteScreens.xml#ListQuoteAdjustments"/>
 
     <view-map name="FindRequest" type="screen" page="component://order/widget/ordermgr/RequestScreens.xml#FindRequest"/>
     <view-map name="EditRequest" type="screen" page="component://order/widget/ordermgr/RequestScreens.xml#EditRequest"/>

Modified: trunk/applications/order/webapp/ordermgr/quote/QuoteForms.xml
===================================================================
--- trunk/applications/order/webapp/ordermgr/quote/QuoteForms.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/webapp/ordermgr/quote/QuoteForms.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -113,6 +113,11 @@
                 </entity-options>
             </drop-down>
         </field>
+        <field name="productStoreId" title="${uiLabelMap.QuoteProductStoreId}">
+            <drop-down allow-empty="true">
+                <entity-options description="${storeName}" entity-name="ProductStore" key-field-name="productStoreId"/>
+            </drop-down>
+        </field>
         <field name="currencyUomId" title="${uiLabelMap.AccountingCurrency}">
             <drop-down allow-empty="true">
                 <entity-options description="${uomId} - ${description}" entity-name="Uom" key-field-name="uomId">
@@ -165,6 +170,13 @@
             list-name="quoteItems" target="" paginate-target="ListQuoteItems" title="" type="list">
         <auto-fields-entity entity-name="QuoteItem" default-field-type="display"/>
         <field name="quoteId"><hidden/></field>
+        <!--
+        TODO: fix this!
+        <field name="quoteItemSeqId" title="${uiLabelMap.OrderOrderQuoteItemSeqId}" widget-style="buttontext" use-when="isPromo==null&#124;&#124;&quot;${isPromo}&quot;.equals(&quot;N&quot;)">
+            <hyperlink also-hidden="false" description="${quoteItemSeqId}" target="EditQuoteItem?quoteId=${quoteId}&amp;quoteItemSeqId=${quoteItemSeqId}"/>
+        </field>
+        <field name="quoteItemSeqId" title="${uiLabelMap.OrderOrderQuoteItemSeqId}" use-when="${isPromo}!=null&amp;&amp;&quot;${isPromo}&quot;.equals(&quot;Y&quot;)"/>
+        -->
         <field name="quoteItemSeqId" title="${uiLabelMap.OrderOrderQuoteItemSeqId}" widget-style="buttontext">
             <hyperlink also-hidden="false" description="${quoteItemSeqId}" target="EditQuoteItem?quoteId=${quoteId}&amp;quoteItemSeqId=${quoteItemSeqId}"/>
         </field>
@@ -224,6 +236,12 @@
         <field name="quoteUnitPrice" title="${uiLabelMap.OrderOrderQuoteUnitPrice}"></field>
         <field name="estimatedDeliveryDate" title="${uiLabelMap.OrderOrderQuoteEstimatedDeliveryDate}"></field>
         <field name="comments" title="${uiLabelMap.CommonComments}"></field>
+        <field name="isPromo" title="${uiLabelMap.OrderOrderIsPromo}">
+            <drop-down allow-empty="true">
+                <option key="N" description="${uiLabelMap.CommonN}"/>
+                <option key="Y" description="${uiLabelMap.CommonY}"/>
+            </drop-down>
+        </field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" widget-style="standardSubmit">
             <submit button-type="button"/>
         </field>
@@ -300,5 +318,9 @@
             <submit/>
         </field>
     </form>
-
+    <form name="ListQuoteAdjustments" default-title-style="tableheadtext"
+            default-tooltip-style="tabletext" default-widget-style="tabletext" list-name="quoteAdjustments"
+            target="" paginate-target="ListQuoteAdjustments" title="" type="list">
+        <auto-fields-entity entity-name="QuoteAdjustment" default-field-type="display"/>
+    </form>
 </forms>

Modified: trunk/applications/order/webapp/ordermgr/quote/QuoteTabBar.ftl
===================================================================
--- trunk/applications/order/webapp/ordermgr/quote/QuoteTabBar.ftl	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/webapp/ordermgr/quote/QuoteTabBar.ftl	2005-09-01 13:11:00 UTC (rev 5620)
@@ -36,6 +36,7 @@
         <#if security.hasEntityPermission("ORDERMGR", "_QUOTE_PRICE", session)>
         <a href="<@ofbizUrl>/ListQuoteCoefficients?quoteId=${quote.quoteId}</@ofbizUrl>" class="${selectedClassMap.ListQuoteCoefficients?default(unselectedClassName)}">${uiLabelMap.OrderOrderQuoteCoefficients}</a>
         <a href="<@ofbizUrl>/ManageQuotePrices?quoteId=${quote.quoteId}</@ofbizUrl>" class="${selectedClassMap.ManageQuotePrices?default(unselectedClassName)}">${uiLabelMap.OrderOrderQuotePrices}</a>
+        <a href="<@ofbizUrl>/ListQuoteAdjustments?quoteId=${quote.quoteId}</@ofbizUrl>" class="${selectedClassMap.ListQuoteAdjustments?default(unselectedClassName)}">${uiLabelMap.OrderOrderQuoteAdjustments}</a>
         </#if>
     </div>
 </#if>

Modified: trunk/applications/order/widget/ordermgr/QuoteScreens.xml
===================================================================
--- trunk/applications/order/widget/ordermgr/QuoteScreens.xml	2005-09-01 12:49:02 UTC (rev 5619)
+++ trunk/applications/order/widget/ordermgr/QuoteScreens.xml	2005-09-01 13:11:00 UTC (rev 5620)
@@ -375,5 +375,31 @@
             </widgets>
         </section>
     </screen>
+    <screen name="ListQuoteAdjustments">
+        <section>
+            <actions>
+                <set field="title" value="List Quote Adjustments"/>
+                <set field="titleProperty" value="PageTitleListQuoteAdjustments"/>
+                <set field="headerItem" value="quote"/>
+                <set field="tabButtonItem" value="ListQuoteAdjustments"/>
+    
+                <set field="quoteId" from-field="parameters.quoteId"/>
+                <entity-one entity-name="Quote" value-name="quote" auto-field-map="true"/>
+                <entity-and entity-name="QuoteAdjustment" list-name="quoteAdjustments">
+                    <field-map env-name="quote.quoteId" field-name="quoteId"/>
+                </entity-and>
+            </actions>
+            <widgets>
+                <decorator-screen name="CommonQuotePriceDecorator">
+                    <decorator-section name="body">
+                        <container>
+                            <link target="autoCreateQuoteAdjustments?quoteId=${quoteId}" text="[${uiLabelMap.OrderAutoCreateQuoteAdjustments}]" style="buttontext"/>
+                        </container>
+                        <include-form name="ListQuoteAdjustments" location="component://order/webapp/ordermgr/quote/QuoteForms.xml"/>
+                    </decorator-section>
+                </decorator-screen>
+            </widgets>
+        </section>
+    </screen>
 </screens>
 



More information about the Svn mailing list