Manual merge of typecheckcleanup200810 branch as of rev 731346 in that branch, resolved all conflicts; with this BigDecimal is not the native type for many entity fields and is used for many calculations; some work is still needed in certain areas of the project but this covers the most critical ones; thanks especially to Scott for his work on this

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk/specialpurpose@731851 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David E. Jones
2009-01-06 07:13:36 +00:00
parent eb0bdd6236
commit 9d34dd9660
10 changed files with 144 additions and 136 deletions
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.sql.Timestamp;
@@ -740,10 +741,10 @@ public class ImportOrdersFromEbay {
}
String amountStr = (String) parameters.get("amountPaid");
Double amountPaid = new Double(0);
BigDecimal amountPaid = BigDecimal.ZERO;
if (UtilValidate.isNotEmpty(amountStr)) {
amountPaid = new Double(amountStr);
amountPaid = new BigDecimal(amountStr);
}
// add the payment EXT_BAY for the paid amount
@@ -775,8 +776,8 @@ public class ImportOrdersFromEbay {
return ServiceUtil.returnFailure(UtilProperties.getMessage(resource, "ordersImportFromEbay.paymentIsStillNotReceived", locale));
}
Double unitPrice = new Double((String) parameters.get("transactionPrice"));
double quantity = new Double((String) parameters.get("quantityPurchased")).doubleValue();
BigDecimal unitPrice = new BigDecimal((String) parameters.get("transactionPrice"));
BigDecimal quantity = new BigDecimal((String) parameters.get("quantityPurchased"));
cart.addItemToEnd(productId, null, quantity, unitPrice, null, null, null, "PRODUCT_ORDER_ITEM", dispatcher, Boolean.FALSE, Boolean.FALSE);
// set partyId from
@@ -46,11 +46,11 @@ invoiceType = delegator.findByPrimaryKey("InvoiceType", ["invoiceTypeId" : invoi
asOfDate : invoiceDate]);
if (result.convertedValue != null) {
context.total = (org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotalBd(delegator,invoiceId)).multiply(new BigDecimal(result.convertedValue.toString())).setScale(decimals, rounding);
context.total = (org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotal(delegator,invoiceId)).multiply(new BigDecimal(result.convertedValue.toString())).setScale(decimals, rounding);
context.amountToApply = org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceNotApplied(delegator,invoiceId).multiply(new BigDecimal(result.convertedValue.toString())).setScale(decimals, rounding);
context.currencyUomId = otherCurrency;
}
} else {
context.total = (org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotalBd(delegator,invoiceId));
context.total = (org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotal(delegator,invoiceId));
context.amountToApply = org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceNotApplied(delegator,invoiceId);
}
+74 -73
View File
@@ -20,6 +20,7 @@ package org.ofbiz.pos;
import java.io.PrintWriter;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
@@ -200,26 +201,26 @@ public class PosTransaction implements Serializable {
return this.orderId;
}
public double getTaxTotal() {
public BigDecimal getTaxTotal() {
return cart.getTotalSalesTax();
}
public double getGrandTotal() {
return UtilFormatOut.formatPriceNumber(cart.getGrandTotal()).doubleValue();
public BigDecimal getGrandTotal() {
return cart.getGrandTotal();
}
public int getNumberOfPayments() {
return cart.selectedPayments();
}
public double getPaymentTotal() {
return UtilFormatOut.formatPriceNumber(cart.getPaymentTotal()).doubleValue();
public BigDecimal getPaymentTotal() {
return cart.getPaymentTotal();
}
public double getTotalDue() {
double grandTotal = this.getGrandTotal();
double paymentAmt = this.getPaymentTotal();
return (grandTotal - paymentAmt);
public BigDecimal getTotalDue() {
BigDecimal grandTotal = this.getGrandTotal();
BigDecimal paymentAmt = this.getPaymentTotal();
return grandTotal.subtract(paymentAmt);
}
public int size() {
@@ -231,24 +232,24 @@ public class PosTransaction implements Serializable {
Map itemInfo = new HashMap();
itemInfo.put("productId", item.getProductId());
itemInfo.put("description", item.getDescription());
itemInfo.put("quantity", UtilFormatOut.formatQuantity(item.getQuantity()));
itemInfo.put("subtotal", UtilFormatOut.formatPrice(item.getItemSubTotal()));
itemInfo.put("quantity", UtilFormatOut.formatQuantity(item.getQuantity().doubleValue()));
itemInfo.put("subtotal", UtilFormatOut.formatPrice(item.getItemSubTotal().doubleValue()));
itemInfo.put("isTaxable", item.taxApplies() ? "T" : " ");
itemInfo.put("discount", "");
itemInfo.put("adjustments", "");
if (item.getOtherAdjustments() != 0) {
if (item.getOtherAdjustments().compareTo(BigDecimal.ZERO) != 0) {
itemInfo.put("itemDiscount", UtilFormatOut.padString(
UtilProperties.getMessage(PosTransaction.resource,"(ItemDiscount)",defaultLocale), Receipt.pridLength[0] + 1, true, ' '));
itemInfo.put("adjustments", UtilFormatOut.formatPrice(item.getOtherAdjustments()));
itemInfo.put("adjustments", UtilFormatOut.formatPrice(item.getOtherAdjustments().doubleValue()));
}
if (isAggregatedItem(item.getProductId())){
ProductConfigWrapper pcw = null;
pcw = item.getConfigWrapper();
itemInfo.put("basePrice", UtilFormatOut.formatPrice(pcw.getDefaultPrice()));
itemInfo.put("basePrice", UtilFormatOut.formatPrice(pcw.getDefaultPrice().doubleValue()));
} else {
itemInfo.put("basePrice", UtilFormatOut.formatPrice(item.getBasePrice()));
itemInfo.put("basePrice", UtilFormatOut.formatPrice(item.getBasePrice().doubleValue()));
}
return itemInfo;
}
@@ -271,8 +272,8 @@ public class PosTransaction implements Serializable {
itemInfo.put("productId", "");
itemInfo.put("sku", "");
itemInfo.put("configDescription", configoption.getDescription());
itemInfo.put("configQuantity", UtilFormatOut.formatQuantity(item.getQuantity()));
itemInfo.put("configBasePrice", UtilFormatOut.formatPrice(configoption.getOffsetPrice()));
itemInfo.put("configQuantity", UtilFormatOut.formatQuantity(item.getQuantity().doubleValue()));
itemInfo.put("configBasePrice", UtilFormatOut.formatPrice(configoption.getOffsetPrice().doubleValue()));
//itemInfo.put("isTaxable", item.taxApplies() ? "T" : " ");
list.add(itemInfo);
}
@@ -334,7 +335,7 @@ public class PosTransaction implements Serializable {
if ("PaymentMethodType".equals(infValue.getEntityName())) {
payInfo.put("description", infValue.getString("description"));
payInfo.put("payInfo", infValue.getString("description"));
payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount));
payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount.doubleValue()));
} else {
String paymentMethodTypeId = infValue.getString("paymentMethodTypeId");
GenericValue pmt = null;
@@ -345,7 +346,7 @@ public class PosTransaction implements Serializable {
}
if (pmt != null) {
payInfo.put("description", pmt.getString("description"));
payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount));
payInfo.put("amount", UtilFormatOut.formatPrice(inf.amount.doubleValue()));
}
if ("CREDIT_CARD".equals(paymentMethodTypeId)) {
@@ -381,14 +382,14 @@ public class PosTransaction implements Serializable {
return payInfo;
}
public double getItemQuantity(String productId) {
public BigDecimal getItemQuantity(String productId) {
trace("request item quantity", productId);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, 0.00);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, BigDecimal.ZERO);
if (item != null) {
return item.getQuantity();
} else {
trace("item not found", productId);
return 0;
return BigDecimal.ZERO;
}
}
@@ -451,7 +452,7 @@ public class PosTransaction implements Serializable {
return pcw;
}
public void addItem(String productId, double quantity) throws CartItemModifyException, ItemNotFoundException {
public void addItem(String productId, BigDecimal quantity) throws CartItemModifyException, ItemNotFoundException {
trace("add item", productId + "/" + quantity);
try {
GenericDelegator delegator = cart.getDelegator();
@@ -484,7 +485,7 @@ public class PosTransaction implements Serializable {
throws ItemNotFoundException, CartItemModifyException {
trace("add item with ProductConfigWrapper", productId );
try {
cart.addOrIncreaseItem(productId, null, 1, null, null, null, null, null, null, null, null, pcw, null, null, null, session.getDispatcher());
cart.addOrIncreaseItem(productId, null, BigDecimal.ONE, null, null, null, null, null, null, null, null, pcw, null, null, null, session.getDispatcher());
} catch (ItemNotFoundException e) {
trace("item not found", e);
throw e;
@@ -503,7 +504,7 @@ public class PosTransaction implements Serializable {
try {
int cartIndexInt = Integer.parseInt(cartIndex);
ShoppingCartItem cartItem = cart.findCartItem(cartIndexInt);
double quantity = cartItem.getQuantity();
BigDecimal quantity = cartItem.getQuantity();
cart.removeCartItem(cartIndexInt, session.getDispatcher());
cart.addOrIncreaseItem(productId, null, quantity, null, null, null, null, null, null, null, null, pcw, null, null, null, session.getDispatcher());
} catch (CartItemModifyException e) {
@@ -520,9 +521,9 @@ public class PosTransaction implements Serializable {
return;
}
public void modifyQty(String productId, double quantity) throws CartItemModifyException {
public void modifyQty(String productId, BigDecimal quantity) throws CartItemModifyException {
trace("modify item quantity", productId + "/" + quantity);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, 0.00);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, BigDecimal.ZERO);
if (item != null) {
try {
item.setQuantity(quantity, session.getDispatcher(), cart, true);
@@ -536,9 +537,9 @@ public class PosTransaction implements Serializable {
}
}
public void modifyPrice(String productId, double price) {
public void modifyPrice(String productId, BigDecimal price) {
trace("modify item price", productId + "/" + price);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, 0.00);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, BigDecimal.ZERO);
if (item != null) {
item.setBasePrice(price);
} else {
@@ -557,7 +558,7 @@ public class PosTransaction implements Serializable {
if (productId != null) {
trace("add item adjustment");
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, 0.00);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, BigDecimal.ZERO);
Integer itemAdj = (Integer) skuDiscounts.get(productId);
if (itemAdj != null) {
item.removeAdjustment(itemAdj.intValue());
@@ -582,7 +583,7 @@ public class PosTransaction implements Serializable {
Iterator i = skuDiscounts.keySet().iterator();
while (i.hasNext()) {
String productId = (String) i.next();
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, 0.00);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, BigDecimal.ZERO);
Integer itemAdj = (Integer) skuDiscounts.remove(productId);
if (itemAdj != null) {
item.removeAdjustment(itemAdj.intValue());
@@ -591,13 +592,13 @@ public class PosTransaction implements Serializable {
}
}
public double GetTotalDiscount() {
public BigDecimal GetTotalDiscount() {
return cart.getOrderOtherAdjustmentTotal();
}
public void voidItem(String productId) throws CartItemModifyException {
trace("void item", productId);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, 0.00);
ShoppingCartItem item = cart.findCartItem(productId, null, null, null, BigDecimal.ZERO);
if (item != null) {
try {
int itemIdx = cart.getItemIndex(item);
@@ -695,17 +696,17 @@ public class PosTransaction implements Serializable {
}
}
public double addPayment(String id, double amount) {
public BigDecimal addPayment(String id, BigDecimal amount) {
return this.addPayment(id, amount, null, null);
}
public double addPayment(String id, double amount, String refNum, String authCode) {
public BigDecimal addPayment(String id, BigDecimal amount, String refNum, String authCode) {
trace("added payment", id + "/" + amount);
if ("CASH".equals(id)) {
// clear cash payments first; so there is only one
cart.clearPayment(id);
}
cart.addPaymentAmount(id, new Double(amount), refNum, authCode, true, true, false);
cart.addPaymentAmount(id, amount, refNum, authCode, true, true, false);
return this.getTotalDue();
}
@@ -775,11 +776,11 @@ public class PosTransaction implements Serializable {
currentTx = null;
}
public double processSale(Output output) throws GeneralException {
public BigDecimal processSale(Output output) throws GeneralException {
trace("process sale");
double grandTotal = this.getGrandTotal();
double paymentAmt = this.getPaymentTotal();
if (grandTotal > paymentAmt) {
BigDecimal grandTotal = this.getGrandTotal();
BigDecimal paymentAmt = this.getPaymentTotal();
if (grandTotal.compareTo(paymentAmt) > 0) {
throw new IllegalStateException();
}
@@ -819,10 +820,10 @@ public class PosTransaction implements Serializable {
}
// get the change due
double change = (grandTotal - paymentAmt);
BigDecimal change = grandTotal.subtract(paymentAmt);
// notify the change due
output.print(UtilProperties.getMessage(PosTransaction.resource,"CHANGE",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue() * -1));
output.print(UtilProperties.getMessage(PosTransaction.resource,"CHANGE",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue().negate().doubleValue()));
// threaded drawer/receipt printing
final PosTransaction currentTrans = this;
@@ -889,16 +890,16 @@ public class PosTransaction implements Serializable {
Iterator i = cart.iterator();
while (i.hasNext()) {
ShoppingCartItem item = (ShoppingCartItem) i.next();
double quantity = item.getQuantity();
double unitPrice = item.getBasePrice();
double subTotal = unitPrice * quantity;
double adjustment = item.getOtherAdjustments();
BigDecimal quantity = item.getQuantity();
BigDecimal unitPrice = item.getBasePrice();
BigDecimal subTotal = unitPrice.multiply(quantity);
BigDecimal adjustment = item.getOtherAdjustments();
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));
Journal.appendNode(line, "td", "price", UtilFormatOut.formatPrice(subTotal));
Journal.appendNode(line, "td", "qty", UtilFormatOut.formatQuantity(quantity.doubleValue()));
Journal.appendNode(line, "td", "price", UtilFormatOut.formatPrice(subTotal.doubleValue()));
Journal.appendNode(line, "td", "index", Integer.toString(cart.getItemIndex(item)));
if (this.isAggregatedItem(item.getProductId())){
@@ -916,19 +917,19 @@ public class PosTransaction implements Serializable {
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()));
Journal.appendNode(option, "td", "price", UtilFormatOut.formatPrice(configoption.getPrice().doubleValue()));
Journal.appendNode(option, "td", "index", Integer.toString(cart.getItemIndex(item)));
}
}
}
if (adjustment != 0) {
if (adjustment.compareTo(BigDecimal.ZERO) != 0) {
// append the promo info
XModel promo = Journal.appendNode(model, "tr", "itemadjustment", "");
Journal.appendNode(promo, "td", "sku", "");
Journal.appendNode(promo, "td", "desc", UtilProperties.getMessage(PosTransaction.resource,"(ItemDiscount)",defaultLocale));
Journal.appendNode(promo, "td", "qty", "");
Journal.appendNode(promo, "td", "price", UtilFormatOut.formatPrice(adjustment));
Journal.appendNode(promo, "td", "price", UtilFormatOut.formatPrice(adjustment.doubleValue()));
}
}
}
@@ -936,17 +937,17 @@ public class PosTransaction implements Serializable {
public void appendTotalDataModel(XModel model) {
if (cart != null) {
double taxAmount = cart.getTotalSalesTax();
double total = cart.getGrandTotal();
BigDecimal taxAmount = cart.getTotalSalesTax();
BigDecimal total = cart.getGrandTotal();
List adjustments = cart.getAdjustments();
Double itemsAdjustmentsAmount = 0.0;
BigDecimal itemsAdjustmentsAmount = BigDecimal.ZERO;
Iterator i = cart.iterator();
while (i.hasNext()) {
ShoppingCartItem item = (ShoppingCartItem) i.next();
double adjustment = item.getOtherAdjustments();
if (adjustment != 0) {
itemsAdjustmentsAmount =+ adjustment;
BigDecimal adjustment = item.getOtherAdjustments();
if (adjustment.compareTo(BigDecimal.ZERO) != 0) {
itemsAdjustmentsAmount = itemsAdjustmentsAmount.add(adjustment);
}
}
@@ -960,20 +961,20 @@ public class PosTransaction implements Serializable {
iter = adjustments.iterator();
while(iter.hasNext()){
GenericValue orderAdjustment = (GenericValue) iter.next();
Double amount = orderAdjustment.getDouble("amount");
Double sourcePercentage = orderAdjustment.getDouble("sourcePercentage");
BigDecimal amount = orderAdjustment.getBigDecimal("amount");
BigDecimal sourcePercentage = orderAdjustment.getBigDecimal("sourcePercentage");
XModel adjustmentLine = Journal.appendNode(model, "tr", "adjustment", "");
Journal.appendNode(adjustmentLine, "td", "sku", "");
Journal.appendNode(adjustmentLine, "td", "desc",
UtilProperties.getMessage(PosTransaction.resource, "(SalesDiscount)",defaultLocale));
if (UtilValidate.isNotEmpty(amount)) {
Journal.appendNode(adjustmentLine, "td", "qty", "");
Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(amount));
Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(amount.doubleValue()));
} else if (UtilValidate.isNotEmpty(sourcePercentage)) {
double percentage = - sourcePercentage.doubleValue()/100; // 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));
amount = new Double((cart.getItemTotal() + itemsAdjustmentsAmount) * percentage); // itemsAdjustmentsAmount is negative
Journal.appendNode(adjustmentLine, "td", "price", UtilFormatOut.formatPrice(- amount)); // amount must be shown as a negative value
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()));
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", "index", "-1");
}
@@ -984,14 +985,14 @@ public class PosTransaction implements Serializable {
Journal.appendNode(taxLine, "td", "desc", UtilProperties.getMessage(PosTransaction.resource,"Sales_Tax",defaultLocale));
Journal.appendNode(taxLine, "td", "qty", "");
Journal.appendNode(taxLine, "td", "price", UtilFormatOut.formatPrice(taxAmount));
Journal.appendNode(taxLine, "td", "price", UtilFormatOut.formatPrice(taxAmount.doubleValue()));
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,"Grand_Total",defaultLocale));
Journal.appendNode(totalLine, "td", "qty", "");
Journal.appendNode(totalLine, "td", "price", UtilFormatOut.formatPrice(total));
Journal.appendNode(totalLine, "td", "price", UtilFormatOut.formatPrice(total.doubleValue()));
Journal.appendNode(totalLine, "td", "index", "-1");
}
}
@@ -1018,18 +1019,18 @@ public class PosTransaction implements Serializable {
Object desc = paymentMethodType != null ? paymentMethodType.get("description",defaultLocale) : "??";
String descString = desc.toString();
double amount = 0;
BigDecimal amount = BigDecimal.ZERO;
if (inf.amount == null) {
amount = cart.getGrandTotal() - cart.getPaymentTotal();
amount = cart.getGrandTotal().subtract(cart.getPaymentTotal());
} else {
amount = inf.amount.doubleValue();
amount = inf.amount;
}
XModel paymentLine = Journal.appendNode(model, "tr", Integer.toString(i), "");
Journal.appendNode(paymentLine, "td", "sku", "");
Journal.appendNode(paymentLine, "td", "desc", descString);
Journal.appendNode(paymentLine, "td", "qty", "-");
Journal.appendNode(paymentLine, "td", "price", UtilFormatOut.formatPrice(-1 * amount));
Journal.appendNode(paymentLine, "td", "price", UtilFormatOut.formatPrice(amount.negate().doubleValue()));
Journal.appendNode(paymentLine, "td", "index", Integer.toString(i));
}
}
@@ -1037,13 +1038,13 @@ public class PosTransaction implements Serializable {
public void appendChangeDataModel(XModel model) {
if (cart != null) {
double changeDue = (-1 * this.getTotalDue());
if (changeDue >= 0) {
BigDecimal changeDue = this.getTotalDue().negate();
if (changeDue.compareTo(BigDecimal.ZERO) >= 0) {
XModel changeLine = Journal.appendNode(model, "tr", "", "");
Journal.appendNode(changeLine, "td", "sku", "");
Journal.appendNode(changeLine, "td", "desc", "Change");
Journal.appendNode(changeLine, "td", "qty", "-");
Journal.appendNode(changeLine, "td", "price", UtilFormatOut.formatPrice(changeDue));
Journal.appendNode(changeLine, "td", "price", UtilFormatOut.formatPrice(changeDue.doubleValue()));
}
}
}
@@ -103,7 +103,7 @@ public class Operator {
if (OPER_TOTAL[0].equals(fieldName)) {
String total = "0.00";
if (trans != null) {
total = UtilFormatOut.formatPrice(trans.getTotalDue());
total = UtilFormatOut.formatPrice(trans.getTotalDue().doubleValue());
}
field.setText(total);
} else if (OPER_DATE[0].equals(fieldName)) {
@@ -22,6 +22,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -466,13 +467,13 @@ public class Receipt extends GenericDevice implements DialogCallback {
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()), 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() < 0 ?
UtilFormatOut.formatPrice(trans.getTotalDue() * -1) : "0.00"), priceLength[type], false, ' '));
expandMap.put("saleDiscount", UtilFormatOut.padString((trans.GetTotalDiscount() != 0 ?
UtilFormatOut.formatPrice(trans.GetTotalDiscount()) : "0.00"), priceLength[type], false, ' '));
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("change", UtilFormatOut.padString((trans.getTotalDue().compareTo(BigDecimal.ZERO) < 0 ?
UtilFormatOut.formatPrice(trans.getTotalDue().negate().doubleValue()) : "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, ' '));
return expandMap;
}
@@ -18,6 +18,7 @@
*/
package org.ofbiz.pos.event;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.ParseException;
@@ -79,16 +80,16 @@ public class ManagerEvents {
Input input = pos.getInput();
String value = input.value();
if (UtilValidate.isNotEmpty(value)) {
double price = 0.00;
BigDecimal price = BigDecimal.ZERO;
boolean parsed = false;
try {
price = Double.parseDouble(value);
price = new BigDecimal(value);
parsed = true;
} catch (NumberFormatException e) {
}
if (parsed) {
price = price / 100;
price = price.movePointLeft(2);
trans.modifyPrice(sku, price);
// re-calc tax
+9 -8
View File
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.ofbiz.pos.event;
import java.math.BigDecimal;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
@@ -149,12 +150,12 @@ public class MenuEvents {
} else {
// check for quantity
double quantity = 1;
BigDecimal quantity = BigDecimal.ONE;
if (func != null && "QTY".equals(func[0])) {
try {
quantity = Double.parseDouble(func[1]);
quantity = new BigDecimal(func[1]);
} catch (NumberFormatException e) {
quantity = 1;
quantity = BigDecimal.ONE;
}
}
@@ -250,19 +251,19 @@ public class MenuEvents {
String value = input.value();
boolean increment = true;
double quantity = 1;
BigDecimal quantity = BigDecimal.ONE;
if (UtilValidate.isNotEmpty(value)) {
try {
quantity = Double.parseDouble(value);
quantity = new BigDecimal(value);
} catch (NumberFormatException e) {
quantity = 1;
quantity = BigDecimal.ONE;
}
} else {
String[] func = input.getLastFunction();
if (func != null && "QTY".equals(func[0])) {
increment = false;
try {
quantity = Double.parseDouble(func[1]);
quantity = new BigDecimal(func[1]);
} catch (NumberFormatException e) {
quantity = trans.getItemQuantity(sku);
}
@@ -270,7 +271,7 @@ public class MenuEvents {
}
// adjust the quantity
quantity = (increment ? trans.getItemQuantity(sku) + quantity : quantity);
quantity = (increment ? trans.getItemQuantity(sku).add(quantity) : quantity);
try {
trans.modifyQty(sku, quantity);
+11 -10
View File
@@ -27,6 +27,7 @@ import org.ofbiz.pos.component.Journal;
import org.ofbiz.pos.screen.PosScreen;
import org.ofbiz.base.util.UtilProperties;
import java.math.BigDecimal;
import java.util.Locale;
public class PaymentEvents {
@@ -40,7 +41,7 @@ public class PaymentEvents {
// all cash transactions are NO_PAYMENT; no need to check
try {
double amount = processAmount(trans, pos, null);
BigDecimal amount = processAmount(trans, pos, null);
Debug.log("Processing [Cash] Amount : " + amount, module);
// add the payment
@@ -212,7 +213,7 @@ public class PaymentEvents {
case 3:
firstName = msrInfoArr[2];
case 2: // card number & exp date found
double amount = 0;
BigDecimal amount = BigDecimal.ZERO;
try {
String[] totalInfo = input.getFunction("TOTAL");
amount = processAmount(trans, pos, totalInfo[1]);
@@ -259,7 +260,7 @@ public class PaymentEvents {
PosTransaction trans = PosTransaction.getCurrentTx(pos.getSession());
try {
double amount = processAmount(trans, pos, null);
BigDecimal amount = processAmount(trans, pos, null);
Debug.log("Processing [" + paymentMethodTypeId + "] Amount : " + amount, module);
// add the payment
@@ -282,7 +283,7 @@ public class PaymentEvents {
input.clearInput();
try {
double amount = processAmount(trans, pos, amountStr);
BigDecimal amount = processAmount(trans, pos, amountStr);
Debug.log("Processing [" + paymentMethodTypeId + "] Amount : " + amount, module);
// add the payment
@@ -356,7 +357,7 @@ public class PaymentEvents {
if (trans.isEmpty()) {
PosScreen newPos = pos.showPage("pospanel");
newPos.showDialog("dialog/error/noitems");
} else if (trans.getTotalDue() > 0) {
} else if (trans.getTotalDue().compareTo(BigDecimal.ZERO) > 0) {
pos.showDialog("dialog/error/notenoughfunds");
} else {
// manual locks (not secured; will be unlocked on clear)
@@ -379,27 +380,27 @@ public class PaymentEvents {
}
}
private static synchronized double processAmount(PosTransaction trans, PosScreen pos, String amountStr) throws GeneralException {
private static synchronized BigDecimal processAmount(PosTransaction trans, PosScreen pos, String amountStr) throws GeneralException {
Input input = pos.getInput();
if (input.isFunctionSet("TOTAL")) {
String amtStr = amountStr != null ? amountStr : input.value();
double amount;
BigDecimal amount;
if (UtilValidate.isNotEmpty(amtStr)) {
try {
amount = Double.parseDouble(amtStr);
amount = new BigDecimal(amtStr);
} catch (NumberFormatException e) {
Debug.logError("Invalid number for amount : " + amtStr, module);
pos.getOutput().print("Invalid Amount!");
input.clearInput();
throw new GeneralException();
}
amount = amount / 100; // convert to decimal
amount = amount.movePointLeft(2); // convert to decimal
Debug.log("Set amount / 100 : " + amount, module);
} else {
Debug.log("Amount is empty; assumption is full amount : " + trans.getTotalDue(), module);
amount = trans.getTotalDue();
if (amount <= 0) {
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new GeneralException();
}
}
+4 -3
View File
@@ -25,6 +25,7 @@ import java.awt.Window;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.math.BigDecimal;
import java.util.*;
import net.xoetrope.xui.XPage;
@@ -216,10 +217,10 @@ public class PosScreen extends XPage implements Runnable, DialogCallback, FocusL
if (updateOutput) {
if (input.isFunctionSet("PAID")) {
output.print(UtilProperties.getMessage(PosTransaction.resource,"CHANGE",defaultLocale)
+ UtilFormatOut.formatPrice(trans.getTotalDue() * -1));
+ UtilFormatOut.formatPrice(trans.getTotalDue().negate().doubleValue()));
} else if (input.isFunctionSet("TOTAL")) {
if (trans.getTotalDue() > 0) {
output.print(UtilProperties.getMessage(PosTransaction.resource,"TOTALD",defaultLocale) + " " + UtilFormatOut.formatPrice(trans.getTotalDue()));
if (trans.getTotalDue().compareTo(BigDecimal.ZERO) > 0) {
output.print(UtilProperties.getMessage(PosTransaction.resource,"TOTALD",defaultLocale) + " " + UtilFormatOut.formatPrice(trans.getTotalDue().doubleValue()));
} else {
output.print(UtilProperties.getMessage(PosTransaction.resource,"PAYFIN",defaultLocale));
}
@@ -18,6 +18,7 @@
*******************************************************************************/
package org.ofbiz.webpos.transaction;
import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -171,9 +172,9 @@ public class WebPosTransaction {
}
}
public void modifyPrice(String productId, double price) {
public void modifyPrice(String productId, BigDecimal price) {
Debug.logInfo("Modify item price " + productId + "/" + price, module);
ShoppingCartItem item = getCart().findCartItem(productId, null, null, null, 0.00);
ShoppingCartItem item = getCart().findCartItem(productId, null, null, null, BigDecimal.ZERO);
if (UtilValidate.isNotEmpty(item)) {
item.setBasePrice(price);
} else {
@@ -189,12 +190,12 @@ public class WebPosTransaction {
}
}
public double processSale() throws GeneralException {
public BigDecimal processSale() throws GeneralException {
//TODO insert check if not enough funds
Debug.log("process sale", module);
double grandTotal = this.getGrandTotal();
double paymentAmt = this.getPaymentTotal();
if (grandTotal > paymentAmt) {
BigDecimal grandTotal = this.getGrandTotal();
BigDecimal paymentAmt = this.getPaymentTotal();
if (grandTotal.compareTo(paymentAmt) > 0) {
throw new IllegalStateException();
}
@@ -233,7 +234,7 @@ public class WebPosTransaction {
}
// get the change due
double change = (grandTotal - paymentAmt);
BigDecimal change = grandTotal.subtract(paymentAmt);
// notify the change due
//output.print(UtilProperties.getMessage(PosTransaction.resource,"CHANGE",defaultLocale) + " " + UtilFormatOut.formatPrice(this.getTotalDue() * -1));
@@ -355,25 +356,25 @@ public class WebPosTransaction {
return INTERNAL_PAYMENT;
}
public double addPayment(String id, double amount) {
public BigDecimal addPayment(String id, BigDecimal amount) {
return this.addPayment(id, amount, null, null);
}
public double addPayment(String id, double amount, String refNum, String authCode) {
public BigDecimal addPayment(String id, BigDecimal amount, String refNum, String authCode) {
Debug.logInfo("Added payment " + id + "/" + amount, module);
if ("CASH".equals(id)) {
// clear cash payments first; so there is only one
getCart().clearPayment(id);
}
getCart().addPaymentAmount(id, new Double(amount), refNum, authCode, true, true, false);
getCart().addPaymentAmount(id, amount, refNum, authCode, true, true, false);
return this.getTotalDue();
}
public double processAmount(String amtStr) throws GeneralException {
double amount;
public BigDecimal processAmount(String amtStr) throws GeneralException {
BigDecimal amount;
if (UtilValidate.isNotEmpty(amtStr)) {
try {
amount = Double.parseDouble(amtStr);
amount = new BigDecimal(amtStr);
} catch (NumberFormatException e) {
Debug.logError("Invalid number for amount : " + amtStr, module);
throw new GeneralException();
@@ -381,7 +382,7 @@ public class WebPosTransaction {
} else {
Debug.log("Amount is empty; assumption is full amount : " + this.getTotalDue(), module);
amount = this.getTotalDue();
if (amount <= 0) {
if (amount.compareTo(BigDecimal.ZERO) <= 0) {
throw new GeneralException();
}
}
@@ -390,7 +391,7 @@ public class WebPosTransaction {
public synchronized void processNoPayment(String paymentMethodTypeId) {
try {
double amount = processAmount(null);
BigDecimal amount = processAmount(null);
Debug.log("Processing [" + paymentMethodTypeId + "] Amount : " + amount, module);
// add the payment
@@ -407,7 +408,7 @@ public class WebPosTransaction {
}
try {
double amount = processAmount(amountStr);
BigDecimal amount = processAmount(amountStr);
Debug.log("Processing [" + paymentMethodTypeId + "] Amount : " + amount, module);
// add the payment
@@ -484,26 +485,26 @@ public class WebPosTransaction {
inf.postalCode = postalCode;
}
public double getTaxTotal() {
public BigDecimal getTaxTotal() {
return getCart().getTotalSalesTax();
}
public double getGrandTotal() {
return UtilFormatOut.formatPriceNumber(getCart().getGrandTotal()).doubleValue();
public BigDecimal getGrandTotal() {
return getCart().getGrandTotal();
}
public int getNumberOfPayments() {
return getCart().selectedPayments();
}
public double getPaymentTotal() {
return UtilFormatOut.formatPriceNumber(getCart().getPaymentTotal()).doubleValue();
public BigDecimal getPaymentTotal() {
return getCart().getPaymentTotal();
}
public double getTotalDue() {
double grandTotal = this.getGrandTotal();
double paymentAmt = this.getPaymentTotal();
return (grandTotal - paymentAmt);
public BigDecimal getTotalDue() {
BigDecimal grandTotal = this.getGrandTotal();
BigDecimal paymentAmt = this.getPaymentTotal();
return grandTotal.subtract(paymentAmt);
}
public String addProductPromoCode(String code) {