svn commit: r1840579 - in /ofbiz/ofbiz-framework/trunk/applications: datamodel/data/demo/ datamodel/entitydef/ order/groovyScripts/entry/ order/minilang/test/ order/src/main/java/org/apache/ofbiz/order/order/ order/src/main/java/org/apache/ofbiz/order/...

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

svn commit: r1840579 - in /ofbiz/ofbiz-framework/trunk/applications: datamodel/data/demo/ datamodel/entitydef/ order/groovyScripts/entry/ order/minilang/test/ order/src/main/java/org/apache/ofbiz/order/order/ order/src/main/java/org/apache/ofbiz/order/...

nmalin
Author: nmalin
Date: Tue Sep 11 14:36:08 2018
New Revision: 1840579

URL: http://svn.apache.org/viewvc?rev=1840579&view=rev
Log:
Implemented: Calculate estimated shipment delivery time
(OFBIZ-10372)
Currently when you pass an order in ofbiz you can select the shipment method to delivery finish good and obtains an amount cost but you have nothing to indicate how the delivration will during.
We have a good example with ship by plane or boat and for road the time is different between the Portugal to Spain and Portugal to Slovenia.

With this information, we can planned the estimated delivery date with the estimated date to produce finish good and the time to delivery them

To fill this gap, we introduce a new entity ShipmentTimeEstimate modelled as ShipmentCostEstimate to define the estimated time for a shipment method, a carrier and two geo location.
During the entry order process, if you select a shipmentMethod, a carrier and geoIds that match a ShipmentTimeEstimate, when you create the order, OFBiz try to resolve the an estimated delivery date from estimatedShipDate, shipBeforeDate, shipAfterDate or now.

Thanks Leila Mekika for initialize this works, Gil Portenseigne for improve the solution and Suraj Khurana for the review

Added:
    ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy   (with props)
    ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl   (with props)
Modified:
    ofbiz/ofbiz-framework/trunk/applications/datamodel/data/demo/OrderDemoData.xml
    ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/shipment-entitymodel.xml
    ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/CheckoutReview.groovy
    ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/ShowCart.groovy
    ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/ShoppingCartTests.xml
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
    ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
    ofbiz/ofbiz-framework/trunk/applications/order/template/entry/CheckoutOptions.ftl
    ofbiz/ofbiz-framework/trunk/applications/order/template/entry/OptionSettings.ftl
    ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml
    ofbiz/ofbiz-framework/trunk/applications/product/servicedef/services_shipment.xml
    ofbiz/ofbiz-framework/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml
    ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/CatalogMenus.xml
    ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingForms.xml
    ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingScreens.xml

Modified: ofbiz/ofbiz-framework/trunk/applications/datamodel/data/demo/OrderDemoData.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/datamodel/data/demo/OrderDemoData.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/datamodel/data/demo/OrderDemoData.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/datamodel/data/demo/OrderDemoData.xml Tue Sep 11 14:36:08 2018
@@ -2097,6 +2097,10 @@ under the License.
     <ShipmentCostEstimate productStoreShipMethId="9015" productStoreId="9000" orderFlatPrice="0.0" orderItemFlatPrice="0.0" orderPricePercent="0.0" shipmentCostEstimateId="9208" shipmentMethodTypeId="GROUND" carrierPartyId="FEDEX" carrierRoleTypeId="CARRIER"/>
     <ShipmentCostEstimate productStoreShipMethId="9016" productStoreId="9000" orderFlatPrice="0.0" orderItemFlatPrice="0.0" orderPricePercent="0.0" shipmentCostEstimateId="9209" shipmentMethodTypeId="GROUND_HOME" carrierPartyId="FEDEX" carrierRoleTypeId="CARRIER"/>
 
+    <ShipmentTimeEstimate shipmentMethodTypeId="EXPRESS" partyId="DHL" roleTypeId="CARRIER" leadTime="1" leadTimeUomId="TF_day" geoIdFrom="_NA_" geoIdTo="_NA_" fromDate="2001-05-13 12:00:00.0"/>
+    <ShipmentTimeEstimate shipmentMethodTypeId="SECOND_DAY" partyId="DHL" roleTypeId="CARRIER" leadTime="2" leadTimeUomId="TF_day" geoIdFrom="_NA_" geoIdTo="_NA_" fromDate="2001-05-13 12:00:00.0"/>
+    <ShipmentTimeEstimate shipmentMethodTypeId="SECOND_DAY" partyId="DHL" roleTypeId="CARRIER" leadTime="2.5" leadTimeUomId="TF_day" geoIdFrom="_NA_" geoIdTo="FRA" fromDate="2001-05-13 12:00:00.0"/>
+
     <ShipmentBoxType shipmentBoxTypeId="FXENV" description="FedEx Envelope" dimensionUomId="LEN_in" boxLength="9.5" boxWidth="12.5" boxHeight="0"/>
     <ShipmentBoxType shipmentBoxTypeId="FXENV_LGL" description="FedEx Envelope (Legal)" dimensionUomId="LEN_in" boxLength="10" boxWidth="15.75" boxHeight="0"/>
     <ShipmentBoxType shipmentBoxTypeId="FXPAK_SM" description="FedEx Pak (Small)" dimensionUomId="LEN_in" boxLength="10.25" boxWidth="12.75" boxHeight="0"/>

Modified: ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/shipment-entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/shipment-entitymodel.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/shipment-entitymodel.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/datamodel/entitydef/shipment-entitymodel.xml Tue Sep 11 14:36:08 2018
@@ -834,6 +834,39 @@ under the License.
         <key-map field-name="priceBreakId" rel-field-name="quantityBreakId"/>
       </relation>
     </entity>
+    <entity entity-name="ShipmentTimeEstimate" package-name="org.apache.ofbiz.shipment.shipment"
+        title="Shipment Time Estimation Entity">
+        <field name="shipmentMethodTypeId" type="id"/>
+        <field name="partyId" type="id"/>
+        <field name="roleTypeId" type="id"/>
+        <field name="geoIdTo" type="id"/>
+        <field name="geoIdFrom" type="id"/>
+        <field name="fromDate" type="date-time"/>
+        <field name="thruDate" type="date-time"/>
+        <field name="leadTime" type="fixed-point"/>
+        <field name="leadTimeUomId" type="id"/>
+        <field name="sequenceNumber" type="numeric"/>
+        <prim-key field="shipmentMethodTypeId"/>
+        <prim-key field="partyId"/>
+        <prim-key field="roleTypeId"/>
+        <prim-key field="geoIdTo"/>
+        <prim-key field="geoIdFrom"/>
+        <prim-key field="fromDate"/>
+        <relation rel-entity-name="CarrierShipmentMethod" type="one" fk-name="SHIPT_EST_METHOD">
+            <key-map field-name="shipmentMethodTypeId"/>
+            <key-map field-name="partyId"/>
+            <key-map field-name="roleTypeId"/>
+        </relation>
+        <relation rel-entity-name="Geo" type="one" title="To" fk-name="SHIPT_EST_GEO_TO">
+            <key-map field-name="geoIdTo" rel-field-name="geoId"/>
+        </relation>
+        <relation rel-entity-name="Geo" type="one" title="from" fk-name="SHIPT_EST_GEO_FROM">
+            <key-map field-name="geoIdFrom" rel-field-name="geoId"/>
+        </relation>
+        <relation rel-entity-name="Uom" type="one" title="Time unit" fk-name="SHIPT_EST_UOM">
+            <key-map field-name="leadTimeUomId" rel-field-name="uomId"/>
+        </relation>
+    </entity>
     <entity entity-name="ShipmentGatewayConfigType"
             package-name="org.apache.ofbiz.shipment.shipment"
             title="Shipment Gateway Config Type">

Modified: ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/CheckoutReview.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/CheckoutReview.groovy?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/CheckoutReview.groovy (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/CheckoutReview.groovy Tue Sep 11 14:36:08 2018
@@ -39,7 +39,7 @@ context.orderItems = orderItems
 
 orderAdjustments = cart.makeAllAdjustments()
 
-orderItemShipGroupInfo = cart.makeAllShipGroupInfos()
+orderItemShipGroupInfo = cart.makeAllShipGroupInfos(dispatcher)
 if (orderItemShipGroupInfo) {
     orderItemShipGroupInfo.each { osiInfo ->
         if ("OrderAdjustment".equals(osiInfo.getEntityName())) {

Modified: ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/ShowCart.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/ShowCart.groovy?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/ShowCart.groovy (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/groovyScripts/entry/ShowCart.groovy Tue Sep 11 14:36:08 2018
@@ -51,7 +51,7 @@ context.orderType = shoppingCart.getOrde
 
 orderItems = shoppingCart.makeOrderItems(dispatcher)
 orderAdjustments = shoppingCart.makeAllAdjustments()
-orderItemShipGroupInfo = shoppingCart.makeAllShipGroupInfos()
+orderItemShipGroupInfo = shoppingCart.makeAllShipGroupInfos(dispatcher)
 if (orderItemShipGroupInfo) {
     orderItemShipGroupInfo.each { osiInfo ->
         if ("OrderAdjustment".equals(osiInfo.getEntityName())) {

Modified: ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/ShoppingCartTests.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/ShoppingCartTests.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/ShoppingCartTests.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/minilang/test/ShoppingCartTests.xml Tue Sep 11 14:36:08 2018
@@ -257,7 +257,9 @@ under the License.
         </call-object-method>
 
         <!-- Shopping Cart Make all ShipGroupInfos -->
-        <call-object-method method-name="makeAllShipGroupInfos" obj-field="shoppingCart"/>
+        <call-object-method method-name="makeAllShipGroupInfos" obj-field="shoppingCart">
+            <field field="dispatcher" type="org.apache.ofbiz.service.LocalDispatcher"/>
+        </call-object-method>
 
         <!-- Shopping Cart checkout and create order -->
         <script>groovy:

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/order/OrderServices.java Tue Sep 11 14:36:08 2018
@@ -4279,7 +4279,7 @@ public class OrderServices {
         }
 
         // Creating objects for New Shipping and Handling Charges Adjustment and Sales Tax Adjustment
-        toStore.addAll(cart.makeAllShipGroupInfos());
+        toStore.addAll(cart.makeAllShipGroupInfos(dispatcher));
         toStore.addAll(cart.makeAllOrderPaymentInfos(dispatcher));
         toStore.addAll(cart.makeAllOrderItemAttributes(orderId, ShoppingCart.FILLED_ONLY));
 

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCart.java Tue Sep 11 14:36:08 2018
@@ -37,8 +37,10 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.stream.Stream;
 
 import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
@@ -65,6 +67,7 @@ import org.apache.ofbiz.order.finaccount
 import org.apache.ofbiz.order.order.OrderReadHelper;
 import org.apache.ofbiz.order.shoppingcart.product.ProductPromoWorker;
 import org.apache.ofbiz.order.shoppingcart.shipping.ShippingEstimateWrapper;
+import org.apache.ofbiz.order.shoppingcart.shipping.ShippingEvents;
 import org.apache.ofbiz.order.shoppinglist.ShoppingListEvents;
 import org.apache.ofbiz.party.contact.ContactHelper;
 import org.apache.ofbiz.party.contact.ContactMechWorker;
@@ -2616,6 +2619,12 @@ public class ShoppingCart implements Ite
         return null;
     }
 
+    public GenericValue getOriginAddress(int idx) {
+        CartShipInfo cartShipInfo = getShipInfo(idx);
+        if (cartShipInfo == null) return null;
+        return cartShipInfo.getOriginAddress(this);
+    }
+
     public GenericValue getShippingAddress() {
         return this.getShippingAddress(0);
     }
@@ -4000,15 +4009,21 @@ public class ShoppingCart implements Ite
         return allOrderContactMechs;
     }
 
-    public List<GenericValue> makeAllShipGroupInfos() {
+    /**
+     * Return all OrderItemShipGroup, OrderContactMech, OrderAdjustment and OrderItemShipGroupAssoc from ShoppingCart
+     * in a single list of {@link GenericValue}
+     * @param dispatcher
+     * @return
+     */
+    public List<GenericValue> makeAllShipGroupInfos(LocalDispatcher dispatcher) {
         List<GenericValue> groups = new LinkedList<>();
         long seqId = 1;
         for (CartShipInfo csi : this.shipInfo) {
             String shipGroupSeqId = csi.shipGroupSeqId;
             if (shipGroupSeqId != null) {
-                groups.addAll(csi.makeItemShipGroupAndAssoc(this.getDelegator(), this, shipGroupSeqId));
+                groups.addAll(csi.makeItemShipGroupAndAssoc(dispatcher, this.getDelegator(), this, shipGroupSeqId));
             } else {
-                groups.addAll(csi.makeItemShipGroupAndAssoc(this.getDelegator(), this, UtilFormatOut.formatPaddedNumber(seqId, 5), true));
+                groups.addAll(csi.makeItemShipGroupAndAssoc(dispatcher, this.getDelegator(), this, UtilFormatOut.formatPaddedNumber(seqId, 5), true));
             }
             seqId++;
         }
@@ -4162,7 +4177,7 @@ public class ShoppingCart implements Ite
         result.put("orderContactMechs", this.makeAllOrderContactMechs());
         result.put("orderItemContactMechs", this.makeAllOrderItemContactMechs());
         result.put("orderPaymentInfo", this.makeAllOrderPaymentInfos(dispatcher));
-        result.put("orderItemShipGroupInfo", this.makeAllShipGroupInfos());
+        result.put("orderItemShipGroupInfo", this.makeAllShipGroupInfos(dispatcher));
         result.put("orderItemSurveyResponses", this.makeAllOrderItemSurveyResponses());
         result.put("orderAdditionalPartyRoleMap", this.getAdditionalPartyRoleMap());
         result.put("orderItemAssociations", this.makeAllOrderItemAssociations());
@@ -4693,6 +4708,38 @@ public class ShoppingCart implements Ite
             }
         }
 
+        public GenericValue getOriginAddress(ShoppingCart cart) {
+            GenericValue originAddress = null;
+            Delegator delegator = cart.delegator;
+            //check information from the cart ship info
+            try {
+                if (originAddress == null && facilityId != null) {
+                    originAddress = ShippingEvents.getShippingOriginContactMechFromFacility(delegator, facilityId);
+                }
+                if (originAddress == null && supplierPartyId != null) {
+                    originAddress = ShippingEvents.getShippingOriginContactMech(delegator, supplierPartyId);
+                }
+                if (originAddress == null && vendorPartyId != null) {
+                    originAddress = ShippingEvents.getShippingOriginContactMech(delegator, vendorPartyId);
+                }
+
+                if (originAddress == null) {
+                    //try now to resolve from the cart
+                    if (cart.getFacilityId() != null) {
+                        originAddress = ShippingEvents.getShippingOriginContactMechFromFacility(delegator, cart.getFacilityId());
+                    }
+                    if (originAddress == null && cart.getShipFromVendorPartyId() != null) {
+                        originAddress = ShippingEvents.getShippingOriginContactMech(delegator, cart.getShipFromVendorPartyId());
+                    }
+                    if (originAddress == null && cart.getBillFromVendorPartyId() != null) {
+                        originAddress = ShippingEvents.getShippingOriginContactMech(delegator, cart.getBillFromVendorPartyId());
+                    }
+                }
+            } catch (GeneralException e) {
+                Debug.logError("Impossible to resolve an originAddress " + e.toString(), module);
+            }
+            return originAddress;
+        }
         public void clearAllTaxInfo() {
             this.shipTaxAdj.clear();
             for (CartShipItemInfo itemInfo : shipItemInfo.values()) {
@@ -4700,11 +4747,11 @@ public class ShoppingCart implements Ite
             }
         }
 
-        public List<GenericValue> makeItemShipGroupAndAssoc(Delegator delegator, ShoppingCart cart, String shipGroupSeqId) {
-            return makeItemShipGroupAndAssoc(delegator, cart, shipGroupSeqId, false);
+        public List<GenericValue> makeItemShipGroupAndAssoc(LocalDispatcher dispatcher, Delegator delegator, ShoppingCart cart, String shipGroupSeqId) {
+            return makeItemShipGroupAndAssoc(dispatcher, delegator, cart, shipGroupSeqId, false);
         }
 
-        public List<GenericValue> makeItemShipGroupAndAssoc(Delegator delegator, ShoppingCart cart, String shipGroupSeqId, boolean newShipGroup) {
+        public List<GenericValue> makeItemShipGroupAndAssoc(LocalDispatcher dispatcher, Delegator delegator, ShoppingCart cart, String shipGroupSeqId, boolean newShipGroup) {
             List<GenericValue> values = new LinkedList<>();
 
             // create order contact mech for shipping address
@@ -4754,9 +4801,10 @@ public class ShoppingCart implements Ite
                     estimatedShipDates.add(estimatedShipDate);
                 }
             }
+            Timestamp estimatedShipDate = null;
             if (estimatedShipDates.size() > 0) {
                 Collections.sort(estimatedShipDates);
-                Timestamp estimatedShipDate  = estimatedShipDates.getLast();
+                estimatedShipDate  = estimatedShipDates.getLast();
                 shipGroup.set("estimatedShipDate", estimatedShipDate);
             }
 
@@ -4768,9 +4816,44 @@ public class ShoppingCart implements Ite
                     estimatedDeliveryDates.add(estimatedDeliveryDate);
                 }
             }
+            Timestamp estimatedDeliveryDate = null;
             if (UtilValidate.isNotEmpty(estimatedDeliveryDates)) {
                 Collections.sort(estimatedDeliveryDates);
-                Timestamp estimatedDeliveryDate = estimatedDeliveryDates.getLast();
+                estimatedDeliveryDate = estimatedDeliveryDates.getLast();
+            } else {
+
+                // check if a shipment time estimate exists to resolve the estimated delivery date
+                long shipTimeEstimateSize = 0;
+                try {
+                    shipTimeEstimateSize = EntityQuery.use(delegator)
+                            .from("ShipmentTimeEstimate")
+                            .where("shipmentMethodTypeId", shipmentMethodTypeId)
+                            .filterByDate()
+                            .queryCount();
+                } catch (GenericEntityException e) {
+                    Debug.logError("Error to resolve ShipmentTimeEstimate quantity", module);
+                }
+                if (shipTimeEstimateSize != 0) {
+                    try {
+                        GenericValue shippingAddress = EntityQuery.use(delegator).from("PostalAddress").where("contactMechId", this.internalContactMechId).cache().queryOne();
+                        GenericValue originAddress = getOriginAddress(cart);
+                        List<GenericValue> shipmentTimeEstimates = ShippingEvents.getShipmentTimeEstimates(delegator, shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId, shippingAddress, originAddress);
+                        GenericValue carrierShipmentMethod = delegator.makeValidValue("CarrierShipmentMethod", shipGroup);
+                        carrierShipmentMethod.put("partyId", carrierPartyId);
+                        if (carrierRoleTypeId == null) carrierRoleTypeId = "CARRIER";
+                        carrierShipmentMethod.put("roleTypeId", carrierRoleTypeId);
+                        Double estimatedDays = ShippingEvents.getShippingTimeEstimateInDay(dispatcher, carrierShipmentMethod, shipmentTimeEstimates);
+                        if (estimatedDays != null) {
+                            Timestamp referenceDate = Stream.of(estimatedShipDate, shipBeforeDate, shipAfterDate, UtilDateTime.nowTimestamp())
+                                    .filter(Objects::nonNull).findFirst().get();
+                            estimatedDeliveryDate = UtilDateTime.addDaysToTimestamp(referenceDate, estimatedDays);
+                        }
+                    } catch (GenericEntityException e) {
+                        Debug.logError("Error to resolve ShipmentTimeEstimate days", module);
+                    }
+                }
+            }
+            if (estimatedDeliveryDate != null) {
                 shipGroup.set("estimatedDeliveryDate", estimatedDeliveryDate);
             }
 

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/ShoppingCartServices.java Tue Sep 11 14:36:08 2018
@@ -332,8 +332,11 @@ public class ShoppingCartServices {
         List<GenericValue> orderItemShipGroupList = orh.getOrderItemShipGroups();
         for (GenericValue orderItemShipGroup: orderItemShipGroupList) {
             // should be sorted by shipGroupSeqId
-            int newShipInfoIndex = cart.addShipInfo();
-            CartShipInfo cartShipInfo = cart.getShipInfo(newShipInfoIndex);
+            int groupIdx = Integer.parseInt(orderItemShipGroup.getString("shipGroupSeqId"));
+            CartShipInfo cartShipInfo = cart.getShipInfo(groupIdx-1);
+            if (cartShipInfo == null) {
+                cartShipInfo = cart.getShipInfo(cart.addShipInfo());
+            }
             cartShipInfo.shipAfterDate = orderItemShipGroup.getTimestamp("shipAfterDate");
             cartShipInfo.shipBeforeDate = orderItemShipGroup.getTimestamp("shipByDate");
             cartShipInfo.shipmentMethodTypeId = orderItemShipGroup.getString("shipmentMethodTypeId");

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEstimateWrapper.java Tue Sep 11 14:36:08 2018
@@ -20,6 +20,7 @@ package org.apache.ofbiz.order.shoppingc
 
 import java.math.BigDecimal;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
@@ -43,9 +44,11 @@ public class ShippingEstimateWrapper {
     protected LocalDispatcher dispatcher = null;
 
     protected Map<GenericValue, BigDecimal> shippingEstimates = null;
+    protected List<GenericValue> shippingTimeEstimates = null;
     protected List<GenericValue> shippingMethods = null;
 
     protected GenericValue shippingAddress = null;
+    protected GenericValue originAddress = null;
     protected Map<String, BigDecimal> shippableItemFeatures = null;
     protected List<BigDecimal> shippableItemSizes = null;
     protected List<Map<String, Object>> shippableItemInfo = null;
@@ -71,6 +74,7 @@ public class ShippingEstimateWrapper {
         this.shippableWeight = cart.getShippableWeight(shipGroup);
         this.shippableTotal = cart.getShippableTotal(shipGroup);
         this.shippingAddress = cart.getShippingAddress(shipGroup);
+        this.originAddress = cart.getOriginAddress(shipGroup);
         this.productStoreId = cart.getProductStoreId();
         this.partyId = cart.getPartyId();
         this.supplierPartyId = cart.getSupplierPartyId(shipGroup);
@@ -90,6 +94,7 @@ public class ShippingEstimateWrapper {
         }
         this.loadShippingMethods();
         this.loadEstimates(totalAllowance);
+        this.loadShipmentTimeEstimates();
     }
 
     protected void loadShippingMethods() {
@@ -123,6 +128,20 @@ public class ShippingEstimateWrapper {
         }
     }
 
+    protected void loadShipmentTimeEstimates() {
+        this.shippingTimeEstimates = new LinkedList<>();
+
+        if (shippingMethods != null) {
+            for (GenericValue shipMethod : shippingMethods) {
+                String shipmentMethodTypeId = shipMethod.getString("shipmentMethodTypeId");
+                String carrierRoleTypeId = shipMethod.getString("roleTypeId");
+                String carrierPartyId = shipMethod.getString("partyId");
+
+                shippingTimeEstimates.addAll(ShippingEvents.getShipmentTimeEstimates(delegator, shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId, shippingAddress, originAddress));
+            }
+        }
+    }
+
     public List<GenericValue> getShippingMethods() {
         return shippingMethods;
     }
@@ -135,4 +154,11 @@ public class ShippingEstimateWrapper {
         return shippingEstimates.get(storeCarrierShipMethod);
     }
 
+    public List<GenericValue> getShippingTimeEstimates() {
+        return shippingTimeEstimates;
+    }
+
+    public Double getShippingTimeEstimateInDay(GenericValue storeCarrierShipMethod) {
+        return ShippingEvents.getShippingTimeEstimateInDay(dispatcher, storeCarrierShipMethod, shippingTimeEstimates);
+    }
 }

Modified: ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/src/main/java/org/apache/ofbiz/order/shoppingcart/shipping/ShippingEvents.java Tue Sep 11 14:36:08 2018
@@ -19,11 +19,14 @@
 package org.apache.ofbiz.order.shoppingcart.shipping;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
+import java.util.Optional;
+import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -31,6 +34,7 @@ import org.apache.ofbiz.base.util.Debug;
 import org.apache.ofbiz.base.util.GeneralException;
 import org.apache.ofbiz.base.util.UtilMisc;
 import org.apache.ofbiz.base.util.UtilValidate;
+import org.apache.ofbiz.common.uom.UomWorker;
 import org.apache.ofbiz.entity.Delegator;
 import org.apache.ofbiz.entity.GenericEntityException;
 import org.apache.ofbiz.entity.GenericValue;
@@ -43,6 +47,7 @@ import org.apache.ofbiz.entity.util.Enti
 import org.apache.ofbiz.order.order.OrderReadHelper;
 import org.apache.ofbiz.order.shoppingcart.ShoppingCart;
 import org.apache.ofbiz.order.shoppingcart.product.ProductPromoWorker;
+import org.apache.ofbiz.party.contact.ContactMechWorker;
 import org.apache.ofbiz.product.store.ProductStoreWorker;
 import org.apache.ofbiz.service.GenericServiceException;
 import org.apache.ofbiz.service.LocalDispatcher;
@@ -55,6 +60,7 @@ import org.apache.ofbiz.service.ServiceU
 public class ShippingEvents {
 
     public static final String module = ShippingEvents.class.getName();
+    private static final List<String> fieldNameGeoIds = UtilMisc.toList("countryGeoId", "countyGeoId", "stateProvinceGeoId", "municipalityGeoId", "postalCodeGeoId");
 
     public static String getShipEstimate(HttpServletRequest request, HttpServletResponse response) {
         ShoppingCart cart = (ShoppingCart) request.getSession().getAttribute("shoppingCart");
@@ -376,7 +382,7 @@ public class ShippingEvents {
                 EntityCondition.makeCondition("contactMechPurposeTypeId", EntityOperator.IN, UtilMisc.toList("SHIP_ORIG_LOCATION", "GENERAL_LOCATION")),
                 EntityUtil.getFilterByDateExpr("contactFromDate", "contactThruDate"),
                 EntityUtil.getFilterByDateExpr("purposeFromDate", "purposeThruDate")
-       );
+        );
         EntityConditionList<EntityCondition> ecl = EntityCondition.makeCondition(conditions, EntityOperator.AND);
 
         List<GenericValue> addresses = delegator.findList("PartyContactWithPurpose", ecl, null, UtilMisc.toList("contactMechPurposeTypeId DESC"), null, false);
@@ -391,7 +397,136 @@ public class ShippingEvents {
         }
         return originAddress != null ? originAddress : generalAddress;
     }
-}
 
+    public static GenericValue getShippingOriginContactMechFromFacility(Delegator delegator, String facilityId) throws GeneralException {
+         GenericValue address = ContactMechWorker.getFacilityContactMechByPurpose(delegator, facilityId, UtilMisc.toList("SHIP_ORIG_LOCATION"));
+         if (address != null) return address;
+         return ContactMechWorker.getFacilityContactMechByPurpose(delegator, facilityId, UtilMisc.toList("GENERAL_LOCATION"));
+    }
+
+    private static List<String> getGeoIdFromPostalContactMech(Delegator delegator, GenericValue address) {
+        List<String> geoIds = new ArrayList<>();
+        if (address != null) {
+            GenericValue addressGV = null;
+            if ("PostalAddress".equals(address.getEntityName())) {
+                addressGV = address;
+            } else {
+                try {
+                    addressGV = EntityQuery.use(delegator).from("PostalAddress").where(address).cache().queryOne();
+                } catch (GeneralException e) {
+                    Debug.logError(e.toString(), module);
+                }
+            }
+            if (addressGV != null) {
+                GenericValue finalAddressGV = addressGV;
+                geoIds = fieldNameGeoIds.stream()
+                        .filter(key -> finalAddressGV.get(key) != null)
+                        .map(key -> finalAddressGV.getString(key))
+                        .collect(Collectors.toList());
+            }
+        }
+        return geoIds;
+    }
+
+    public static List<GenericValue> getShipmentTimeEstimates(Delegator delegator, String shipmentMethodTypeId,
+            String partyId, String roleTypeId, GenericValue shippingAddress, GenericValue originAddress) {
+        //Retrieve origin Geo
+        List<String> geoIdFroms = getGeoIdFromPostalContactMech(delegator, originAddress);
+        //Retrieve destination Geo
+        List<String> geoIdTos = getGeoIdFromPostalContactMech(delegator, shippingAddress);
+        return getShipmentTimeEstimates(delegator, shipmentMethodTypeId, partyId, roleTypeId, geoIdFroms, geoIdTos);
+    }
+
+
+    public static List<GenericValue> getShipmentTimeEstimates(Delegator delegator, String shipmentMethodTypeId,
+            String partyId, String roleTypeId, List<String> geoIdFroms, List<String> geoIdTos) {
+
+        List<GenericValue> shippingTimeEstimates = new LinkedList<>();
+        if ("NO_SHIPPING".equals(shipmentMethodTypeId)) {
+            return shippingTimeEstimates;
+        }
 
+        List<EntityCondition> conditionList = new ArrayList<>();
+        if (UtilValidate.isNotEmpty(shipmentMethodTypeId)) {
+            conditionList.add(EntityCondition.makeCondition("shipmentMethodTypeId", shipmentMethodTypeId));
+        }
+        if (UtilValidate.isNotEmpty(partyId)) {
+            conditionList.add(EntityCondition.makeCondition("partyId", partyId));
+        }
+        if (UtilValidate.isNotEmpty(roleTypeId)) {
+            conditionList.add(EntityCondition.makeCondition("roleTypeId", roleTypeId));
+        }
+        List<EntityCondition> geoConditionList = new ArrayList<>();
+        if (geoIdFroms == null) geoIdFroms = new ArrayList<>();
+        if (geoIdTos == null) geoIdTos = new ArrayList<>();
+        geoConditionList.add(EntityCondition.makeCondition("geoIdFrom", EntityOperator.IN, geoIdFroms));
+        geoConditionList.add(EntityCondition.makeCondition("geoIdTo", EntityOperator.IN, geoIdTos));
+        geoConditionList.addAll(conditionList);
+        EntityCondition condition = EntityCondition.makeCondition(geoConditionList);
+
+        try {
+            shippingTimeEstimates = EntityQuery.use(delegator)
+                    .from("ShipmentTimeEstimate")
+                    .where(condition)
+                    .filterByDate()
+                    .orderBy("sequenceNumber")
+                    .cache()
+                    .queryList();
+            if (UtilValidate.isEmpty(shippingTimeEstimates)) {
+                geoIdFroms.add("_NA_");
+                geoIdTos.add("_NA_");
+                geoConditionList = new ArrayList<>();
+                geoConditionList.add(EntityCondition.makeCondition("geoIdFrom", EntityOperator.IN, geoIdFroms));
+                geoConditionList.add(EntityCondition.makeCondition("geoIdTo", EntityOperator.IN, geoIdTos));
+                geoConditionList.addAll(conditionList);
+                condition = EntityCondition.makeCondition(geoConditionList);
+                shippingTimeEstimates = EntityQuery.use(delegator)
+                        .from("ShipmentTimeEstimate")
+                        .where(condition)
+                        .filterByDate()
+                        .cache()
+                        .orderBy("geoIdFrom", "geoIdTo")
+                        .queryList();
+            }
+        } catch (GenericEntityException e) {
+            String errMsg = "Failure getting shipment time estimate: " + e.getLocalizedMessage();
+            Debug.logError(errMsg, module);
+        }
+
+        return shippingTimeEstimates;
+    }
+
+    /**
+     * Return the {@link GenericValue} ShipmentTimeEstimate matching the carrier shipment method
+     * @param storeCarrierShipMethod ShipmentMethod used for estimation
+     * @param shippingTimeEstimates available configured estimation
+     * @return
+     */
+    public static GenericValue getShippingTimeEstimate(GenericValue storeCarrierShipMethod, List<GenericValue> shippingTimeEstimates) {
+        if (shippingTimeEstimates == null) return null;
+        List<String> pkFields = storeCarrierShipMethod.getDelegator().getModelEntity("CarrierShipmentMethod").getPkFieldNames();
+        Optional<GenericValue> shippingTimeEstimate = shippingTimeEstimates.stream()
+                .filter(shippingTimeEstimateAnalyze ->
+                        pkFields.stream()
+                                .allMatch(k ->
+                                        storeCarrierShipMethod.getString(k).equals(
+                                                shippingTimeEstimateAnalyze.getString(k))))
+                .findFirst();
+        return shippingTimeEstimate.orElse(null);
+    }
+
+    /**
+     * Return the number of days estimated for shipping
+     * @param dispatcher
+     * @param storeCarrierShipMethod ShipmentMethod used for estimation
+     * @param shippingTimeEstimates available configured estimation
+     * @return
+     */
+    public static Double getShippingTimeEstimateInDay(LocalDispatcher dispatcher, GenericValue storeCarrierShipMethod, List<GenericValue> shippingTimeEstimates) {
+        GenericValue shippingTimeEstimate = getShippingTimeEstimate(storeCarrierShipMethod, shippingTimeEstimates);
+        if (shippingTimeEstimate == null) return null;
+        BigDecimal leadTimeConverted = UomWorker.convertUom(shippingTimeEstimate.getBigDecimal("leadTime"), shippingTimeEstimate.getString("leadTimeUomId"), "TF_day", dispatcher);
+        return leadTimeConverted != null ? leadTimeConverted.setScale(2, BigDecimal.ROUND_UP).doubleValue() : null;
+    }
+}
 

Modified: ofbiz/ofbiz-framework/trunk/applications/order/template/entry/CheckoutOptions.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/template/entry/CheckoutOptions.ftl?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/template/entry/CheckoutOptions.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/template/entry/CheckoutOptions.ftl Tue Sep 11 14:36:08 2018
@@ -172,9 +172,11 @@ function submitForm(form, mode, value) {
                         <span>
                           <#if shoppingCart.getShippingContactMechId()??>
                             <#assign shippingEst = shippingEstWpr.getShippingEstimate(carrierShipmentMethod)?default(-1)>
+                            <#assign shippingTimeEstimateInDay = shippingEstWpr.getShippingTimeEstimateInDay(carrierShipmentMethod)?default(-1)>
                           </#if>
                           <#if carrierShipmentMethod.partyId != "_NA_">${carrierShipmentMethod.partyId!}&nbsp;</#if>${carrierShipmentMethod.description!}
                           <#if shippingEst?has_content> - <#if (shippingEst > -1)><@ofbizCurrency amount=shippingEst isoCode=shoppingCart.getCurrency()/><#else>${uiLabelMap.OrderCalculatedOffline}</#if></#if>
+                          <#if (shippingTimeEstimateInDay?? && shippingTimeEstimateInDay > 0)> - ${shippingTimeEstimateInDay} ${uiLabelMap.CommonDays}</#if>
                         </span>
                         </label>
                       </td>

Modified: ofbiz/ofbiz-framework/trunk/applications/order/template/entry/OptionSettings.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/order/template/entry/OptionSettings.ftl?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/order/template/entry/OptionSettings.ftl (original)
+++ ofbiz/ofbiz-framework/trunk/applications/order/template/entry/OptionSettings.ftl Tue Sep 11 14:36:08 2018
@@ -82,6 +82,7 @@ under the License.
                       <#if carrierShipmentMethod.partyId != "_NA_">${carrierShipmentMethod.partyId!}&nbsp;</#if>${carrierShipmentMethod.description!}
                       <#if cart.getShippingContactMechId(shipGroupIndex)??>
                         <#assign shippingEst = shipEstimateWrapper.getShippingEstimate(carrierShipmentMethod)?default(-1)>
+                        <#assign shippingTimeEstimateInDay = shipEstimateWrapper.getShippingTimeEstimateInDay(carrierShipmentMethod)?default(-1)>
                         <#if shippingEst?has_content>
                           &nbsp;-&nbsp;
                           <#if (shippingEst > -1)>
@@ -89,6 +90,7 @@ under the License.
                           <#else>
                             Calculated Offline
                           </#if>
+                          <#if (shippingTimeEstimateInDay > 0)> - ${shippingTimeEstimateInDay} ${uiLabelMap.CommonDays}</#if>
                         </#if>
                       </#if>
                     </label>

Modified: ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/config/ProductUiLabels.xml Tue Sep 11 14:36:08 2018
@@ -10675,6 +10675,10 @@
         <value xml:lang="zh">编辑货运路线分区</value>
         <value xml:lang="zh-TW">編輯貨運路線分區</value>
     </property>
+    <property key="PageTitleEditShipmentTimeEstimates">
+        <value xml:lang="en">Edit Shipment Time Estimates</value>
+        <value xml:lang="fr">Modification des temps de livraison estimé</value>
+    </property>
     <property key="PageTitleEditSubscription">
         <value xml:lang="de">Abonnemente bearbeiten</value>
         <value xml:lang="en">Edit Subscription</value>
@@ -11254,6 +11258,10 @@
         <value xml:lang="zh">运输方法类型列表</value>
         <value xml:lang="zh-TW">運輸方法類型清單</value>
     </property>
+    <property key="PageTitleListShipmentTimeEstimates">
+        <value xml:lang="en">Shipment Time Estimates List</value>
+        <value xml:lang="fr">Liste des temps de livraison estimé</value>
+    </property>
     <property key="PageTitleLookupBulkAddProduct">
         <value xml:lang="de">Massenhinzufügung Produkte</value>
         <value xml:lang="en">Bulk Add Product</value>
@@ -29540,6 +29548,10 @@
         <value xml:lang="zh">第三方邮政编码</value>
         <value xml:lang="zh-TW">協力廠商郵遞區號</value>
     </property>
+    <property key="ProductShipmentTimeEstimates">
+        <value xml:lang="en">Shipment Time Estimates</value>
+        <value xml:lang="fr">Temps de livraison estimé</value>
+    </property>
     <property key="ProductShipmentTotalVolume">
         <value xml:lang="de">Total Volumen</value>
         <value xml:lang="en">Total Volume</value>

Added: ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy?rev=1840579&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy (added)
+++ ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy Tue Sep 11 14:36:08 2018
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+String carrierShipmentString = request.getParameter("carrierShipmentString")
+if (carrierShipmentString) {
+    StringTokenizer st = new StringTokenizer(carrierShipmentString, "|")
+    if (st.countTokens() != 3) {
+        return "error"
+    }
+    request.setAttribute("addShipmentMethodEstimate", "Y")
+    request.setAttribute("partyId", st.nextToken())
+    request.setAttribute("roleTypeId", st.nextToken())
+    request.setAttribute("shipmentMethodTypeId", st.nextToken())
+    return "success"
+} else {
+    return "error"
+}
+

Propchange: ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/applications/product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/ofbiz-framework/trunk/applications/product/servicedef/services_shipment.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/servicedef/services_shipment.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/servicedef/services_shipment.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/servicedef/services_shipment.xml Tue Sep 11 14:36:08 2018
@@ -1085,6 +1085,28 @@ under the License.
         <auto-attributes include="pk" mode="IN"/>
     </service>
 
+    <!-- ShipmentTimeEstimate  -->
+
+    <service name="createShipmentTimeEstimate" engine="entity-auto" invoke="create" default-entity-name="ShipmentTimeEstimate" auth="true">
+        <description>Create a ShipmentTimeEstimate</description>
+        <auto-attributes include="pk" mode="IN"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+        <override name="fromDate" optional="true"/>
+    </service>
+    <service name="updateShipmentTimeEstimate" engine="entity-auto" invoke="update" default-entity-name="ShipmentTimeEstimate" auth="true">
+        <description>Update a ShipmentTimeEstimate</description>
+        <auto-attributes include="pk" mode="IN"/>
+        <auto-attributes include="nonpk" mode="IN" optional="true"/>
+    </service>
+    <service name="removeShipmentTimeEstimate" engine="entity-auto" invoke="delete" default-entity-name="ShipmentTimeEstimate" auth="true">
+        <description>Remove a ShipmentTimeEstimate</description>
+        <auto-attributes include="pk" mode="IN"/>
+    </service>
+    <service name="expireShipmentTimeEstimate" engine="entity-auto" invoke="expire" default-entity-name="ShipmentTimeEstimate" auth="true">
+        <description>Expire a ShipmentTimeEstimate</description>
+        <auto-attributes include="pk" mode="IN"/>
+    </service>
+
     <service name="updateShipmentReceipt" engine="entity-auto" invoke="update" default-entity-name="ShipmentReceipt" auth="true">
         <description>Update a ShipmentReceipt record</description>
         <auto-attributes include="pk" mode="IN"/>

Added: ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl?rev=1840579&view=auto
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl (added)
+++ ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl Tue Sep 11 14:36:08 2018
@@ -0,0 +1,40 @@
+<#--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<form name="addscte" method="post" action="<@ofbizUrl>${targetUrl!}</@ofbizUrl>">
+    <table cellspacing="0" class="basic-table">
+        <tr>
+            <td align="right" class="label">${uiLabelMap.ProductCarrierShipmentMethod}</td>
+            <td>
+                <select name="carrierShipmentString">
+                    <option>${uiLabelMap.ProductSelectOne}</option>
+                <#list carrierShipmentMethods as shipmentMethod>
+                    <option value="${shipmentMethod.partyId}|${shipmentMethod.roleTypeId}|${shipmentMethod.shipmentMethodTypeId}">${shipmentMethod.shipmentMethodTypeId} (${shipmentMethod.partyId}/${shipmentMethod.roleTypeId})</option>
+                </#list>
+                </select>
+            </td>
+        </tr>
+        <tr>
+            <td></td>
+            <td>
+                <input type="submit" class="smallSubmit" value="${uiLabelMap.CommonAdd}"/>
+            </td>
+        </tr>
+    </table>
+</form>
+

Propchange: ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl
------------------------------------------------------------------------------
    svn:keywords = Date Rev Author URL Id

Propchange: ofbiz/ofbiz-framework/trunk/applications/product/template/shipment/SelectShipmentMethod.ftl
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/ofbiz-framework/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/webapp/catalog/WEB-INF/controller.xml Tue Sep 11 14:36:08 2018
@@ -2092,6 +2092,7 @@ under the License.
         <security https="true" auth="true"/>
         <response name="success" type="view" value="EditProductStoreShipmentCostEstimates"/>
     </request-map>
+    <request-map uri="EditProductStoreShipmentTimeEstimates"><security https="true" auth="true"/><response name="success" type="view" value="EditProductStoreShipmentCostEstimates"/></request-map>
     <request-map uri="storeCreateShipRate">
         <security https="true" auth="true"/>
         <event type="service" invoke="createShipmentEstimate"/>
@@ -2201,6 +2202,33 @@ under the License.
         <response name="error" type="view" value="ListCarrierShipmentMethods"/>
     </request-map>
 
+    <!-- ================ ShipmentTimeEstimate Requests ================= -->
+    <request-map uri="ListShipmentTimeEstimates"><security https="true" auth="true"/><response name="success" type="view" value="ListShipmentTimeEstimates"/></request-map>
+    <request-map uri="prepareCreateShipmentTimeEstimate">
+        <security https="true" auth="true"/>
+        <event type="groovy" path="component://product/groovyScripts/catalog/PrepareCreateShipmentTimeEstimate.groovy"/>
+        <response name="success" type="view" value="ListShipmentTimeEstimates"/>
+        <response name="error" type="view" value="ListShipmentTimeEstimates"/>
+    </request-map>
+    <request-map uri="createShipmentTimeEstimate">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="createShipmentTimeEstimate"/>
+        <response name="success" type="view" value="ListShipmentTimeEstimates"/>
+        <response name="error" type="view" value="ListShipmentTimeEstimates"/>
+    </request-map>
+    <request-map uri="updateShipmentTimeEstimate">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="updateShipmentTimeEstimate"/>
+        <response name="success" type="view" value="ListShipmentTimeEstimates"/>
+        <response name="error" type="view" value="ListShipmentTimeEstimates"/>
+    </request-map>
+    <request-map uri="expireShipmentTimeEstimate">
+        <security https="true" auth="true"/>
+        <event type="service" invoke="expireShipmentTimeEstimate"/>
+        <response name="success" type="view" value="ListShipmentTimeEstimates"/>
+        <response name="error" type="view" value="ListShipmentTimeEstimates"/>
+    </request-map>
+
     <!-- ================ ProductStore Survey Requests ================= -->
     <request-map uri="EditProductStoreSurveys">
         <security https="true" auth="true"/>
@@ -3211,6 +3239,7 @@ under the License.
     <view-map name="ListQuantityBreaks" type="screen" page="component://product/widget/catalog/ShippingScreens.xml#ListQuantityBreaks"/>
     <view-map name="ListShipmentMethodTypes" type="screen" page="component://product/widget/catalog/ShippingScreens.xml#ListShipmentMethodTypes"/>
     <view-map name="ListCarrierShipmentMethods" type="screen" page="component://product/widget/catalog/ShippingScreens.xml#ListCarrierShipmentMethods"/>
+    <view-map name="ListShipmentTimeEstimates" type="screen" page="component://product/widget/catalog/ShippingScreens.xml#ListShipmentTimeEstimates"/>
 
     <view-map name="EditProductTag" type="screen" page="component://product/widget/catalog/ProductScreens.xml#EditProductTag"/>
 

Modified: ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/CatalogMenus.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/CatalogMenus.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/CatalogMenus.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/CatalogMenus.xml Tue Sep 11 14:36:08 2018
@@ -97,6 +97,9 @@ under the License.
         <menu-item name="ListCarrierShipmentMethods" title="${uiLabelMap.ProductCarrierShipmentMethods}">
             <link target="ListCarrierShipmentMethods"/>
         </menu-item>
+        <menu-item name="ListShipmentTimeEstimates" title="${uiLabelMap.ProductShipmentTimeEstimates}">
+            <link target="ListShipmentTimeEstimates"/>
+        </menu-item>
     </menu>
 
     <menu name="CategoryTabBar" extends="CommonTabBarMenu" extends-resource="component://common/widget/CommonMenus.xml">

Modified: ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingForms.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingForms.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingForms.xml Tue Sep 11 14:36:08 2018
@@ -118,4 +118,50 @@
         <field name="sequenceNumber" tooltip="${uiLabelMap.ProductUsedForDisplayOrdering}"><text/></field>
         <field name="submitButton" title="${uiLabelMap.CommonSubmit}" widget-style="smallSubmit"><submit button-type="button"/></field>
     </form>
+
+    <form name="ListShipmentTimeEstimates" target="" title="" type="list"  list-name="shipmentTimeEstimates"
+        paginate-target="ListShipmentTimeEstimates" odd-row-style="alternate-row" default-table-style="basic-table">
+        <field name="shipmentMethodTypeId"><display-entity entity-name="ShipmentMethodType" description="${description} [${shipmentMethodTypeId}]"/></field>
+        <field name="partyId"><display-entity entity-name="PartyNameView" description="${firstName} ${middleName} ${lastName} ${groupName} [${partyId}]"/></field>
+        <field name="roleTypeId"><display-entity entity-name="RoleType"/></field>
+        <field name="geoIdFrom"><display-entity entity-name="Geo" key-field-name="geoId" description="${geoName}"/></field>
+        <field name="geoIdTo"><display-entity entity-name="Geo" key-field-name="geoId" description="${geoName}"/></field>
+        <field name="fromDate"><display type="date-time"/></field>
+        <field name="thruDate"><display type="date-time"/></field>
+        <field name="leadTime"><display/></field>
+        <field name="leadTimeUomId"><display-entity entity-name="Uom" key-field-name="uomId"/></field>
+        <field name="editLink" title=" " widget-style="buttontext">
+            <hyperlink target="ListShipmentTimeEstimates" description="${uiLabelMap.CommonEdit}" also-hidden="false">
+                <auto-parameters-service service-name="updateShipmentTimeEstimate"/>
+            </hyperlink>
+        </field>
+        <field name="expireLink" title=" " widget-style="buttontext">
+            <hyperlink target="expireShipmentTimeEstimate" description="${uiLabelMap.CommonExpire}" also-hidden="false">
+                <auto-parameters-service service-name="expireShipmentTimeEstimate"/>
+            </hyperlink>
+        </field>
+    </form>
+    <form name="EditShipmentTimeEstimate" type="single" target="createShipmentTimeEstimate" title="" default-map-name="shipmentTimeEstimate"
+        header-row-style="header-row" default-table-style="basic-table">
+        <alt-target use-when="shipmentTimeEstimate != null" target="updateShipmentTimeEstimate"/>
+        <field name="shipmentMethodTypeId"><display-entity entity-name="ShipmentMethodType" description="${description} [${shipmentMethodTypeId}]"/></field>
+        <field name="partyId"><display-entity entity-name="PartyNameView" description="${firstName} ${middleName} ${lastName} ${groupName} [${partyId}]"/></field>
+        <field name="roleTypeId"><display-entity entity-name="RoleType"/></field>
+        <field name="geoIdTo" use-when="shipmentTimeEstimate == null"><lookup target-form-name="LookupGeo" default-value="_NA_"/></field>
+        <field name="geoIdTo" use-when="shipmentTimeEstimate != null"><display-entity entity-name="Geo" key-field-name="geoId" description="${geoName}"/></field>
+        <field name="geoIdFrom" use-when="shipmentTimeEstimate == null"><lookup target-form-name="LookupGeo" default-value="_NA_"/></field>
+        <field name="geoIdFrom" use-when="shipmentTimeEstimate != null"><display-entity entity-name="Geo" key-field-name="geoId" description="${geoName}"/></field>
+        <field name="fromDate" use-when="shipmentTimeEstimate == null"><date-time/></field>
+        <field name="fromDate" use-when="shipmentTimeEstimate != null"><display/></field>
+        <field name="thruDate"><date-time/></field>
+        <field name="leadTime" required-field="true"><text/></field>
+        <field name="leadTimeUomId">
+            <drop-down no-current-selected-key="TF_day" current="selected">
+                <entity-options entity-name="Uom" description="${description}" key-field-name="uomId">
+                    <entity-constraint name="uomTypeId" value="TIME_FREQ_MEASURE"/>
+                </entity-options>
+            </drop-down>
+        </field>
+        <field name="submitButton" title="${uiLabelMap.CommonSubmit}" widget-style="smallSubmit"><submit button-type="button"/></field>
+    </form>
 </forms>

Modified: ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingScreens.xml?rev=1840579&r1=1840578&r2=1840579&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingScreens.xml (original)
+++ ofbiz/ofbiz-framework/trunk/applications/product/widget/catalog/ShippingScreens.xml Tue Sep 11 14:36:08 2018
@@ -103,4 +103,65 @@ under the License.
        </section>
     </screen>
 
+    <screen name="ListShipmentTimeEstimates">
+       <section>
+            <actions>
+                <set field="titleProperty" value="PageTitleListShipmentTimeEstimates"/>
+                <set field="headerItem" value="shipping"/>
+                <set field="tabButtonItem" value="ListShipmentTimeEstimates"/>
+
+                <entity-condition entity-name="ShipmentTimeEstimate" list="shipmentTimeEstimates">
+                    <order-by field-name="shipmentMethodTypeId"/>
+                </entity-condition>
+                <entity-one entity-name="ShipmentTimeEstimate" value-field="shipmentTimeEstimate"/>
+
+                <entity-condition entity-name="CarrierShipmentMethod" list="carrierShipmentMethods">
+                    <order-by field-name="sequenceNumber"/>
+                </entity-condition>
+                <set field="targetUrl" value="prepareCreateShipmentTimeEstimate"/><!-- Necessary for SelectShipmentMethod.ftl -->
+
+                <entity-one entity-name="CarrierShipmentMethod" value-field="carrierShipmentMethod"/>
+
+                <set field="dependentForm" value="EditShipmentTimeEstimate"/>
+                <set field="paramKey" value="shipmentMethodTypeId"/>
+                <set field="mainId" value="shipmentMethodTypeId"/>
+                <set field="dependentId" value="partyId"/>
+                <set field="requestName" value="getShipmentPartyList"/>
+                <set field="responseName" value="partyList"/>
+                <set field="dependentKeyName" value="partyId"/>
+                <set field="descName" value="partyName"/>
+                <set field="selectedDependentOption" from-field="shipmentMethodTypeId" default-value="_none_"/>
+            </actions>
+            <widgets>
+                <decorator-screen name="CommonShippingDecorator" location="${parameters.mainDecoratorLocation}">
+                    <decorator-section name="body">
+                        <screenlet title="${uiLabelMap.PageTitleListShipmentTimeEstimates}">
+                            <include-form name="ListShipmentTimeEstimates" location="component://product/widget/catalog/ShippingForms.xml"/>
+                        </screenlet>
+                        <section>
+                            <condition>
+                                <and>
+                                    <if-empty field="carrierShipmentMethod"/>
+                                    <if-empty field="parameters.addShipmentMethodEstimate"/>
+                                </and>
+                            </condition>
+                            <widgets>
+                                <screenlet title="${uiLabelMap.PageTitleEditShipmentTimeEstimates}">
+                                    <platform-specific>
+                                        <html><html-template location="component://product/template/shipment/SelectShipmentMethod.ftl"/></html>
+                                    </platform-specific>
+                                </screenlet>
+                            </widgets>
+                            <fail-widgets>
+                                <screenlet title="${uiLabelMap.PageTitleEditShipmentTimeEstimates}">
+                                    <include-form name="EditShipmentTimeEstimate" location="component://product/widget/catalog/ShippingForms.xml"/>
+                                </screenlet>
+                            </fail-widgets>
+                        </section>
+                    </decorator-section>
+                </decorator-screen>
+            </widgets>
+       </section>
+    </screen>
+
 </screens>