You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2009/02/17 22:16:35 UTC
svn commit: r745257 - in /ofbiz/trunk: applications/order/servicedef/
applications/order/src/org/ofbiz/order/order/
applications/order/src/org/ofbiz/order/shoppingcart/
applications/order/src/org/ofbiz/order/shoppingcart/shipping/
framework/base/src/or...
Author: jleroux
Date: Tue Feb 17 21:16:33 2009
New Revision: 745257
URL: http://svn.apache.org/viewvc?rev=745257&view=rev
Log:
BigDecimal in POS (complete). Integration of ofbiz-1945.patch changes (with some modifications) but still not used since it miss some features:
* AutoSave (automatically save current transaction)
* Add a saved sale to the current sale
* Remove a savec sale
* Replace current sale by a saved sale and remove simultaneously the saved sale
Modified:
ofbiz/trunk/applications/order/servicedef/services.xml
ofbiz/trunk/applications/order/src/org/ofbiz/order/order/OrderLookupServices.java
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/component/Operator.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/device/impl/Receipt.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/LoadSale.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/PosScreen.java
ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/SaveSale.java
Modified: ofbiz/trunk/applications/order/servicedef/services.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/servicedef/services.xml?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/servicedef/services.xml (original)
+++ ofbiz/trunk/applications/order/servicedef/services.xml Tue Feb 17 21:16:33 2009
@@ -304,7 +304,21 @@
<attribute name="itemAttributesMap" type="Map" mode="IN" string-map-prefix="iam_" optional="true"/>
<attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/>
</service>
-
+ <service name="loadCartForUpdate" engine="java" auth="true"
+ location="org.ofbiz.order.order.OrderServices" invoke="loadCartForUpdate">
+ <description>Load an existing shopping cart</description>
+ <attribute name="orderId" type="String" mode="INOUT" optional="false"/>
+ <!-- <attribute name="userLogin" type="String" mode="IN" optional="false"/> -->
+ <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="OUT" optional="false"/>
+ </service>
+ <service name="saveUpdatedCartToOrder" engine="java" auth="true"
+ location="org.ofbiz.order.order.OrderServices" invoke="saveUpdatedCartToOrder">
+ <description>Update the quantities/prices for an existing order</description>
+ <attribute name="orderId" type="String" mode="INOUT" optional="false"/>
+ <attribute name="shoppingCart" type="org.ofbiz.order.shoppingcart.ShoppingCart" mode="IN" optional="false"/>
+ <!-- <attribute name="locale" type="" mode="IN" optional="false"/> -->
+ <attribute name="changeMap" type="Map" mode="IN" optional="false"/>
+ </service>
<service name="appendOrderItem" engine="java" auth="true"
location="org.ofbiz.order.order.OrderServices" invoke="addItemToApprovedOrder">
<description>Append an itemto an existing order</description>
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=745257&r1=745256&r2=745257&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 Tue Feb 17 21:16:33 2009
@@ -64,6 +64,7 @@
// list of fields to select (initial list)
List fieldsToSelect = FastList.newInstance();
fieldsToSelect.add("orderId");
+ fieldsToSelect.add("orderName");
fieldsToSelect.add("statusId");
fieldsToSelect.add("orderTypeId");
fieldsToSelect.add("orderDate");
Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/ShoppingCartServices.java Tue Feb 17 21:16:33 2009
@@ -204,6 +204,12 @@
return ServiceUtil.returnError(e.getMessage());
}
+ // set the order name
+ String orderName = orh.getOrderName();
+ if (orderName != null){
+ cart.setOrderName(orderName);
+ }
+
// set the role information
GenericValue placingParty = orh.getPlacingParty();
if (placingParty != null) {
@@ -453,7 +459,13 @@
// set the PO number on the cart
cart.setPoNumber(item.getString("correspondingPoId"));
-
+
+ List<GenericValue> itemAdjustments = orh.getOrderItemAdjustments(item);
+ if(itemAdjustments != null){
+ for(GenericValue itemAdjustment : itemAdjustments){
+ cartItem.addAdjustment(itemAdjustment);
+ }
+ }
}
if (UtilValidate.isNotEmpty(orderItems)) {
@@ -520,6 +532,13 @@
}
}
+ List adjustments = orh.getOrderHeaderAdjustments();
+ // If applyQuoteAdjustments is set to false then standard cart adjustments are used.
+ if (!adjustments.isEmpty()) {
+ // The cart adjustments are added to the cart
+ cart.getAdjustments().addAll(adjustments);
+ }
+
Map<String, Object> result = ServiceUtil.returnSuccess();
result.put("shoppingCart", cart);
return result;
Modified: ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java (original)
+++ ofbiz/trunk/applications/order/src/org/ofbiz/order/shoppingcart/shipping/ShippingEvents.java Tue Feb 17 21:16:33 2009
@@ -152,6 +152,10 @@
String standardMessage = "A problem occurred calculating shipping. Fees will be calculated offline.";
List errorMessageList = new ArrayList();
+ if (shipmentMethodTypeId.equals("NO_SHIPPING")){
+ return ServiceUtil.returnSuccess();
+ }
+
if (shipmentMethodTypeId == null || carrierPartyId == null) {
if ("SALES_ORDER".equals(orderTypeId)) {
errorMessageList.add("Please Select Your Shipping Method.");
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilFormatOut.java Tue Feb 17 21:16:33 2009
@@ -52,6 +52,15 @@
return formatPrice(price.doubleValue());
}
+ /** Formats a BigDecimal representing a price into a string
+ * @param price The price BigDecimal to be formatted
+ * @return A String with the formatted price
+ */
+ public static String formatPrice(BigDecimal price) {
+ if (price == null) return "";
+ return priceDecimalFormat.format(price);
+ }
+
/** Formats a double representing a price into a string
* @param price The price double to be formatted
* @return A String with the formatted price
@@ -155,6 +164,15 @@
return formatPercentage(percentage.doubleValue());
}
+ /** Formats a BigDecimal representing a percentage into a string
+ * @param percentage The percentage Decimal to be formatted
+ * @return A String with the formatted percentage
+ */
+ public static String formatPercentage(BigDecimal percentage) {
+ if (percentage == null) return "";
+ return formatPercentage(percentage);
+ }
+
/** Formats a double representing a percentage into a string
* @param percentage The percentage double to be formatted
* @return A String with the formatted percentage
@@ -234,6 +252,17 @@
return formatQuantity(quantity.doubleValue());
}
+ /** Formats an BigDecimal representing a quantity into a string
+ * @param quantity The quantity BigDecimal to be formatted
+ * @return A String with the formatted quantity
+ */
+ public static String formatQuantity(BigDecimal quantity) {
+ if (quantity == null)
+ return "";
+ else
+ return quantityDecimalFormat.format(quantity);
+ }
+
/** Formats an double representing a quantity into a string
* @param quantity The quantity double to be formatted
* @return A String with the formatted quantity
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/PosTransaction.java Tue Feb 17 21:16:33 2009
@@ -28,6 +28,8 @@
import java.util.Locale;
import java.util.Map;
import java.util.ArrayList;
+
+import javolution.util.FastMap;
//import javax.swing.SwingWorker;
import net.xoetrope.xui.data.XModel;
@@ -40,6 +42,7 @@
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilNumber;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.collections.LifoSet;
@@ -72,6 +75,10 @@
public class PosTransaction implements Serializable {
+ public static final int scale = UtilNumber.getBigDecimalScale("order.decimals");
+ public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");
+ public static final BigDecimal ZERO = (BigDecimal.ZERO).setScale(scale, rounding);
+
public static final String resource = "PosUiLabels";
public static final String module = PosTransaction.class.getName();
public static final int NO_PAYMENT = 0;
@@ -101,7 +108,7 @@
protected int drawerIdx = 0;
private GenericValue shipAddress = null;
- private Map skuDiscounts = new HashMap();
+ private Map skuDiscounts = FastMap.newInstance();
private int cartDiscount = -1;
@@ -229,11 +236,11 @@
public Map getItemInfo(int index) {
ShoppingCartItem item = cart.findCartItem(index);
- Map itemInfo = new HashMap();
+ Map itemInfo = FastMap.newInstance();
itemInfo.put("productId", item.getProductId());
itemInfo.put("description", item.getDescription());
- itemInfo.put("quantity", UtilFormatOut.formatQuantity(item.getQuantity().doubleValue()));
- itemInfo.put("subtotal", UtilFormatOut.formatPrice(item.getItemSubTotal().doubleValue()));
+ itemInfo.put("quantity", UtilFormatOut.formatQuantity(item.getQuantity()));
+ itemInfo.put("subtotal", UtilFormatOut.formatPrice(item.getItemSubTotal()));
itemInfo.put("isTaxable", item.taxApplies() ? "T" : " ");
itemInfo.put("discount", "");
@@ -241,15 +248,15 @@
if (item.getOtherAdjustments().compareTo(BigDecimal.ZERO) != 0) {
itemInfo.put("itemDiscount", UtilFormatOut.padString(
UtilProperties.getMessage(PosTransaction.resource,"PosItemDiscount",defaultLocale), Receipt.pridLength[0] + 1, true, ' '));
- itemInfo.put("adjustments", UtilFormatOut.formatPrice(item.getOtherAdjustments().doubleValue()));
+ itemInfo.put("adjustments", UtilFormatOut.formatPrice(item.getOtherAdjustments()));
}
if (isAggregatedItem(item.getProductId())){
ProductConfigWrapper pcw = null;
pcw = item.getConfigWrapper();
- itemInfo.put("basePrice", UtilFormatOut.formatPrice(pcw.getDefaultPrice().doubleValue()));
+ itemInfo.put("basePrice", UtilFormatOut.formatPrice(pcw.getDefaultPrice()));
} else {
- itemInfo.put("basePrice", UtilFormatOut.formatPrice(item.getBasePrice().doubleValue()));
+ itemInfo.put("basePrice", UtilFormatOut.formatPrice(item.getBasePrice()));
}
return itemInfo;
}
@@ -267,13 +274,13 @@
Iterator iter = selected.iterator();
while(iter.hasNext()){
ConfigOption configoption = (ConfigOption)iter.next();
- Map itemInfo = new HashMap();
+ Map itemInfo = FastMap.newInstance();
if (configoption.isSelected() && !configoption.isDefault()){
itemInfo.put("productId", "");
itemInfo.put("sku", "");
itemInfo.put("configDescription", configoption.getDescription());
- itemInfo.put("configQuantity", UtilFormatOut.formatQuantity(item.getQuantity().doubleValue()));
- itemInfo.put("configBasePrice", UtilFormatOut.formatPrice(configoption.getOffsetPrice().doubleValue()));
+ itemInfo.put("configQuantity", UtilFormatOut.formatQuantity(item.getQuantity()));
+ itemInfo.put("configBasePrice", UtilFormatOut.formatPrice(configoption.getOffsetPrice()));
//itemInfo.put("isTaxable", item.taxApplies() ? "T" : " ");
list.add(itemInfo);
}
@@ -287,7 +294,7 @@
GenericValue infValue = inf.getValueObject(session.getDelegator());
GenericValue paymentPref = null;
try {
- Map fields = new HashMap();
+ Map fields = FastMap.newInstance();
fields.put("paymentMethodTypeId", inf.paymentMethodTypeId);
if (inf.paymentMethodId != null) {
fields.put("paymentMethodId", inf.paymentMethodId);
@@ -312,7 +319,7 @@
}
//Debug.log("PaymentPref - " + paymentPref, module);
- Map payInfo = new HashMap();
+ Map payInfo = FastMap.newInstance();
// locate the auth info
GenericValue authTrans = null;
@@ -335,7 +342,7 @@
if ("PaymentMethodType".equals(infValue.getEntityName())) {
payInfo.put("description", infValue.getString("description"));
payInfo.put("payInfo", infValue.getString("description"));
- payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount.doubleValue()));
+ payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount));
} else {
String paymentMethodTypeId = infValue.getString("paymentMethodTypeId");
GenericValue pmt = null;
@@ -346,7 +353,7 @@
}
if (pmt != null) {
payInfo.put("description", pmt.getString("description"));
- payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount.doubleValue()));
+ payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount));
}
if ("CREDIT_CARD".equals(paymentMethodTypeId)) {
@@ -547,13 +554,13 @@
}
}
- public void addDiscount(String productId, double discount, boolean percent) {
+ public void addDiscount(String productId, BigDecimal discount, boolean percent) {
GenericValue adjustment = session.getDelegator().makeValue("OrderAdjustment");
adjustment.set("orderAdjustmentTypeId", "DISCOUNT_ADJUSTMENT");
if (percent) {
- adjustment.set("sourcePercentage", new Double(discount * 100));
+ adjustment.set("sourcePercentage", discount.movePointRight(2));
} else {
- adjustment.set("amount", new Double(discount));
+ adjustment.set("amount", discount);
}
if (productId != null) {
@@ -786,6 +793,9 @@
// attach the party ID to the cart
cart.setOrderPartyId(partyId);
+ // Set the shipping type
+ cart.setShipmentMethodTypeId("NO_SHIPPING");
+ // cart.setCarrierPartyId();
// validate payment methods
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosValidating",defaultLocale));
@@ -795,18 +805,42 @@
}
// store the "order"
- output.print(UtilProperties.getMessage(PosTransaction.resource,"PosSaving",defaultLocale));
- Map orderRes = ch.createOrder(session.getUserLogin());
- //Debug.log("Create Order Resp : " + orderRes, module);
-
- if (orderRes != null && ServiceUtil.isError(orderRes)) {
- throw new GeneralException(ServiceUtil.getErrorMessage(orderRes));
- } else if (orderRes != null) {
- this.orderId = (String) orderRes.get("orderId");
- }
+ if (UtilValidate.isEmpty(this.orderId)){ // if order does not exist
+ output.print(UtilProperties.getMessage(PosTransaction.resource,"Saving",defaultLocale));
+ Map orderRes = ch.createOrder(session.getUserLogin());
+ //Debug.log("Create Order Resp : " + orderRes, module);
+
+ if (orderRes != null && ServiceUtil.isError(orderRes)) {
+ throw new GeneralException(ServiceUtil.getErrorMessage(orderRes));
+ } else if (orderRes != null) {
+ this.orderId = (String) orderRes.get("orderId");
+ }
+ } else { // if the order has already been created
+ Map changeMap = UtilMisc.toMap("itemReasonMap",
+ UtilMisc.toMap("reasonEnumId", "EnumIdHere"), // TODO: where does this come from?
+ "itemCommentMap",
+ UtilMisc.toMap("changeComments", "change Comments here")); //TODO
+
+ Map svcCtx = FastMap.newInstance();
+ svcCtx.put("userLogin", session.getUserLogin());
+ svcCtx.put("orderId", orderId);
+ svcCtx.put("shoppingCart", cart);
+ svcCtx.put("locale", this.locale);
+ svcCtx.put("changeMap", changeMap);
+
+ Map svcRes = null;
+ try {
+ LocalDispatcher dispatcher = session.getDispatcher();
+ svcRes = dispatcher.runSync("saveUpdatedCartToOrder", svcCtx);
+ } catch (GenericServiceException e) {
+ Debug.logError(e, module);
+ //pos.showDialog("dialog/error/exception", e.getMessage());
+ throw new GeneralException(ServiceUtil.getErrorMessage(svcRes));
+ }
+ }
// process the payment(s)
- output.print(UtilProperties.getMessage(PosTransaction.resource,"PosProcessing",defaultLocale));
+ output.print(UtilProperties.getMessage(PosTransaction.resource, "PosProcessing", defaultLocale));
Map payRes = null;
try {
payRes = ch.processPayment(ProductStoreWorker.getProductStore(productStoreId, session.getDelegator()), session.getUserLogin(), true);
@@ -823,7 +857,7 @@
BigDecimal change = grandTotal.subtract(paymentAmt);
// notify the change due
- output.print(UtilProperties.getMessage(PosTransaction.resource,"PosChange",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue().negate().doubleValue()));
+ output.print(UtilProperties.getMessage(PosTransaction.resource,"PosChange",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue().negate()));
// threaded drawer/receipt printing
final PosTransaction currentTrans = this;
@@ -898,8 +932,8 @@
XModel line = Journal.appendNode(model, "tr", ""+cart.getItemIndex(item), "");
Journal.appendNode(line, "td", "sku", item.getProductId());
Journal.appendNode(line, "td", "desc", item.getName());
- Journal.appendNode(line, "td", "qty", UtilFormatOut.formatQuantity(quantity.doubleValue()));
- Journal.appendNode(line, "td", "price", UtilFormatOut.formatPrice(subTotal.doubleValue()));
+ Journal.appendNode(line, "td", "qty", UtilFormatOut.formatQuantity(quantity));
+ Journal.appendNode(line, "td", "price", UtilFormatOut.formatPrice(subTotal));
Journal.appendNode(line, "td", "index", Integer.toString(cart.getItemIndex(item)));
if (this.isAggregatedItem(item.getProductId())){
@@ -917,7 +951,7 @@
Journal.appendNode(option, "td", "sku", "");
Journal.appendNode(option, "td", "desc", configoption.getDescription());
Journal.appendNode(option, "td", "qty", "");
- Journal.appendNode(option, "td", "price", UtilFormatOut.formatPrice(configoption.getPrice().doubleValue()));
+ Journal.appendNode(option, "td", "price", UtilFormatOut.formatPrice(configoption.getPrice()));
Journal.appendNode(option, "td", "index", Integer.toString(cart.getItemIndex(item)));
}
}
@@ -929,7 +963,7 @@
Journal.appendNode(promo, "td", "sku", "");
Journal.appendNode(promo, "td", "desc", UtilProperties.getMessage(PosTransaction.resource,"PosItemDiscount",defaultLocale));
Journal.appendNode(promo, "td", "qty", "");
- Journal.appendNode(promo, "td", "price", UtilFormatOut.formatPrice(adjustment.doubleValue()));
+ Journal.appendNode(promo, "td", "price", UtilFormatOut.formatPrice(adjustment));
}
}
}
@@ -955,7 +989,7 @@
Iterator iter = adjustments.iterator();
while(iter.hasNext()){
GenericValue orderAdjustment = (GenericValue) iter.next();
- Double amount = orderAdjustment.getDouble("amount");
+ BigDecimal amount = orderAdjustment.getBigDecimal("amount");
}
iter = adjustments.iterator();
@@ -969,12 +1003,12 @@
UtilProperties.getMessage(PosTransaction.resource, "PosSalesDiscount",defaultLocale));
if (UtilValidate.isNotEmpty(amount)) {
Journal.appendNode(adjustmentLine, "td", "qty", "");
- Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(amount.doubleValue()));
+ Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(amount));
} else if (UtilValidate.isNotEmpty(sourcePercentage)) {
BigDecimal percentage = sourcePercentage.movePointLeft(2).negate(); // sourcePercentage is negative and must be show as a positive value (it's a discount not an amount)
- Journal.appendNode(adjustmentLine, "td", "qty", UtilFormatOut.formatPercentage(percentage.doubleValue()));
+ Journal.appendNode(adjustmentLine, "td", "qty", UtilFormatOut.formatPercentage(percentage));
amount = cart.getItemTotal().add(itemsAdjustmentsAmount).multiply(percentage); // itemsAdjustmentsAmount is negative
- Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(amount.negate().doubleValue())); // amount must be shown as a negative value
+ Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(amount.negate())); // amount must be shown as a negative value
}
Journal.appendNode(adjustmentLine, "td", "index", "-1");
}
@@ -985,14 +1019,14 @@
Journal.appendNode(taxLine, "td", "desc", UtilProperties.getMessage(PosTransaction.resource,"PosSalesTax",defaultLocale));
Journal.appendNode(taxLine, "td", "qty", "");
- Journal.appendNode(taxLine, "td", "price", UtilFormatOut.formatPrice(taxAmount.doubleValue()));
+ Journal.appendNode(taxLine, "td", "price", UtilFormatOut.formatPrice(taxAmount));
Journal.appendNode(taxLine, "td", "index", "-1");
XModel totalLine = Journal.appendNode(model, "tr", "total", "");
Journal.appendNode(totalLine, "td", "sku", "");
Journal.appendNode(totalLine, "td", "desc", UtilProperties.getMessage(PosTransaction.resource,"PosGrandTotal",defaultLocale));
Journal.appendNode(totalLine, "td", "qty", "");
- Journal.appendNode(totalLine, "td", "price", UtilFormatOut.formatPrice(total.doubleValue()));
+ Journal.appendNode(totalLine, "td", "price", UtilFormatOut.formatPrice(total));
Journal.appendNode(totalLine, "td", "index", "-1");
}
}
@@ -1030,7 +1064,7 @@
Journal.appendNode(paymentLine, "td", "sku", "");
Journal.appendNode(paymentLine, "td", "desc", descString);
Journal.appendNode(paymentLine, "td", "qty", "-");
- Journal.appendNode(paymentLine, "td", "price", UtilFormatOut.formatPrice(amount.negate().doubleValue()));
+ Journal.appendNode(paymentLine, "td", "price", UtilFormatOut.formatPrice(amount.negate()));
Journal.appendNode(paymentLine, "td", "index", Integer.toString(i));
}
}
@@ -1044,7 +1078,7 @@
Journal.appendNode(changeLine, "td", "sku", "");
Journal.appendNode(changeLine, "td", "desc", "Change");
Journal.appendNode(changeLine, "td", "qty", "-");
- Journal.appendNode(changeLine, "td", "price", UtilFormatOut.formatPrice(changeDue.doubleValue()));
+ Journal.appendNode(changeLine, "td", "price", UtilFormatOut.formatPrice(changeDue));
}
}
}
@@ -1058,7 +1092,7 @@
expYear = "20" + expYear;
}
- Map svcCtx = new HashMap();
+ Map svcCtx = FastMap.newInstance();
svcCtx.put("userLogin", session.getUserLogin());
svcCtx.put("partyId", partyId);
svcCtx.put("cardNumber", cardNumber);
@@ -1152,6 +1186,50 @@
pos.showDialog("dialog/error/nosales");
}
}
+
+ public void loadOrder(PosScreen pos) {
+ List<GenericValue> orders = findOrders();
+ if (!orders.isEmpty()) {
+ LoadSale loadSale = new LoadSale(createOrderHash(orders), this, pos);
+ loadSale.openDlg();
+ } else {
+ pos.showDialog("dialog/error/nosales");
+ }
+ }
+
+ private List<GenericValue> findOrders() {
+ LocalDispatcher dispatcher = session.getDispatcher();
+
+ Map svcCtx = FastMap.newInstance();
+ svcCtx.put("userLogin", session.getUserLogin());
+ svcCtx.put("partyId", partyId);
+ List orderStatusIds = new ArrayList();
+ orderStatusIds.add("ORDER_CREATED");
+ svcCtx.put("orderStatusId", orderStatusIds);
+ svcCtx.put("viewIndex", 1);
+ svcCtx.put("viewSize", 25);
+ svcCtx.put("showAll", "Y");
+
+ Map svcRes = null;
+ try {
+ svcRes = dispatcher.runSync("findOrders", svcCtx);
+ } catch (GenericServiceException e) {
+ Debug.logError(e, module);
+ }
+
+ if (svcRes == null) {
+ Debug.log(UtilProperties.getMessage("EcommerceUiLabels","EcommerceNoShoppingListsCreate",locale), module);
+ } else if (ServiceUtil.isError(svcRes)) {
+ Debug.logError(ServiceUtil.getErrorMessage(svcRes) + " - " + svcRes, module);
+ } else{
+ Integer orderListSize = (Integer) svcRes.get("orderListSize");
+ if (orderListSize > 0){
+ List orderList = (List) svcRes.get("orderList");
+ return orderList;
+ }
+ }
+ return null;
+ }
/* public void configureItem(String cartIndex, PosScreen pos) {
trace("configure item", cartIndex);
@@ -1210,20 +1288,76 @@
return salesMap;
}
- public boolean addListToCart(String shoppingListId, PosScreen pos, boolean append) {
+ public Map<String, String> createOrderHash(List<GenericValue> orders) {
+ Map<String, String> hash = FastMap.newInstance();
+ for (GenericValue order : orders) {
+ String orderName = order.getString("orderName");
+ String orderId = order.getString("orderId");
+ if(orderName != null){
+ hash.put(orderId, orderName);
+ }
+ }
+ return hash;
+ }
+
+ public boolean addListToCart(String shoppingListId, PosScreen pos, boolean append) {
GenericDelegator delegator = session.getDelegator();
LocalDispatcher dispatcher = session.getDispatcher();
String includeChild = null; // Perhaps will be used later ...
- String prodCatalogId = null;
+ String prodCatalogId = null;
- try {
- ShoppingListEvents.addListToCart(delegator, dispatcher, cart, prodCatalogId, shoppingListId, (includeChild != null), true, append);
- } catch (IllegalArgumentException e) {
- Debug.logError(e, module);
- pos.showDialog("dialog/error/exception", e.getMessage());
- return false;
+ try {
+ ShoppingListEvents.addListToCart(delegator, dispatcher, cart, prodCatalogId, shoppingListId, (includeChild != null), true, append);
+ } catch (IllegalArgumentException e) {
+ Debug.logError(e, module);
+ pos.showDialog("dialog/error/exception", e.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ public boolean restoreOrder(String orderId, PosScreen pos, boolean append) {
+ GenericDelegator delegator = session.getDelegator();
+ LocalDispatcher dispatcher = session.getDispatcher();
+
+ Map svcCtx = FastMap.newInstance();
+ svcCtx.put("userLogin", session.getUserLogin());
+ svcCtx.put("orderId", orderId);
+ svcCtx.put("skipInventoryChecks", Boolean.TRUE);
+ svcCtx.put("skipProductChecks", Boolean.TRUE);
+
+ Map svcRes = null;
+ try {
+ svcRes = dispatcher.runSync("loadCartFromOrder", svcCtx);
+ } catch (GenericServiceException e) {
+ Debug.logError(e, module);
+ pos.showDialog("dialog/error/exception", e.getMessage());
+ }
+
+ if (svcRes == null) {
+ Debug.log(UtilProperties.getMessage("EcommerceUiLabels","EcommerceNoShoppingListsCreate",locale), module);
+ } else if (ServiceUtil.isError(svcRes)) {
+ Debug.logError(ServiceUtil.getErrorMessage(svcRes) + " - " + svcRes, module);
+ } else{
+ ShoppingCart restoredCart = (ShoppingCart) svcRes.get("shoppingCart");
+ if(append){
+ // TODO: add stuff to append items
+ this.cart = restoredCart;
+ this.orderId = orderId;
+ }else{
+ this.cart = restoredCart;
+ this.orderId = orderId;
}
+ this.ch = new CheckOutHelper(session.getDispatcher(), session.getDelegator(), cart);
+ if (session.getUserLogin() != null) {
+ cart.addAdditionalPartyRole(session.getUserLogin().getString("partyId"), "SALES_REP");
+ }
+ cart.setFacilityId(facilityId);
+ cart.setTerminalId(terminalId);
+ cart.setOrderId(orderId);
return true;
+ }
+ return false;
}
public boolean clearList(String shoppingListId, PosScreen pos) {
@@ -1238,11 +1372,42 @@
return true;
}
-
+
public void saveSale(PosScreen pos) {
SaveSale SaveSale = new SaveSale(this, pos);
SaveSale.openDlg();
}
+
+ public void saveOrder(String shoppingListName, PosScreen pos) {
+ if (cart.size() == 0 ) {
+ pos.showDialog("dialog/error/exception", UtilProperties.getMessage("OrderErrorUiLabels", "OrderUnableToCreateNewShoppingList",locale));
+ return;
+ }
+ GenericDelegator delegator = this.session.getDelegator();
+ LocalDispatcher dispatcher = session.getDispatcher();
+ GenericValue userLogin = session.getUserLogin();
+ Locale locale = defaultLocale;
+ String shoppingListId = null;
+
+ if (!UtilValidate.isEmpty(shoppingListName)) {
+ // attach the party ID to the cart
+ cart.setOrderPartyId(partyId);
+ cart.setOrderName(shoppingListName);
+ //cart.setExternalId(shoppingListName);
+ //cart.setInternalCode("Internal Code");
+ //Debug.logInfo(UtilProperties.getMessage("pos","Saving",defaultLocale), module);
+ //ch.setCheckOutOptions(null, null, null, null, null, "shipping instructions", null, null, null, "InternalId", null, null, null);
+ Map orderRes = ch.createOrder(session.getUserLogin());
+
+ if (orderRes != null && ServiceUtil.isError(orderRes)) {
+ Debug.logError(ServiceUtil.getErrorMessage(orderRes), module);
+ //throw new GeneralException(ServiceUtil.getErrorMessage(orderRes));
+ } else if (orderRes != null) {
+ this.orderId = (String) orderRes.get("orderId");
+ }
+ }
+ }
+
public void saveSale(String shoppingListName, PosScreen pos) {
if (cart.size() == 0 ) {
pos.showDialog("dialog/error/exception", UtilProperties.getMessage("OrderErrorUiLabels", "OrderUnableToCreateNewShoppingList",locale));
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/component/Operator.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/component/Operator.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/component/Operator.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/component/Operator.java Tue Feb 17 21:16:33 2009
@@ -103,7 +103,7 @@
if (OPER_TOTAL[0].equals(fieldName)) {
String total = "0.00";
if (trans != null) {
- total = UtilFormatOut.formatPrice(trans.getTotalDue().doubleValue());
+ total = UtilFormatOut.formatPrice(trans.getTotalDue());
}
field.setText(total);
} else if (OPER_DATE[0].equals(fieldName)) {
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/device/impl/Receipt.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/device/impl/Receipt.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/device/impl/Receipt.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/device/impl/Receipt.java Tue Feb 17 21:16:33 2009
@@ -467,13 +467,13 @@
expandMap.put("orderId", trans.getOrderId());
expandMap.put("dateStamp", dateString);
expandMap.put("drawerNo", Integer.toString(trans.getDrawerNumber()));
- expandMap.put("taxTotal", UtilFormatOut.padString(UtilFormatOut.formatPrice(trans.getTaxTotal().doubleValue()), priceLength[type], false, ' '));
- expandMap.put("grandTotal", UtilFormatOut.padString(UtilFormatOut.formatPrice(trans.getGrandTotal().doubleValue()), priceLength[type], false, ' '));
- expandMap.put("totalPayments", UtilFormatOut.padString(UtilFormatOut.formatPrice(trans.getPaymentTotal().doubleValue()), priceLength[type], false, ' '));
+ expandMap.put("taxTotal", UtilFormatOut.padString(UtilFormatOut.formatPrice(trans.getTaxTotal()), priceLength[type], false, ' '));
+ expandMap.put("grandTotal", UtilFormatOut.padString(UtilFormatOut.formatPrice(trans.getGrandTotal()), priceLength[type], false, ' '));
+ expandMap.put("totalPayments", UtilFormatOut.padString(UtilFormatOut.formatPrice(trans.getPaymentTotal()), priceLength[type], false, ' '));
expandMap.put("change", UtilFormatOut.padString((trans.getTotalDue().compareTo(BigDecimal.ZERO) < 0 ?
- UtilFormatOut.formatPrice(trans.getTotalDue().negate().doubleValue()) : "0.00"), priceLength[type], false, ' '));
+ UtilFormatOut.formatPrice(trans.getTotalDue().negate()) : "0.00"), priceLength[type], false, ' '));
expandMap.put("saleDiscount", UtilFormatOut.padString((trans.GetTotalDiscount().compareTo(BigDecimal.ZERO) != 0 ?
- UtilFormatOut.formatPrice(trans.GetTotalDiscount().doubleValue()) : "0.00"), priceLength[type], false, ' '));
+ UtilFormatOut.formatPrice(trans.GetTotalDiscount()) : "0.00"), priceLength[type], false, ' '));
return expandMap;
}
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/ManagerEvents.java Tue Feb 17 21:16:33 2009
@@ -33,6 +33,7 @@
import org.ofbiz.base.util.UtilDateTime;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilNumber;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.cache.UtilCache;
@@ -63,6 +64,11 @@
public static boolean mgrLoggedIn = false;
static DecimalFormat priceDecimalFormat = new DecimalFormat("#,##0.00");
+ // scales and rounding modes for BigDecimal math
+ public static final int scale = UtilNumber.getBigDecimalScale("order.decimals");
+ public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");
+ public static final BigDecimal ZERO = (BigDecimal.ZERO).setScale(scale, rounding);
+
public static synchronized void modifyPrice(PosScreen pos) {
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
String sku = null;
@@ -80,7 +86,7 @@
Input input = pos.getInput();
String value = input.value();
if (UtilValidate.isNotEmpty(value)) {
- BigDecimal price = BigDecimal.ZERO;
+ BigDecimal price = ZERO;
boolean parsed = false;
try {
price = new BigDecimal(value);
@@ -111,13 +117,12 @@
Input input = pos.getInput();
if (!trans.isOpen()) {
if (input.isFunctionSet("OPEN")) {
+ BigDecimal amt = ZERO;
String amountStr = input.value();
- if (UtilValidate.isNotEmpty(amountStr))
- {
+ if (UtilValidate.isNotEmpty(amountStr)) {
try {
- double amt = Double.parseDouble(amountStr);
- amt = amt / 100;
- amountStr = UtilFormatOut.formatPrice(amt);
+ amt = new BigDecimal(amountStr);
+ amt = amt.movePointLeft(2);
} catch (NumberFormatException e)
{
Debug.logError(e, module);
@@ -128,14 +133,7 @@
state.set("openedDate", UtilDateTime.nowTimestamp());
state.set("openedByUserLoginId", pos.getSession().getUserId());
state.set("startingTxId", trans.getTransactionId());
- try
- {
- state.set("startingDrawerAmount", new Double(priceDecimalFormat.parse(amountStr).doubleValue()));
- }
- catch (ParseException pe)
- {
- Debug.logError(pe, module);
- }
+ state.set("startingDrawerAmount", amt);
try {
state.create();
} catch (GenericEntityException e) {
@@ -172,10 +170,11 @@
String[] func = input.getFunction("CLOSE");
String lastValue = input.value();
if (UtilValidate.isNotEmpty(lastValue)) {
+
try {
- double dbl = Double.parseDouble(lastValue);
- dbl = dbl / 100;
- lastValue = UtilFormatOut.formatPrice(dbl);
+ BigDecimal amt = new BigDecimal(lastValue);
+ amt = amt.movePointLeft(2);
+ lastValue = amt.toString();
} catch (NumberFormatException e) {
Debug.logError(e, module);
}
@@ -210,18 +209,11 @@
GenericValue state = trans.getTerminalState();
state.set("closedDate", UtilDateTime.nowTimestamp());
state.set("closedByUserLoginId", pos.getSession().getUserId());
- try
- {
- state.set("actualEndingCash", new Double(priceDecimalFormat.parse(closeInfo[0]).doubleValue()));
- state.set("actualEndingCheck", new Double(priceDecimalFormat.parse(closeInfo[1]).doubleValue()));
- state.set("actualEndingCc", new Double(priceDecimalFormat.parse(closeInfo[2]).doubleValue()));
- state.set("actualEndingGc", new Double(priceDecimalFormat.parse(closeInfo[3]).doubleValue()));
- state.set("actualEndingOther", new Double(priceDecimalFormat.parse(closeInfo[4]).doubleValue()));
- }
- catch (ParseException pe)
- {
- Debug.logError(pe, module);
- }
+ state.set("actualEndingCash", new BigDecimal(closeInfo[0]));
+ state.set("actualEndingCheck", new BigDecimal(closeInfo[1]));
+ state.set("actualEndingCc", new BigDecimal(closeInfo[2]));
+ state.set("actualEndingGc", new BigDecimal(closeInfo[3]));
+ state.set("actualEndingOther", new BigDecimal(closeInfo[4]));
state.set("endingTxId", trans.getTransactionId());
Debug.log("Updated State - " + state, module);
try {
@@ -427,8 +419,10 @@
Map mapInOut = PaidInOut.openDlg();
if (null != mapInOut.get("amount")) {
String amount = (String) mapInOut.get("amount");
+ BigDecimal amt = ZERO;
try {
- double dbl = Double.parseDouble(amount);
+ amt = new BigDecimal(amount);
+ amt = amt.movePointLeft(2);
} catch (NumberFormatException e) {
Debug.logError(e, module);
return;
@@ -436,15 +430,7 @@
GenericValue internTx = pos.getSession().getDelegator().makeValue("PosTerminalInternTx");
internTx.set("posTerminalLogId", trans.getTerminalLogId());
- try
- {
- internTx.set("paidAmount", new Double(priceDecimalFormat.parse(amount).doubleValue() / 100));
- }
- catch (ParseException pe)
- {
- Debug.logError(pe, module);
- return;
- }
+ internTx.set("paidAmount", amt);
internTx.set("reasonComment", mapInOut.get("reasonComment"));
internTx.set("reasonEnumId", mapInOut.get("reason"));
try {
@@ -470,12 +456,12 @@
state = trans.getTerminalState();
}
- double checkTotal = 0.00;
- double cashTotal = 0.00;
- double gcTotal = 0.00;
- double ccTotal = 0.00;
- double othTotal = 0.00;
- double total = 0.00;
+ BigDecimal checkTotal = ZERO;
+ BigDecimal cashTotal = ZERO;
+ BigDecimal gcTotal = ZERO;
+ BigDecimal ccTotal = ZERO;
+ BigDecimal othTotal = ZERO;
+ BigDecimal total = ZERO;
GenericDelegator delegator = pos.getSession().getDelegator();
List<EntityExpr> exprs = UtilMisc.toList(EntityCondition.makeCondition("originFacilityId", EntityOperator.EQUALS, trans.getFacilityId()),
@@ -500,20 +486,20 @@
Timestamp orderDate = ohpp.getTimestamp("orderDate");
if (orderDate.after(dayStart) && orderDate.before(dayEnd)) {
String pmt = ohpp.getString("paymentMethodTypeId");
- Double amt = ohpp.getDouble("maxAmount");
+ BigDecimal amt = ohpp.getBigDecimal("maxAmount");
if ("CASH".equals(pmt)) {
- cashTotal += amt.doubleValue();
+ cashTotal = cashTotal.add(amt);
} else if ("PERSONAL_CHECK".equals(pmt)) {
- checkTotal += amt.doubleValue();
+ checkTotal = checkTotal.add(amt);
} else if ("GIFT_CARD".equals(pmt)) {
- gcTotal += amt.doubleValue();
+ gcTotal = gcTotal.add(amt);
} else if ("CREDIT_CARD".equals(pmt)) {
- ccTotal += amt.doubleValue();
+ ccTotal = ccTotal.add(amt);
} else {
- othTotal += amt.doubleValue();
+ othTotal = othTotal.add(amt);
}
- total += amt.doubleValue();
+ total = total.add(amt);
}
}
@@ -553,12 +539,12 @@
if (runBalance) {
// actuals
- double cashEnd = state.getDouble("actualEndingCash").doubleValue();
- double checkEnd = state.getDouble("actualEndingCheck").doubleValue();
- double ccEnd = state.getDouble("actualEndingCc").doubleValue();
- double gcEnd = state.getDouble("actualEndingGc").doubleValue();
- double othEnd = state.getDouble("actualEndingOther").doubleValue();
- double grossEnd = cashEnd + checkEnd + ccEnd + gcEnd + othEnd;
+ BigDecimal cashEnd = state.getBigDecimal("actualEndingCash");
+ BigDecimal checkEnd = state.getBigDecimal("actualEndingCheck");
+ BigDecimal ccEnd = state.getBigDecimal("actualEndingCc");
+ BigDecimal gcEnd = state.getBigDecimal("actualEndingGc");
+ BigDecimal othEnd = state.getBigDecimal("actualEndingOther");
+ BigDecimal grossEnd = cashEnd.add(checkEnd.add(ccEnd.add(gcEnd.add(othEnd))));
reportMap.put("cashEnd", UtilFormatOut.padString(UtilFormatOut.formatPrice(cashEnd), 8, false, ' '));
reportMap.put("checkEnd", UtilFormatOut.padString(UtilFormatOut.formatPrice(checkEnd), 8, false, ' '));
@@ -568,12 +554,12 @@
reportMap.put("grossEnd", UtilFormatOut.padString(UtilFormatOut.formatPrice(grossEnd), 8, false, ' '));
// diffs
- double cashDiff = cashEnd - cashTotal;
- double checkDiff = checkEnd - checkTotal;
- double ccDiff = ccEnd - ccTotal;
- double gcDiff = gcEnd - gcTotal;
- double othDiff = othEnd - othTotal;
- double grossDiff = cashDiff + checkDiff + ccDiff + gcDiff + othDiff;
+ BigDecimal cashDiff = cashEnd.subtract(cashTotal);
+ BigDecimal checkDiff = checkEnd.subtract(checkTotal);
+ BigDecimal ccDiff = ccEnd.subtract(ccTotal);
+ BigDecimal gcDiff = gcEnd.subtract(gcTotal);
+ BigDecimal othDiff = othEnd.subtract(othTotal);
+ BigDecimal grossDiff = cashDiff.add(checkDiff.add(ccDiff.add(gcDiff.add(othDiff))));
reportMap.put("cashDiff", UtilFormatOut.padString(UtilFormatOut.formatPrice(cashDiff), 8, false, ' '));
reportMap.put("checkDiff", UtilFormatOut.padString(UtilFormatOut.formatPrice(checkDiff), 8, false, ' '));
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/event/MenuEvents.java Tue Feb 17 21:16:33 2009
@@ -24,6 +24,7 @@
import java.util.ListIterator;
import java.awt.AWTEvent;
+import org.ofbiz.base.util.UtilNumber;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
@@ -43,6 +44,11 @@
public static final String module = MenuEvents.class.getName();
+ // scales and rounding modes for BigDecimal math
+ public static final int scale = UtilNumber.getBigDecimalScale("order.decimals");
+ public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");
+ public static final BigDecimal ZERO = (BigDecimal.ZERO).setScale(scale, rounding);
+
// extended number events
public static synchronized void triggerClear(PosScreen pos) {
// clear the pieces
@@ -298,18 +304,18 @@
Input input = pos.getInput();
String value = input.value();
if (UtilValidate.isNotEmpty(value)) {
- double amount = 0.00;
+ BigDecimal amount = ZERO;
boolean percent = false;
if (value.endsWith("%")) {
percent = true;
value = value.substring(0, value.length() - 1);
}
try {
- amount = Double.parseDouble(value);
+ amount = new BigDecimal(value);
} catch (NumberFormatException e) {
}
- amount = (amount / 100) * -1;
+ amount = amount.movePointLeft(2).negate();
trans.addDiscount(null, amount, percent);
trans.calcTax();
}
@@ -337,18 +343,18 @@
Input input = pos.getInput();
String value = input.value();
if (UtilValidate.isNotEmpty(value)) {
- double amount = 0.00;
+ BigDecimal amount = ZERO;
boolean percent = false;
if (value.endsWith("%")) {
percent = true;
value = value.substring(0, value.length() - 1);
}
try {
- amount = Double.parseDouble(value);
+ amount = new BigDecimal(value);
} catch (NumberFormatException e) {
}
- amount = (amount / 100) * -1;
+ amount = amount.movePointLeft(2).negate();
trans.addDiscount(sku, amount, percent);
trans.calcTax();
}
@@ -411,6 +417,7 @@
public static synchronized void loadSale(PosScreen pos) {
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
trans.loadSale(pos);
+// trans.loadOrder(pos); // TODO use order instead of shopping list
}
public static synchronized String getSelectedItem(PosScreen pos) {
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/LoadSale.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/LoadSale.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/LoadSale.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/LoadSale.java Tue Feb 17 21:16:33 2009
@@ -26,6 +26,8 @@
import javax.swing.DefaultListModel;
import javax.swing.ListSelectionModel;
+import javolution.util.FastMap;
+
import net.xoetrope.swing.XButton;
import net.xoetrope.swing.XDialog;
import net.xoetrope.swing.XList;
@@ -46,7 +48,7 @@
public static final String module = LoadSale.class.getName();
protected static PosScreen m_pos = null;
protected XDialog m_dialog = null;
- static protected Hashtable m_saleMap = new Hashtable();
+ static protected Map<String, String> m_saleMap = FastMap.newInstance();
protected XList m_salesList = null;
protected XButton m_cancel = null;
protected XButton m_add = null;
@@ -58,7 +60,7 @@
//TODO : make getter and setter for members (ie m_*) if needed (extern calls). For that in Eclipse use Source/Generate Getters and setters
- public LoadSale(Hashtable saleMap, PosTransaction trans, PosScreen page) {
+ public LoadSale(Map<String, String> saleMap, PosTransaction trans, PosScreen page) {
m_saleMap.putAll(saleMap);
m_trans = trans;
m_pos = page;
@@ -212,6 +214,7 @@
final ClassLoader cl = this.getClassLoader(m_pos);
Thread.currentThread().setContextClassLoader(cl);
if (!m_trans.addListToCart(sale, m_pos, addToCart)) {
+// if (!m_trans.restoreOrder(sale, m_pos, addToCart)) { // TODO use order instead of shopping list
Debug.logError("Error while loading cart from shopping list : " + sale, module);
}
else {
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/PosScreen.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/PosScreen.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/PosScreen.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/PosScreen.java Tue Feb 17 21:16:33 2009
@@ -217,10 +217,10 @@
if (updateOutput) {
if (input.isFunctionSet("PAID")) {
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosChange",defaultLocale)
- + UtilFormatOut.formatPrice(trans.getTotalDue().negate().doubleValue()));
+ + UtilFormatOut.formatPrice(trans.getTotalDue().negate()));
} else if (input.isFunctionSet("TOTAL")) {
if (trans.getTotalDue().compareTo(BigDecimal.ZERO) > 0) {
- output.print(UtilProperties.getMessage(PosTransaction.resource,"PosTotalD",defaultLocale) + " " + UtilFormatOut.formatPrice(trans.getTotalDue().doubleValue()));
+ output.print(UtilProperties.getMessage(PosTransaction.resource,"PosTotalD",defaultLocale) + " " + UtilFormatOut.formatPrice(trans.getTotalDue()));
} else {
output.print(UtilProperties.getMessage(PosTransaction.resource,"PosPayFin",defaultLocale));
}
Modified: ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/SaveSale.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/SaveSale.java?rev=745257&r1=745256&r2=745257&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/SaveSale.java (original)
+++ ofbiz/trunk/specialpurpose/pos/src/org/ofbiz/pos/screen/SaveSale.java Tue Feb 17 21:16:33 2009
@@ -50,7 +50,7 @@
protected XButton m_save = null;
protected XButton m_saveAndClear = null;
// New button for Save and Print funtion
- protected XButton m_saveAndPrint = null;
+ //protected XButton m_saveAndPrint = null; //FIXME : button does not exist yet
protected static PosTransaction m_trans = null;
public static SimpleDateFormat sdf = new SimpleDateFormat(UtilProperties.getMessage(PosTransaction.resource,"PosDateTimeFormat",Locale.getDefault()));
private static boolean ShowKeyboardInSaveSale = UtilProperties.propertyValueEqualsIgnoreCase("parameters", "ShowKeyboardInSaveSale", "Y");
@@ -73,7 +73,7 @@
m_save = (XButton) m_dialog.findComponent("BtnSave");
m_saveAndClear = (XButton) m_dialog.findComponent("BtnSaveAndClear");
// Save and Print
- m_saveAndPrint = (XButton) m_dialog.findComponent("BtnSaveAndPrint");
+ //m_saveAndPrint = (XButton) m_dialog.findComponent("BtnSaveAndPrint"); //FIXME : button does not exist yet
XEventHelper.addMouseHandler(this, m_cancel, "cancel");
XEventHelper.addMouseHandler(this, m_save, "save");
@@ -144,7 +144,8 @@
private void saveSale(String sale) {
final ClassLoader cl = this.getClassLoader(m_pos);
Thread.currentThread().setContextClassLoader(cl);
- m_trans.saveSale(sale, m_pos);
+ m_trans.saveSale(sale, m_pos);
+// m_trans.saveOrder(sale, m_pos); // TODO use order instead of shopping list
this.m_dialog.closeDlg();
}