Author: mor
Date: Wed Jun 3 07:18:58 2009 New Revision: 781283 URL: http://svn.apache.org/viewvc?rev=781283&view=rev Log: Added an option to create a duplicate order with total adjusted to $0 from an existing order in case of shipment is lost for the existing order etc. This order can be created through a new link "Create Replacement Order" under Action screelet on the Order Detail Page. This link only appear for an order in complete status. Modified: ofbiz/trunk/applications/order/config/OrderUiLabels.xml ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml ofbiz/trunk/applications/order/webapp/ordermgr/order/ordershippinginfo.ftl Modified: ofbiz/trunk/applications/order/config/OrderUiLabels.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/config/OrderUiLabels.xml?rev=781283&r1=781282&r2=781283&view=diff ============================================================================== --- ofbiz/trunk/applications/order/config/OrderUiLabels.xml (original) +++ ofbiz/trunk/applications/order/config/OrderUiLabels.xml Wed Jun 3 07:18:58 2009 @@ -6900,6 +6900,9 @@ <value xml:lang="th">à¸à¸±à¸à¸£à¸²</value> <value xml:lang="zh">è¯çº§</value> </property> + <property key="OrderCreateReplacementOrder"> + <value xml:lang="en">Create Replacement Order</value> + </property> <property key="OrderReAuthService"> <value xml:lang="en">Re Auth Service</value> <value xml:lang="es">Servicio de reautentificación</value> Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java?rev=781283&r1=781282&r2=781283&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/CheckOutEvents.java Wed Jun 3 07:18:58 2009 @@ -20,7 +20,6 @@ import java.math.BigDecimal; import java.text.DecimalFormat; -import java.text.ParseException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -35,7 +34,9 @@ import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; +import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.marketing.tracking.TrackingCodeEvents; +import org.ofbiz.order.order.OrderReadHelper; import org.ofbiz.party.party.PartyWorker; import org.ofbiz.product.catalog.CatalogWorker; import org.ofbiz.product.store.ProductStoreWorker; @@ -1071,4 +1072,62 @@ return null; } } -} + + /** Create a replacement order from an existing order against a lost shipment etc. **/ + public static String createReplacementOrder(HttpServletRequest request, HttpServletResponse response) { + LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); + GenericDelegator delegator = (GenericDelegator) request.getAttribute("delegator"); + HttpSession session = request.getSession(); + GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); + ShoppingCart cart = (ShoppingCart) request.getSession().getAttribute("shoppingCart"); + + Map context = cart.makeCartMap(dispatcher, false); + String originalOrderId = request.getParameter("orderId"); + + // create the replacement order adjustment + List <GenericValue>orderAdjustments = (List) context.get("orderAdjustments"); + List <GenericValue>orderItems = (List) context.get("orderItems"); + OrderReadHelper orderReadHelper = new OrderReadHelper(orderAdjustments, orderItems); + BigDecimal grandTotal = orderReadHelper.getOrderGrandTotal(); + if (grandTotal.compareTo(new BigDecimal(0)) != 0) { + GenericValue adjustment = delegator.makeValue("OrderAdjustment"); + adjustment.set("orderAdjustmentTypeId", "REPLACE_ADJUSTMENT"); + adjustment.set("amount", grandTotal.negate()); + adjustment.set("comments", "ReShip Order for Order #" + originalOrderId); + adjustment.set("createdDate", UtilDateTime.nowTimestamp()); + adjustment.set("createdByUserLogin", userLogin.getString("userLoginId")); + cart.addAdjustment(adjustment); + } + // create the order association + List<ShoppingCartItem> cartLines = cart.items(); + for (ShoppingCartItem sci : cartLines) { + int index = cart.getItemIndex(sci); + try { + Map orderItemMap = FastMap.newInstance(); + orderItemMap.put("orderId", originalOrderId); + orderItemMap.put("isPromo", sci.getIsPromo() ? "Y" : "N"); + orderItemMap.put("productId", sci.getProductId()); + orderItemMap.put("orderItemTypeId", sci.getItemType()); + GenericValue orderItem = EntityUtil.getFirst(delegator.findByAnd("OrderItem", orderItemMap)); + if (UtilValidate.isNotEmpty(orderItem)) { + sci.setAssociatedOrderId(orderItem.getString("orderId")); + sci.setAssociatedOrderItemSeqId(orderItem.getString("orderItemSeqId")); + sci.setOrderItemAssocTypeId("REPLACEMENT"); + cart.addItem(index, sci); + } + } catch (GenericEntityException e) { + Debug.logError(e, module); + } catch (CartItemModifyException e) { + Debug.logError(e.getMessage(), module); + } + } + + String result = createOrder(request, response); + if ("error".equals(result)) { + return "error"; + } else { + request.setAttribute("orderId", request.getAttribute("orderId")); + return "success"; + } + } +} \ No newline at end of file Modified: ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml?rev=781283&r1=781282&r2=781283&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/WEB-INF/controller.xml Wed Jun 3 07:18:58 2009 @@ -483,6 +483,27 @@ <response name="success" type="request" value="finalizeOrder"/> <response name="error" type="view" value="orderview"/> </request-map> + + <!-- Create a replacement order from an existing order against a lost shipment etc. --> + <request-map uri="loadCartForReplacementOrder"> + <security https="true" auth="true"/> + <event type="java" path="org.ofbiz.order.shoppingcart.ShoppingCartEvents" invoke="loadCartFromOrder"/> + <response name="success" type="request" value="createReplacementOrder"/> + <response name="error" type="view" value="orderview"/> + </request-map> + <request-map uri="createReplacementOrder"> + <security https="true" auth="true"/> + <event type="java" path="org.ofbiz.order.shoppingcart.CheckOutEvents" invoke="createReplacementOrder"/> + <response name="success" type="request" value="clearCartForReplacementOrder"/> + <response name="error" type="view" value="orderview"/> + </request-map> + <request-map uri="clearCartForReplacementOrder"> + <security https="true" auth="true"/> + <event type="java" path="org.ofbiz.order.shoppingcart.ShoppingCartEvents" invoke="destroyCart"/> + <response name="success" type="view" value="orderview"/> + <response name="success" type="view" value="orderview"/> + </request-map> + <request-map uri="addseperator"> <security https="true" auth="true"/> <event type="java" path="org.ofbiz.order.shoppingcart.ShoppingCartEvents" invoke="addSeparator"/> Modified: ofbiz/trunk/applications/order/webapp/ordermgr/order/ordershippinginfo.ftl URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/webapp/ordermgr/order/ordershippinginfo.ftl?rev=781283&r1=781282&r2=781283&view=diff ============================================================================== --- ofbiz/trunk/applications/order/webapp/ordermgr/order/ordershippinginfo.ftl (original) +++ ofbiz/trunk/applications/order/webapp/ordermgr/order/ordershippinginfo.ftl Wed Jun 3 07:18:58 2009 @@ -97,6 +97,9 @@ <li><a href="<@ofbizUrl>editOrderItems?${paramString}</@ofbizUrl>" class="buttontext">${uiLabelMap.OrderEditItems}</a></li> </#if> <li><a href="<@ofbizUrl>loadCartFromOrder?${paramString}&finalizeMode=init</@ofbizUrl>" class="buttontext">${uiLabelMap.OrderCreateAsNewOrder}</a></li> + <#if orderHeader.statusId == "ORDER_COMPLETED"> + <li><a href="<@ofbizUrl>loadCartForReplacementOrder?${paramString}</@ofbizUrl>" class="buttontext">${uiLabelMap.OrderCreateReplacementOrder}</a></li> + </#if> </#if> <li><a href="<@ofbizUrl>OrderHistory?orderId=${orderId}</@ofbizUrl>" class="buttontext">${uiLabelMap.OrderOrderHistory}</a></li> </ul> |
Free forum by Nabble | Edit this page |