📄 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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.form;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.util.*;
import java.math.*;
import java.text.*;
import java.beans.*;
import java.sql.*;
import org.compiere.util.*;
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.minigrid.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
/**
* Allocation Form
*
* @author Jorg Janke
* @version $Id: VAllocation.java,v 1.20 2003/03/21 02:31:38 jjanke Exp $
*/
public class VAllocation extends CPanel
implements FormPanel, ActionListener, TableModelListener, VetoableChangeListener
{
/**
* Allocation Constructor
*/
public VAllocation()
{
} // VAllocation
/**
* 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.trace(Log.l1_User, "VAllocation.init - 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.error("VAllocation.init", e);
}
} // init
/** Window No */
private int m_WindowNo = 0;
/** FormFrame */
private FormFrame m_frame;
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 = new VLookup();
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 JTextField differenceField = new JTextField();
private JButton allocateButton = new JButton();
private JLabel currencyLabel = new JLabel();
private VLookup currencyPick = new VLookup();
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 autoCalc = new JCheckBox();
/**
* Static Init
* @throws Exception
*/
private void jbInit() throws Exception
{
CompiereColor.setBackground(this);
//
mainPanel.setLayout(mainLayout);
dateLabel.setText(Msg.getMsg(Env.getCtx(), "Date"));
autoCalc.setSelected(true);
autoCalc.setText(Msg.getMsg(Env.getCtx(), "AutoCalc"));
//
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(autoCalc, 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()
{
m_frame.dispose();
} // 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.create (Env.getCtx(), AD_Column_ID, m_WindowNo, DisplayType.TableDir, false);
currencyPick = new VLookup("C_Currency_ID", true, false, true, lookupCur, DisplayType.TableDir, m_WindowNo);
currencyPick.setValue(new Integer(m_C_Currency_ID));
currencyPick.addVetoableChangeListener(this);
// BPartner
AD_Column_ID = 3499; // C_Invoice.C_BPartner_ID
MLookup lookupBP = MLookupFactory.create (Env.getCtx(), AD_Column_ID, m_WindowNo, DisplayType.Search, false);
bpartnerSearch = new VLookup("C_BPartner_ID", true, false, true, lookupBP, DisplayType.Search, m_WindowNo);
bpartnerSearch.addVetoableChangeListener(this);
// Translation
statusBar.setStatusLine(Msg.getMsg(Env.getCtx(), "AllocateStatus"));
statusBar.setStatusDB("");
// Date set to today
dateField.setValue(new Timestamp(System.currentTimeMillis()));
dateField.addVetoableChangeListener(this);
} // dynInit
/**
* Load Business Partner Info
* - Payments
* - Invoices
*/
private void loadBPartner ()
{
Log.trace(Log.l3_Util, "VAllocation.loadBPartner - 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;
/********************************
* Load unallocated Payments
* 1-TrxDate, 2-DocumentNo, (3-Currency, 4-PayAmt,)
* 5-ConvAmt, 6-ConvOpen, 7-Allocated
*/
Vector data = new Vector();
StringBuffer sql = new StringBuffer("SELECT p.DateTrx,p.DocumentNo,p.C_Payment_ID," // 1..3
+ "c.ISO_Code,p.PayAmt," // 4..5
+ "C_Currency_Convert(p.PayAmt,p.C_Currency_ID,?,null,null,p.AD_Client_ID,p.AD_Org_ID),"// 6 #1
+ "C_Currency_Convert(C_Payment_Available(C_Payment_ID),p.C_Currency_ID,?,null,null,p.AD_Client_ID,p.AD_Org_ID)*p.MultiplierAP," // 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_BPartner_ID=?"); // #3
if (!multiCurrency.isSelected())
sql.append(" AND p.C_Currency_ID=?"); // #4
sql.append(" ORDER BY p.DateTrx,p.DocumentNo");
Log.trace(Log.l5_DData, "PaySQL=" + sql.toString());
try
{
PreparedStatement pstmt = DB.prepareStatement(sql.toString());
pstmt.setInt(1, m_C_Currency_ID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -