📄 calloutsystem.java
字号:
// DeliveryRule
s = rs.getString(4);
if (s != null && s.length() != 0)
mTab.setValue("DeliveryRule", s);
// FreightCostRule
s = rs.getString(5);
if (s != null && s.length() != 0)
mTab.setValue("FreightCostRule", s);
// DeliveryViaRule
s = rs.getString(6);
if (s != null && s.length() != 0)
mTab.setValue("DeliveryViaRule", s);
}
rs.close();
pstmt.close();
} // re-read customer rules
}
catch (SQLException e)
{
s_log.error("Order_DocType", e);
return e.getLocalizedMessage();
}
return "";
} // Order_DocType
/**
* Order - Defaults for BPartner.
* - PriceList
* - Currency
* - Location/BillTo
* - Contact
* - Defaults: PaymentRule, PaymentTerm
*/
private static String Order_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.InvoiceRule,p.DeliveryRule,p.FreightCostRule,DeliveryViaRule,"
+ "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 (indirect: 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));
}
// 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);
mTab.setValue("BillTo_ID", null);
}
else
{
mTab.setValue("C_BPartner_Location_ID", new Integer(locID));
mTab.setValue("BillTo_ID", new Integer(locID));
}
// Contact - overwritten by InfoBP selection
int contID = rs.getInt("C_BPartner_Contact_ID");
if (C_BPartner_ID.toString().equals(Env.getContext(ctx, WindowNo, Env.TAB_INFO, "C_BPartner_ID")))
{
String cont = Env.getContext(ctx, WindowNo, Env.TAB_INFO, "C_BPartner_Contact_ID");
if (cont.length() > 0)
contID = Integer.parseInt(cont);
}
if (contID == 0)
mTab.setValue("C_BPartner_Contact_ID", null);
else
mTab.setValue("C_BPartner_Contact_ID", new Integer(contID));
// CreditAvailable
double CreditAvailable = rs.getDouble("CreditAvailable");
if (!rs.wasNull() && CreditAvailable < 0)
mTab.fireDataStatusEEvent("CreditLimitOver",
DisplayType.getNumberFormat(DisplayType.Amount).format(CreditAvailable));
// PO Reference
String s = rs.getString("POReference");
if (s != null && s.length() != 0)
mTab.setValue("POReference", s);
else
mTab.setValue("POReference", null);
// SO Description
s = rs.getString("SO_Description");
if (s != null && s.trim().length() != 0)
mTab.setValue("Description", s);
// IsDiscountPrinted
s = rs.getString("IsDiscountPrinted");
if (s != null && s.length() != 0)
mTab.setValue("IsDiscountPrinted", s);
else
mTab.setValue("IsDiscountPrinted", "N");
// Defaults, if not Walkin Receipt or Walkin Invoice
String OrderType = Env.getContext(ctx, WindowNo, "OrderType");
mTab.setValue("InvoiceRule", MOrder.InvoiceRule_AfterDelivery);
mTab.setValue("DeliveryRule", MOrder.DeliveryRule_Availability);
mTab.setValue("PaymentRule", MOrder.PaymentRule_PaymentTerm);
if (OrderType.equals(DocSubTypeSO_Prepay))
{
mTab.setValue("InvoiceRule", MOrder.InvoiceRule_Immediate);
mTab.setValue("DeliveryRule", MOrder.DeliveryRule_Receipt);
}
else if (OrderType.equals(DocSubTypeSO_POS)) // for POS
mTab.setValue("PaymentRule", MOrder.PaymentRule_Cash);
else
{
// PaymentRule
s = rs.getString(IsSOTrx ? "PaymentRule" : "PaymentRulePO");
if (s != null && s.length() != 0)
{
if (s.equals("B")) // No Cache in Non POS
s = "P";
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);
// InvoiceRule
s = rs.getString("InvoiceRule");
if (s != null && s.length() != 0)
mTab.setValue("InvoiceRule", s);
// DeliveryRule
s = rs.getString("DeliveryRule");
if (s != null && s.length() != 0)
mTab.setValue("DeliveryRule", s);
// FreightCostRule
s = rs.getString("FreightCostRule");
if (s != null && s.length() != 0)
mTab.setValue("FreightCostRule", s);
// DeliveryViaRule
s = rs.getString("DeliveryViaRule");
if (s != null && s.length() != 0)
mTab.setValue("DeliveryViaRule", s);
}
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.error("Order_BPartner", e);
return e.getLocalizedMessage();
}
return "";
} // Order_BPartner
/**
* Order - Defaults for PriceList. (used also in Invoice)
* - Currency
* - IsTaxIncluded, EnforcePriceLimit
*/
private static String Order_PriceList (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
Integer M_PriceList_ID = (Integer)value;
if (M_PriceList_ID == null || M_PriceList_ID.intValue()== 0)
return "";
String SQL = "SELECT pl.IsTaxIncluded,pl.EnforcePriceLimit,pl.C_Currency_ID,c.StdPrecision,"
+ "plv.M_PriceList_Version_ID,plv.ValidFrom "
+ "FROM M_PriceList pl,C_Currency c,M_PriceList_Version plv "
+ "WHERE pl.C_Currency_ID=c.C_Currency_ID"
+ " AND pl.M_PriceList_ID=plv.M_PriceList_ID"
+ " AND pl.M_PriceList_ID=? " // 1
+ "ORDER BY plv.ValidFrom DESC";
// Use newest price list - may not be future
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, M_PriceList_ID.intValue());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
// Tax Included
mTab.setValue("IsTaxIncluded", rs.getString(1));
// Price Limit Enforce
Env.setContext(ctx, WindowNo, "EnforcePriceLimit", rs.getString(2));
// Currency
Integer ii = new Integer(rs.getInt(3));
mTab.setValue("C_Currency_ID", ii);
// Precision
Env.setContext(ctx, WindowNo, "StdPrecision", rs.getInt(4));
// PriceList Version
Env.setContext(ctx, WindowNo, "M_PriceList_Version_ID", rs.getInt(5));
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.error("Order_PriceList", e);
return e.getLocalizedMessage();
}
return "";
} // Prder_PriceList
/**
* Order - Defaults for Product.
* - UOM
* - PriceList, PriceStd, PriceLimit
* - Currency
*/
private static String Order_Product (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
Integer M_Product_ID = (Integer)value;
if (M_Product_ID == null || M_Product_ID.intValue() == 0)
return "";
calloutActive = true;
mTab.setValue("C_Charge_ID", null);
// get order date - or default to today's date
Timestamp orderDate = (Timestamp)mTab.getValue("DateOrdered");
if (orderDate == null)
orderDate = new Timestamp(System.currentTimeMillis());
String 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_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=pl.M_PriceList_ID"
+ " AND pv.IsActive='Y'"
+ " AND p.M_Product_ID=?" // 1
+ " AND pv.M_PriceList_Version_ID=?"; // 2
try
{
boolean noPrice = true;
BigDecimal priceActual = Env.ZERO;
// Check if Product was selected from Info
int M_PriceList_Version_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_Version_ID");
if (M_PriceList_Version_ID != 0)
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, M_Product_ID.intValue());
pstmt.setInt(2, M_PriceList_Version_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
s_log.info("Order_Product - Selected PL Version");
noPrice = false;
// 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));
}
else
s_log.info("Order_Product NOT FOUND Selected PL Version - Product_ID="
+ M_Product_ID + ", PL_Version_ID=" + M_PriceList_Version_ID);
rs.close();
pstmt.close();
// Check/Update Warehouse Setting
// int M_Warehouse_ID = Env.getContextAsInt(WindowNo, "M_Warehouse_ID");
// Integer wh = (Integer)mTab.getValue("M_Warehouse_ID");
// if (wh.intValue() != M_Warehouse_ID)
// {
// mTab.setValue("M_Warehouse_ID", new Integer(M_Warehouse_ID));
// ADias_log.warn(WindowNo, "WarehouseChanged");
// }
}
// Search Pricelist for current version
int M_PriceList_ID = 0;
if (noPrice)
{
M_PriceList_ID = Env.getContextAsInt(ctx, WindowNo, "M_PriceList_ID");
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"
+ " INNER JOIN M_ProductPrice pp ON (p.M_Product_ID=pp.M_Product_ID)"
+ " INNER JOIN M_PriceList_Version pv ON (pp.M_PriceList_Version_ID=pv.M_PriceList_Version_ID)"
+ " INNER JOIN M_Pricelist pl ON (pv.M_PriceList_ID=pl.M_PriceList_ID) "
+ "WHERE pv.IsActive='Y'"
+ " 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 Current PL Version");
// 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();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -