📄 vpayment.java
字号:
sBankAccountCombo.setSelectedItem(kp);
/**
* Load Cash Books
*/
SQL = Access.addROAccessSQL(Env.getCtx(),
"SELECT C_CashBook_ID, Name, AD_Org_ID FROM C_CashBook WHERE IsActive='Y'",
"C_CashBook", false);
kp = null;
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
int key = rs.getInt(1);
String name = rs.getString(2);
KeyNamePair pp = new KeyNamePair(key, name);
bCashBookCombo.addItem(pp);
if (key == m_C_CashBook_ID)
kp = pp;
if (kp == null && key == m_AD_Org_ID) // Default Org
kp = pp;
}
rs.close();
pstmt.close();
}
catch (SQLException epc)
{
Log.error ("VPayment.dynInit -CashBook-", epc);
}
// Set Selection
if (kp != null)
{
bCashBookCombo.setSelectedItem(kp);
if (m_C_CashBook_ID == 0)
m_C_CashBook_ID = kp.getKey(); // set to default to avoid 'cashbook changed' message
}
//
return true;
} // dynInit
/**
* Init OK to be able to make changes?
* @return true if init OK
*/
public boolean isInitOK()
{
return m_initOK;
} // isInitOK
/**
* Fill s_Currencies with EMU currencies
*/
private void loadCurrencies()
{
s_Currencies = new Hashtable(12); // Currenly only 10+1
String SQL = "SELECT C_Currency_ID, ISO_Code FROM C_Currency "
+ "WHERE (IsEMUMember='Y' AND EMUEntryDate<SysDate) OR IsEuro='Y' "
+ "ORDER BY 2";
try
{
PreparedStatement pstmt = DB.prepareStatement(SQL);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
int id = rs.getInt(1);
String name = rs.getString(2);
s_Currencies.put(new Integer(id), new KeyNamePair(id, name));
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("VPayment.loadCurrencies", e);
}
} // loadCurrencies
/*************************************************************************/
/**
* Action Listener
* @param e event
*/
public void actionPerformed(ActionEvent e)
{
// Log.trace(Log.l5_DData, "VPayment.actionPerformed - " + e.getActionCommand());
// Finish
if (e.getActionCommand().equals(ConfirmPanel.A_OK))
{
if (saveChanges())
dispose();
}
else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL))
dispose();
// Payment Method Change
else if (e.getSource() == paymentCombo)
{
// get selection
ValueNamePair pp = (ValueNamePair)paymentCombo.getSelectedItem();
if (pp != null)
{
String s = pp.getValue().toLowerCase() + "Panel";
centerLayout.show(centerPanel, s); // switch to panel
}
}
// Check Currency change
else if (e.getSource() == sCurrencyCombo)
{
KeyNamePair pp = (KeyNamePair)sCurrencyCombo.getSelectedItem();
BigDecimal amt = DB.getConvertedAmt(m_Amount, m_C_Currency_ID, pp.getKey(), m_AD_Client_ID, m_AD_Org_ID);
sAmountField.setText(m_Format.format(amt));
}
// Cash Currency change
else if (e.getSource() == bCurrencyCombo)
{
KeyNamePair pp = (KeyNamePair)bCurrencyCombo.getSelectedItem();
BigDecimal amt = DB.getConvertedAmt(m_Amount, m_C_Currency_ID, pp.getKey(), m_AD_Client_ID, m_AD_Org_ID);
bAmountField.setText(m_Format.format(amt));
}
// Online
else if (e.getSource() == kOnline || e.getSource() == sOnline || e.getSource() == tOnline)
online();
} // actionPerformed
/*************************************************************************/
/**
* Save Changes
* @returns true, if eindow can exit
*/
private boolean saveChanges()
{
Log.trace(Log.l3_Util, "VPayment.saveChanges");
if (!checkMandatory())
return false;
ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem();
String PaymentRule = vp.getValue();
// only Payment Rule
if (m_onlyRule)
{
if (!PaymentRule.equals(m_PaymentRule))
m_mTab.setValue("PaymentRule", PaymentRule);
return true;
}
//
Timestamp DateAcct = m_DateAcct;
int C_PaymentTerm_ID = m_C_PaymentTerm_ID;
int C_Payment_ID = m_C_Payment_ID;
int C_CashLine_ID = m_C_CashLine_ID;
int C_CashBook_ID = m_C_CashBook_ID;
String CCType = m_CCType;
//
int C_BankAccount_ID = 0;
// B (Cash) (Currency)
if (PaymentRule.equals(PAYMENTRULE_CASH))
{
KeyNamePair kp = (KeyNamePair)bCashBookCombo.getSelectedItem();
if (kp != null)
C_CashBook_ID = kp.getKey();
DateAcct = (Timestamp)bDateField.getValue();
}
// K (CreditCard) Type, Number, Exp, Approval
else if (PaymentRule.equals(PAYMENTRULE_CREDITCARD))
{
vp = (ValueNamePair)kTypeCombo.getSelectedItem();
if (vp != null)
CCType = vp.getValue();
}
// T (Transfer) BPartner_Bank
else if (PaymentRule.equals(PAYMENTRULE_TRANSFER))
{
tAccountCombo.getSelectedItem();
}
// P (PaymentTerm) PaymentTerm
else if (PaymentRule.equals(PAYMENTRULE_ONCREDIT))
{
KeyNamePair kp = (KeyNamePair)pTermCombo.getSelectedItem();
if (kp != null)
C_PaymentTerm_ID = kp.getKey();
}
// S (Check) (Currency) CheckNo, Routing
else if (PaymentRule.equals(PAYMENTRULE_CHECK))
{
// sCurrencyCombo.getSelectedItem();
KeyNamePair kp = (KeyNamePair)sBankAccountCombo.getSelectedItem();
if (kp != null)
C_BankAccount_ID = kp.getKey();
}
else
return false;
// find Bank Account if not qualified yet
if ("KTS".indexOf(PaymentRule) != -1 && C_BankAccount_ID == 0)
{
String tender = MPayment.TENDER_CREDITCARD;
if (PaymentRule.equals("T"))
tender = MPayment.TENDER_ACH;
else if (PaymentRule.equals("S"))
tender = MPayment.TENDER_CHECK;
C_BankAccount_ID = MPayment.findBankAccount(Env.getCtx(), tender, CCType, m_AD_Client_ID,
m_C_Currency_ID, m_Amount);
}
/***********************
* Changed PaymentRule
*/
if (!PaymentRule.equals(m_PaymentRule))
{
// We had a CashBook Entry
if (m_PaymentRule.equals(PAYMENTRULE_CASH))
{
if (m_mCashBook != null)
{
if (m_mCashBook.reverse(Env.getCtx(), m_WindowNo)) // Reverse Cashbook Entry
Log.trace(Log.l4_Data, "CashCancelled");
else
ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCancelled");
}
C_CashLine_ID = 0; // reset
}
// We had a Payment
if ("KTS".indexOf(m_PaymentRule) != -1 && "KTS".indexOf(PaymentRule) == -1)
{
if (m_mPayment != null)
{
if (m_mPayment.cancel()) // Cancel Payment
Log.trace(Log.l4_Data, "PaymentCancelled " + m_mPayment.getDocumentNo());
else
ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCancelled " + m_mPayment.getDocumentNo());
}
C_Payment_ID = 0; // reset
}
}
// Get Order and optionally Invoice
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Order_ID");
int C_Invoice_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Invoice_ID");
if (C_Invoice_ID == 0 && m_DocStatus.equals("CO"))
C_Invoice_ID = getInvoiceID (C_Order_ID);
// Amount sign negative, if ARC (Credit Memo) or API (AP Invoice)
boolean negateAmt = false;
String sql = "SELECT DECODE (dt.DocBaseType, 'ARC','Y', 'API','Y', 'N'), dt.DocBaseType "
+ "FROM C_DocType dt, C_Invoice i "
+ "WHERE dt.C_DocType_ID = i.C_DocType_ID"
+ " AND i.C_Invoice_ID=?";
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, C_Invoice_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
negateAmt = "Y".equals(rs.getString(1));
else
Log.error("VPayment.saveChanges - NegateAmount not found C_Invoice_ID=" + C_Invoice_ID);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error("VPayment.saveChanges - NegateAmount", e);
}
BigDecimal payAmount = m_Amount;
if (negateAmt)
payAmount = m_Amount.negate();
// Info
Log.trace(Log.l4_Data, "VPayment.saveChanges",
"C_Order_ID=" + C_Order_ID + ", C_Invoice_ID=" + C_Invoice_ID + ", NegateAmt=" + negateAmt);
/***********************
* CashBook
*/
if (PaymentRule.equals(PAYMENTRULE_CASH))
{
String description = (String)m_mTab.getValue("DocumentNo");
// Create new
if (m_mCashBook == null)
{
if (C_Invoice_ID == 0)
{
Log.trace(Log.l4_Data, "VPayment.saveChanges - No Invoice!");
ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCreated");
}
else
{
Log.trace(Log.l4_Data, "VPayment.saveChanges - New CashBook");
C_CashLine_ID = MCashBook.createCashBookEntry(Env.getCtx(), m_WindowNo,
m_AD_Client_ID, m_AD_Org_ID, DateAcct, C_Invoice_ID,
payAmount, description, C_CashBook_ID);
if (C_CashLine_ID != 0)
Log.trace(Log.l4_Data, "VPayment.saveChanges - CashCreated");
else
ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCreated");
}
}
// Changed Cash Book or Date
else if (C_CashBook_ID != m_C_CashBook_ID || !m_mCashBook.isSameDate(DateAcct))
{
Log.trace(Log.l4_Data, "VPayment.saveChanges - Changed CashBook/Date");
boolean reversal = m_mCashBook.reverse(Env.getCtx(), m_WindowNo);
C_CashLine_ID = MCashBook.createCashBookEntry(Env.getCtx(), m_WindowNo,
m_AD_Client_ID, m_AD_Org_ID, DateAcct, C_Invoice_ID,
payAmount, description, C_CashBook_ID);
if (reversal && C_CashLine_ID != 0)
Log.trace(Log.l4_Data, "VPayment.saveChanges - CashChanged");
else
ADialog.error(m_WindowNo, this, "PaymentError", "CashNotChanged");
}
// Changed Amount
else if (payAmount.compareTo(m_mCashBook.getAmount()) != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -