Modified: ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java?rev=721986&r1=721985&r2=721986&view=diff ============================================================================== --- ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java (original) +++ ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReadHelper.java Sun Nov 30 22:51:11 2008 @@ -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,10 +232,10 @@ } // 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"); - paymentMethodAmounts.put(paymentMethodKey, new Double(chargedToPaymentPref.setScale(scale, rounding).doubleValue())); + paymentMethodAmounts.put(paymentMethodKey, chargedToPaymentPref.setScale(scale, rounding)); } } return paymentMethodAmounts; @@ -267,7 +267,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; @@ -658,16 +658,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; } } } @@ -830,11 +830,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); } } @@ -853,11 +853,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); } } @@ -1038,7 +1038,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; @@ -1111,23 +1111,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 @@ -1136,9 +1135,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) { @@ -1146,15 +1145,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]); } } @@ -1223,9 +1222,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; @@ -1270,10 +1269,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 @@ -1285,30 +1284,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() { @@ -1434,9 +1433,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; } } } @@ -1451,7 +1450,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; } @@ -1472,8 +1471,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; } @@ -1705,7 +1704,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(); @@ -1718,16 +1717,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; } @@ -1881,10 +1880,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); @@ -2088,10 +2086,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() { @@ -2235,14 +2233,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) { @@ -2493,13 +2491,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; @@ -2668,8 +2666,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")); @@ -2689,11 +2687,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); } } @@ -2790,16 +2788,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/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java?rev=721986&r1=721985&r2=721986&view=diff ============================================================================== --- ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java (original) +++ ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderReturnServices.java Sun Nov 30 22:51:11 2008 @@ -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; } } Modified: ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderServices.java?rev=721986&r1=721985&r2=721986&view=diff ============================================================================== --- ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderServices.java (original) +++ ofbiz/branches/typecheckcleanup200810/applications/order/src/org/ofbiz/order/order/OrderServices.java Sun Nov 30 22:51:11 2008 @@ -253,17 +253,17 @@ if (currentProductId != null) { // only normalize items with a product associated (ignore non-product items) if (normalizedItemQuantities.get(currentProductId) == null) { - normalizedItemQuantities.put(currentProductId, new Double(orderItem.getDouble("quantity").doubleValue())); + normalizedItemQuantities.put(currentProductId, orderItem.getBigDecimal("quantity")); normalizedItemNames.put(currentProductId, orderItem.getString("itemDescription")); } else { - Double currentQuantity = (Double) normalizedItemQuantities.get(currentProductId); - normalizedItemQuantities.put(currentProductId, new Double(currentQuantity.doubleValue() + orderItem.getDouble("quantity").doubleValue())); + BigDecimal currentQuantity = (BigDecimal) normalizedItemQuantities.get(currentProductId); + normalizedItemQuantities.put(currentProductId, currentQuantity.add(orderItem.getBigDecimal("quantity"))); } try { // count product ordered quantities // run this synchronously so it will run in the same transaction - dispatcher.runSync("countProductQuantityOrdered", UtilMisc.<String, Object>toMap("productId", currentProductId, "quantity", orderItem.getDouble("quantity"), "userLogin", userLogin)); + dispatcher.runSync("countProductQuantityOrdered", UtilMisc.<String, Object>toMap("productId", currentProductId, "quantity", orderItem.getBigDecimal("quantity"), "userLogin", userLogin)); } catch (GenericServiceException e1) { Debug.logError(e1, "Error calling countProductQuantityOrdered service", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCallingCountProductQuantityOrderedService",locale) + e1.toString()); @@ -279,7 +279,7 @@ while (normalizedIter.hasNext()) { // lookup the product entity for each normalized item; error on products not found String currentProductId = (String) normalizedIter.next(); - Double currentQuantity = (Double) normalizedItemQuantities.get(currentProductId); + BigDecimal currentQuantity = (BigDecimal) normalizedItemQuantities.get(currentProductId); String itemName = (String) normalizedItemNames.get(currentProductId); GenericValue product = null; @@ -727,20 +727,19 @@ techDataCalendarExcDay = delegator.makeValue("TechDataCalendarExcDay"); techDataCalendarExcDay.set("calendarId", fixedAsset.get("calendarId")); techDataCalendarExcDay.set("exceptionDateStartTime", exceptionDateStartTime); - techDataCalendarExcDay.set("usedCapacity",new Double(00.00)); // initialise to zero - techDataCalendarExcDay.set("exceptionCapacity", fixedAsset.getDouble("productionCapacity")); + techDataCalendarExcDay.set("usedCapacity", BigDecimal.ZERO); // initialise to zero + techDataCalendarExcDay.set("exceptionCapacity", fixedAsset.getBigDecimal("productionCapacity")); // Debug.logInfo(" techData excday record not found creating for calendarId: " + techDataCalendarExcDay.getString("calendarId") + // " and date: " + exceptionDateStartTime.toString(), module); } // add the quantity to the quantity on the date record - Double newUsedCapacity = new Double(techDataCalendarExcDay.getDouble("usedCapacity").doubleValue() + - workEffort.getDouble("quantityToProduce").doubleValue()); + BigDecimal newUsedCapacity = techDataCalendarExcDay.getBigDecimal("usedCapacity").add(workEffort.getBigDecimal("quantityToProduce")); // check to see if the requested quantity is available on the requested day but only when the maximum capacity is set on the fixed asset if (fixedAsset.get("productionCapacity") != null) { // Debug.logInfo("see if maximum not reached, available: " + techDataCalendarExcDay.getString("exceptionCapacity") + // " already allocated: " + techDataCalendarExcDay.getString("usedCapacity") + // " Requested: " + workEffort.getString("quantityToProduce"), module); - if (newUsedCapacity.compareTo(techDataCalendarExcDay.getDouble("exceptionCapacity")) > 0) { + if (newUsedCapacity.compareTo(techDataCalendarExcDay.getBigDecimal("exceptionCapacity")) > 0) { String errMsg = "ERROR: fixed_Asset_sold_out AssetId: " + workEffort.get("fixedAssetId") + " on date: " + techDataCalendarExcDay.getString("exceptionDateStartTime"); Debug.logError(errMsg, module); errorMessages.add(errMsg); @@ -1144,9 +1143,9 @@ Iterator assocProductsIter = assocProducts.iterator(); while (assocProductsIter.hasNext()) { GenericValue productAssoc = (GenericValue) assocProductsIter.next(); - Double quantityOrd = productAssoc.getDouble("quantity"); - Double quantityKit = orderItemShipGroupAssoc.getDouble("quantity"); - Double quantity = new Double(quantityOrd.doubleValue() * quantityKit.doubleValue()); + BigDecimal quantityOrd = productAssoc.getBigDecimal("quantity"); + BigDecimal quantityKit = orderItemShipGroupAssoc.getBigDecimal("quantity"); + BigDecimal quantity = quantityOrd.multiply(quantityKit); Map reserveInput = new HashMap(); reserveInput.put("productStoreId", productStoreId); reserveInput.put("productId", productAssoc.getString("productIdTo")); @@ -1178,7 +1177,7 @@ reserveInput.put("shipGroupSeqId", orderItemShipGroupAssoc.getString("shipGroupSeqId")); reserveInput.put("facilityId", shipGroupFacilityId); // use the quantity from the orderItemShipGroupAssoc, NOT the orderItem, these are reserved by item-group assoc - reserveInput.put("quantity", orderItemShipGroupAssoc.getDouble("quantity")); + reserveInput.put("quantity", orderItemShipGroupAssoc.getBigDecimal("quantity")); reserveInput.put("userLogin", userLogin); Map reserveResult = dispatcher.runSync("reserveStoreInventory", reserveInput); @@ -1477,7 +1476,6 @@ } // prepare the service context - // pass in BigDecimal values instead of Double Map serviceContext = UtilMisc.toMap("productStoreId", orh.getProductStoreId(), "itemProductList", products, "itemAmountList", amounts, "itemShippingList", shipAmts, "itemPriceList", itPrices, "orderShippingAmount", orderShipping); serviceContext.put("shippingAddress", shippingAddress); @@ -1541,7 +1539,7 @@ createOrderAdjContext.put("orderItemSeqId", "_NA_"); createOrderAdjContext.put("shipGroupSeqId", "_NA_"); createOrderAdjContext.put("description", "Tax adjustment due to order change"); - createOrderAdjContext.put("amount", new Double(orderTaxDifference.doubleValue())); + createOrderAdjContext.put("amount", orderTaxDifference); createOrderAdjContext.put("userLogin", userLogin); Map createOrderAdjResponse = null; try { @@ -1607,7 +1605,7 @@ shippingTotal = ZERO; Debug.log("No valid order items found - " + shippingTotal, module); } else { - shippingTotal = UtilValidate.isEmpty(shippingEstMap.get("shippingTotal")) ? ZERO : new BigDecimal(((Double) shippingEstMap.get("shippingTotal")).doubleValue()); + shippingTotal = UtilValidate.isEmpty(shippingEstMap.get("shippingTotal")) ? ZERO : (BigDecimal)shippingEstMap.get("shippingTotal"); shippingTotal = shippingTotal.setScale(orderDecimals, orderRounding); Debug.log("Got new shipping estimate - " + shippingTotal, module); } @@ -1791,7 +1789,7 @@ Locale locale = (Locale) context.get("locale"); GenericValue userLogin = (GenericValue) context.get("userLogin"); - Double cancelQuantity = (Double) context.get("cancelQuantity"); + BigDecimal cancelQuantity = (BigDecimal) context.get("cancelQuantity"); String orderId = (String) context.get("orderId"); String orderItemSeqId = (String) context.get("orderItemSeqId"); String shipGroupSeqId = (String) context.get("shipGroupSeqId"); @@ -1840,33 +1838,33 @@ return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCannotCancelItemItemNotFound", UtilMisc.toMap("itemMsgInfo",itemMsgInfo), locale)); } - Double aisgaCancelQuantity = orderItemShipGroupAssoc.getDouble("cancelQuantity"); + BigDecimal aisgaCancelQuantity = orderItemShipGroupAssoc.getBigDecimal("cancelQuantity"); if (aisgaCancelQuantity == null) { - aisgaCancelQuantity = new Double(0.0); + aisgaCancelQuantity = BigDecimal.ZERO; } - Double availableQuantity = Double.valueOf(orderItemShipGroupAssoc.getDouble("quantity").doubleValue() - aisgaCancelQuantity.doubleValue()); + BigDecimal availableQuantity = orderItemShipGroupAssoc.getBigDecimal("quantity").subtract(aisgaCancelQuantity); - Double itemCancelQuantity = orderItem.getDouble("cancelQuantity"); + BigDecimal itemCancelQuantity = orderItem.getBigDecimal("cancelQuantity"); if (itemCancelQuantity == null) { - itemCancelQuantity = new Double(0.0); + itemCancelQuantity = BigDecimal.ZERO; } - Double itemQuantity = Double.valueOf(orderItem.getDouble("quantity").doubleValue() - itemCancelQuantity.doubleValue()); - if (availableQuantity == null) availableQuantity = new Double(0.0); - if (itemQuantity == null) itemQuantity = new Double(0.0); + BigDecimal itemQuantity = orderItem.getBigDecimal("quantity").subtract(itemCancelQuantity); + if (availableQuantity == null) availableQuantity = BigDecimal.ZERO; + if (itemQuantity == null) itemQuantity = BigDecimal.ZERO; - Double thisCancelQty = null; + BigDecimal thisCancelQty = null; if (cancelQuantity != null) { - thisCancelQty = new Double(cancelQuantity.doubleValue()); + thisCancelQty = cancelQuantity; } else { - thisCancelQty = new Double(availableQuantity.doubleValue()); + thisCancelQty = availableQuantity; } - if (availableQuantity.doubleValue() >= thisCancelQty.doubleValue()) { - if (availableQuantity.doubleValue() == 0) { + if (availableQuantity.compareTo(thisCancelQty) >= 0) { + if (availableQuantity.compareTo(BigDecimal.ZERO) == 0) { continue; //OrderItemShipGroupAssoc already cancelled } - orderItem.set("cancelQuantity", Double.valueOf(itemCancelQuantity.doubleValue() + thisCancelQty.doubleValue())); - orderItemShipGroupAssoc.set("cancelQuantity", Double.valueOf(aisgaCancelQuantity.doubleValue() + thisCancelQty.doubleValue())); + orderItem.set("cancelQuantity", itemCancelQuantity.add(thisCancelQty)); + orderItemShipGroupAssoc.set("cancelQuantity", aisgaCancelQuantity.add(thisCancelQty)); try { List toStore = UtilMisc.toList(orderItem, orderItemShipGroupAssoc); @@ -1907,7 +1905,7 @@ } } - if (thisCancelQty.doubleValue() >= itemQuantity.doubleValue()) { + if (thisCancelQty.compareTo(itemQuantity) >= 0) { // all items are cancelled -- mark the item as cancelled Map statusCtx = UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItem.getString("orderItemSeqId"), "statusId", "ITEM_CANCELLED", "userLogin", userLogin); try { @@ -3136,14 +3134,14 @@ String productId = (String) context.get("productId"); String prodCatalogId = (String) context.get("prodCatalogId"); BigDecimal basePrice = (BigDecimal) context.get("basePrice"); - Double quantity = (Double) context.get("quantity"); - Double amount = (Double) context.get("amount"); + BigDecimal quantity = (BigDecimal) context.get("quantity"); + BigDecimal amount = (BigDecimal) context.get("amount"); String overridePrice = (String) context.get("overridePrice"); String reasonEnumId = (String) context.get("reasonEnumId"); String changeComments = (String) context.get("changeComments"); if (amount == null) { - amount = new Double(0.00); + amount = BigDecimal.ZERO; } int shipGroupIdx = -1; @@ -3171,13 +3169,13 @@ // add in the new product try { - ShoppingCartItem item = ShoppingCartItem.makeItem(null, productId, null, quantity.doubleValue(), null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, null, null, null, Boolean.FALSE, Boolean.FALSE); + ShoppingCartItem item = ShoppingCartItem.makeItem(null, productId, null, quantity, null, null, null, null, null, null, null, null, prodCatalogId, null, null, null, dispatcher, cart, null, null, null, Boolean.FALSE, Boolean.FALSE); if (basePrice != null && overridePrice != null) { - item.setBasePrice(basePrice.doubleValue()); + item.setBasePrice(basePrice); // special hack to make sure we re-calc the promos after a price change - item.setQuantity(quantity.doubleValue() + 1, dispatcher, cart, false); - item.setQuantity(quantity.doubleValue(), dispatcher, cart, false); - item.setBasePrice(basePrice.doubleValue()); + item.setQuantity(quantity.add(BigDecimal.ONE), dispatcher, cart, false); + item.setQuantity(quantity, dispatcher, cart, false); + item.setBasePrice(basePrice); item.setIsModifiedPrice(true); } @@ -3246,24 +3244,24 @@ while (i.hasNext()) { String key = (String) i.next(); String quantityStr = (String) itemQtyMap.get(key); - double groupQty = 0.0; + BigDecimal groupQty = BigDecimal.ZERO; try { - groupQty = Double.parseDouble(quantityStr); + groupQty = new BigDecimal(quantityStr); } catch (NumberFormatException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); } - if (groupQty == 0) { + if (groupQty.compareTo(BigDecimal.ZERO) == 0) { return ServiceUtil.returnError("Quantity must be >0, use cancel item to cancel completely!"); } String[] itemInfo = key.split(":"); - Double tally = (Double) itemTotals.get(itemInfo[0]); + BigDecimal tally = (BigDecimal) itemTotals.get(itemInfo[0]); if (tally == null) { - tally = new Double(groupQty); + tally = groupQty; } else { - tally = new Double(tally.doubleValue() + groupQty); + tally = tally.add(groupQty); } itemTotals.put(itemInfo[0], tally); } @@ -3275,12 +3273,12 @@ ShoppingCartItem cartItem = cart.findCartItem(itemSeqId); if (cartItem != null) { - Double qty = (Double) itemTotals.get(itemSeqId); - double priceSave = cartItem.getBasePrice(); + BigDecimal qty = (BigDecimal) itemTotals.get(itemSeqId); + BigDecimal priceSave = cartItem.getBasePrice(); // set quantity try { - cartItem.setQuantity(qty.doubleValue(), dispatcher, cart, false, false); // trigger external ops, don't reset ship groups (and update prices for both PO and SO items) + cartItem.setQuantity(qty, dispatcher, cart, false, false); // trigger external ops, don't reset ship groups (and update prices for both PO and SO items) } catch (CartItemModifyException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -3293,20 +3291,8 @@ if (overridePriceMap.containsKey(itemSeqId)) { String priceStr = (String) itemPriceMap.get(itemSeqId); if (UtilValidate.isNotEmpty(priceStr)) { - double price = -1; - //parse the price - NumberFormat nf = null; - if (locale != null) { - nf = NumberFormat.getNumberInstance(locale); - } else { - nf = NumberFormat.getNumberInstance(); - } - try { - price = nf.parse(priceStr).doubleValue(); - } catch (ParseException e) { - Debug.logError(e, module); - return ServiceUtil.returnError(e.getMessage()); - } + BigDecimal price = new BigDecimal("-1"); + price = new BigDecimal(priceStr).setScale(orderDecimals, orderRounding); cartItem.setBasePrice(price); cartItem.setIsModifiedPrice(true); Debug.log("Set item price: [" + itemSeqId + "] " + price, module); @@ -3334,9 +3320,9 @@ while (gai.hasNext()) { String key = (String) gai.next(); String quantityStr = (String) itemQtyMap.get(key); - double groupQty = 0.0; + BigDecimal groupQty = BigDecimal.ZERO; try { - groupQty = Double.parseDouble(quantityStr); + groupQty = new BigDecimal(quantityStr); } catch (NumberFormatException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -3563,11 +3549,11 @@ throw new GeneralException(ServiceUtil.getErrorMessage(result)); } - Double shippingTotal = (Double) result.get("shippingTotal"); + BigDecimal shippingTotal = (BigDecimal) result.get("shippingTotal"); if (shippingTotal == null) { - shippingTotal = new Double(0.00); + shippingTotal = BigDecimal.ZERO; } - cart.setItemShipGroupEstimate(shippingTotal.doubleValue(), gi); + cart.setItemShipGroupEstimate(shippingTotal, gi); } // calc the sales tax @@ -3641,8 +3627,8 @@ // Existing order item found. Check for modifications and store if any String oldItemDescription = oldOrderItem.getString("itemDescription") != null ? oldOrderItem.getString("itemDescription") : ""; - Double oldQuantity = oldOrderItem.getDouble("quantity") != null ? oldOrderItem.getDouble("quantity") : Double.valueOf(0.00); - Double oldUnitPrice = oldOrderItem.getDouble("unitPrice") != null ? oldOrderItem.getDouble("unitPrice") : Double.valueOf(0.00); + BigDecimal oldQuantity = oldOrderItem.getBigDecimal("quantity") != null ? oldOrderItem.getBigDecimal("quantity") : BigDecimal.ZERO; + BigDecimal oldUnitPrice = oldOrderItem.getBigDecimal("unitPrice") != null ? oldOrderItem.getBigDecimal("unitPrice") : BigDecimal.ZERO; boolean changeFound = false; Map modifiedItem = FastMap.newInstance(); @@ -3651,13 +3637,13 @@ changeFound = true; } - Double quantityDif = Double.valueOf(valueObj.getDouble("quantity").doubleValue() - oldQuantity.doubleValue()); - Double unitPriceDif = Double.valueOf(valueObj.getDouble("unitPrice").doubleValue() - oldUnitPrice.doubleValue()); - if (quantityDif.doubleValue() != 0) { + BigDecimal quantityDif = valueObj.getBigDecimal("quantity").subtract(oldQuantity); + BigDecimal unitPriceDif = valueObj.getBigDecimal("unitPrice").subtract(oldUnitPrice); + if (quantityDif.compareTo(BigDecimal.ZERO) != 0) { modifiedItem.put("quantity", quantityDif); changeFound = true; } - if (unitPriceDif.doubleValue() != 0) { + if (unitPriceDif.compareTo(BigDecimal.ZERO) != 0) { modifiedItem.put("unitPrice", unitPriceDif); changeFound = true; } @@ -3697,7 +3683,7 @@ appendedItem.put("orderId", valueObj.getString("orderId")); appendedItem.put("orderItemSeqId", valueObj.getString("orderItemSeqId")); - appendedItem.put("quantity", valueObj.getDouble("quantity")); + appendedItem.put("quantity", valueObj.getBigDecimal("quantity")); appendedItem.put("changeTypeEnumId", "ODR_ITM_APPEND"); modifiedItems.add(appendedItem); } @@ -3793,7 +3779,7 @@ try { Debug.log("Calling process payments...", module); //Debug.set(Debug.VERBOSE, true); - paymentResp = CheckOutHelper.processPayment(orderId, orh.getOrderGrandTotal().doubleValue(), orh.getCurrency(), productStore, userLogin, false, false, dispatcher, delegator); + paymentResp = CheckOutHelper.processPayment(orderId, orh.getOrderGrandTotal(), orh.getCurrency(), productStore, userLogin, false, false, dispatcher, delegator); //Debug.set(Debug.VERBOSE, false); } catch (GeneralException e) { Debug.logError(e, module); @@ -3815,8 +3801,8 @@ Locale locale = (Locale) context.get("locale"); ShoppingCart cart = new ShoppingCart(dctx.getDelegator(), "9000", "webStore", locale, "USD"); try { - cart.addOrIncreaseItem("GZ-1005", null, 1, null, null, null, null, null, null, null, "DemoCatalog", null, null, null, null, dctx.getDispatcher()); - } catch (CartItemModifyException e) { + cart.addOrIncreaseItem("GZ-1005", null, BigDecimal.ONE, null, null, null, null, null, null, null, "DemoCatalog", null, null, null, null, dctx.getDispatcher()); + } catch (CartItemModifyException e) { Debug.logError(e, module); } catch (ItemNotFoundException e) { Debug.logError(e, module); @@ -3884,12 +3870,12 @@ // create the payment Map paymentParams = new HashMap(); - double maxAmount = orderPaymentPreference.getDouble("maxAmount").doubleValue(); + BigDecimal maxAmount = orderPaymentPreference.getBigDecimal("maxAmount"); //if (maxAmount > 0.0) { paymentParams.put("paymentTypeId", "CUSTOMER_PAYMENT"); paymentParams.put("paymentMethodTypeId", orderPaymentPreference.getString("paymentMethodTypeId")); paymentParams.put("paymentPreferenceId", orderPaymentPreference.getString("orderPaymentPreferenceId")); - paymentParams.put("amount", new Double(maxAmount)); + paymentParams.put("amount", maxAmount); paymentParams.put("statusId", "PMNT_RECEIVED"); paymentParams.put("effectiveDate", UtilDateTime.nowTimestamp()); paymentParams.put("partyIdFrom", billToParty.getString("partyId")); @@ -4192,7 +4178,7 @@ try { int itemIndex = cart.addOrIncreaseItem(item.getString("productId"), null, // amount - item.getDouble("quantity").doubleValue(), + item.getBigDecimal("quantity"), null, null, null, // reserv item.getTimestamp("shipBeforeDate"), item.getTimestamp("shipAfterDate"), @@ -4336,18 +4322,18 @@ if (! "PRODUCT_ORDER_ITEM".equals(orderItem.getString("orderItemTypeId"))) continue; // Get the cancelled quantity for the item - double orderItemCancelQuantity = 0; + BigDecimal orderItemCancelQuantity = BigDecimal.ZERO; if (! UtilValidate.isEmpty(orderItem.get("cancelQuantity")) ) { - orderItemCancelQuantity = orderItem.getDouble("cancelQuantity").doubleValue(); + orderItemCancelQuantity = orderItem.getBigDecimal("cancelQuantity"); } - if (orderItemCancelQuantity <= 0) continue; + if (orderItemCancelQuantity.compareTo(BigDecimal.ZERO) <= 0) continue; String productId = orderItem.getString("productId"); if (productRequirementQuantities.containsKey(productId)) { - orderItemCancelQuantity += ((Double) productRequirementQuantities.get(productId)).doubleValue(); + orderItemCancelQuantity = orderItemCancelQuantity.add((BigDecimal) productRequirementQuantities.get(productId)); } - productRequirementQuantities.put(productId, new Double(orderItemCancelQuantity)); + productRequirementQuantities.put(productId, orderItemCancelQuantity); } @@ -4355,7 +4341,7 @@ Iterator cqit = productRequirementQuantities.keySet().iterator(); while (cqit.hasNext()) { String productId = (String) cqit.next(); - Double requiredQuantity = (Double) productRequirementQuantities.get(productId); + BigDecimal requiredQuantity = (BigDecimal) productRequirementQuantities.get(productId); Map createRequirementResult = dispatcher.runSync("createRequirement", UtilMisc.<String, Object>toMap("requirementTypeId", "PRODUCT_REQUIREMENT", "facilityId", facilityId, "productId", productId, "quantity", requiredQuantity, "userLogin", userLogin)); if (ServiceUtil.isError(createRequirementResult)) return createRequirementResult; } @@ -4408,29 +4394,29 @@ if (! "PRODUCT_ORDER_ITEM".equals(orderItem.getString("orderItemTypeId"))) continue; // Get the ordered quantity for the item - double orderItemQuantity = 0; + BigDecimal orderItemQuantity = BigDecimal.ZERO; if (! UtilValidate.isEmpty(orderItem.get("quantity"))) { - orderItemQuantity = orderItem.getDouble("quantity").doubleValue(); + orderItemQuantity = orderItem.getBigDecimal("quantity"); } - double orderItemCancelQuantity = 0; + BigDecimal orderItemCancelQuantity = BigDecimal.ZERO; if (! UtilValidate.isEmpty(orderItem.get("cancelQuantity")) ) { - orderItemCancelQuantity = orderItem.getDouble("cancelQuantity").doubleValue(); + orderItemCancelQuantity = orderItem.getBigDecimal("cancelQuantity"); } // Get the received quantity for the order item - ignore the quantityRejected, since rejected items should be reordered List shipmentReceipts = orderItem.getRelated("ShipmentReceipt"); - double receivedQuantity = 0; + BigDecimal receivedQuantity = BigDecimal.ZERO; Iterator srit = shipmentReceipts.iterator(); while (srit.hasNext()) { GenericValue shipmentReceipt = (GenericValue) srit.next(); if (! UtilValidate.isEmpty(shipmentReceipt.get("quantityAccepted")) ) { - receivedQuantity += shipmentReceipt.getDouble("quantityAccepted").doubleValue(); + receivedQuantity = receivedQuantity.add(shipmentReceipt.getBigDecimal("quantityAccepted")); } } - double quantityToCancel = orderItemQuantity - orderItemCancelQuantity - receivedQuantity; - if (quantityToCancel > 0) { - Map cancelOrderItemResult = dispatcher.runSync("cancelOrderItem", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItem.get("orderItemSeqId"), "cancelQuantity", new Double(quantityToCancel), "userLogin", userLogin)); + BigDecimal quantityToCancel = orderItemQuantity.subtract(orderItemCancelQuantity).subtract(receivedQuantity); + if (quantityToCancel.compareTo(BigDecimal.ZERO) > 0) { + Map cancelOrderItemResult = dispatcher.runSync("cancelOrderItem", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItem.get("orderItemSeqId"), "cancelQuantity", quantityToCancel, "userLogin", userLogin)); if (ServiceUtil.isError(cancelOrderItemResult)) return cancelOrderItemResult; } @@ -4480,9 +4466,9 @@ Iterator i = itemMap.keySet().iterator(); while (i.hasNext()) { String item = (String) i.next(); - Double price = (Double) itemMap.get(item); + BigDecimal price = (BigDecimal) itemMap.get(item); try { - cart.addNonProductItem("BULK_ORDER_ITEM", item, null, price, 1, null, null, null, dispatcher); + cart.addNonProductItem("BULK_ORDER_ITEM", item, null, price, BigDecimal.ONE, null, null, null, dispatcher); } catch (CartItemModifyException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); |
Free forum by Nabble | Edit this page |