Fix [2904193] - Posting zero for interest bank statement line

https://sourceforge.net/tracker/?func=detail&atid=879332&aid=2904193&group_id=176962
Found a bigger problem with this - in postgresql reading a zero can lead to read a 0E-12 (zero with scale 12) and the comparison of this number .equals(Env.ZERO) return false - comparing with compareTo returns true
SF Tracker: 2904193
This commit is contained in:
Carlos Ruiz 2009-12-16 04:21:32 +00:00
parent 837badd6ae
commit 6fbc51b639
12 changed files with 42 additions and 40 deletions

View File

@ -230,19 +230,21 @@ public final class FactLine extends X_Fact_Acct
if (AmtSourceCr != null)
setAmtSourceCr (AmtSourceCr);
// one needs to be non zero
if (getAmtSourceDr().equals(Env.ZERO) && getAmtSourceCr().equals(Env.ZERO))
if (getAmtSourceDr().compareTo(Env.ZERO)==0 && getAmtSourceCr().compareTo(Env.ZERO)==0)
return false;
// Currency Precision
int precision = MCurrency.getStdPrecision(getCtx(), C_Currency_ID);
if (AmtSourceDr != null && AmtSourceDr.scale() > precision)
{
BigDecimal AmtSourceDr1 = AmtSourceDr.setScale(precision, BigDecimal.ROUND_HALF_UP);
if (AmtSourceDr1.compareTo(AmtSourceDr) != 0)
log.warning("Source DR Precision " + AmtSourceDr + " -> " + AmtSourceDr1);
setAmtSourceDr(AmtSourceDr1);
}
if (AmtSourceCr != null && AmtSourceCr.scale() > precision)
{
BigDecimal AmtSourceCr1 = AmtSourceCr.setScale(precision, BigDecimal.ROUND_HALF_UP);
if (AmtSourceCr1.compareTo(AmtSourceCr) != 0)
log.warning("Source CR Precision " + AmtSourceCr + " -> " + AmtSourceCr1);
setAmtSourceCr(AmtSourceCr1);
}

View File

@ -104,7 +104,7 @@ public class Matcher
BigDecimal qty1 = rs.getBigDecimal(8);
BigDecimal qty2 = rs.getBigDecimal(9);
BigDecimal Qty = qty1.min(qty2);
if (Qty.equals(Env.ZERO))
if (Qty.compareTo(Env.ZERO)==0)
continue;
Timestamp dateTrx1 = rs.getTimestamp(6);
Timestamp dateTrx2 = rs.getTimestamp(7);

View File

@ -263,19 +263,19 @@ public class ProductInfo
// Try to find non ZERO Price
String costSource = "PriceList-PO";
BigDecimal costs = getPriceList (as, true);
if (costs == null || costs.equals(Env.ZERO))
if (costs == null || costs.compareTo(Env.ZERO)==0)
{
costSource = "PO Cost";
costs = getPOCost(as);
}
if (costs == null || costs.equals(Env.ZERO))
if (costs == null || costs.compareTo(Env.ZERO)==0)
{
costSource = "PriceList";
costs = getPriceList (as, false);
}
// if not found use $1 (to be able to do material transactions)
if (costs == null || costs.equals(Env.ZERO))
if (costs == null || costs.compareTo(Env.ZERO)==0)
{
costSource = "Not Found";
costs = new BigDecimal("1");
@ -341,12 +341,12 @@ public class ProductInfo
return null;
BigDecimal price = PriceLimit; // best bet
if (price == null || price.equals(Env.ZERO))
if (price == null || price.compareTo(Env.ZERO)==0)
price = PriceStd;
if (price == null || price.equals(Env.ZERO))
if (price == null || price.compareTo(Env.ZERO)==0)
price = PriceList;
// Convert
if (price != null && !price.equals(Env.ZERO))
if (price != null && price.compareTo(Env.ZERO)!=0)
price = MConversionRate.convert (as.getCtx(),
price, C_Currency_ID, as.getC_Currency_ID(),
as.getAD_Client_ID(), 0);
@ -396,12 +396,12 @@ public class ProductInfo
return null;
BigDecimal cost = PriceLastPO; // best bet
if (cost == null || cost.equals(Env.ZERO))
if (cost == null || cost.compareTo(Env.ZERO)==0)
cost = PricePO;
if (cost == null || cost.equals(Env.ZERO))
if (cost == null || cost.compareTo(Env.ZERO)==0)
cost = PriceList;
// Convert - standard precision!! - should be costing precision
if (cost != null && !cost.equals(Env.ZERO))
if (cost != null && cost.compareTo(Env.ZERO)!=0)
cost = MConversionRate.convert (as.getCtx(),
cost, C_Currency_ID, as.getC_Currency_ID(), m_AD_Client_ID, m_AD_Org_ID);
return cost;

View File

@ -193,7 +193,7 @@ public class CalloutTimeExpense extends CalloutEngine
// Converted Amount = Unit price
BigDecimal ConvertedAmt = ExpenseAmt;
// convert if required
if (!ConvertedAmt.equals(Env.ZERO) && C_Currency_To_ID != C_Currency_From_ID.intValue())
if (ConvertedAmt.compareTo(Env.ZERO)!=0 && C_Currency_To_ID != C_Currency_From_ID.intValue())
{
int AD_Client_ID = Env.getContextAsInt (ctx, WindowNo, "AD_Client_ID");
int AD_Org_ID = Env.getContextAsInt (ctx, WindowNo, "AD_Org_ID");

View File

@ -239,7 +239,7 @@ public class MAsset extends X_A_Asset
public BigDecimal getQty ()
{
BigDecimal qty = super.getQty();
if (qty == null || qty.equals(Env.ZERO))
if (qty == null || qty.compareTo(Env.ZERO)==0)
setQty(Env.ONE);
return super.getQty();
} // getQty

View File

@ -106,7 +106,7 @@ public class MConversionRate extends X_C_Conversion_Rate
{
if (Amt == null)
throw new IllegalArgumentException("Required parameter missing - Amt");
if (CurFrom_ID == CurTo_ID || Amt.equals(Env.ZERO))
if (CurFrom_ID == CurTo_ID || Amt.compareTo(Env.ZERO)==0)
return Amt;
// Get Rate
BigDecimal retValue = getRate (CurFrom_ID, CurTo_ID,

View File

@ -62,7 +62,7 @@ public class MUOMConversion extends X_C_UOM_Conversion
static public BigDecimal convert (Properties ctx,
int C_UOM_ID, int C_UOM_To_ID, BigDecimal qty)
{
if (qty == null || qty.equals(Env.ZERO) || C_UOM_ID == C_UOM_To_ID)
if (qty == null || qty.compareTo(Env.ZERO)==0 || C_UOM_ID == C_UOM_To_ID)
return qty;
BigDecimal retValue = getRate (ctx, C_UOM_ID, C_UOM_To_ID);
if (retValue != null)
@ -397,7 +397,7 @@ public class MUOMConversion extends X_C_UOM_Conversion
BigDecimal qty, boolean StdPrecision)
{
// Nothing to do
if (qty == null || qty.equals(Env.ZERO)
if (qty == null || qty.compareTo(Env.ZERO)==0
|| C_UOM_From_ID == C_UOM_To_ID)
return qty;
//
@ -530,7 +530,7 @@ public class MUOMConversion extends X_C_UOM_Conversion
int M_Product_ID, int C_UOM_To_ID, BigDecimal qtyPrice)
{
// No conversion
if (qtyPrice == null || qtyPrice.equals(Env.ZERO)
if (qtyPrice == null || qtyPrice.compareTo(Env.ZERO)==0
|| C_UOM_To_ID == 0|| M_Product_ID == 0)
{
s_log.fine("No Conversion - QtyPrice=" + qtyPrice);

View File

@ -365,12 +365,12 @@ public class ProductCost
}
// Return Costs
if (costType != null && cost != null && !cost.equals(Env.ZERO))
if (costType != null && cost != null && cost.compareTo(Env.ZERO)!=0)
{
log.fine("Costs=" + cost);
return cost;
}
else if (current != null && !current.equals(Env.ZERO))
else if (current != null && current.compareTo(Env.ZERO)!=0)
{
log.fine("Current=" + current);
return current;
@ -414,19 +414,19 @@ public class ProductCost
// Try to find non ZERO Price
String costSource = "PriceList-PO";
BigDecimal costs = getPriceList (as, true);
if (costs == null || costs.equals(Env.ZERO))
if (costs == null || costs.compareTo(Env.ZERO)==0)
{
costSource = "PO Cost";
costs = getPOCost(as);
}
if (costs == null || costs.equals(Env.ZERO))
if (costs == null || costs.compareTo(Env.ZERO)==0)
{
costSource = "PriceList";
costs = getPriceList (as, false);
}
// if not found use $1 (to be able to do material transactions)
if (costs == null || costs.equals(Env.ZERO))
if (costs == null || costs.compareTo(Env.ZERO)==0)
{
costSource = "Not Found";
costs = new BigDecimal("1");
@ -492,12 +492,12 @@ public class ProductCost
return null;
BigDecimal price = PriceLimit; // best bet
if (price == null || price.equals(Env.ZERO))
if (price == null || price.compareTo(Env.ZERO)==0)
price = PriceStd;
if (price == null || price.equals(Env.ZERO))
if (price == null || price.compareTo(Env.ZERO)==0)
price = PriceList;
// Convert
if (price != null && !price.equals(Env.ZERO))
if (price != null && price.compareTo(Env.ZERO)!=0)
price = MConversionRate.convert (as.getCtx(),
price, C_Currency_ID, as.getC_Currency_ID(),
as.getAD_Client_ID(), 0);
@ -547,12 +547,12 @@ public class ProductCost
return null;
BigDecimal cost = PriceLastPO; // best bet
if (cost == null || cost.equals(Env.ZERO))
if (cost == null || cost.compareTo(Env.ZERO)==0)
cost = PricePO;
if (cost == null || cost.equals(Env.ZERO))
if (cost == null || cost.compareTo(Env.ZERO)==0)
cost = PriceList;
// Convert - standard precision!! - should be costing precision
if (cost != null && !cost.equals(Env.ZERO))
if (cost != null && cost.compareTo(Env.ZERO)!=0)
cost = MConversionRate.convert (as.getCtx(),
cost, C_Currency_ID, as.getC_Currency_ID(), as.getAD_Client_ID(), as.getAD_Org_ID());
return cost;

View File

@ -526,7 +526,7 @@ public class POSManager
cashLine.setWriteOffAmt(writeOffAmount);
cashLine.setDiscountAmt(discountAmt);
if(!(discountAmt.equals(Env.ZERO)))
if(!(discountAmt.compareTo(Env.ZERO)==0))
{
cashLine.setAmount(invoice.getGrandTotal().subtract(discountAmt).subtract(writeOffAmount));
}
@ -570,7 +570,7 @@ public class POSManager
paymentCreated = true;
BigDecimal amt = null;
if(!(discountAmt.equals(Env.ZERO)))
if(!(discountAmt.compareTo(Env.ZERO)==0))
{
amt = invoice.getGrandTotal().subtract(discountAmt).subtract(writeOffAmount);
}
@ -833,7 +833,7 @@ public class POSManager
}
}
if(!subTotal.equals(Env.ZERO))
if(subTotal.compareTo(Env.ZERO)!=0)
{
try
{
@ -891,11 +891,11 @@ public class POSManager
totalLines = totalLines.add(bean.getLineNetAmt());
totalTax = totalTax.add(bean.getTaxAmt());
totalQty=totalQty.add(bean.getQtyTotal());
if (bean.getDiscountAmt()!=null && !bean.getDiscountAmt().equals(Env.ZERO))
if (bean.getDiscountAmt()!=null && bean.getDiscountAmt().compareTo(Env.ZERO)!=0)
{
discountAmt = bean.getDiscountAmt();
}
if (bean.getWriteOffAmt()!=null && !bean.getWriteOffAmt().equals(Env.ZERO))
if (bean.getWriteOffAmt()!=null && bean.getWriteOffAmt().compareTo(Env.ZERO)!=0)
{
writeOffAmt = bean.getWriteOffAmt();
}

View File

@ -295,7 +295,7 @@ public class ShoppingcartManager
//weird logic!
BigDecimal discountedTotal = bean.getPayAmt();
/*if(bean.getDiscountAmt()!=null && bean.getDiscountAmt().equals(Env.ZERO))
/*if(bean.getDiscountAmt()!=null && bean.getDiscountAmt().compareTo(Env.ZERO)==0)
{
discountedTotal = null;
} */

View File

@ -289,7 +289,7 @@ public class POSSalesReportManager
taxAmt = webOrderLineBean.getTaxAmt();
if(taxAmt.equals(Env.ZERO))
if(taxAmt.compareTo(Env.ZERO)==0)
{
if(order.getOrderType().equals(UDIOrderTypes.POS_ORDER.getOrderType()))
@ -859,7 +859,7 @@ public class POSSalesReportManager
if (!sales.equals(Env.ZERO))
if (sales.compareTo(Env.ZERO)!=0)
{
BigDecimal profit = sales.subtract(cost);

View File

@ -318,13 +318,13 @@ public class StockManager
discountedLineTotal = bean.getPrice();
}
if (discountPercentOnLine != null && !discountPercentOnLine.equals(Env.ZERO))
if (discountPercentOnLine != null && discountPercentOnLine.compareTo(Env.ZERO)!=0)
{
BigDecimal discFactor = (Env.ONEHUNDRED.subtract(discountPercentOnLine)).divide(Env.ONEHUNDRED, 12, RoundingMode.HALF_DOWN);
actualLineInclTotalPrice = (lineTotal).multiply(discFactor).setScale(2, RoundingMode.HALF_UP);
}
else if (discountedLineInclUnitPrice != null && !discountedLineInclUnitPrice.equals(Env.ZERO))
else if (discountedLineInclUnitPrice != null && discountedLineInclUnitPrice.compareTo(Env.ZERO)!=0)
{
if(isTaxIncluded)
{