Modified: ofbiz/trunk/applications/order/servicedef/services_requirement.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_requirement.xml?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_requirement.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_requirement.xml Mon Jan 5 23:13:36 2009 @@ -102,8 +102,8 @@ <attribute mode="IN" name="statusIds" type="List" optional="true"/> <!-- By default, this service looks for approved requirements. To override this, pass in a list of requirement statusIds to search. --> <attribute mode="OUT" name="requirementsForSupplier" type="java.util.List" optional="true"/> <attribute mode="OUT" name="distinctProductCount" type="Integer" optional="true"/> - <attribute mode="OUT" name="quantityTotal" type="Double" optional="true"/> - <attribute mode="OUT" name="amountTotal" type="Double" optional="true"/> + <attribute mode="OUT" name="quantityTotal" type="BigDecimal" optional="true"/> + <attribute mode="OUT" name="amountTotal" type="BigDecimal" optional="true"/> </service> <service name="createOrderRequirementCommitment" engine="simple" auth="true" location="org/ofbiz/order/order/OrderServices.xml" invoke="createOrderRequirementCommitment"> @@ -116,7 +116,7 @@ <attribute name="orderId" type="String" mode="IN" optional="false"/> <attribute name="orderItemSeqId" type="String" mode="IN" optional="false"/> <attribute name="productId" type="String" mode="IN" optional="true"/> - <attribute name="quantity" type="Double" mode="IN" optional="true"/> + <attribute name="quantity" type="BigDecimal" mode="IN" optional="true"/> <attribute name="requirementId" type="String" mode="OUT" optional="true"/> </service> <service name="checkCreateStockRequirementQoh" engine="simple" auth="true" default-entity-name="ItemIssuance" @@ -136,7 +136,7 @@ <attribute name="orderItemSeqId" type="String" mode="IN" optional="false"/> <attribute name="inventoryItemId" type="String" mode="IN" optional="true"/> <attribute name="productId" type="String" mode="IN" optional="true"/> - <attribute name="quantity" type="Double" mode="IN" optional="true"/> + <attribute name="quantity" type="BigDecimal" mode="IN" optional="true"/> <attribute name="requirementId" type="String" mode="OUT" optional="true"/> </service> <service name="createRequirementFromItemATP" engine="simple" auth="true" @@ -147,7 +147,7 @@ <attribute name="orderItemSeqId" type="String" mode="IN" optional="false"/> <attribute name="inventoryItemId" type="String" mode="IN" optional="true"/> <attribute name="productId" type="String" mode="IN" optional="true"/> - <attribute name="quantity" type="Double" mode="IN" optional="true"/> + <attribute name="quantity" type="BigDecimal" mode="IN" optional="true"/> <attribute name="requirementId" type="String" mode="OUT" optional="true"/> </service> @@ -162,7 +162,7 @@ location="org.ofbiz.manufacturing.jobshopmgt.ProductionRunServices" invoke="approveRequirement" auth="true"> <description>Approves a requirement.</description> <attribute mode="IN" name="requirementId" optional="false" type="String"/> - <attribute mode="IN" name="quantity" optional="true" type="Double"/> + <attribute mode="IN" name="quantity" optional="true" type="BigDecimal"/> </service> <service name="autoAssignRequirementToSupplier" engine="simple" auth="true" @@ -176,7 +176,7 @@ <description>Create the inventory transfers required to fulfill the requirement.</description> <attribute mode="IN" name="requirementId" optional="false" type="String"/> <attribute mode="IN" name="fromFacilityId" optional="false" type="String"/> - <attribute mode="IN" name="quantity" optional="true" type="Double"/> + <attribute mode="IN" name="quantity" optional="true" type="BigDecimal"/> </service> <service name="createAutoRequirementsForOrder" engine="java" Modified: ofbiz/trunk/applications/order/servicedef/services_return.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_return.xml?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_return.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_return.xml Mon Jan 5 23:13:36 2009 @@ -131,8 +131,8 @@ invoke="updateReturnAdjustment"> <description></description> <implements service="returnAdjustmentInterface"/> - <attribute name="originalReturnPrice" type="Double" mode="IN" optional="true"/> - <attribute name="originalReturnQuantity" type="Double" mode="IN" optional="true"/> + <attribute name="originalReturnPrice" type="BigDecimal" mode="IN" optional="true"/> + <attribute name="originalReturnQuantity" type="BigDecimal" mode="IN" optional="true"/> <override name="returnAdjustmentId" optional="false"/> </service> <service name="removeReturnAdjustment" engine="simple" location="org/ofbiz/order/order/OrderReturnServices.xml" @@ -184,7 +184,7 @@ <description>Gets the item's initial cost based on the inventory item record associated with the order item or 0.00 if none found.</description> <attribute name="returnId" type="String" mode="IN" optional="false"/> <attribute name="returnItemSeqId" type="String" mode="IN" optional="false"/> - <attribute name="initialItemCost" type="Double" mode="OUT" optional="false"/> + <attribute name="initialItemCost" type="BigDecimal" mode="OUT" optional="false"/> </service> <service name="checkReturnComplete" engine="java" @@ -260,8 +260,8 @@ location="org.ofbiz.order.order.OrderReturnServices" invoke="getReturnableQuantity"> <description>Get the quantity allowed for an item to be returned</description> <attribute name="orderItem" type="GenericValue" mode="IN" optional="false"/> - <attribute name="returnableQuantity" type="Double" mode="OUT" optional="false"/> - <attribute name="returnablePrice" type="Double" mode="OUT" optional="false"/> + <attribute name="returnableQuantity" type="BigDecimal" mode="OUT" optional="false"/> + <attribute name="returnablePrice" type="BigDecimal" mode="OUT" optional="false"/> </service> <service name="getReturnableItems" engine="java" location="org.ofbiz.order.order.OrderReturnServices" invoke="getReturnableItems"> @@ -285,7 +285,7 @@ location="org.ofbiz.order.order.OrderReturnServices" invoke="refundBillingAccountPayment" auth="true"> <description>Refunds A Billing Account Payment</description> <attribute name="orderPaymentPreference" type="GenericValue" mode="IN" optional="false"/> - <attribute name="refundAmount" type="Double" mode="IN" optional="false"/> + <attribute name="refundAmount" type="BigDecimal" mode="IN" optional="false"/> <attribute name="paymentId" type="String" mode="OUT" optional="false"/> </service> Modified: ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml (original) +++ ofbiz/trunk/applications/order/servicedef/services_shoppinglist.xml Mon Jan 5 23:13:36 2009 @@ -58,10 +58,10 @@ <attribute name="partyId" type="String" mode="IN" optional="true"/> <attribute name="productStoreId" type="String" mode="IN" optional="true"/> <attribute name="productStoreGroupId" type="String" mode="IN" optional="true"/> - <attribute name="quantity" type="Double" mode="IN" optional="true"/> + <attribute name="quantity" type="BigDecimal" mode="IN" optional="true"/> <attribute name="currencyUomId" type="String" mode="IN" optional="true"/> <attribute name="autoUserLogin" type="GenericValue" mode="IN" optional="true"/> - <attribute name="totalPrice" type="Double" mode="OUT" optional="false"/> + <attribute name="totalPrice" type="BigDecimal" mode="OUT" optional="false"/> </service> <service name="runShoppingListAutoReorder" engine="java" auth="true" use-transaction="false" @@ -100,11 +100,11 @@ <description>Interface of shopping list items</description> <attribute name="shoppingListId" type="String" mode="IN" optional="false"/> <attribute name="productId" type="String" mode="IN" optional="true"/> - <attribute name="quantity" type="Double" mode="IN" optional="true"/> + <attribute name="quantity" type="BigDecimal" mode="IN" optional="true"/> <attribute name="reservStart" type="Timestamp" mode="IN" optional="true"/> - <attribute name="reservLength" type="Double" mode="IN" optional="true"/> - <attribute name="reservPersons" type="Double" mode="IN" optional="true"/> - <attribute name="quantityPurchased" type="Double" mode="IN" optional="true"/> + <attribute name="reservLength" type="BigDecimal" mode="IN" optional="true"/> + <attribute name="reservPersons" type="BigDecimal" mode="IN" optional="true"/> + <attribute name="quantityPurchased" type="BigDecimal" mode="IN" optional="true"/> <attribute name="configId" type="String" mode="IN" optional="true"/> </service> <service name="createShoppingListItem" engine="simple" auth="true" Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/OrderManagerEvents.java Mon Jan 5 23:13:36 2009 @@ -18,6 +18,7 @@ */ package org.ofbiz.order; +import java.math.BigDecimal; import java.text.NumberFormat; import java.util.Iterator; import java.util.LinkedList; @@ -141,9 +142,9 @@ return "error"; } - Double grandTotal = new Double(0.00); + BigDecimal grandTotal = BigDecimal.ZERO; if (orderHeader != null) { - grandTotal = orderHeader.getDouble("grandTotal"); + grandTotal = orderHeader.getBigDecimal("grandTotal"); } // get the payment types to receive @@ -182,21 +183,21 @@ String amountStr = request.getParameter(paymentMethodTypeId + "_amount"); String paymentReference = request.getParameter(paymentMethodTypeId + "_reference"); if (!UtilValidate.isEmpty(amountStr)) { - double paymentTypeAmount = 0.00; + BigDecimal paymentTypeAmount = BigDecimal.ZERO; try { - paymentTypeAmount = NumberFormat.getNumberInstance(locale).parse(amountStr).doubleValue(); + paymentTypeAmount = new BigDecimal(NumberFormat.getNumberInstance(locale).parse(amountStr).doubleValue()); } catch (java.text.ParseException pe) { request.setAttribute("_ERROR_MESSAGE_", UtilProperties.getMessage(resource_error,"OrderProblemsPaymentParsingAmount", locale)); return "error"; } - if (paymentTypeAmount > 0.00) { + if (paymentTypeAmount.compareTo(BigDecimal.ZERO) > 0) { // create the OrderPaymentPreference // TODO: this should be done with a service Map prefFields = UtilMisc.toMap("orderPaymentPreferenceId", delegator.getNextSeqId("OrderPaymentPreference")); GenericValue paymentPreference = delegator.makeValue("OrderPaymentPreference", prefFields); paymentPreference.set("paymentMethodTypeId", paymentMethodType.getString("paymentMethodTypeId")); - paymentPreference.set("maxAmount", new Double(paymentTypeAmount)); + paymentPreference.set("maxAmount", paymentTypeAmount); paymentPreference.set("statusId", "PAYMENT_RECEIVED"); paymentPreference.set("orderId", orderId); paymentPreference.set("createdDate", UtilDateTime.nowTimestamp()); @@ -236,7 +237,7 @@ // get the current payment prefs GenericValue offlineValue = null; List currentPrefs = null; - double paymentTally = 0.00; + BigDecimal paymentTally = BigDecimal.ZERO; try { EntityConditionList<EntityExpr> ecl = EntityCondition.makeCondition(UtilMisc.toList( EntityCondition.makeCondition("orderId", EntityOperator.EQUALS, orderId), @@ -254,9 +255,9 @@ if ("EXT_OFFLINE".equals(paymentMethodType)) { offlineValue = cp; } else { - Double cpAmt = cp.getDouble("maxAmount"); + BigDecimal cpAmt = cp.getBigDecimal("maxAmount"); if (cpAmt != null) { - paymentTally += cpAmt.doubleValue(); + paymentTally = paymentTally.add(cpAmt); } } } @@ -264,7 +265,7 @@ // now finish up boolean okayToApprove = false; - if (paymentTally >= grandTotal.doubleValue()) { + if (paymentTally.compareTo(grandTotal) >= 0) { // cancel the offline preference okayToApprove = true; if (offlineValue != null) { Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/finaccount/FinAccountHelper.java Mon Jan 5 23:13:36 2009 @@ -84,7 +84,7 @@ if ((transactions != null) && (transactions.size() == 1)) { GenericValue firstEntry = (GenericValue) transactions.get(0); if (firstEntry.get(fieldName) != null) { - BigDecimal valueToAdd = new BigDecimal(firstEntry.getDouble(fieldName).doubleValue()); + BigDecimal valueToAdd = firstEntry.getBigDecimal(fieldName); return initialValue.add(valueToAdd).setScale(decimals, rounding); } else { return initialValue; Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java Mon Jan 5 23:13:36 2009 @@ -456,11 +456,11 @@ paramList.add("hasBackOrders=" + hasBackOrders); if ("Y".equals(hasBackOrders)) { conditions.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.NOT_EQUAL, null)); - conditions.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.GREATER_THAN, new Double(0))); + conditions.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.GREATER_THAN, BigDecimal.ZERO)); } else if ("N".equals(hasBackOrders)) { List orExpr = FastList.newInstance(); orExpr.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, null)); - orExpr.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, new Double(0))); + orExpr.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.EQUALS, BigDecimal.ZERO)); conditions.add(EntityCondition.makeCondition(orExpr, EntityOperator.OR)); } } 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?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Mon Jan 5 23:13:36 2009 @@ -203,7 +203,7 @@ } /** - * Returns a Map of paymentMethodId -> amount charged (Double) based on PaymentGatewayResponse. + * Returns a Map of paymentMethodId -> amount charged (BigDecimal) based on PaymentGatewayResponse. * @return */ public Map getReceivedPaymentTotalsByPaymentMethod() { @@ -232,15 +232,14 @@ } // if chargedToPaymentPref > 0 - if (chargedToPaymentPref.compareTo(ZERO) == 1) { + if (chargedToPaymentPref.compareTo(ZERO) > 0) { // key of the resulting map is paymentMethodId or paymentMethodTypeId if the paymentMethodId is not available String paymentMethodKey = paymentPref.getString("paymentMethodId") != null ? paymentPref.getString("paymentMethodId") : paymentPref.getString("paymentMethodTypeId"); if(paymentMethodAmounts.containsKey(paymentMethodKey)){ - Double value = (Double)paymentMethodAmounts.get(paymentMethodKey); - if(value != null) - chargedToPaymentPref = chargedToPaymentPref.add(new BigDecimal(value.doubleValue())); + BigDecimal value = (BigDecimal) paymentMethodAmounts.get(paymentMethodKey); + if (value != null) chargedToPaymentPref = chargedToPaymentPref.add(value); } - paymentMethodAmounts.put(paymentMethodKey, new Double(chargedToPaymentPref.setScale(scale, rounding).doubleValue())); + paymentMethodAmounts.put(paymentMethodKey, chargedToPaymentPref.setScale(scale, rounding)); } } return paymentMethodAmounts; @@ -272,7 +271,7 @@ // if refundedToPaymentPref > 0 if (refundedToPaymentPref.compareTo(ZERO) == 1) { String paymentMethodId = paymentPref.getString("paymentMethodId") != null ? paymentPref.getString("paymentMethodId") : paymentPref.getString("paymentMethodTypeId"); - paymentMethodAmounts.put(paymentMethodId, new Double(refundedToPaymentPref.setScale(scale, rounding).doubleValue())); + paymentMethodAmounts.put(paymentMethodId, refundedToPaymentPref.setScale(scale, rounding)); } } return paymentMethodAmounts; @@ -663,16 +662,16 @@ * Returns the OrderPaymentPreference.maxAmount for the billing account associated with the order, or 0 if there is no * billing account or no max amount set */ - public double getBillingAccountMaxAmount() { + public BigDecimal getBillingAccountMaxAmount() { if (getBillingAccount() == null) { - return 0.0; + return BigDecimal.ZERO; } else { List paymentPreferences = getPaymentPreferences(); GenericValue billingAccountPaymentPreference = EntityUtil.getFirst(EntityUtil.filterByAnd(paymentPreferences, UtilMisc.toMap("paymentMethodTypeId", "EXT_BILLACT"))); - if ((billingAccountPaymentPreference != null) && (billingAccountPaymentPreference.getDouble("maxAmount") != null)) { - return billingAccountPaymentPreference.getDouble("maxAmount").doubleValue(); + if ((billingAccountPaymentPreference != null) && (billingAccountPaymentPreference.getBigDecimal("maxAmount") != null)) { + return billingAccountPaymentPreference.getBigDecimal("maxAmount"); } else { - return 0.0; + return BigDecimal.ZERO; } } } @@ -835,11 +834,11 @@ Iterator fai = featureAppls.iterator(); while (fai.hasNext()) { GenericValue appl = (GenericValue) fai.next(); - Double lastQuantity = (Double) featureMap.get(appl.getString("productFeatureId")); + BigDecimal lastQuantity = (BigDecimal) featureMap.get(appl.getString("productFeatureId")); if (lastQuantity == null) { - lastQuantity = new Double(0); + lastQuantity = BigDecimal.ZERO; } - Double newQuantity = new Double(lastQuantity.doubleValue() + getOrderItemQuantity(item).doubleValue()); + BigDecimal newQuantity = lastQuantity.add(getOrderItemQuantity(item)); featureMap.put(appl.getString("productFeatureId"), newQuantity); } } @@ -858,11 +857,11 @@ GenericValue adj = (GenericValue) afi.next(); String featureId = adj.getString("productFeatureId"); if (featureId != null) { - Double lastQuantity = (Double) featureMap.get(featureId); + BigDecimal lastQuantity = (BigDecimal) featureMap.get(featureId); if (lastQuantity == null) { - lastQuantity = new Double(0); + lastQuantity = BigDecimal.ZERO; } - Double newQuantity = new Double(lastQuantity.doubleValue() + getOrderItemQuantity(item).doubleValue()); + BigDecimal newQuantity = lastQuantity.add(getOrderItemQuantity(item)); featureMap.put(featureId, newQuantity); } } @@ -1043,7 +1042,7 @@ Iterator i = validItems.iterator(); while (i.hasNext()) { GenericValue item = (GenericValue) i.next(); - shippableSizes.add(new Double(this.getItemSize(item))); + shippableSizes.add(this.getItemSize(item)); } } return shippableSizes; @@ -1116,23 +1115,22 @@ return total; } - // TODO: Might want to use BigDecimal here if precision matters - public double getItemSize(GenericValue item) { + public BigDecimal getItemSize(GenericValue item) { GenericDelegator delegator = orderHeader.getDelegator(); - double size = 0; + BigDecimal size = BigDecimal.ZERO; GenericValue product = null; try { product = item.getRelatedOne("Product"); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting Product from OrderItem", module); - return 0; + return BigDecimal.ZERO; } if (product != null) { if (ProductWorker.shippingApplies(product)) { - Double height = product.getDouble("shippingHeight"); - Double width = product.getDouble("shippingWidth"); - Double depth = product.getDouble("shippingDepth"); + BigDecimal height = product.getBigDecimal("shippingHeight"); + BigDecimal width = product.getBigDecimal("shippingWidth"); + BigDecimal depth = product.getBigDecimal("shippingDepth"); String isVariant = product.getString("isVariant"); if ((height == null || width == null || depth == null) && "Y".equals(isVariant)) { // get the virtual product and check its values @@ -1141,9 +1139,9 @@ if (UtilValidate.isNotEmpty(virtualId)) { GenericValue virtual = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", virtualId)); if (virtual != null) { - if (height == null) height = virtual.getDouble("shippingHeight"); - if (width == null) width = virtual.getDouble("shippingWidth"); - if (depth == null) depth = virtual.getDouble("shippingDepth"); + if (height == null) height = virtual.getBigDecimal("shippingHeight"); + if (width == null) width = virtual.getBigDecimal("shippingWidth"); + if (depth == null) depth = virtual.getBigDecimal("shippingDepth"); } } } catch (GenericEntityException e) { @@ -1151,15 +1149,15 @@ } } - if (height == null) height = new Double(0); - if (width == null) width = new Double(0); - if (depth == null) depth = new Double(0); + if (height == null) height = BigDecimal.ZERO; + if (width == null) width = BigDecimal.ZERO; + if (depth == null) depth = BigDecimal.ZERO; // determine girth (longest field is length) - double[] sizeInfo = { height.doubleValue(), width.doubleValue(), depth.doubleValue() }; + BigDecimal[] sizeInfo = { height, width, depth }; Arrays.sort(sizeInfo); - size = (sizeInfo[0] * 2) + (sizeInfo[1] * 2) + sizeInfo[2]; + size = sizeInfo[0].multiply(new BigDecimal("2")).add(sizeInfo[1].multiply(new BigDecimal("2"))).add(sizeInfo[2]); } } @@ -1228,9 +1226,9 @@ public Map getItemInfoMap(GenericValue item) { Map itemInfo = FastMap.newInstance(); itemInfo.put("productId", item.getString("productId")); - itemInfo.put("quantity", Double.valueOf(getOrderItemQuantity(item).doubleValue())); - itemInfo.put("weight", new Double(this.getItemWeight(item).doubleValue())); - itemInfo.put("size", new Double(this.getItemSize(item))); + itemInfo.put("quantity", getOrderItemQuantity(item)); + itemInfo.put("weight", this.getItemWeight(item)); + itemInfo.put("size", this.getItemSize(item)); itemInfo.put("piecesIncluded", new Long(this.getItemPiecesIncluded(item))); itemInfo.put("featureSet", this.getItemFeatureSet(item)); return itemInfo; @@ -1275,10 +1273,10 @@ * This works by adding up the amount allocated to each unprocessed OrderPaymentPreference and the * amounts received and refunded as payments for the settled ones. */ - public double getOrderOpenAmount() throws GenericEntityException { + public BigDecimal getOrderOpenAmount() throws GenericEntityException { GenericDelegator delegator = orderHeader.getDelegator(); BigDecimal total = getOrderGrandTotal(); - double openAmount = 0; + BigDecimal openAmount = BigDecimal.ZERO; List prefs = getPaymentPreferences(); // add up the covered amount, but skip preferences which are declined or cancelled @@ -1290,30 +1288,30 @@ List responses = pref.getRelatedByAnd("PaymentGatewayResponse", UtilMisc.toMap("transCodeEnumId", "PGT_CAPTURE")); for (Iterator respIter = responses.iterator(); respIter.hasNext(); ) { GenericValue response = (GenericValue) respIter.next(); - Double amount = response.getDouble("amount"); + BigDecimal amount = response.getBigDecimal("amount"); if (amount != null) { - openAmount += amount.doubleValue(); + openAmount = openAmount.add(amount); } } responses = pref.getRelatedByAnd("PaymentGatewayResponse", UtilMisc.toMap("transCodeEnumId", "PGT_REFUND")); for (Iterator respIter = responses.iterator(); respIter.hasNext(); ) { GenericValue response = (GenericValue) respIter.next(); - Double amount = response.getDouble("amount"); + BigDecimal amount = response.getBigDecimal("amount"); if (amount != null) { - openAmount -= amount.doubleValue(); + openAmount = openAmount.subtract(amount); } } } else { // all others are currently "unprocessed" payment preferences - Double maxAmount = pref.getDouble("maxAmount"); + BigDecimal maxAmount = pref.getBigDecimal("maxAmount"); if (maxAmount != null) { - openAmount += maxAmount.doubleValue(); + openAmount = openAmount.add(maxAmount); } } } - openAmount = new BigDecimal(openAmount).setScale(scale, rounding).doubleValue(); + openAmount = total.subtract(openAmount).setScale(scale, rounding); // return either a positive amount or positive zero - return Math.max(total.doubleValue() - openAmount, 0); + return openAmount.compareTo(BigDecimal.ZERO) > 0 ? openAmount : BigDecimal.ZERO; } public List getOrderHeaderAdjustments() { @@ -1439,9 +1437,9 @@ Iterator recIter = receipts.iterator(); while (recIter.hasNext()) { GenericValue rec = (GenericValue) recIter.next(); - Double rejected = rec.getDouble("quantityRejected"); - if (rejected != null && rejected.doubleValue() > 0) { - return true; + BigDecimal rejected = rec.getBigDecimal("quantityRejected"); + if (rejected != null && rejected.compareTo(BigDecimal.ZERO) > 0) { + return true; } } } @@ -1456,7 +1454,7 @@ while (i.hasNext()) { GenericValue item = (GenericValue) i.next(); int shippedQuantity = (int) getItemShippedQuantity(item); - Double orderedQuantity = (Double) item.get("quantity"); + BigDecimal orderedQuantity = (BigDecimal) item.get("quantity"); if (shippedQuantity != orderedQuantity.intValue() && shippedQuantity > 0) { return true; } @@ -1477,8 +1475,8 @@ Iterator recIter = receipts.iterator(); while (recIter.hasNext()) { GenericValue rec = (GenericValue) recIter.next(); - Double acceptedQuantity = rec.getDouble("quantityAccepted"); - Double orderedQuantity = (Double) item.get("quantity"); + BigDecimal acceptedQuantity = rec.getBigDecimal("quantityAccepted"); + BigDecimal orderedQuantity = (BigDecimal) item.get("quantity"); if (acceptedQuantity.intValue() != orderedQuantity.intValue() && acceptedQuantity.intValue() > 0) { return true; } @@ -1710,7 +1708,7 @@ * In other words, this method will count the ReturnItems * related to each OrderItem. * - * @return Map of returned quantities as Doubles keyed to the orderItemSeqId + * @return Map of returned quantities as BigDecimals keyed to the orderItemSeqId */ public Map getOrderItemReturnedQuantities() { List returnItems = getOrderReturnItems(); @@ -1723,16 +1721,16 @@ UtilMisc.toMap("orderId", orderItem.get("orderId"), "orderItemSeqId", orderItem.get("orderItemSeqId"))); // add up the returned quantities for this group TODO: received quantity should be used eventually - double returned = 0; + BigDecimal returned = BigDecimal.ZERO; for (Iterator groupiter = group.iterator(); groupiter.hasNext(); ) { GenericValue returnItem = (GenericValue) groupiter.next(); - if (returnItem.getDouble("returnQuantity") != null) { - returned += (returnItem.getDouble("returnQuantity")).doubleValue(); + if (returnItem.getBigDecimal("returnQuantity") != null) { + returned = returned.add(returnItem.getBigDecimal("returnQuantity")); } } // the quantity returned per order item - returnMap.put(orderItem.get("orderItemSeqId"), new Double(returned)); + returnMap.put(orderItem.get("orderItemSeqId"), returned); } return returnMap; } @@ -1886,10 +1884,9 @@ BigDecimal itemTaxes = this.getOrderItemTax(orderItem); BigDecimal itemShipping = this.getOrderItemShipping(orderItem); - BigDecimal quantityReturnedDouble = (BigDecimal) itemReturnedQuantities.get(orderItem.get("orderItemSeqId")); - BigDecimal quantityReturned = ZERO; - if (quantityReturnedDouble != null) { - quantityReturned = quantityReturnedDouble; + BigDecimal quantityReturned = (BigDecimal) itemReturnedQuantities.get(orderItem.get("orderItemSeqId")); + if (quantityReturned == null) { + quantityReturned = BigDecimal.ZERO; } BigDecimal quantityNotReturned = itemQuantity.subtract(quantityReturned); @@ -2093,10 +2090,10 @@ return reservedQty.subtract(backordered).setScale(scale, rounding); } - public double getItemCanceledQuantity(GenericValue orderItem) { - Double cancelQty = orderItem.getDouble("cancelQuantity"); - if (cancelQty == null) cancelQty = new Double(0); - return cancelQty.doubleValue(); + public BigDecimal getItemCanceledQuantity(GenericValue orderItem) { + BigDecimal cancelQty = orderItem.getBigDecimal("cancelQuantity"); + if (cancelQty == null) cancelQty = BigDecimal.ZERO; + return cancelQty; } public BigDecimal getTotalOrderItemsQuantity() { @@ -2240,14 +2237,14 @@ return orderQty.subtract(cancelQty).setScale(scale, rounding); } - public static Double getOrderItemShipGroupQuantity(GenericValue shipGroupAssoc) { - Double cancelQty = shipGroupAssoc.getDouble("cancelQuantity"); - Double orderQty = shipGroupAssoc.getDouble("quantity"); + public static BigDecimal getOrderItemShipGroupQuantity(GenericValue shipGroupAssoc) { + BigDecimal cancelQty = shipGroupAssoc.getBigDecimal("cancelQuantity"); + BigDecimal orderQty = shipGroupAssoc.getBigDecimal("quantity"); - if (cancelQty == null) cancelQty = new Double(0.0); - if (orderQty == null) orderQty = new Double(0.0); + if (cancelQty == null) cancelQty = BigDecimal.ZERO; + if (orderQty == null) orderQty = BigDecimal.ZERO; - return new Double(orderQty.doubleValue() - cancelQty.doubleValue()); + return orderQty.subtract(cancelQty); } public static GenericValue getProductStoreFromOrder(GenericDelegator delegator, String orderId) { @@ -2498,13 +2495,13 @@ return promoAdjTotal.setScale(scale, rounding); } - public static Double getWorkEffortRentalLenght(GenericValue workEffort){ - Double length = null; + public static BigDecimal getWorkEffortRentalLength(GenericValue workEffort){ + BigDecimal length = null; if (workEffort.get("estimatedStartDate") != null && workEffort.get("estimatedCompletionDate") != null) { - length = new Double(UtilDateTime.getInterval(workEffort.getTimestamp("estimatedStartDate"),workEffort.getTimestamp("estimatedCompletionDate"))/86400000); + length = new BigDecimal(UtilDateTime.getInterval(workEffort.getTimestamp("estimatedStartDate"),workEffort.getTimestamp("estimatedCompletionDate"))/86400000); } return length; - } + } public static BigDecimal getWorkEffortRentalQuantity(GenericValue workEffort){ BigDecimal persons = BigDecimal.ONE; @@ -2673,8 +2670,8 @@ return newOrderAdjustmentsList; } - public static double getQuantityOnOrder(GenericDelegator delegator, String productId) { - double quantity = 0.0; + public static BigDecimal getQuantityOnOrder(GenericDelegator delegator, String productId) { + BigDecimal quantity = BigDecimal.ZERO; // first find all open purchase orders List openOrdersExprs = UtilMisc.toList(EntityCondition.makeCondition("orderTypeId", EntityOperator.EQUALS, "PURCHASE_ORDER")); @@ -2694,11 +2691,11 @@ Iterator i = openOrders.iterator(); while (i.hasNext()) { GenericValue order = (GenericValue) i.next(); - Double thisQty = order.getDouble("quantity"); + BigDecimal thisQty = order.getBigDecimal("quantity"); if (thisQty == null) { - thisQty = new Double(0); + thisQty = BigDecimal.ZERO; } - quantity += thisQty.doubleValue(); + quantity = quantity.add(thisQty); } } @@ -2795,16 +2792,16 @@ } /** Get the quantity of order items that have been invoiced */ - public static double getOrderItemInvoicedQuantity(GenericValue orderItem) { - double invoiced = 0; + public static BigDecimal getOrderItemInvoicedQuantity(GenericValue orderItem) { + BigDecimal invoiced = BigDecimal.ZERO; try { // this is simply the sum of quantity billed in all related OrderItemBillings List billings = orderItem.getRelated("OrderItemBilling"); for (Iterator iter = billings.iterator(); iter.hasNext(); ) { GenericValue billing = (GenericValue) iter.next(); - Double quantity = billing.getDouble("quantity"); + BigDecimal quantity = billing.getBigDecimal("quantity"); if (quantity != null) { - invoiced += quantity.doubleValue(); + invoiced = invoiced.add(quantity); } } } catch (GenericEntityException e) { Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original) +++ ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Mon Jan 5 23:13:36 2009 @@ -125,14 +125,14 @@ } // worker method which can be used in screen iterations - public static Double getReturnItemInitialCost(GenericDelegator delegator, String returnId, String returnItemSeqId) { + public static BigDecimal getReturnItemInitialCost(GenericDelegator delegator, String returnId, String returnItemSeqId) { if (delegator == null || returnId == null || returnItemSeqId == null) { throw new IllegalArgumentException("Method parameters cannot contain nulls"); } Debug.log("Finding the initial item cost for return item : " + returnId + " / " + returnItemSeqId, module); // the cost holder - Double itemCost = new Double(0.00); + BigDecimal itemCost = BigDecimal.ZERO; // get the return item information GenericValue returnItem = null; @@ -173,7 +173,7 @@ if (inventoryItem != null) { Debug.log("Located inventory item - " + inventoryItem.getString("inventoryItemId"), module); if (inventoryItem.get("unitCost") != null) { - itemCost = inventoryItem.getDouble("unitCost"); + itemCost = inventoryItem.getBigDecimal("unitCost"); } else { Debug.logInfo("Found item cost; but cost was null. Returning default amount (0.00)", module); } @@ -332,13 +332,13 @@ } String itemStatus = orderItem.getString("statusId"); - double orderQty = orderItem.getDouble("quantity").doubleValue(); - if (orderItem.getDouble("cancelQuantity") != null) { - orderQty -= orderItem.getDouble("cancelQuantity").doubleValue(); + BigDecimal orderQty = orderItem.getBigDecimal("quantity"); + if (orderItem.getBigDecimal("cancelQuantity") != null) { + orderQty = orderQty.subtract(orderItem.getBigDecimal("cancelQuantity")); } // get the returnable quantity - double returnableQuantity = 0.00; + BigDecimal returnableQuantity = BigDecimal.ZERO; if (returnable && (itemStatus.equals("ITEM_APPROVED") || itemStatus.equals("ITEM_COMPLETED"))) { List returnedItems = null; try { @@ -350,7 +350,7 @@ if (returnedItems == null || returnedItems.size() == 0) { returnableQuantity = orderQty; } else { - double returnedQty = 0.00; + BigDecimal returnedQty = BigDecimal.ZERO; Iterator ri = returnedItems.iterator(); while (ri.hasNext()) { GenericValue returnItem = (GenericValue) ri.next(); @@ -363,11 +363,11 @@ } String returnStatus = returnHeader.getString("statusId"); if (!returnStatus.equals("RETURN_CANCELLED")) { - returnedQty += returnItem.getDouble("returnQuantity").doubleValue(); + returnedQty = returnedQty.add(returnItem.getBigDecimal("returnQuantity")); } } - if (returnedQty < orderQty) { - returnableQuantity = orderQty - returnedQty; + if (returnedQty.compareTo(orderQty) < 0) { + returnableQuantity = orderQty.subtract(returnedQty); } } } @@ -375,8 +375,8 @@ // get the returnable price now equals to orderItem.unitPrice, since adjustments are booked separately Map result = ServiceUtil.returnSuccess(); - result.put("returnableQuantity", new Double(returnableQuantity)); - result.put("returnablePrice", orderItem.get("unitPrice")); + result.put("returnableQuantity", returnableQuantity); + result.put("returnablePrice", orderItem.getBigDecimal("unitPrice")); return result; } @@ -429,8 +429,8 @@ } // items not issued/shipped are considered as returnable only if they are // not physical items - Double quantityIssued = orderItemQuantityIssued.getDouble("quantityIssued"); - if (UtilValidate.isEmpty(quantityIssued) || quantityIssued.doubleValue() == 0) { + BigDecimal quantityIssued = orderItemQuantityIssued.getBigDecimal("quantityIssued"); + if (UtilValidate.isEmpty(quantityIssued) || quantityIssued.compareTo(BigDecimal.ZERO) == 0) { try { GenericValue itemProduct = item.getRelatedOne("Product"); if (ProductWorker.isPhysical(itemProduct)) { @@ -454,7 +454,7 @@ } else { // Don't add the OrderItem to the map of returnable OrderItems if there isn't any returnable quantity. - if (((Double) serviceResult.get("returnableQuantity")).doubleValue() == 0 ) { + if (((BigDecimal) serviceResult.get("returnableQuantity")).compareTo(BigDecimal.ZERO) == 0 ) { continue; } Map returnInfo = new HashMap(); @@ -495,7 +495,7 @@ while (itemAdjustmentsIt.hasNext()) { GenericValue itemAdjustment = (GenericValue)itemAdjustmentsIt.next(); returnInfo = new HashMap(); - returnInfo.put("returnableQuantity", new Double(1.0)); + returnInfo.put("returnableQuantity", BigDecimal.ONE); // TODO: the returnablePrice should be set to the amount minus the already returned amount returnInfo.put("returnablePrice", itemAdjustment.get("amount")); returnInfo.put("itemTypeKey", itemTypeKey); @@ -630,7 +630,7 @@ return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorGettingReturnHeaderItemInformation", locale)); } - BigDecimal adjustments = new BigDecimal(getReturnAdjustmentTotal(delegator, UtilMisc.toMap("returnId", returnId, "returnTypeId", "RTN_CREDIT"))); + BigDecimal adjustments = getReturnAdjustmentTotal(delegator, UtilMisc.toMap("returnId", returnId, "returnTypeId", "RTN_CREDIT")); if (returnHeader != null && ((returnItems != null && returnItems.size() > 0) || adjustments.compareTo(ZERO) > 0)) { String billingAccountId = returnHeader.getString("billingAccountId"); @@ -704,7 +704,7 @@ // create a return item response Map itemResponse = UtilMisc.toMap("paymentId", paymentId); itemResponse.put("billingAccountId", billingAccountId); - itemResponse.put("responseAmount", new Double(creditTotal.doubleValue())); + itemResponse.put("responseAmount", creditTotal); itemResponse.put("responseDate", now); itemResponse.put("userLogin", userLogin); Map serviceResults = null; @@ -823,7 +823,7 @@ if (storeCreditValidDays != null) thruDate = UtilDateTime.getDayEnd(UtilDateTime.nowTimestamp(), storeCreditValidDays); // create the billing account - Map input = UtilMisc.toMap("accountLimit", new Double(0.00), "description", "Credit Account for Return #" + returnHeader.get("returnId"), "userLogin", userLogin); + Map input = UtilMisc.toMap("accountLimit", BigDecimal.ZERO, "description", "Credit Account for Return #" + returnHeader.get("returnId"), "userLogin", userLogin); input.put("accountCurrencyUomId", returnHeader.get("currencyUomId")); input.put("thruDate", thruDate); Map results = dispatcher.runSync("createBillingAccount", input); @@ -868,7 +868,7 @@ return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorGettingReturnHeaderItemInformation", locale)); } - BigDecimal adjustments = new BigDecimal(getReturnAdjustmentTotal(delegator, UtilMisc.toMap("returnId", returnId, "returnTypeId", "RTN_REFUND"))); + BigDecimal adjustments = getReturnAdjustmentTotal(delegator, UtilMisc.toMap("returnId", returnId, "returnTypeId", "RTN_REFUND")); if (returnHeader != null && ((returnItems != null && returnItems.size() > 0) || adjustments.compareTo(ZERO) > 0)) { Map itemsByOrder = new HashMap(); @@ -895,7 +895,7 @@ Map.Entry entry = (Map.Entry) itemByOrderIt.next(); String orderId = (String) entry.getKey(); List items = (List) entry.getValue(); - Double orderTotal = (Double) totalByOrder.get(orderId); + BigDecimal orderTotal = (BigDecimal) totalByOrder.get(orderId); // get order header & payment prefs GenericValue orderHeader = null; @@ -961,11 +961,11 @@ // See how much we can refund to the payment method BigDecimal orderPayPrefReceivedTotal = ZERO ; if (receivedPaymentTotalsByPaymentMethod.containsKey(orderPayPrefKey)) { - orderPayPrefReceivedTotal = orderPayPrefReceivedTotal.add(new BigDecimal(((Double) receivedPaymentTotalsByPaymentMethod.get(orderPayPrefKey)).doubleValue()).setScale(decimals, rounding)); + orderPayPrefReceivedTotal = orderPayPrefReceivedTotal.add((BigDecimal)receivedPaymentTotalsByPaymentMethod.get(orderPayPrefKey)).setScale(decimals, rounding); } BigDecimal orderPayPrefRefundedTotal = ZERO ; if (refundedTotalsByPaymentMethod.containsKey(orderPayPrefKey)) { - orderPayPrefRefundedTotal = orderPayPrefRefundedTotal.add(new BigDecimal(((Double) refundedTotalsByPaymentMethod.get(orderPayPrefKey)).doubleValue()).setScale(decimals, rounding)); + orderPayPrefRefundedTotal = orderPayPrefRefundedTotal.add((BigDecimal)refundedTotalsByPaymentMethod.get(orderPayPrefKey)).setScale(decimals, rounding); } BigDecimal orderPayPrefAvailableTotal = orderPayPrefReceivedTotal.subtract(orderPayPrefRefundedTotal); @@ -983,7 +983,7 @@ } // Keep a decreasing total of the amount remaining to refund - BigDecimal amountLeftToRefund = new BigDecimal(orderTotal.doubleValue()).setScale(decimals, rounding); + BigDecimal amountLeftToRefund = orderTotal.setScale(decimals, rounding); // This can be extended to support additional electronic types List electronicTypes = UtilMisc.toList("CREDIT_CARD", "EFT_ACCOUNT", "FIN_ACCOUNT", "GIFT_CARD"); @@ -1031,7 +1031,7 @@ if (electronicTypes.contains(paymentMethodTypeId)) { try { // for electronic types such as CREDIT_CARD and EFT_ACCOUNT, use refundPayment service - serviceResult = dispatcher.runSync("refundPayment", UtilMisc.<String, Object>toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount", new Double(amountToRefund.setScale(decimals, rounding).doubleValue()), "userLogin", userLogin)); + serviceResult = dispatcher.runSync("refundPayment", UtilMisc.<String, Object>toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount", amountToRefund.setScale(decimals, rounding), "userLogin", userLogin)); if (ServiceUtil.isError(serviceResult) || ServiceUtil.isFailure(serviceResult)) { Debug.logError("Error in refund payment: " + ServiceUtil.getErrorMessage(serviceResult), module); continue; @@ -1044,7 +1044,7 @@ } else if (paymentMethodTypeId.equals("EXT_BILLACT")) { try { // for Billing Account refunds - serviceResult = dispatcher.runSync("refundBillingAccountPayment", UtilMisc.<String, Object>toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount", new Double(amountToRefund.setScale(decimals, rounding).doubleValue()), "userLogin", userLogin)); + serviceResult = dispatcher.runSync("refundBillingAccountPayment", UtilMisc.<String, Object>toMap("orderPaymentPreference", orderPaymentPreference, "refundAmount", amountToRefund.setScale(decimals, rounding), "userLogin", userLogin)); if (ServiceUtil.isError(serviceResult) || ServiceUtil.isFailure(serviceResult)) { Debug.logError("Error in refund payment: " + ServiceUtil.getErrorMessage(serviceResult), module); continue; @@ -1057,7 +1057,7 @@ } else { // handle manual refunds try { - Map input = UtilMisc.toMap("userLogin", userLogin, "amount", new Double(amountLeftToRefund.doubleValue()), "statusId", "PMNT_NOT_PAID"); + Map input = UtilMisc.toMap("userLogin", userLogin, "amount", amountLeftToRefund, "statusId", "PMNT_NOT_PAID"); input.put("partyIdTo", returnHeader.get("fromPartyId")); input.put("partyIdFrom", returnHeader.get("toPartyId")); input.put("paymentTypeId", "CUSTOMER_REFUND"); @@ -1081,7 +1081,7 @@ // Fill out the data for the new ReturnItemResponse Map response = FastMap.newInstance(); response.put("orderPaymentPreferenceId", orderPaymentPreference.getString("orderPaymentPreferenceId")); - response.put("responseAmount", new Double(amountToRefund.setScale(decimals, rounding).doubleValue())); + response.put("responseAmount", amountToRefund.setScale(decimals, rounding)); response.put("responseDate", now); response.put("userLogin", userLogin); response.put("paymentId", paymentId); @@ -1156,7 +1156,7 @@ GenericValue userLogin = (GenericValue) context.get("userLogin"); GenericValue paymentPref = (GenericValue) context.get("orderPaymentPreference"); - Double refundAmount = (Double) context.get("refundAmount"); + BigDecimal refundAmount = (BigDecimal) context.get("refundAmount"); GenericValue orderHeader = null; try { @@ -1302,7 +1302,7 @@ if (paymentId != null) { // create a payment application for the invoice Map input = UtilMisc.toMap("paymentId", paymentId, "invoiceId", invoice.getString("invoiceId")); - input.put("amountApplied", new Double(amountApplied.doubleValue())); + input.put("amountApplied", amountApplied); input.put("userLogin", userLogin); if (response.get("billingAccountId") != null) { GenericValue billingAccount = response.getRelatedOne("BillingAccount"); @@ -1397,7 +1397,7 @@ orderMap.put("webSiteId", orderHeader.get("webSiteId")); orderMap.put("visitId", orderHeader.get("visitId")); orderMap.put("currencyUom", orderHeader.get("currencyUom")); - orderMap.put("grandTotal", new Double(0.00)); + orderMap.put("grandTotal", BigDecimal.ZERO); // make the contact mechs List contactMechs = new ArrayList(); @@ -1437,8 +1437,8 @@ */ // make the order items - double orderPriceTotal = 0.00; - double additionalItemTotal = 0.00; + BigDecimal orderPriceTotal = BigDecimal.ZERO; + BigDecimal additionalItemTotal = BigDecimal.ZERO; List orderItems = new ArrayList(); List orderItemShipGroupInfo = new ArrayList(); List orderItemShipGroupIds = new ArrayList(); // this is used to store the ship group ids of the groups already added to the orderItemShipGroupInfo list @@ -1458,10 +1458,10 @@ continue; } if (orderItem != null) { - Double quantity = returnItem.getDouble("returnQuantity"); - Double unitPrice = returnItem.getDouble("returnPrice"); + BigDecimal quantity = returnItem.getBigDecimal("returnQuantity"); + BigDecimal unitPrice = returnItem.getBigDecimal("returnPrice"); if (quantity != null && unitPrice != null) { - orderPriceTotal += (quantity.doubleValue() * unitPrice.doubleValue()); + orderPriceTotal = orderPriceTotal.add(quantity.multiply(unitPrice)); // Check if the product being returned has a Refurbished Equivalent and if so // (and there is inventory for the assoc product) use that product instead GenericValue refurbItem = null; @@ -1572,11 +1572,11 @@ continue; } if (UtilValidate.isNotEmpty(repairItemProduct)) { - Double repairUnitQuantity = repairItem.getDouble("quantity"); + BigDecimal repairUnitQuantity = repairItem.getBigDecimal("quantity"); if (UtilValidate.isEmpty(repairUnitQuantity)) { - repairUnitQuantity = new Double(1.0); + repairUnitQuantity = BigDecimal.ONE; } - Double repairQuantity = new Double(quantity.doubleValue() * repairUnitQuantity.doubleValue()); + BigDecimal repairQuantity = quantity.multiply(repairUnitQuantity); newItem = delegator.makeValue("OrderItem", UtilMisc.toMap("orderItemSeqId", UtilFormatOut.formatPaddedNumber(itemCount++, 5))); // price @@ -1610,14 +1610,14 @@ } if (priceResult.get("listPrice") != null) { - newItem.set("unitListPrice", (Double)priceResult.get("listPrice")); + newItem.set("unitListPrice", (BigDecimal)priceResult.get("listPrice")); } - Double repairUnitPrice = null; + BigDecimal repairUnitPrice = null; if (priceResult.get("basePrice") != null) { - repairUnitPrice = (Double)priceResult.get("basePrice"); + repairUnitPrice = (BigDecimal)priceResult.get("basePrice"); } else { - repairUnitPrice = new Double(0.0); + repairUnitPrice = BigDecimal.ZERO; } newItem.set("unitPrice", repairUnitPrice); @@ -1627,7 +1627,7 @@ newItem.set("itemDescription", ProductContentWrapper.getProductContentAsText(repairItemProduct, "PRODUCT_NAME", locale, null)); newItem.set("statusId", "ITEM_CREATED"); orderItems.add(newItem); - additionalItemTotal = additionalItemTotal + (repairQuantity.doubleValue() * repairUnitPrice.doubleValue()); + additionalItemTotal = additionalItemTotal.add(repairQuantity.multiply(repairUnitPrice)); if (UtilValidate.isNotEmpty(orderItemShipGroupAssoc)) { GenericValue newOrderItemShipGroupAssoc = delegator.makeValue("OrderItemShipGroupAssoc", UtilMisc.toMap("orderItemSeqId", newItem.getString("orderItemSeqId"), "shipGroupSeqId", orderItemShipGroupAssoc.getString("shipGroupSeqId"), "quantity", repairQuantity)); orderItemShipGroupInfo.add(newOrderItemShipGroupAssoc); @@ -1659,14 +1659,14 @@ // create the replacement adjustment GenericValue adj = delegator.makeValue("OrderAdjustment"); adj.set("orderAdjustmentTypeId", "REPLACE_ADJUSTMENT"); - adj.set("amount", new Double(orderPriceTotal * -1)); + adj.set("amount", orderPriceTotal.negate()); adj.set("comments", "Replacement Item Return #" + returnId); adj.set("createdDate", nowTimestamp); adj.set("createdByUserLogin", userLogin.getString("userLoginId")); orderMap.put("orderAdjustments", UtilMisc.toList(adj)); // Payment preference - if (additionalItemTotal > 0) { + if (additionalItemTotal.compareTo(BigDecimal.ZERO) > 0) { GenericValue paymentMethod = null; try { paymentMethod = returnHeader.getRelatedOne("PaymentMethod"); @@ -1744,7 +1744,7 @@ // create a ReturnItemResponse and attach to each ReturnItem Map itemResponse = FastMap.newInstance(); itemResponse.put("replacementOrderId", createdOrderId); - itemResponse.put("responseAmount", new Double(orderPriceTotal)); + itemResponse.put("responseAmount", orderPriceTotal); itemResponse.put("responseDate", nowTimestamp); itemResponse.put("userLogin", userLogin); String returnItemResponseId = null; @@ -1871,9 +1871,9 @@ String orderId = returnItem.getString("orderId"); if (orderId != null) { if (returnItemsByOrderId != null) { - Double totalForOrder = null; + BigDecimal totalForOrder = null; if (totalByOrder != null) { - totalForOrder = (Double) totalByOrder.get(orderId); + totalForOrder = (BigDecimal) totalByOrder.get(orderId); } List returnItemList = (List) returnItemsByOrderId.get(orderId); @@ -1881,7 +1881,7 @@ returnItemList = new ArrayList(); } if (totalForOrder == null) { - totalForOrder = new Double(0.00); + totalForOrder = BigDecimal.ZERO; } // add to the items list @@ -1890,18 +1890,18 @@ if (totalByOrder != null) { // add on the total for this line - Double quantity = returnItem.getDouble("returnQuantity"); - Double amount = returnItem.getDouble("returnPrice"); + BigDecimal quantity = returnItem.getBigDecimal("returnQuantity"); + BigDecimal amount = returnItem.getBigDecimal("returnPrice"); if (quantity == null) { - quantity = new Double(0); + quantity = BigDecimal.ZERO; } if (amount == null) { - amount = new Double(0.00); + amount = BigDecimal.ZERO; } - double thisTotal = amount.doubleValue() * quantity.doubleValue(); - double existingTotal = totalForOrder.doubleValue(); + BigDecimal thisTotal = amount.multiply(quantity); + BigDecimal existingTotal = totalForOrder; Map condition = UtilMisc.toMap("returnId", returnItem.get("returnId"), "returnItemSeqId", returnItem.get("returnItemSeqId")); - Double newTotal = new Double(existingTotal + thisTotal + getReturnAdjustmentTotal(delegator, condition) ); + BigDecimal newTotal = existingTotal.add(thisTotal).add(getReturnAdjustmentTotal(delegator, condition)); totalByOrder.put(orderId, newTotal); } } @@ -1917,8 +1917,8 @@ Map condition = UtilMisc.toMap("returnId", returnId, "returnItemSeqId", org.ofbiz.common.DataModelConstants.SEQ_ID_NA, "returnTypeId", returnTypeId); - double existingTotal = ((Double) totalByOrder.get(orderId)).doubleValue() + getReturnAdjustmentTotal(delegator, condition); - totalByOrder.put(orderId, new Double(existingTotal)); + BigDecimal existingTotal = ((BigDecimal)totalByOrder.get(orderId)).add(getReturnAdjustmentTotal(delegator, condition)); + totalByOrder.put(orderId, existingTotal); } } } @@ -2026,7 +2026,7 @@ GenericValue returnItem = null; GenericValue returnHeader = null; - Double amount; + BigDecimal amount; // if orderAdjustment is not empty, then copy most return adjustment information from orderAdjustment's if (orderAdjustmentId != null) { @@ -2078,7 +2078,7 @@ // calculate the returnAdjustment amount if (returnItem != null) { // returnAdjustment for returnItem if (needRecalculate(returnAdjustmentTypeId)) { - Debug.logInfo("returnPrice:" + returnItem.getDouble("returnPrice") + ",returnQuantity:" + returnItem.getDouble("returnQuantity") + ",sourcePercentage:" + orderAdjustment.getDouble("sourcePercentage"), module); + Debug.logInfo("returnPrice:" + returnItem.getBigDecimal("returnPrice") + ",returnQuantity:" + returnItem.getBigDecimal("returnQuantity") + ",sourcePercentage:" + orderAdjustment.getBigDecimal("sourcePercentage"), module); if (orderAdjustment == null) { Debug.logError("orderAdjustment [" + orderAdjustmentId + "] not found", module); return ServiceUtil.returnError("orderAdjustment [" + orderAdjustmentId + "] not found"); @@ -2087,10 +2087,10 @@ BigDecimal orderTotal = orderItem.getBigDecimal("quantity").multiply(orderItem.getBigDecimal("unitPrice")); amount = getAdjustmentAmount("RET_SALES_TAX_ADJ".equals(returnAdjustmentTypeId), returnTotal, orderTotal, orderAdjustment.getBigDecimal("amount")); } else { - amount = (Double) context.get("amount"); + amount = (BigDecimal) context.get("amount"); } } else { // returnAdjustment for returnHeader - amount = (Double) context.get("amount"); + amount = (BigDecimal) context.get("amount"); } // store the return adjustment @@ -2103,7 +2103,7 @@ if (orderAdjustment != null && orderAdjustment.get("taxAuthorityRateSeqId") != null) { newReturnAdjustment.set("taxAuthorityRateSeqId", orderAdjustment.getString("taxAuthorityRateSeqId")); } - newReturnAdjustment.set("amount", (UtilValidate.isEmpty(amount)? new Double(0.0): amount)); + newReturnAdjustment.set("amount", amount == null ? BigDecimal.ZERO : amount); newReturnAdjustment.set("returnAdjustmentTypeId", returnAdjustmentTypeId); newReturnAdjustment.set("description", description); newReturnAdjustment.set("returnItemSeqId", UtilValidate.isEmpty(returnItemSeqId) ? "_NA_" : returnItemSeqId); @@ -2124,7 +2124,7 @@ GenericValue returnItem = null; GenericValue returnAdjustment = null; String returnAdjustmentTypeId = null; - Double amount; + BigDecimal amount; try { @@ -2137,18 +2137,18 @@ // calculate the returnAdjustment amount if (returnItem != null) { // returnAdjustment for returnItem - double originalReturnPrice = (context.get("originalReturnPrice") != null) ? ((Double) context.get("originalReturnPrice")).doubleValue() : returnItem.getDouble("returnPrice").doubleValue(); - double originalReturnQuantity = (context.get("originalReturnQuantity") != null) ? ((Double) context.get("originalReturnQuantity")).doubleValue() : returnItem.getDouble("returnQuantity").doubleValue(); + BigDecimal originalReturnPrice = (context.get("originalReturnPrice") != null) ? ((BigDecimal) context.get("originalReturnPrice")) : returnItem.getBigDecimal("returnPrice"); + BigDecimal originalReturnQuantity = (context.get("originalReturnQuantity") != null) ? ((BigDecimal) context.get("originalReturnQuantity")) : returnItem.getBigDecimal("returnQuantity"); if (needRecalculate(returnAdjustmentTypeId)) { BigDecimal returnTotal = returnItem.getBigDecimal("returnPrice").multiply(returnItem.getBigDecimal("returnQuantity")); - BigDecimal originalReturnTotal = new BigDecimal(originalReturnPrice).multiply(new BigDecimal(originalReturnQuantity)); + BigDecimal originalReturnTotal = originalReturnPrice.multiply(originalReturnQuantity); amount = getAdjustmentAmount("RET_SALES_TAX_ADJ".equals(returnAdjustmentTypeId), returnTotal, originalReturnTotal, returnAdjustment.getBigDecimal("amount")); } else { - amount = (Double) context.get("amount"); + amount = (BigDecimal) context.get("amount"); } } else { // returnAdjustment for returnHeader - amount = (Double) context.get("amount"); + amount = (BigDecimal) context.get("amount"); } Map result = null; @@ -2226,8 +2226,8 @@ * @param condition * @return */ - public static double getReturnAdjustmentTotal(GenericDelegator delegator, Map condition) { - double total = 0.0; + public static BigDecimal getReturnAdjustmentTotal(GenericDelegator delegator, Map condition) { + BigDecimal total = BigDecimal.ZERO; List adjustments; try { // TODO: find on a view-entity with a sum is probably more efficient @@ -2237,7 +2237,7 @@ while (adjustmentIterator.hasNext()) { GenericValue returnAdjustment = (GenericValue) adjustmentIterator.next(); if ((returnAdjustment != null) && (returnAdjustment.get("amount") != null)) { - total += returnAdjustment.getDouble("amount").doubleValue(); + total = total.add(returnAdjustment.getBigDecimal("amount")); } } } @@ -2284,7 +2284,7 @@ * @param amount * @return new returnAdjustment amount */ - public static Double getAdjustmentAmount(boolean isSalesTax, BigDecimal returnTotal, BigDecimal originalTotal, BigDecimal amount) { + public static BigDecimal getAdjustmentAmount(boolean isSalesTax, BigDecimal returnTotal, BigDecimal originalTotal, BigDecimal amount) { String settingPrefix = isSalesTax ? "salestax" : "order"; String decimalsPrefix = isSalesTax ? ".calc" : ""; int decimals = UtilNumber.getBigDecimalScale(settingPrefix + decimalsPrefix + ".decimals"); @@ -2297,6 +2297,6 @@ } else { newAmount = ZERO; } - return new Double(newAmount.doubleValue()); + return newAmount; } } |
Free forum by Nabble | Edit this page |