📄 calloutsystem.java
字号:
// no prices yet - look base pricelist
if (noPrice)
{
s_log.info("Order_Product NOT FOUND Current PL Version - Product_ID="
+ M_Product_ID + ", PL_ID=" + M_PriceList_ID);
// Find if via Base Pricelist
SQL = "SELECT BOM_PriceStd(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceStd," // 1
+ "BOM_PriceList(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceList," // 2
+ "BOM_PriceLimit(p.M_Product_ID,pv.M_PriceList_Version_ID) AS PriceLimit," // 3
+ "p.C_UOM_ID,pv.ValidFrom,pl.C_Currency_ID,pl.EnforcePriceLimit " // 4..7
+ "FROM M_Product p, M_ProductPrice pp, M_Pricelist pl, M_Pricelist bpl, M_PriceList_Version pv "
+ "WHERE p.M_Product_ID=pp.M_Product_ID"
+ " AND pp.M_PriceList_Version_ID=pv.M_PriceList_Version_ID"
+ " AND pv.M_PriceList_ID=bpl.M_PriceList_ID"
+ " AND pv.IsActive='Y'"
+ " AND bpl.M_PriceList_ID=pl.BasePriceList_ID" // Base
+ " AND p.M_Product_ID=?" // 1
+ " AND pl.M_PriceList_ID=?" // 2
+ " ORDER BY pv.ValidFrom DESC";
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, M_Product_ID.intValue());
pstmt.setInt(2, M_PriceList_ID);
ResultSet rs = pstmt.executeQuery();
//
while (rs.next() && noPrice)
{
java.sql.Date plDate = rs.getDate(5);
// we have the price list
// if order date is after or equal PriceList validFrom
if (plDate == null || !orderDate.before(plDate))
{
noPrice = false;
s_log.info("Order_Product Base Price List");
// Price Std
priceActual = rs.getBigDecimal(1);
// Price List
mTab.setValue("PriceList", rs.getBigDecimal(2));
if (rs.wasNull())
mTab.setValue("PriceList", Env.ZERO);
// Price Limit
mTab.setValue("PriceLimit", rs.getBigDecimal(3));
if (rs.wasNull())
mTab.setValue("PriceLimit", Env.ZERO);
// UOM
Integer ii = new Integer(rs.getInt(4));
if (!rs.wasNull())
mTab.setValue("C_UOM_ID", ii);
// Currency
ii = new Integer(rs.getInt(6));
if (!rs.wasNull())
mTab.setValue("C_Currency_ID", ii);
// Price Limit Enforce
Env.setContext(ctx, WindowNo, "EnforcePriceLimit", rs.getString(7));
}
}
rs.close();
pstmt.close();
}
// still no price, get UOM
if (noPrice)
{
SQL = "SELECT C_UOM_ID FROM M_Product WHERE M_Product_ID=?";
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, M_Product_ID.intValue());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
s_log.info("Order_Product Only UOM");
Integer ii = new Integer(rs.getInt(1));
if (!rs.wasNull())
mTab.setValue("C_UOM_ID", ii);
}
rs.close();
pstmt.close();
}
//
calloutActive = false; // calculate discount, etc.
//
if (priceActual == null)
priceActual = Env.ZERO;
mTab.setValue("PriceActual", priceActual);
}
catch (SQLException e)
{
s_log.error("Order_Product " + e.getMessage());
calloutActive = false;
return e.getLocalizedMessage();
}
return "";
} // Order_Product
/**
* Order - Tax.
* - called when tax basis changes (BPartner Loaction, Product)
* - sets C_Tax_ID
*/
private static String Order_Tax (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
String column = mField.getColumnName();
if (value == null)
return "";
// Check Product
int M_Product_ID = 0;
if (column.equals("M_Product_ID"))
M_Product_ID = ((Integer)value).intValue();
else
M_Product_ID = Env.getContextAsInt(ctx, WindowNo, "M_Product_ID");
int C_Charge_ID = 0;
if (column.equals("C_Charge_ID"))
C_Charge_ID = ((Integer)value).intValue();
else
C_Charge_ID = Env.getContextAsInt(ctx, WindowNo, "C_Charge_ID");
s_log.debug("Product=" + M_Product_ID + ", C_Charge_ID=" + C_Charge_ID);
if (M_Product_ID == 0 && C_Charge_ID == 0)
return "";
// Check Partner Location
int shipC_BPartner_Location_ID = 0;
if (column.equals("C_BPartner_Location_ID"))
shipC_BPartner_Location_ID = ((Integer)value).intValue();
else
shipC_BPartner_Location_ID = Env.getContextAsInt(ctx, WindowNo, "C_BPartner_Location_ID");
if (shipC_BPartner_Location_ID == 0)
return "";
s_log.debug("Ship BP_Location=" + shipC_BPartner_Location_ID);
//
Timestamp billDate = Env.getContextAsDate(ctx, WindowNo, "DateOrdered");
s_log.debug("Bill Date=" + billDate);
Timestamp shipDate = Env.getContextAsDate(ctx, WindowNo, "DatePromised");
s_log.debug("Ship Date=" + shipDate);
int AD_Org_ID = Env.getContextAsInt(ctx, WindowNo, "AD_Org_ID");
s_log.debug("Org=" + AD_Org_ID);
int M_Warehouse_ID = Env.getContextAsInt(ctx, WindowNo, "M_Warehouse_ID");
s_log.debug("Warehouse=" + M_Warehouse_ID);
int billC_BPartner_Location_ID = Env.getContextAsInt(ctx, WindowNo, "BillTo_ID");
if (billC_BPartner_Location_ID == 0)
billC_BPartner_Location_ID = shipC_BPartner_Location_ID;
s_log.debug("Bill BP_Location=" + billC_BPartner_Location_ID);
//
int C_Tax_ID = Tax.get (ctx, M_Product_ID, C_Charge_ID, billDate, shipDate,
AD_Org_ID, M_Warehouse_ID, billC_BPartner_Location_ID, shipC_BPartner_Location_ID,
Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y"));
s_log.debug("Tax ID=" + C_Tax_ID);
//
if (C_Tax_ID == 0)
mTab.fireDataStatusEEvent(Log.retrieveError());
else
mTab.setValue("C_Tax_ID", new Integer(C_Tax_ID));
return "";
} // Order_Tax
/**
* Order - Amount.
* - called from QtyOrdered, Discount and PriceActual
* - calculates LineNetAmt
* - enforces PriceLimit
*/
private static String Order_Amt (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
if (calloutActive)
return "";
calloutActive = true;
BigDecimal QtyOrdered, PriceActual, PriceLimit, Discount, PriceList;
int StdPrecision = Env.getContextAsInt(ctx, WindowNo, "StdPrecision");
// get values
QtyOrdered = (BigDecimal)mTab.getValue("QtyOrdered");
PriceActual = ((BigDecimal)mTab.getValue("PriceActual")).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
Discount = (BigDecimal)mTab.getValue("Discount");
//
PriceLimit = ((BigDecimal)mTab.getValue("PriceLimit")).setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
PriceList = (BigDecimal)mTab.getValue("PriceList");
s_log.debug("Ordered=" + QtyOrdered + ", List=" + PriceList + ", Limit=" + PriceLimit + ", Precision=" + StdPrecision);
s_log.debug("~ Actual=" + PriceActual + ", Discount=" + Discount);
// calculate Discount
if (mField.getColumnName().equals("PriceActual") || mField.getColumnName().equals("PriceList"))
{
if (PriceList.intValue() == 0)
Discount = Env.ZERO;
else
Discount = new BigDecimal ((PriceList.doubleValue() - PriceActual.doubleValue()) / PriceList.doubleValue() * 100.0);
if (Discount.scale() > 2)
Discount = Discount.setScale(2, BigDecimal.ROUND_HALF_UP);
mTab.setValue("Discount", Discount);
}
// calculate Actual
else if (mField.getColumnName().equals("Discount"))
{
PriceActual = new BigDecimal ((100.0 - Discount.doubleValue()) / 100.0 * PriceList.doubleValue());
if (PriceActual.scale() > StdPrecision)
PriceActual = PriceActual.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
mTab.setValue("PriceActual", PriceActual);
}
s_log.debug("= Actual=" + PriceActual + ", Discount=" + Discount);
// Check PriceLimit
if (!mField.getColumnName().equals("QtyOrdered"))
{
String epl = Env.getContext(ctx, WindowNo, "EnforcePriceLimit");
// Check Price Limit?
if (epl != null && epl.equals("Y") && PriceLimit.doubleValue() != 0.0
&& PriceActual.compareTo(PriceLimit) < 0)
{
mTab.setValue ("PriceActual", PriceLimit);
mTab.fireDataStatusEEvent ("UnderLimitPrice", "");
PriceActual = PriceLimit;
// Repeat Discount calc
if (PriceList.intValue() != 0)
{
Discount = new BigDecimal ((PriceList.doubleValue () - PriceActual.doubleValue ()) / PriceList.doubleValue () * 100.0);
if (Discount.scale () > 2)
Discount = Discount.setScale (2, BigDecimal.ROUND_HALF_UP);
mTab.setValue ("Discount", Discount);
}
}
}
// Multiply
BigDecimal LineNetAmt = QtyOrdered.multiply(PriceActual);
if (LineNetAmt.scale() > StdPrecision)
LineNetAmt = LineNetAmt.setScale(StdPrecision, BigDecimal.ROUND_HALF_UP);
mTab.setValue("LineNetAmt", LineNetAmt);
s_log.debug("Line=" + LineNetAmt);
calloutActive = false;
return "";
} // Order_Amt
/*************************************************************************/
/**
* Invoice - DocType.
* - sets HasCharges
* - sets Approval
* - gets DocNo
*/
private static String Invoice_DocType (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
Integer C_DocType_ID = (Integer)value;
if (C_DocType_ID == null || C_DocType_ID.intValue() == 0)
return "";
try
{
String SQL = "SELECT d.HasCharges,d.IsApproved,d.IsDocNoControlled,"
+ "s.CurrentNext, d.DocBaseType "
+ "FROM C_DocType d, AD_Sequence s "
+ "WHERE C_DocType_ID=?" // 1
+ " AND d.DocNoSequence_ID=s.AD_Sequence_ID(+)";
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, C_DocType_ID.intValue());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
// Charges - Set Context
Env.setContext(ctx, WindowNo, "HasCharges", rs.getString(1));
// Approval required?
String YN = "Y";
if (rs.getString(2).equals("Y"))
YN = "N";
mTab.setValue("IsApproved", YN);
Env.setContext(ctx, WindowNo, "IsApproved", YN); // otherwise overwritten by default
// DocumentNo
if (rs.getString(3).equals("Y"))
mTab.setValue("DocumentNo", "<" + rs.getString(4) + ">");
// DocBaseType - Set Context
String s = rs.getString(5);
Env.setContext(ctx, WindowNo, "DocBaseType", s);
// AP Check & AR Credit Memo
if (s.startsWith("AP"))
mTab.setValue("PaymentRule", "S"); // Check
else if (s.endsWith("C"))
mTab.setValue("PaymentRule", "P"); // OnCredit
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.error("Invoice_DocType", e);
return e.getLocalizedMessage();
}
return "";
} // Invoice_DocType
/**
* Invoice - Defaults for BPartner.
* - PriceList
* - Currency
* - PaymentRule, PaymentTerm
* - Location/BillTo
* - Contact
*/
private static String Invoice_BPartner (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
Integer C_BPartner_ID = (Integer)value;
if (C_BPartner_ID == null || C_BPartner_ID.intValue() == 0)
return "";
String SQL = "SELECT p.AD_Language,p.C_PaymentTerm_ID,"
+ "p.M_PriceList_ID,p.PaymentRule,p.POReference,"
+ "p.SO_Description,p.IsDiscountPrinted,"
+ "p.SO_CreditLimit-p.SO_CreditUsed AS CreditAvailable,"
+ "l.C_BPartner_Location_ID,c.C_BPartner_Contact_ID,"
+ "p.PO_PriceList_ID, p.PaymentRulePO, p.PO_PaymentTerm_ID "
+ "FROM C_BPartner p, C_BPartner_Location l, C_BPartner_Contact c "
+ "WHERE p.C_BPartner_ID=l.C_BPartner_ID(+)"
+ " AND p.C_BPartner_ID=c.C_BPartner_ID(+)"
+ " AND p.C_BPartner_ID=?"; // 1
boolean IsSOTrx = Env.getContext(ctx, WindowNo, "IsSOTrx").equals("Y");
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, C_BPartner_ID.intValue());
ResultSet rs = pstmt.executeQuery();
//
if (rs.next())
{
// PriceList & IsTaxIncluded & Currency
Integer ii = new Integer(rs.getInt(IsSOTrx ? "M_PriceList_ID" : "PO_PriceList_ID"));
if (!rs.wasNull())
mTab.setValue("M_PriceList_ID", ii);
else
{ // get default PriceList
int i = Env.getContextAsInt(ctx, "#M_PriceList_ID");
if (i != 0)
mTab.setValue("M_PriceList_ID", new Integer(i));
}
// PaymentRule
String s = rs.getString(IsSOTrx ? "PaymentRule" : "PaymentRulePO");
if (s != null && s.length() != 0)
{
if (Env.getContext(ctx, WindowNo, "DocBaseType").endsWith("C")) // Credits are Payment Term
s = "P";
else if (IsSOTrx && (s.equals("S") || s.equals("U"))) // No Check/Transfer for SO_Trx
s = "P"; // Payment Term
mTab.setValue("PaymentRule", s);
}
// Payment Term
ii = new Integer(rs.getInt(IsSOTrx ? "C_PaymentTerm_ID" : "PO_PaymentTerm_ID"));
if (!rs.wasNull())
mTab.setValue("C_PaymentTerm_ID", ii);
// Location(s) - overwritten by InfoBP selectiion
int locID = rs.getInt("C_BPartner_Location_ID");
if (C_BPartner_ID.toString().equals(Env.getContext(ctx, WindowNo, Env.TAB_INFO, "C_BPartner_ID")))
{
String loc = Env.getContext(ctx, WindowNo, Env.TAB_INFO, "C_BPartner_Location_ID");
if (loc.length() > 0)
locID = Integer.parseInt(loc);
}
if (locID == 0)
mTab.setValue("C_BPartner_Location_ID", null);
else
mTab.setValue("C_BPartner_Location_ID", new Integer(locID));
// Contact - overwritten by InfoBP selection
int contID = rs.getInt("C_BPartner_Contact_ID");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -