📄 mproductpricing.java
字号:
m_PriceList = rs.getBigDecimal (2);
if (rs.wasNull ())
m_PriceList = Env.ZERO;
m_PriceLimit = rs.getBigDecimal (3);
if (rs.wasNull ())
m_PriceLimit = Env.ZERO;
//
m_C_UOM_ID = rs.getInt (4);
m_C_Currency_ID = rs.getInt (6);
m_M_Product_Category_ID = rs.getInt(7);
m_enforcePriceLimit = "Y".equals(rs.getString(8));
m_isTaxIncluded = "Y".equals(rs.getString(9));
//
log.fine("M_PriceList_ID=" + m_M_PriceList_ID
+ "(" + plDate + ")" + " - " + m_PriceStd);
m_calculated = true;
break;
}
}
rs.close();
pstmt.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
m_calculated = false;
}
if (!m_calculated)
log.finer("Not found (BPL)");
return m_calculated;
} // calculateBPL
/**
* Set Base Info (UOM)
*/
private void setBaseInfo()
{
if (m_M_Product_ID == 0)
return;
//
String sql = "SELECT C_UOM_ID, M_Product_Category_ID FROM M_Product WHERE M_Product_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
m_C_UOM_ID = rs.getInt (1);
m_M_Product_Category_ID = rs.getInt(2);
}
rs.close();
pstmt.close();
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
} // setBaseInfo
/**
* Is Tax Included
* @return tax included
*/
public boolean isTaxIncluded()
{
return m_isTaxIncluded;
} // isTaxIncluded
/**************************************************************************
* Calculate (Business Partner) Discount
*/
private void calculateDiscount()
{
m_discountSchema = false;
if (m_C_BPartner_ID == 0 || m_M_Product_ID == 0)
return;
int M_DiscountSchema_ID = 0;
BigDecimal FlatDiscount = null;
String sql = "SELECT COALESCE(p.M_DiscountSchema_ID,g.M_DiscountSchema_ID),"
+ " COALESCE(p.PO_DiscountSchema_ID,g.PO_DiscountSchema_ID), p.FlatDiscount "
+ "FROM C_BPartner p"
+ " INNER JOIN C_BP_Group g ON (p.C_BP_Group_ID=g.C_BP_Group_ID) "
+ "WHERE p.C_BPartner_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, m_C_BPartner_ID);
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
{
M_DiscountSchema_ID = rs.getInt(m_isSOTrx ? 1 : 2);
FlatDiscount = rs.getBigDecimal(3);
if (FlatDiscount == null)
FlatDiscount = Env.ZERO;
}
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
// No Discount Schema
if (M_DiscountSchema_ID == 0)
return;
MDiscountSchema sd = MDiscountSchema.get(Env.getCtx(), M_DiscountSchema_ID); // not correct
if (sd.get_ID() == 0)
return;
//
m_discountSchema = true;
m_PriceStd = sd.calculatePrice(m_Qty, m_PriceStd, m_M_Product_ID,
m_M_Product_Category_ID, FlatDiscount);
} // calculateDiscount
/**************************************************************************
* Calculate Discount Percentage based on Standard/List Price
* @return Discount
*/
public BigDecimal getDiscount()
{
BigDecimal Discount = Env.ZERO;
if (m_PriceList.intValue() != 0)
Discount = new BigDecimal ((m_PriceList.doubleValue() - m_PriceStd.doubleValue())
/ m_PriceList.doubleValue() * 100.0);
if (Discount.scale() > 2)
Discount = Discount.setScale(2, BigDecimal.ROUND_HALF_UP);
return Discount;
} // getDiscount
/**************************************************************************
* Get Product ID
* @return id
*/
public int getM_Product_ID()
{
return m_M_Product_ID;
}
/**
* Get PriceList ID
* @return pl
*/
public int getM_PriceList_ID()
{
return m_M_PriceList_ID;
} // getM_PriceList_ID
/**
* Set PriceList
* @param M_PriceList_ID pl
*/
public void setM_PriceList_ID( int M_PriceList_ID)
{
m_M_PriceList_ID = M_PriceList_ID;
m_calculated = false;
} // setM_PriceList_ID
/**
* Get PriceList Version
* @return plv
*/
public int getM_PriceList_Version_ID()
{
return m_M_PriceList_Version_ID;
} // getM_PriceList_Version_ID
/**
* Set PriceList Version
* @param M_PriceList_Version_ID plv
*/
public void setM_PriceList_Version_ID (int M_PriceList_Version_ID)
{
m_M_PriceList_Version_ID = M_PriceList_Version_ID;
m_calculated = false;
} // setM_PriceList_Version_ID
/**
* Get Price Date
* @return date
*/
public Timestamp getPriceDate()
{
return m_PriceDate;
} // getPriceDate
/**
* Set Price Date
* @param priceDate date
*/
public void setPriceDate(Timestamp priceDate)
{
m_PriceDate = priceDate;
m_calculated = false;
} // setPriceDate
/**
* Set Precision.
*/
private void setPrecision ()
{
if (m_M_PriceList_ID != 0)
m_precision = MPriceList.getPricePrecision(Env.getCtx(), getM_PriceList_ID());
} // setPrecision
/**
* Get Precision
* @return precision - -1 = no rounding
*/
public int getPrecision()
{
return m_precision;
} // getPrecision
/**
* Round
* @param bd number
* @return rounded number
*/
private BigDecimal round (BigDecimal bd)
{
if (m_precision >= 0 // -1 = no rounding
&& bd.scale() > m_precision)
return bd.setScale(m_precision, BigDecimal.ROUND_HALF_UP);
return bd;
} // round
/**************************************************************************
* Get C_UOM_ID
* @return uom
*/
public int getC_UOM_ID()
{
if (!m_calculated)
calculatePrice();
return m_C_UOM_ID;
}
/**
* Get Price List
* @return list
*/
public BigDecimal getPriceList()
{
if (!m_calculated)
calculatePrice();
return round(m_PriceList);
}
/**
* Get Price Std
* @return std
*/
public BigDecimal getPriceStd()
{
if (!m_calculated)
calculatePrice();
return round(m_PriceStd);
}
/**
* Get Price Limit
* @return limit
*/
public BigDecimal getPriceLimit()
{
if (!m_calculated)
calculatePrice();
return round(m_PriceLimit);
}
/**
* Get Price List Currency
* @return currency
*/
public int getC_Currency_ID()
{
if (!m_calculated)
calculatePrice();
return m_C_Currency_ID;
}
/**
* Is Price List enforded?
* @return enforce limit
*/
public boolean isEnforcePriceLimit()
{
if (!m_calculated)
calculatePrice();
return m_enforcePriceLimit;
} // isEnforcePriceLimit
/**
* Is a DiscountSchema active?
* @return active Discount Schema
*/
public boolean isDiscountSchema()
{
return m_discountSchema;
} // isDiscountSchema
/**
* Is the Price Calculated (i.e. found)?
* @return calculated
*/
public boolean isCalculated()
{
return m_calculated;
} // isCalculated
} // MProductPrice
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -