📄 vpayselect.java
字号:
ResultSet rs = pstmt.executeQuery();
ValueNamePair vp = null;
while (rs.next())
{
vp = new ValueNamePair(rs.getString(2), rs.getString(3)); // returns also not active
fieldPaymentRule.addItem(vp);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("VPaySelect.loadBankInfo - SQL=" + sql, e);
}
fieldPaymentRule.setSelectedIndex(0);
} // loadBankInfo
/**
* Query and create TableInfo
*/
private void loadTableInfo()
{
Log.trace(Log.l3_Util, "VPaySelect.loadTableInfo");
// not yet initialized
if (m_sql == null)
return;
String sql = m_sql;
// Parameters
Timestamp payDate = (Timestamp)fieldPayDate.getValue();
miniTable.setColorCompare(payDate);
Log.trace(Log.l4_Data, "PayDate", payDate.toString());
BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem();
//
if (onlyDue.isSelected())
sql += " AND i.DateInvoiced+p.NetDays <= ?";
//
KeyNamePair pp = (KeyNamePair)fieldBPartner.getSelectedItem();
int C_BPartner_ID = pp.getKey();
if (C_BPartner_ID != 0)
sql += " AND i.C_BPartner_ID=?";
sql += " ORDER BY 2,3";
// Get Open Invoices
try
{
int index = 1;
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setTimestamp(index++, payDate);
pstmt.setTimestamp(index++, payDate);
pstmt.setTimestamp(index++, payDate);
pstmt.setInt(index++, bi.C_Currency_ID);
pstmt.setTimestamp(index++, payDate);
pstmt.setInt(index++, m_AD_Client_ID);
if (onlyDue.isSelected())
pstmt.setTimestamp(index++, payDate);
if (C_BPartner_ID != 0)
pstmt.setInt(index++, C_BPartner_ID);
//
ResultSet rs = pstmt.executeQuery();
miniTable.loadTable(rs);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
Log.error ("VPaySelect.loadTableInfo", e);
}
calculateSelection();
} // loadTableInfo
/**
* Dispose
*/
public void dispose()
{
m_frame.dispose();
} // dispose
/*************************************************************************/
/**
* ActionListener
* @param e event
*/
public void actionPerformed (ActionEvent e)
{
// Update Bank Info
if (e.getSource() == fieldBankAccount)
loadBankInfo();
// Generate PaySelection
else if (e.getSource() == bGenerate)
{
cmd_generate();
dispose();
}
else if (e.getSource() == bCancel)
dispose();
// Update Open Invoices
else if (e.getSource() == fieldBPartner || e.getSource() == bRefresh)
loadTableInfo();
} // actionPerformed
/**
* Table Model Listener
* @param e event
*/
public void tableChanged(TableModelEvent e)
{
if (e.getColumn() == 0)
calculateSelection();
} // valueChanged
/**
* Calculate selected rows.
* - add up selected rows
*/
public void calculateSelection()
{
m_noSelected = 0;
BigDecimal invoiceAmt = new BigDecimal(0.0);
int rows = miniTable.getRowCount();
for (int i = 0; i < rows; i++)
{
IDColumn id = (IDColumn)miniTable.getModel().getValueAt(i, 0);
if (id.isSelected())
{
BigDecimal amt = (BigDecimal)miniTable.getModel().getValueAt(i, 9);
invoiceAmt = invoiceAmt.add(amt);
m_noSelected++;
}
}
// Information
BigDecimal remaining = m_bankBalance.subtract(invoiceAmt);
StringBuffer info = new StringBuffer();
info.append(m_noSelected).append(" ").append(Msg.getMsg(Env.getCtx(), "Selected")).append(" - ");
info.append(m_format.format(invoiceAmt)).append(", ");
info.append(Msg.getMsg(Env.getCtx(), "Remaining")).append(" ").append(m_format.format(remaining));
dataStatus.setText(info.toString());
//
bGenerate.setEnabled(m_noSelected != 0);
} // calculateSelection
/**
* Generate PaySelection
*/
private void cmd_generate()
{
Log.trace(Log.l1_User, "VPaySelect.cmd_generate");
miniTable.stopEditor(true);
if (miniTable.getRowCount() == 0)
return;
miniTable.setRowSelectionInterval(0,0);
calculateSelection();
if (m_noSelected == 0)
return;
String PaymentRule = ((ValueNamePair)fieldPaymentRule.getSelectedItem()).getValue();
// Create Header
int C_PaySelection_ID = DB.getKeyNextNo(Env.getCtx(), m_WindowNo, "C_PaySelection");
int AD_Org_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Org_ID"));
int AD_User_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_User_ID"));
Timestamp now = new Timestamp(System.currentTimeMillis());
String Name = Msg.getMsg(Env.getCtx(), "VPaySelect") + " - " + now.toString();
BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem();
int C_BankAccount_ID = bi.C_BankAccount_ID;
int C_Currency_ID = bi.C_Currency_ID;
String PayDate = DB.TO_DATE((Timestamp)fieldPayDate.getValue(), true);
StringBuffer sql = new StringBuffer("INSERT INTO C_PaySelection (");
sql.append("C_PaySelection_ID,AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, ")
.append("Name,Description, C_BankAccount_ID,PayDate, ")
.append("IsApproved,TotalAmt,Processing,CreateFrom,Processed");
sql.append(") VALUES (");
sql.append(C_PaySelection_ID).append(",").append(m_AD_Client_ID).append(",").append(AD_Org_ID)
.append(", 'Y',SysDate,").append(AD_User_ID).append(",SysDate,").append(AD_User_ID).append(", ")
.append("'").append(Name).append("',null, ")
.append(C_BankAccount_ID).append(",").append(PayDate).append(", 'Y',0,'N','N','N')");
// execute cmd
int no = DB.executeUpdate(sql.toString());
if (no != 1)
{
ValueNamePair pp = Log.retrieveError();
ADialog.error(m_WindowNo, this, pp.getValue(), pp.getName());
return;
}
else
Log.trace(Log.l4_Data, "PaySelect.cmd_generate", "PaySelection=" + Name);
// Create Lines
int rows = miniTable.getRowCount();
int line = 0;
for (int i = 0; i < rows; i++)
{
IDColumn id = (IDColumn)miniTable.getModel().getValueAt(i, 0);
if (id.isSelected())
{
int C_PaySelectionLine_ID = DB.getKeyNextNo(Env.getCtx(), m_WindowNo, "C_PaySelectionLine");
line += 10;
int C_Invoice_ID = id.getRecord_ID().intValue();
BigDecimal DiffAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 6);
BigDecimal PayAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 9);
//
sql = new StringBuffer("INSERT INTO C_PaySelectionLine (");
sql.append("C_PaySelectionLine_ID,C_PaySelection_ID, ")
.append("AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, ")
.append("Line,PaymentRule,IsManual, ")
.append("C_Invoice_ID,PayAmt,DifferenceAmt");
sql.append(") VALUES (");
sql.append(C_PaySelectionLine_ID).append(",").append(C_PaySelection_ID)
.append(",").append(m_AD_Client_ID).append(",").append(AD_Org_ID)
.append(", 'Y',SysDate,").append(AD_User_ID).append(",SysDate,").append(AD_User_ID).append(", ")
.append(line).append(",'").append(PaymentRule).append("','N', ")
.append(C_Invoice_ID).append(",").append(PayAmt).append(",").append(DiffAmt)
.append(")");
// execute cmd
no = DB.executeUpdate(sql.toString());
if (no != 1)
{
ValueNamePair pp = Log.retrieveError();
ADialog.error(m_WindowNo, this, pp.getValue(), pp.getName());
return;
}
else
Log.trace(Log.l6_Database, "PaySelect.cmd_generate", "C_Invoice_ID=" + C_Invoice_ID + ", PayAmt=" + PayAmt);
}
} // for all rows in table
// Ask to Post it
if (!ADialog.ask(m_WindowNo, this, "VPaySelectGenerate?", "(" + Name + ")"))
return;
// Run Process
ProcessInfo pi = new ProcessInfo (m_frame.getTitle(), 155, C_PaySelection_ID);
ProcessCtl.process(this, m_WindowNo, pi); // calls lockUI/..
} // cmd_generate
/**
* Lock User Interface
* Called from the Worker before processing
* @param pi process info
*/
public void lockUI (ProcessInfo pi)
{
this.setEnabled(false);
m_isLocked = true;
} // lockUI
/**
* Unlock User Interface.
* Called from the Worker when processing is done
* @param pi process info
*/
public void unlockUI (ProcessInfo pi)
{
// this.setEnabled(true);
// m_isLocked = false;
// Ask to Print it
if (!ADialog.ask(m_WindowNo, this, "VPaySelectPrint?", "(" + pi.Summary + ")"))
return;
// Start PayPrint
int AD_Form_ID = 106; // Payment Print/Export
FormFrame ff = new FormFrame();
ff.openForm (AD_Form_ID);
ff.pack();
this.setVisible(false);
AEnv.showCenterScreen(ff);
this.dispose();
} // unlockUI
/**
* Is the UI locked (Internal method)
* @return true, if UI is locked
*/
public boolean isUILocked()
{
return m_isLocked;
} // isLoacked
/**
* Method to be executed async.
* Called from the ASyncProcess worker
* @param pi process info
*/
public void executeASync (ProcessInfo pi)
{
Log.trace(Log.l3_Util, "VPaySelect.executeASync");
} // executeASync
/*************************************************************************/
/**
* Bank Account Info
*/
public class BankInfo
{
public BankInfo (int newC_BankAccount_ID, int newC_Currency_ID,
String newName, String newCurrency, BigDecimal newBalance, boolean newTransfers)
{
C_BankAccount_ID = newC_BankAccount_ID;
C_Currency_ID = newC_Currency_ID;
Name = newName;
Currency = newCurrency;
Balance = newBalance;
}
int C_BankAccount_ID;
int C_Currency_ID;
String Name;
String Currency;
BigDecimal Balance;
boolean Transfers;
public String toString()
{
return Name;
}
} // BankInfo
} // VPaySelect
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -