svn commit: r566181 - in /ofbiz/trunk/applications/order: entitydef/ script/org/ofbiz/order/quote/ script/org/ofbiz/order/request/ src/org/ofbiz/order/order/ src/org/ofbiz/order/shoppingcart/

Posted by hansbak-2 on
URL: http://ofbiz.116.s1.nabble.com/svn-commit-r566181-in-ofbiz-trunk-applications-order-entitydef-script-org-ofbiz-order-quote-script-o-tp212822.html

Author: hansbak
Date: Wed Aug 15 07:17:37 2007
New Revision: 566181

URL: http://svn.apache.org/viewvc?view=rev&rev=566181
Log:
OFBIZ 1171, patch from Bilgin Ibryam to allow reservations also on quotes.

Modified:
    ofbiz/trunk/applications/order/entitydef/entitymodel.xml
    ofbiz/trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml
    ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml
    ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
    ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java

Modified: ofbiz/trunk/applications/order/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitymodel.xml?view=diff&rev=566181&r1=566180&r2=566181
==============================================================================
--- ofbiz/trunk/applications/order/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/order/entitydef/entitymodel.xml Wed Aug 15 07:17:37 2007
@@ -1328,6 +1328,9 @@
       <field name="quantity" type="floating-point"></field>
       <field name="selectedAmount" type="floating-point"></field>
       <field name="quoteUnitPrice" type="currency-amount"></field>
+      <field name="reservStart" type="date-time"></field>
+      <field name="reservLength" type="floating-point"></field>
+      <field name="reservPersons" type="floating-point"></field>            
       <field name="estimatedDeliveryDate" type="date-time"></field>
       <field name="comments" type="comment"></field>
       <field name="isPromo" type="indicator"></field>
@@ -1652,6 +1655,9 @@
       <field name="quantity" type="floating-point"></field>
       <field name="selectedAmount" type="floating-point"></field>
       <field name="maximumAmount" type="currency-amount"></field>
+      <field name="reservStart" type="date-time"></field>
+      <field name="reservLength" type="floating-point"></field>
+      <field name="reservPersons" type="floating-point"></field>      
       <field name="description" type="description"></field>
       <field name="story" type="very-long"></field>
       <prim-key field="custRequestId"/>

Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml?view=diff&rev=566181&r1=566180&r2=566181
==============================================================================
--- ofbiz/trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml (original)
+++ ofbiz/trunk/applications/order/script/org/ofbiz/order/quote/QuoteServices.xml Wed Aug 15 07:17:37 2007
@@ -709,6 +709,10 @@
                     <call-object-method obj-field-name="item" method-name="getSelectedAmount" ret-field-name="createQuoteItemInMap.selectedAmount"/>
                     <call-object-method obj-field-name="item" method-name="getBasePrice" ret-field-name="createQuoteItemInMap.quoteUnitPrice"/>
                     <call-object-method obj-field-name="item" method-name="getItemComment" ret-field-name="createQuoteItemInMap.comments"/>
+                    <call-object-method obj-field-name="item" method-name="getReservStart" ret-field-name="createQuoteItemInMap.reservStart"/>
+                    <call-object-method obj-field-name="item" method-name="getReservLength" ret-field-name="createQuoteItemInMap.reservLength"/>
+                    <call-object-method obj-field-name="item" method-name="getReservPersons" ret-field-name="createQuoteItemInMap.reservPersons"/>
+
                     <call-service service-name="createQuoteItem" in-map-name="createQuoteItemInMap">
                         <result-to-field result-name="quoteItemSeqId" field-name="quoteItemSeqId"/>
                     </call-service>
@@ -802,6 +806,9 @@
             <set field="createQuoteItemInMap.productId" from-field="custRequestItem.productId"/>
             <set field="createQuoteItemInMap.quantity" from-field="custRequestItem.quantity"/>
             <set field="createQuoteItemInMap.selectedAmount" from-field="custRequestItem.selectedAmount"/>
+            <set field="createQuoteItemInMap.reservStart" from-field="custRequestItem.reservStart"/>
+            <set field="createQuoteItemInMap.reservLength" from-field="custRequestItem.reservLength"/>
+            <set field="createQuoteItemInMap.reservPersons" from-field="custRequestItem.reservPersons"/>          
             <call-service service-name="createQuoteItem" in-map-name="createQuoteItemInMap"/>
         </iterate>
         <!-- roles -->

Modified: ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml?view=diff&rev=566181&r1=566180&r2=566181
==============================================================================
--- ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml (original)
+++ ofbiz/trunk/applications/order/script/org/ofbiz/order/request/CustRequestServices.xml Wed Aug 15 07:17:37 2007
@@ -218,6 +218,9 @@
                 <call-object-method obj-field-name="item" method-name="getQuantity" ret-field-name="createCustRequestItemInMap.quantity"/>
                 <!--<call-object-method obj-field-name="item" method-name="getSelectedAmount" ret-field-name="createCustRequestItemInMap.selectedAmount"/>-->
                 <!--<call-object-method obj-field-name="item" method-name="getItemComment" ret-field-name="createCustRequestItemInMap.comments"/>-->
+                <call-object-method obj-field-name="item" method-name="getReservStart" ret-field-name="createCustRequestItemInMap.reservStart"/>
+                <call-object-method obj-field-name="item" method-name="getReservLength" ret-field-name="createCustRequestItemInMap.reservLength"/>
+                <call-object-method obj-field-name="item" method-name="getReservPersons" ret-field-name="createCustRequestItemInMap.reservPersons"/>                                
                 <call-service service-name="createCustRequestItem" in-map-name="createCustRequestItemInMap">
                     <result-to-field result-name="custRequestItemSeqId" field-name="custRequestItemSeqId"/>
                 </call-service>

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?view=diff&rev=566181&r1=566180&r2=566181
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Wed Aug 15 07:17:37 2007
@@ -1620,18 +1620,16 @@
     }
 
     public String getCurrentOrderItemWorkEffort(GenericValue orderItem)    {
+        String orderItemSeqId = orderItem.getString("orderItemSeqId");
+        String orderId = orderItem.getString("orderId");
+        GenericDelegator delegator = orderItem.getDelegator();
         GenericValue workOrderItemFulFillment;
+        GenericValue workEffort;
         try {
-            workOrderItemFulFillment = orderItem.getRelatedOne("WorkOrderItemFulFillment");
-        }
-        catch (GenericEntityException e) {
-            return null;
-        }
-        GenericValue workEffort = null;
-        try {
-        workEffort = workOrderItemFulFillment.getRelatedOne("WorkEffort");
-        }
-        catch (GenericEntityException e) {
+            List workOrderItemFulFillments = delegator.findByAndCache("WorkOrderItemFulfillment", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));
+            workOrderItemFulFillment = EntityUtil.getFirst(workOrderItemFulFillments);
+            workEffort = workOrderItemFulFillment.getRelatedOne("WorkEffort");
+        } catch (GenericEntityException e) {
             return null;
         }
         return workEffort.getString("workEffortId");
@@ -2659,6 +2657,14 @@
         return getOrderItemTotalBd(orderItem, adjustments).doubleValue();
     }
 
+    public static Double getWorkEffortRentalLenght(GenericValue workEffort){
+        Double length = null;
+        if (workEffort.get("estimatedStartDate") != null && workEffort.get("estimatedCompletionDate") != null) {
+            length = new Double(UtilDateTime.getInterval(workEffort.getTimestamp("estimatedStartDate"),workEffort.getTimestamp("estimatedCompletionDate"))/86400000);
+        }
+        return length;
+        }
+    
     public static BigDecimal getWorkEffortRentalQuantityBd(GenericValue workEffort){
         BigDecimal persons = new BigDecimal(1);
         if (workEffort.get("reservPersons") != null)

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java?view=diff&rev=566181&r1=566180&r2=566181
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCart.java Wed Aug 15 07:17:37 2007
@@ -544,6 +544,16 @@
         return addItemToEnd(productId, amount, quantity, unitPrice, features, attributes, prodCatalogId, itemType, dispatcher, triggerExternalOps, triggerPriceRules, Boolean.FALSE, Boolean.FALSE);
     }
 
+    /** Add an (rental)item to the shopping cart. */
+    public int addItemToEnd(String productId, Double amount, double quantity, Double unitPrice, Timestamp reservStart, Double reservLengthDbl, Double reservPersonsDbl, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules) throws CartItemModifyException, ItemNotFoundException {
+        return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, reservStart, reservLengthDbl, reservPersonsDbl, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, Boolean.FALSE, Boolean.FALSE));
+    }    
+
+    /** Add an (rental)item to the shopping cart. */
+    public int addItemToEnd(String productId, Double amount, double quantity, Double unitPrice, Timestamp reservStart, Double reservLengthDbl, Double reservPersonsDbl, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException, ItemNotFoundException {
+        return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, reservStart, reservLengthDbl, reservPersonsDbl, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, skipInventoryChecks, skipProductChecks));
+    }    
+    
     /** Add an item to the shopping cart. */
     public int addItemToEnd(String productId, Double amount, double quantity, Double unitPrice, HashMap features, HashMap attributes, String prodCatalogId, String itemType, LocalDispatcher dispatcher, Boolean triggerExternalOps, Boolean triggerPriceRules, Boolean skipInventoryChecks, Boolean skipProductChecks) throws CartItemModifyException, ItemNotFoundException {
         return addItemToEnd(ShoppingCartItem.makeItem(null, productId, amount, quantity, unitPrice, null, null, null, null, null, features, attributes, prodCatalogId, null, itemType, null, dispatcher, this, triggerExternalOps, triggerPriceRules, null, skipInventoryChecks, skipProductChecks));

Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java?view=diff&rev=566181&r1=566180&r2=566181
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java Wed Aug 15 07:17:37 2007
@@ -25,6 +25,7 @@
 import java.util.Map;
 import java.util.HashMap;
 import java.util.LinkedList;
+import java.sql.Timestamp;
 
 import javolution.util.FastMap;
 
@@ -311,8 +312,29 @@
                     // product item
                     String prodCatalogId = item.getString("prodCatalogId");
                     String productId = item.getString("productId");
+                    
+                    //prepare the rental data
+                    Timestamp reservStart = null;
+                    Double reservLength = null;
+                    Double reservPersons = null;
+                    
+                    GenericValue workEffort = null;                  
+                    String workEffortId = orh.getCurrentOrderItemWorkEffort(item);
+                    if (workEffortId != null) {
+                        try {
+                            workEffort = delegator.findByPrimaryKey("WorkEffort", UtilMisc.toMap("workEffortId", workEffortId));
+                        } catch (GenericEntityException e) {
+                            Debug.logError(e, module);
+                        }
+                    }            
+                    if (workEffort != null && "ASSET_USAGE".equals(workEffort.getString("workEffortTypeId"))){
+                        reservStart = workEffort.getTimestamp("estimatedStartDate");
+                        reservLength = OrderReadHelper.getWorkEffortRentalLenght(workEffort);
+                        reservPersons = workEffort.getDouble("reservPersons");
+                    }    //end of rental data
+                    
                     try {
-                        itemIndex = cart.addItemToEnd(productId, amount, quantityDbl, null, null, null, prodCatalogId, item.getString("orderItemTypeId"), dispatcher, null, null, skipInventoryChecks, skipProductChecks);
+                        itemIndex = cart.addItemToEnd(productId, amount, quantityDbl, null, reservStart, reservLength, reservPersons, null, null, prodCatalogId, item.getString("orderItemTypeId"), dispatcher, null, null, skipInventoryChecks, skipProductChecks);
                     } catch (ItemNotFoundException e) {
                         Debug.logError(e, module);
                         return ServiceUtil.returnError(e.getMessage());
@@ -556,6 +578,12 @@
                     // pass to the cart the quoteUnitPrice/amount value.
                     quoteUnitPrice = new Double(quoteUnitPrice.doubleValue() / amount.doubleValue());
                 }
+                
+                //rental product data
+                Timestamp reservStart = item.getTimestamp("reservStart");
+                Double reservLength = item.getDouble("reservLength");
+                Double reservPersons = item.getDouble("reservPersons");
+                
                 int itemIndex = -1;
                 if (item.get("productId") == null) {
                     // non-product item
@@ -571,7 +599,7 @@
                     // product item
                     String productId = item.getString("productId");
                     try {
-                        itemIndex = cart.addItemToEnd(productId, amount, quantity.doubleValue(), quoteUnitPrice, null, null, null, null, dispatcher, new Boolean(!applyQuoteAdjustments), new Boolean(quoteUnitPrice.doubleValue() == 0));
+                        itemIndex = cart.addItemToEnd(productId, amount, quantity.doubleValue(), quoteUnitPrice, reservStart, reservLength, reservPersons, null, null, null, null, dispatcher, new Boolean(!applyQuoteAdjustments), new Boolean(quoteUnitPrice.doubleValue() == 0));
                     } catch (ItemNotFoundException e) {
                         Debug.logError(e, module);
                         return ServiceUtil.returnError(e.getMessage());