Author: jleroux
Date: Mon Feb 16 12:04:55 2009 New Revision: 744902 URL: http://svn.apache.org/viewvc?rev=744902&view=rev Log: As suggested in dev ML: Currently the 'historic" promotions (PPIP_ORST_HIST, PPIP_ORST_YEAR, PPIP_ORST_LAST_YEAR) do not include taxes in their calculation which uses remainingSubTotal. But, for B2C, in countries which are used to (or must) show prices with taxes (most of countries using VAT I guess), the price the client effectively pay is taxes included (the final client will never get back taxes paid, contrary to B2B case). So I propose to introduce a new field in ProductStore, namely includeTaxInRemainingSubTotal. If this field is set to Yes, then in the calculation of remainingSubTotal (done in service resetGrandTotal), the taxes will be included. Actually my question is : in order to minize the number of fields and keep them consistent maybe we could simply use showPricesWithVatTax. It could be argued though that we really need to create the new field includeTaxInRemainingSubTotal in order to be able to deal with B2B case. But maybe it's no really needed because we set the field showPricesWithVatTax to Yes for the same basic reason that bring us to include taxes in remainingSubTotal calculation. Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=744902&r1=744901&r2=744902&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderServices.java Mon Feb 16 12:04:55 2009 @@ -1272,8 +1272,27 @@ // get the new grand total BigDecimal updatedTotal = orh.getOrderGrandTotal(); - // calculate subTotal as grandTotal - returnsTotal - (tax + shipping of items not returned) - BigDecimal remainingSubTotal = updatedTotal.subtract(orh.getOrderReturnedTotal()).subtract(orh.getOrderNonReturnedTaxAndShipping()); + String productStoreId = orderHeader.getString("productStoreId"); + String showPricesWithVatTax = null; + if (UtilValidate.isNotEmpty(productStoreId)) { + GenericValue productStore = null; + try { + productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId)); + } catch (GenericEntityException e) { + String errorMessage = UtilProperties.getMessage(resource_error, "OrderErrorCouldNotFindProductStoreWithID", UtilMisc.toMap("productStoreId", productStoreId), (Locale) context.get("locale")) + e.toString(); + Debug.logError(e, errorMessage, module); + return ServiceUtil.returnError(errorMessage + e.getMessage() + ")."); + } + showPricesWithVatTax = productStore.getString("showPricesWithVatTax"); + } + BigDecimal remainingSubTotal = ZERO; + if (UtilValidate.isNotEmpty(productStoreId) && "Y".equalsIgnoreCase(showPricesWithVatTax)) { + // calculate subTotal as grandTotal + taxes - (returnsTotal + shipping of all items) + remainingSubTotal = updatedTotal.subtract(orh.getOrderReturnedTotal()).subtract(orh.getShippingTotal()); + } else { + // calculate subTotal as grandTotal - returnsTotal - (tax + shipping of items not returned) + remainingSubTotal = updatedTotal.subtract(orh.getOrderReturnedTotal()).subtract(orh.getOrderNonReturnedTaxAndShipping()); + } if (currentTotal == null || currentSubTotal == null || updatedTotal.compareTo(currentTotal) != 0 || remainingSubTotal.compareTo(currentSubTotal) != 0) { @@ -3352,7 +3371,7 @@ Map itemPriceMap = (Map) context.get("itemPriceMap"); Map itemQtyMap = (Map) context.get("itemQtyMap"); Map itemReasonMap = (Map) context.get("itemReasonMap"); - Map itemCommentMap = (Map) context.get("itemCommentMap"); + Map itemCommentMap = (Map) context.get("itemCommentMap"); Map itemAttributesMap = (Map) context.get("itemAttributesMap"); // obtain a shopping cart object for updating @@ -3519,6 +3538,28 @@ return result; } + public static Map loadCartForUpdate(DispatchContext dctx, Map context){ + LocalDispatcher dispatcher = dctx.getDispatcher(); + GenericDelegator delegator = dctx.getDelegator(); + + String orderId = (String) context.get("orderId"); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + + ShoppingCart cart = null; + Map result = null; + try { + cart = loadCartForUpdate(dispatcher, delegator, userLogin, orderId); + result = ServiceUtil.returnSuccess(); + result.put("shoppingCart", cart); + } catch (GeneralException e) { + Debug.logError(e, module); + result = ServiceUtil.returnError(e.getMessage()); + } + + result.put("orderId", orderId); + return result; + } + /* * Warning: loadCartForUpdate(...) and saveUpdatedCartToOrder(...) must always * be used together in this sequence. @@ -3685,6 +3726,31 @@ return cart; } + public static Map saveUpdatedCartToOrder(DispatchContext dctx, Map context) throws GeneralException { + + LocalDispatcher dispatcher = dctx.getDispatcher(); + GenericDelegator delegator = dctx.getDelegator(); + + String orderId = (String) context.get("orderId"); + GenericValue userLogin = (GenericValue) context.get("userLogin"); + ShoppingCart cart = (ShoppingCart) context.get("shoppingCart"); + Map changeMap = (Map) context.get("changeMap"); + Locale locale = (Locale) context.get("locale"); + + Map result = null; + try { + saveUpdatedCartToOrder(dispatcher, delegator, cart, locale, userLogin, orderId, changeMap); + result = ServiceUtil.returnSuccess(); + //result.put("shoppingCart", cart); + } catch (GeneralException e) { + Debug.logError(e, module); + result = ServiceUtil.returnError(e.getMessage()); + } + + result.put("orderId", orderId); + return result; + } + private static void saveUpdatedCartToOrder(LocalDispatcher dispatcher, GenericDelegator delegator, ShoppingCart cart, Locale locale, GenericValue userLogin, String orderId, Map changeMap) throws GeneralException { // get/set the shipping estimates. if it's a SALES ORDER, then return an error if there are no ship estimates int shipGroups = cart.getShipGroupSize(); |
Free forum by Nabble | Edit this page |