📄 vpayselect.java
字号:
+ " IN (SELECT PaymentRule FROM C_BankAccountDoc WHERE C_BankAccount_ID=?) "
+ info.Query.substring(info.Query.indexOf(" ORDER BY"));
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, bi.C_BankAccount_ID);
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.log(Level.SEVERE, sql, e);
}
fieldPaymentRule.setSelectedIndex(0);
} // loadBankInfo
/**
* Query and create TableInfo
*/
private void loadTableInfo()
{
log.config("");
// not yet initialized
if (m_sql == null)
return;
String sql = m_sql;
// Parameters
Timestamp payDate = (Timestamp)fieldPayDate.getValue();
miniTable.setColorCompare(payDate);
log.config("PayDate=" + payDate);
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";
//
log.finest(sql + " - C_Currecny_ID=" + bi.C_Currency_ID + ", C_BPartner_ID=" + C_BPartner_ID);
// Get Open Invoices
try
{
int index = 1;
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setTimestamp(index++, payDate); // DiscountAmt
pstmt.setInt(index++, bi.C_Currency_ID); // DueAmt
pstmt.setTimestamp(index++, payDate);
pstmt.setTimestamp(index++, payDate); // PayAmt
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.log(Level.SEVERE, sql, e);
}
calculateSelection();
} // loadTableInfo
/**
* Dispose
*/
public void dispose()
{
if (m_frame != null)
m_frame.dispose();
m_frame = null;
} // 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)
{
generatePaySelect();
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 generatePaySelect()
{
log.info("");
// String trxName Trx.createTrxName("PaySelect");
// Trx trx = Trx.get(trxName, true); trx needs to be committed too
String trxName = null;
Trx trx = null;
//
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
m_ps = new MPaySelection(Env.getCtx(), 0, trxName);
m_ps.setName (Msg.getMsg(Env.getCtx(), "VPaySelect") + " - " + fieldPayDate.getTimestamp());
m_ps.setPayDate (fieldPayDate.getTimestamp());
BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem();
m_ps.setC_BankAccount_ID(bi.C_BankAccount_ID);
m_ps.setIsApproved(true);
if (!m_ps.save())
{
ADialog.error(m_WindowNo, this, "SaveError", Msg.translate(Env.getCtx(), "C_PaySelection_ID"));
m_ps = null;
return;
}
log.config(m_ps.toString());
// 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())
{
line += 10;
MPaySelectionLine psl = new MPaySelectionLine (m_ps, line, PaymentRule);
int C_Invoice_ID = id.getRecord_ID().intValue();
BigDecimal OpenAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 8);
BigDecimal PayAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 9);
boolean isSOTrx = false;
//
psl.setInvoice(C_Invoice_ID, isSOTrx,
OpenAmt, PayAmt, OpenAmt.subtract(PayAmt));
if (!psl.save(trxName))
{
ADialog.error(m_WindowNo, this, "SaveError", Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID"));
return;
}
log.fine("C_Invoice_ID=" + C_Invoice_ID + ", PayAmt=" + PayAmt);
}
} // for all rows in table
// Ask to Post it
if (!ADialog.ask(m_WindowNo, this, "VPaySelectGenerate?", "(" + m_ps.getName() + ")"))
return;
// Prepare Process PaySelectionCreateCheck
ProcessInfo pi = new ProcessInfo (m_frame.getTitle(), 155,
MPaySelection.Table_ID, m_ps.getC_PaySelection_ID());
pi.setAD_User_ID (Env.getAD_User_ID(Env.getCtx()));
pi.setAD_Client_ID(Env.getAD_Client_ID(Env.getCtx()));
// Execute Process
ProcessCtl.process(this, m_WindowNo, pi, trx);
// ProcessCtl worker = new ProcessCtl(this, pi, trx);
// worker.start(); // complete tasks in unlockUI
} // generatePaySelect
/**
* 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 // Window is disposed
if (!ADialog.ask(0, this, "VPaySelectPrint?", "(" + pi.getSummary() + ")"))
return;
// Start PayPrint
int AD_Form_ID = 106; // Payment Print/Export
FormFrame ff = new FormFrame();
ff.openForm (AD_Form_ID);
// Set Parameter
if (m_ps != null)
{
VPayPrint pp = (VPayPrint)ff.getFormPanel();
pp.setPaySelection(m_ps.getC_PaySelection_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.config("-");
} // 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 + -