📄 calloutsystem.java
字号:
/*************************************************************************/
/**
* InOut - DocType.
* - sets MovementType
* - gets DocNo
*/
private static String InOut_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
{
Env.setContext(ctx, WindowNo, "C_DocTypeTarget_ID", C_DocType_ID.intValue());
String SQL = "SELECT d.DocBaseType, d.IsDocNoControlled, s.CurrentNext "
+ "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())
{
// Set Movement Type
String DocBaseType = rs.getString("DocBaseType");
if (DocBaseType.equals("MMS")) // Material Shipments
mTab.setValue("MovementType", "C-"); // Customer Shipments
else if (DocBaseType.equals("MMR")) // Material Receipts
mTab.setValue("MovementType", "V+"); // Vendor Receipts
// DocumentNo
if (rs.getString("IsDocNoControlled").equals("Y"))
mTab.setValue("DocumentNo", "<" + rs.getString("CurrentNext") + ">");
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.error("InOut_DocType", e);
return e.getLocalizedMessage();
}
return "";
} // InOut_DocType
/**
* M_InOut - Defaults for BPartner.
* - Location
* - Contact
*/
private static String InOut_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 "
+ "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
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
pstmt.setInt(1, C_BPartner_ID.intValue());
ResultSet rs = pstmt.executeQuery();
BigDecimal bd;
if (rs.next())
{
// Location
Integer ii = new Integer(rs.getInt("C_BPartner_Location_ID"));
if (rs.wasNull())
mTab.setValue("C_BPartner_Location_ID", null);
else
mTab.setValue("C_BPartner_Location_ID", ii);
// Contact
ii = new Integer(rs.getInt("C_BPartner_Contact_ID"));
if (rs.wasNull())
mTab.setValue("C_BPartner_Contact_ID", null);
else
mTab.setValue("C_BPartner_Contact_ID", ii);
// CreditAvailable
double CreditAvailable = rs.getDouble("CreditAvailable");
if (!rs.wasNull() && CreditAvailable < 0)
mTab.fireDataStatusEEvent("CreditLimitOver",
DisplayType.getNumberFormat(DisplayType.Amount).format(CreditAvailable));
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.error("InOut_BPartner", e);
return e.getLocalizedMessage();
}
return "";
} // InOut_BPartner
/*************************************************************************/
/**
* BankStmt - Amount.
* Calculate ChargeAmt = StmtAmt - TrxAmt - InterestAmt
* or id Charge is entered - InterestAmt = StmtAmt - TrxAmt - ChargeAmt
*/
private static String BankStmt_Amount (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
if (calloutActive)
return "";
calloutActive = true;
// Get Stmt & Trx
BigDecimal stmt = (BigDecimal)mTab.getValue("StmtAmt");
if (stmt == null)
stmt = Env.ZERO;
BigDecimal trx = (BigDecimal)mTab.getValue("TrxAmt");
if (trx == null)
trx = Env.ZERO;
BigDecimal bd = stmt.subtract(trx);
// Charge - calculate Interest
if (mField.getColumnName().equals("ChargeAmt"))
{
BigDecimal charge = (BigDecimal)value;
if (charge == null)
charge = Env.ZERO;
bd = bd.subtract(charge);
// s_log.trace(s_log.l5_DData, "Interest (" + bd + ") = Stmt(" + stmt + ") - Trx(" + trx + ") - Charge(" + charge + ")");
mTab.setValue("InterestAmt", bd);
}
// Calculate Charge
else
{
BigDecimal interest = (BigDecimal)mTab.getValue("InterestAmt");
if (interest == null)
interest = Env.ZERO;
bd = bd.subtract(interest);
// s_log.trace(s_log.l5_DData, "Charge (" + bd + ") = Stmt(" + stmt + ") - Trx(" + trx + ") - Interest(" + interest + ")");
mTab.setValue("ChargeAmt", bd);
}
calloutActive = false;
return "";
} // BankStmt_Amount
/**
* BankStmt - Payment.
* Update Transaction Amount when payment is selected
*/
private static String BankStmt_Payment (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
Integer C_Payment_ID = (Integer)value;
if (C_Payment_ID == null || C_Payment_ID.intValue() == 0)
return "";
String sql = "SELECT PayAmt FROM C_Payment_v WHERE C_Payment_ID=?"; // 1
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, C_Payment_ID.intValue());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
BigDecimal bd = rs.getBigDecimal(1);
mTab.setValue("TrxAmt", bd);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.error("BankStmt_Payment", e);
return e.getLocalizedMessage();
}
// Recalculate Amounts
BankStmt_Amount (ctx, WindowNo, mTab, mField, value);
return "";
} // BankStmt_Payment
/*************************************************************************/
/**
* Payment_Invoice.
* when Invoice selected
* - set C_Currency_ID
* - InvCurrency_ID/InvTotalAmt (Env),
* - C_BPartner_ID
* - DiscountAmt = C_Invoice_Discount (ID, DateTrx)
* - InvTotalAmt - C_Invoice_Open (ID)
* - PayAmt = InvTotalAmt - Discount
* - WriteOffAmt = 0
*/
private static String Payment_Invoice (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
if (calloutActive) // assuming it is resetting value
return "";
calloutActive = true;
Integer C_Invoice_ID = (Integer)value;
if (C_Invoice_ID == null || C_Invoice_ID.intValue() == 0)
{
Env.setContext(ctx, WindowNo, "InvCurrency_ID", null);
Env.setContext(ctx, WindowNo, "InvTotalAmt", null);
calloutActive = false;
return "";
}
// Date
Timestamp ts = (Timestamp)mTab.getValue("DateTrx");
if (ts == null)
ts = new Timestamp(System.currentTimeMillis());
boolean isSOTrx = true;
//
String sql = "SELECT C_BPartner_ID,C_Currency_ID," // 1..2
+ " C_Invoice_Open(C_Invoice_ID)," // 3
+ " C_Invoice_Discount(C_Invoice_ID,?), IsSOTrx " // 4..5
+ "FROM C_Invoice WHERE C_Invoice_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setTimestamp(1, ts);
pstmt.setInt(2, C_Invoice_ID.intValue());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
mTab.setValue("C_BPartner_ID", new Integer(rs.getInt(1)));
int C_Currency_ID = rs.getInt(2);
mTab.setValue("C_Currency_ID", new Integer(C_Currency_ID));
Env.setContext(ctx, WindowNo, "InvCurrency_ID", C_Currency_ID);
//
BigDecimal InvoiceOpen = rs.getBigDecimal(3);
if (InvoiceOpen == null)
InvoiceOpen = Env.ZERO;
Env.setContext(ctx, WindowNo, "InvTotalAmt", InvoiceOpen.toString());
BigDecimal DiscountAmt = rs.getBigDecimal(4);
if (DiscountAmt == null)
DiscountAmt = Env.ZERO;
mTab.setValue("PayAmt", InvoiceOpen.subtract(DiscountAmt));
mTab.setValue("DiscountAmt", DiscountAmt);
mTab.setValue("WriteOffAmt", Env.ZERO);
// reset as dependent fields get reset
Env.setContext(ctx, WindowNo, "C_Invoice_ID", C_Invoice_ID.toString());
mTab.setValue("C_Invoice_ID", C_Invoice_ID);
isSOTrx = "Y".equals(rs.getString(5));
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
s_log.error("Payment_Invoice", e);
calloutActive = false;
return e.getLocalizedMessage();
}
calloutActive = false;
return Payment_DocType(ctx, WindowNo, mTab, mField, value);
} // Payment_Invoice
/**
* Payment_Document Type.
* Verify that Document Type (AP/AR) and Invoice (SO/PO) are in sync
*/
private static String Payment_DocType (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
int C_Invoice_ID = Env.getContextAsInt(ctx, WindowNo, "C_Invoice_ID");
int C_DocType_ID = Env.getContextAsInt(ctx, WindowNo, "C_DocType_ID");
// if (mField.getColumnName().equals("C_DocType_ID"))
// {
// }
s_log.debug("Payment_DocType - C_Invoice_ID=" + C_Invoice_ID + ", C_DocType_ID=" + C_DocType_ID);
if (C_Invoice_ID == 0 || C_DocType_ID == 0)
return "";
String sql = "SELECT CASE WHEN (i.IsSOTrx='Y' AND dt.DocBaseType='ARR')"
+ " OR (i.IsSOTrx='N' AND dt.DocBaseType='APP') THEN 'Y'"
+ " ELSE 'N' END CASE "
+ "FROM C_Invoice i, C_DocType dt "
+ "WHERE i.C_Invoice_ID=? AND dt.C_DocType_ID=?";
String result = null;
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, C_Invoice_ID);
pstmt.setInt(2, C_DocType_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
result = rs.getString(1);
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
s_log.error("Payment_DocType", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
if ("N".equals(result))
return "PaymentDocTypeInvoiceInconsistent";
return "";
} // Payment_DocType
/**
* Payment_No_Verify.
* - Verify Credit Card No
*/
private static String Payment_No_Verify (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value)
{
String colName = mField.getColumnName();
// CC
if (colName.equals("CreditCardNumber"))
{
String cc = (String)value;
if (cc == null || cc.length() == 0)
return "";
return MPayment.validateCreditCardNumber(cc);
}
if (colName.equals("RoutingNo"))
{
String rt = (String)value;
if (rt == null || rt.length() == 0)
return "";
return MPayment.validateBankRoutingNo(rt);
}
s_log.warn("No Verification available");
return "";
} // Payment_CCNo_Verify
/**
* Payment_Amounts.
* when C_Currency_ID, DiscountAnt, PayAmt, WriteOffAmt, OverUnderAmt, IsOverUnderPayment change
* making sure that add up to InvTotalAmt in InvCurrency_ID (created by Payment_Invoice)
*/
private static String Payment_Amounts (Properties ctx, int WindowNo, MTab mTab, MField mField, Object value, Object oldValue)
{
if (calloutActive) // assuming it is resetting value
return "";
// New Payment
if (Env.getContextAsInt(ctx, WindowNo, "C_Payment_ID") == 0
&& Env.getContextAsInt(ctx, WindowNo, "C_BPartner_ID") == 0
&& Env.getContextAsInt(ctx, WindowNo, "C_Invoice_ID") == 0)
return "";
calloutActive = true;
// Check, if I
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -