vpayment.java
来自「Java写的ERP系统」· Java 代码 · 共 1,324 行 · 第 1/4 页
JAVA
1,324 行
{
Log.trace(Log.l4_Data, "VPayment.saveChanges - Changed CashBook Amount");
m_mCashBook.setAmount(payAmount);
m_mCashBook.update();
Log.trace(Log.l4_Data, "VPayment.saveChanges - CashChanged");
}
else
Log.trace(Log.l4_Data, "VPayment.saveChanges - No Change");
}
/***********************
* Payments
*/
if ("KTS".indexOf(PaymentRule) != -1)
{
// Online
if (m_OnlinePayment_ID != 0)
C_Payment_ID = m_OnlinePayment_ID;
else
{
m_mPayment = new MPayment(Env.getCtx(), 0);
if (PaymentRule.equals(PAYMENTRULE_CREDITCARD))
{
m_mPayment.setC_BankAccount_ID(C_BankAccount_ID);
m_mPayment.setCreditCard(MPayment.TRX_SALES, CCType,
kNumberField.getText(), "", kExpField.getText());
}
else if (PaymentRule.equals(PAYMENTRULE_TRANSFER))
{
m_mPayment.setBankACH(C_BankAccount_ID, m_isSOTrx, tRoutingField.getText(),
tNumberField.getText());
}
else if (PaymentRule.equals(PAYMENTRULE_CHECK))
{
m_mPayment.setBankCheck(C_BankAccount_ID, m_isSOTrx, sRoutingField.getText(),
sNumberField.getText(), sCheckField.getText());
}
m_mPayment.setC_BPartner_ID(m_C_BPartner_ID);
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
m_mPayment.setDateTrx(m_DateAcct);
// Set Amount
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
// Save/Post
if (m_mPayment.save() && m_mPayment.post())
ADialog.info(m_WindowNo, this, "PaymentCreated", m_mPayment.getDocumentNo());
else
ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated");
C_Payment_ID = m_mPayment.getID();
}
}
/**********************
* Save Values to mTab
*/
Log.trace(Log.l4_Data, "VPayment.saveChanges", "Saving changes");
if (!PaymentRule.equals(m_PaymentRule))
m_mTab.setValue("PaymentRule", PaymentRule);
//
if (!DateAcct.equals(m_DateAcct))
m_mTab.setValue("DateAcct", DateAcct);
//
if (C_PaymentTerm_ID != m_C_PaymentTerm_ID)
m_mTab.setValue("C_PaymentTerm_ID", new Integer(C_PaymentTerm_ID));
//
if (C_Payment_ID != m_C_Payment_ID)
{
if (C_Payment_ID == 0)
m_mTab.setValue("C_Payment_ID", null);
else
m_mTab.setValue("C_Payment_ID", new Integer(C_Payment_ID));
}
//
if (C_CashLine_ID != m_C_CashLine_ID)
{
if (C_CashLine_ID == 0)
m_mTab.setValue("C_CashLine_ID", null);
else
m_mTab.setValue("C_CashLine_ID", new Integer(C_CashLine_ID));
}
//
return true;
} // saveChanges
/**
* Check Mandatory
* @return true if all mandatory items are OK
*/
private boolean checkMandatory()
{
Log.trace(Log.l4_Data, "VPayment.checkMandatory");
ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem();
String PaymentRule = vp.getValue();
// only Payment Rule
if (m_onlyRule)
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;
/***********************
* Mandatory Data Check
*/
boolean dataOK = true;
// 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();
//
String error = MPayment.validateCreditCardNumber(kNumberField.getText(), CCType);
if (error.length() != 0)
{
kNumberField.setBackground(CompierePLAF.getFieldBackground_Error());
if (error.indexOf("?") == -1)
{
ADialog.error(m_WindowNo, this, error);
dataOK = false;
}
else // warning
{
if (!ADialog.ask(m_WindowNo, this, error))
dataOK = false;
}
}
error = MPayment.validateCreditCardExp(kExpField.getText());
if(error.length() != 0)
{
kExpField.setBackground(CompierePLAF.getFieldBackground_Error());
ADialog.error(m_WindowNo, this, error);
dataOK = false;
}
}
// T (Transfer) BPartner_Bank
else if (PaymentRule.equals(PAYMENTRULE_TRANSFER))
{
tAccountCombo.getSelectedItem();
String error = MPayment.validateBankRoutingNo(tRoutingField.getText());
if (error.length() != 0)
{
tRoutingField.setBackground(CompierePLAF.getFieldBackground_Error());
ADialog.error(m_WindowNo, this, error);
dataOK = false;
}
error = MPayment.validateBankAccountNo(tNumberField.getText());
if (error.length() != 0)
{
tNumberField.setBackground(CompierePLAF.getFieldBackground_Error());
ADialog.error(m_WindowNo, this, error);
dataOK = false;
}
}
// P (PaymentTerm) PaymentTerm
else if (PaymentRule.equals(PAYMENTRULE_PAYMENTTERM))
{
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();
String error = MPayment.validateBankRoutingNo(sRoutingField.getText());
if (error.length() != 0)
{
sRoutingField.setBackground(CompierePLAF.getFieldBackground_Error());
ADialog.error(m_WindowNo, this, error);
dataOK = false;
}
error = MPayment.validateBankAccountNo(sNumberField.getText());
if (error.length() != 0)
{
sNumberField.setBackground(CompierePLAF.getFieldBackground_Error());
ADialog.error(m_WindowNo, this, error);
dataOK = false;
}
error = MPayment.validateBankCheckNo(sCheckField.getText());
if (error.length() != 0)
{
sCheckField.setBackground(CompierePLAF.getFieldBackground_Error());
ADialog.error(m_WindowNo, this, error);
dataOK = false;
}
}
else
{
Log.error("VPayment.checkMandatory - Unknown PaymentRule " + PaymentRule);
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);
if (C_BankAccount_ID == 0)
{
ADialog.error(m_WindowNo, this, "PaymentNoProcessor");
dataOK = false;
}
}
//
Log.trace(Log.l3_Util, "VPayment.checkMandatory - OK=" + dataOK);
return dataOK;
} // checkMandatory
/**
* Get Invoice ID for Order
* @param C_Order_ID order
* @returns C_Invoice_ID or 0 if not found
*/
private static int getInvoiceID (int C_Order_ID)
{
int retValue = 0;
String sql = "SELECT C_Invoice_ID FROM C_Invoice WHERE C_Order_ID=? "
+ "ORDER BY C_Invoice_ID DESC"; // last invoice
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, C_Order_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("VPayment.getInvoiceID", e);
}
return retValue;
} // getInvoiceID
/*************************************************************************/
/**
* Process Online (sales only)
*/
private void online()
{
Log.trace(Log.l3_Util, "VPayment.online");
m_OnlinePayment_ID = 0;
if (!checkMandatory())
return;
boolean processed = false;
String info = "";
//
ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem();
String PaymentRule = vp.getValue();
// -- CreditCard
if (PaymentRule.equals(PAYMENTRULE_CREDITCARD))
{
vp = (ValueNamePair)kTypeCombo.getSelectedItem();
String CCType = vp.getValue();
m_mPayment = new MPayment(Env.getCtx(), 0);
//
m_mPayment.setCreditCard(MPayment.TRX_SALES, CCType,
kNumberField.getText(), "", kExpField.getText());
m_mPayment.setAmount(m_C_Currency_ID, m_Amount);
m_mPayment.setPaymentProcessor();
m_mPayment.setC_BPartner_ID(m_C_BPartner_ID);
//
int C_Invoice_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Invoice_ID");
if (C_Invoice_ID == 0 && m_DocStatus.equals("CO"))
{
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Order_ID");
C_Invoice_ID = getInvoiceID (C_Order_ID);
}
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
m_mPayment.setDateTrx(m_DateAcct);
// Set Amount
m_mPayment.setAmount(m_C_Currency_ID, m_Amount);
processed = m_mPayment.processOnline();
info = m_mPayment.getR_RespMsg() + " (" + m_mPayment.getR_AuthCode()
+ ") ID=" + m_mPayment.getR_PnRef();
boolean saved = m_mPayment.save();
if (processed)
{
if (m_mPayment.post())
ADialog.info(m_WindowNo, this, "PaymentProcessed", info + "\n" + m_mPayment.getDocumentNo());
else
ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated");
saveChanges();
dispose();
}
else
{
ADialog.error(m_WindowNo, this, "PaymentNotProcessed", info);
}
m_OnlinePayment_ID = m_mPayment.getID();
}
else
ADialog.error(m_WindowNo, this, "PaymentNoProcessor");
} // online
} // VPayment
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?