📄 vallocation.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.form;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.util.logging.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.minigrid.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.process.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Allocation Form
*
* @author Jorg Janke
* @version $Id: VAllocation.java,v 1.57 2006/02/12 02:18:26 jjanke Exp $
*/
public class VAllocation extends CPanel
implements FormPanel, ActionListener, TableModelListener, VetoableChangeListener
{
/**
* Initialize Panel
* @param WindowNo window
* @param frame frame
*/
public void init (int WindowNo, FormFrame frame)
{
m_WindowNo = WindowNo;
m_frame = frame;
Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", "Y"); // defaults to no
m_C_Currency_ID = Env.getContextAsInt(Env.getCtx(), "$C_Currency_ID"); // default
//
log.info("Currency=" + m_C_Currency_ID);
try
{
dynInit();
jbInit();
calculate();
frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
frame.getContentPane().add(statusBar, BorderLayout.SOUTH);
}
catch(Exception e)
{
log.log(Level.SEVERE, "", e);
}
} // init
/** Window No */
private int m_WindowNo = 0;
/** FormFrame */
private FormFrame m_frame;
/** Logger */
private static CLogger log = CLogger.getCLogger(VAllocation.class);
private boolean m_calculating = false;
private int m_C_Currency_ID = 0;
private int m_C_BPartner_ID = 0;
private int m_noInvoices = 0;
private int m_noPayments = 0;
// Index changed if multi-currency
private int i_payment = 7;
//
private int i_open = 6;
private int i_discount = 7;
private int i_writeOff = 8;
private int i_applied = 9;
// private int i_multiplier = 10;
//
private CPanel mainPanel = new CPanel();
private BorderLayout mainLayout = new BorderLayout();
private CPanel parameterPanel = new CPanel();
private CPanel allocationPanel = new CPanel();
private GridBagLayout parameterLayout = new GridBagLayout();
private JLabel bpartnerLabel = new JLabel();
private VLookup bpartnerSearch = null;
private MiniTable invoiceTable = new MiniTable();
private MiniTable paymentTable = new MiniTable();
private JSplitPane infoPanel = new JSplitPane();
private CPanel paymentPanel = new CPanel();
private CPanel invoicePanel = new CPanel();
private JLabel paymentLabel = new JLabel();
private JLabel invoiceLabel = new JLabel();
private BorderLayout paymentLayout = new BorderLayout();
private BorderLayout invoiceLayout = new BorderLayout();
private JLabel paymentInfo = new JLabel();
private JLabel invoiceInfo = new JLabel();
private JScrollPane paymentScrollPane = new JScrollPane();
private JScrollPane invoiceScrollPane = new JScrollPane();
private GridBagLayout allocationLayout = new GridBagLayout();
private JLabel differenceLabel = new JLabel();
private CTextField differenceField = new CTextField();
private JButton allocateButton = new JButton();
private JLabel currencyLabel = new JLabel();
private VLookup currencyPick = null;
private JCheckBox multiCurrency = new JCheckBox();
private JLabel allocCurrencyLabel = new JLabel();
private StatusBar statusBar = new StatusBar();
private JLabel dateLabel = new JLabel();
private VDate dateField = new VDate();
private JCheckBox autoWriteOff = new JCheckBox();
private ArrayList<Integer> m_bpartnerCheck = new ArrayList<Integer>();
/**
* Static Init
* @throws Exception
*/
private void jbInit() throws Exception
{
CompiereColor.setBackground(this);
//
mainPanel.setLayout(mainLayout);
dateLabel.setText(Msg.getMsg(Env.getCtx(), "Date"));
autoWriteOff.setSelected(false);
autoWriteOff.setText(Msg.getMsg(Env.getCtx(), "AutoWriteOff", true));
autoWriteOff.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoWriteOff", false));
//
parameterPanel.setLayout(parameterLayout);
allocationPanel.setLayout(allocationLayout);
bpartnerLabel.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
paymentLabel.setRequestFocusEnabled(false);
paymentLabel.setText(" " + Msg.translate(Env.getCtx(), "C_Payment_ID"));
invoiceLabel.setRequestFocusEnabled(false);
invoiceLabel.setText(" " + Msg.translate(Env.getCtx(), "C_Invoice_ID"));
paymentPanel.setLayout(paymentLayout);
invoicePanel.setLayout(invoiceLayout);
invoiceInfo.setHorizontalAlignment(SwingConstants.RIGHT);
invoiceInfo.setHorizontalTextPosition(SwingConstants.RIGHT);
invoiceInfo.setText(".");
paymentInfo.setHorizontalAlignment(SwingConstants.RIGHT);
paymentInfo.setHorizontalTextPosition(SwingConstants.RIGHT);
paymentInfo.setText(".");
differenceLabel.setText(Msg.getMsg(Env.getCtx(), "Difference"));
differenceField.setBackground(CompierePLAF.getFieldBackground_Inactive());
differenceField.setEditable(false);
differenceField.setText("0");
differenceField.setColumns(8);
differenceField.setHorizontalAlignment(SwingConstants.RIGHT);
allocateButton.setText(Msg.getMsg(Env.getCtx(), "Process"));
allocateButton.addActionListener(this);
currencyLabel.setText(Msg.translate(Env.getCtx(), "C_Currency_ID"));
multiCurrency.setText(Msg.getMsg(Env.getCtx(), "MultiCurrency"));
multiCurrency.addActionListener(this);
allocCurrencyLabel.setText(".");
invoiceScrollPane.setPreferredSize(new Dimension(200, 200));
paymentScrollPane.setPreferredSize(new Dimension(200, 200));
mainPanel.add(parameterPanel, BorderLayout.NORTH);
parameterPanel.add(bpartnerLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
parameterPanel.add(bpartnerSearch, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
parameterPanel.add(dateLabel, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
parameterPanel.add(dateField, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
parameterPanel.add(currencyLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
parameterPanel.add(currencyPick, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
parameterPanel.add(multiCurrency, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
mainPanel.add(allocationPanel, BorderLayout.SOUTH);
allocationPanel.add(differenceLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0));
allocationPanel.add(differenceField, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
allocationPanel.add(allocateButton, new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
allocationPanel.add(allocCurrencyLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
allocationPanel.add(autoWriteOff, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0
,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
paymentPanel.add(paymentLabel, BorderLayout.NORTH);
paymentPanel.add(paymentInfo, BorderLayout.SOUTH);
paymentPanel.add(paymentScrollPane, BorderLayout.CENTER);
paymentScrollPane.getViewport().add(paymentTable, null);
invoicePanel.add(invoiceLabel, BorderLayout.NORTH);
invoicePanel.add(invoiceInfo, BorderLayout.SOUTH);
invoicePanel.add(invoiceScrollPane, BorderLayout.CENTER);
invoiceScrollPane.getViewport().add(invoiceTable, null);
//
mainPanel.add(infoPanel, BorderLayout.CENTER);
infoPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
infoPanel.setBorder(BorderFactory.createEtchedBorder());
infoPanel.setTopComponent(paymentPanel);
infoPanel.setBottomComponent(invoicePanel);
infoPanel.add(paymentPanel, JSplitPane.TOP);
infoPanel.add(invoicePanel, JSplitPane.BOTTOM);
infoPanel.setContinuousLayout(true);
infoPanel.setPreferredSize(new Dimension(670,250));
infoPanel.setDividerLocation(110);
} // jbInit
/**
* Dispose
*/
public void dispose()
{
if (m_frame != null)
m_frame.dispose();
m_frame = null;
} // dispose
/**
* Dynamic Init (prepare dynamic fields)
* @throws Exception if Lookups cannot be initialized
*/
private void dynInit() throws Exception
{
// Currency
int AD_Column_ID = 3505; // C_Invoice.C_Currency_ID
MLookup lookupCur = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir);
currencyPick = new VLookup("C_Currency_ID", true, false, true, lookupCur);
currencyPick.setValue(new Integer(m_C_Currency_ID));
currencyPick.addVetoableChangeListener(this);
// BPartner
AD_Column_ID = 3499; // C_Invoice.C_BPartner_ID
MLookup lookupBP = MLookupFactory.get (Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.Search);
bpartnerSearch = new VLookup("C_BPartner_ID", true, false, true, lookupBP);
bpartnerSearch.addVetoableChangeListener(this);
// Translation
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "AllocateStatus"));
statusBar.setStatusDB("");
// Date set to Login Date
dateField.setValue(Env.getContextAsDate(Env.getCtx(), "#Date"));
dateField.addVetoableChangeListener(this);
} // dynInit
/**
* Load Business Partner Info
* - Payments
* - Invoices
*/
private void loadBPartner ()
{
log.config("BPartner=" + m_C_BPartner_ID + ", Cur=" + m_C_Currency_ID);
// Need to have both values
if (m_C_BPartner_ID == 0 || m_C_Currency_ID == 0)
return;
// Async BPartner Test
Integer key = new Integer(m_C_BPartner_ID);
if (!m_bpartnerCheck.contains(key))
{
new Thread()
{
public void run()
{
MPayment.setIsAllocated (Env.getCtx(), m_C_BPartner_ID, null);
MInvoice.setIsPaid (Env.getCtx(), m_C_BPartner_ID, null);
}
}.start();
m_bpartnerCheck.add(key);
}
/********************************
* Load unallocated Payments
* 1-TrxDate, 2-DocumentNo, (3-Currency, 4-PayAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-Allocated
*/
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
StringBuffer sql = new StringBuffer("SELECT p.DateTrx,p.DocumentNo,p.C_Payment_ID," // 1..3
+ "c.ISO_Code,p.PayAmt," // 4..5
+ "currencyConvert(p.PayAmt,p.C_Currency_ID,?,p.DateTrx,p.C_ConversionType_ID,p.AD_Client_ID,p.AD_Org_ID),"// 6 #1
+ "currencyConvert(paymentAvailable(C_Payment_ID),p.C_Currency_ID,?,p.DateTrx,p.C_ConversionType_ID,p.AD_Client_ID,p.AD_Org_ID)," // 7 #2
+ "p.MultiplierAP "
+ "FROM C_Payment_v p" // Corrected for AP/AR
+ " INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID) "
+ "WHERE p.IsAllocated='N' AND p.Processed='Y'"
+ " AND p.C_Charge_ID IS NULL" // Prepayments OK
+ " AND p.C_BPartner_ID=?"); // #3
if (!multiCurrency.isSelected())
sql.append(" AND p.C_Currency_ID=?"); // #4
sql.append(" ORDER BY p.DateTrx,p.DocumentNo");
log.fine("PaySQL=" + sql.toString());
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString(), null);
pstmt.setInt(1, m_C_Currency_ID);
pstmt.setInt(2, m_C_Currency_ID);
pstmt.setInt(3, m_C_BPartner_ID);
if (!multiCurrency.isSelected())
pstmt.setInt(4, m_C_Currency_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>();
line.add(new Boolean(false)); // 0-Selection
line.add(rs.getTimestamp(1)); // 1-TrxDate
KeyNamePair pp = new KeyNamePair(rs.getInt(3), rs.getString(2));
line.add(pp); // 2-DocumentNo
if (multiCurrency.isSelected())
{
line.add(rs.getString(4)); // 3-Currency
line.add(rs.getBigDecimal(5)); // 4-PayAmt
}
line.add(rs.getBigDecimal(6)); // 3/5-ConvAmt
BigDecimal available = rs.getBigDecimal(7);
if (available == null || available.signum() == 0) // nothing available
continue;
line.add(available); // 4/6-ConvOpen/Available
line.add(Env.ZERO); // 5/7-Payment
// line.add(rs.getBigDecimal(8)); // 6/8-Multiplier
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -