use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class Match method cmd_process.
// cmd_search
/**
* Process Button Pressed - Process Matching
*/
protected void cmd_process(IMiniTable xMatchedTable, IMiniTable xMatchedToTable, int matchMode, int matchFrom, Object matchTo, BigDecimal m_xMatched) {
log.config("");
// Matched From
int matchedRow = xMatchedTable.getSelectedRow();
if (matchedRow < 0)
return;
// KeyNamePair BPartner = (KeyNamePair)xMatchedTable.getValueAt(matchedRow, I_BPartner);
KeyNamePair lineMatched = (KeyNamePair) xMatchedTable.getValueAt(matchedRow, I_Line);
KeyNamePair Product = (KeyNamePair) xMatchedTable.getValueAt(matchedRow, I_Product);
double totalQty = m_xMatched.doubleValue();
// Matched To
for (int row = 0; row < xMatchedToTable.getRowCount(); row++) {
IDColumn id = (IDColumn) xMatchedToTable.getValueAt(row, 0);
if (id != null && id.isSelected()) {
// need to be the same product
KeyNamePair ProductCompare = (KeyNamePair) xMatchedToTable.getValueAt(row, I_Product);
if (Product.getKey() != ProductCompare.getKey())
continue;
KeyNamePair lineMatchedTo = (KeyNamePair) xMatchedToTable.getValueAt(row, I_Line);
// Qty
double qty = 0.0;
if (matchMode == MODE_NOTMATCHED)
// doc
qty = ((Double) xMatchedToTable.getValueAt(row, I_QTY)).doubleValue();
// matched
qty -= ((Double) xMatchedToTable.getValueAt(row, I_MATCHED)).doubleValue();
if (qty > totalQty)
qty = totalQty;
totalQty -= qty;
// Invoice or PO
boolean invoice = true;
if (matchFrom == MATCH_ORDER || matchTo.equals(m_matchOptions[MATCH_ORDER]))
invoice = false;
// Get Shipment_ID
int M_InOutLine_ID = 0;
int Line_ID = 0;
if (matchFrom == MATCH_SHIPMENT) {
// upper table
M_InOutLine_ID = lineMatched.getKey();
Line_ID = lineMatchedTo.getKey();
} else {
// lower table
M_InOutLine_ID = lineMatchedTo.getKey();
Line_ID = lineMatched.getKey();
}
// Create it
String innerTrxName = Trx.createTrxName("Match");
Trx innerTrx = Trx.get(innerTrxName, true);
if (createMatchRecord(invoice, M_InOutLine_ID, Line_ID, new BigDecimal(qty), innerTrxName))
innerTrx.commit();
else
innerTrx.rollback();
innerTrx.close();
innerTrx = null;
}
}
// requery
//cmd_search();
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class VCreateFromInvoiceUI method actionPerformed.
/**
* Action Listener
* @param e event
*/
public void actionPerformed(ActionEvent e) {
log.config("Action=" + e.getActionCommand());
if (m_actionActive)
return;
m_actionActive = true;
log.config("Action=" + e.getActionCommand());
// Order
if (e.getSource().equals(orderField)) {
KeyNamePair pp = (KeyNamePair) orderField.getSelectedItem();
int C_Order_ID = 0;
if (pp != null)
C_Order_ID = pp.getKey();
// set Invoice, RMA and Shipment to Null
rmaField.setSelectedIndex(-1);
shipmentField.setSelectedIndex(-1);
loadOrder(C_Order_ID, true);
} else // Shipment
if (e.getSource().equals(shipmentField)) {
KeyNamePair pp = (KeyNamePair) shipmentField.getSelectedItem();
int M_InOut_ID = 0;
if (pp != null)
M_InOut_ID = pp.getKey();
// set Order, RMA and Invoice to Null
orderField.setSelectedIndex(-1);
rmaField.setSelectedIndex(-1);
loadShipment(M_InOut_ID);
} else // RMA
if (e.getSource().equals(rmaField)) {
KeyNamePair pp = (KeyNamePair) rmaField.getSelectedItem();
int M_RMA_ID = 0;
if (pp != null)
M_RMA_ID = pp.getKey();
// set Order and Invoice to Null
orderField.setSelectedIndex(-1);
shipmentField.setSelectedIndex(-1);
loadRMA(M_RMA_ID);
}
m_actionActive = false;
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class WHRPayPrint method setPaySelection.
// dispose
/**
* Set Payment Selection
* @param HR_PaySelection_ID id
*/
public void setPaySelection(int HR_PaySelection_ID) {
if (HR_PaySelection_ID == 0)
return;
//
for (int i = 0; i < fPaySelect.getItemCount(); i++) {
KeyNamePair pp = fPaySelect.getItemAtIndex(i).toKeyNamePair();
if (pp.getKey() == HR_PaySelection_ID) {
fPaySelect.setSelectedIndex(i);
loadPaySelectInfo();
return;
}
}
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class ProductCategoryListTag method getCategories.
// doEndTag
/**
* Get Product Category Options.
* @param AD_Client_ID client
* @return array of category options
*/
private option[] getCategories(int AD_Client_ID) {
option[] options = (option[]) s_categories.get(new Integer(AD_Client_ID));
if (options != null)
return options;
String sql = "SELECT M_Product_Category_ID, Name " + "FROM M_Product_Category " + "WHERE AD_Client_ID=" + AD_Client_ID + " AND IsActive='Y' AND IsSelfService='Y' " + "ORDER BY Name";
KeyNamePair[] pairs = DB.getKeyNamePairs(sql, true);
options = new option[pairs.length];
//
for (int i = 0; i < pairs.length; i++) {
if (i == 0) {
options[i] = new option("-1");
options[i].addElement(" ");
} else {
options[i] = new option(pairs[i].getID());
options[i].addElement(Util.maskHTML(pairs[i].getName()));
}
}
//
s_categories.put(new Integer(AD_Client_ID), options);
return options;
}
use of org.compiere.util.KeyNamePair in project adempiere by adempiere.
the class WPayment method dynInit.
// jbInit
/**************************************************************************
* Dynamic Init.
* B (Cash) (Currency)
* K (CreditCard) Type, Number, Exp, Approval
* L (DirectDebit) BPartner_Bank
* P (PaymentTerm) PaymentTerm
* S (Check) (Currency) CheckNo, Routing
*
* Currencies are shown, if member of EMU
* @param button payment type button
* @return true if init OK
* @throws Exception
*/
private boolean dynInit(WButtonEditor button) throws Exception {
m_DocStatus = (String) m_mTab.getValue("DocStatus");
log.config(m_DocStatus);
if (m_mTab.getValue("C_BPartner_ID") == null) {
FDialog.error(0, this, "SaveErrorRowNotFound");
return false;
}
// Is the Trx posted?
// String Posted = (String)m_mTab.getValue("Posted");
// if (Posted != null && Posted.equals("Y"))
// return false;
// DocStatus
m_DocStatus = (String) m_mTab.getValue("DocStatus");
if (m_DocStatus == null)
m_DocStatus = "";
// Is the Trx closed? Reversed / Voided / Cloased
if (m_DocStatus.equals("RE") || m_DocStatus.equals("VO") || m_DocStatus.equals("CL"))
return false;
// Document is not complete - allow to change the Payment Rule only
if (m_DocStatus.equals("CO") || m_DocStatus.equals("WP"))
m_onlyRule = false;
else
m_onlyRule = true;
// PO only Rule
if (// Only order has Warehouse
!m_onlyRule && !m_isSOTrx && m_mTab.getValue("M_Warehouse_ID") != null)
m_onlyRule = true;
centerPanel.setVisible(!m_onlyRule);
// Amount
m_Amount = (BigDecimal) m_mTab.getValue("GrandTotal");
if (!m_onlyRule && m_Amount.compareTo(Env.ZERO) == 0) {
FDialog.error(m_WindowNo, this, "PaymentZero");
return false;
}
bAmountField.setValue(m_Amount);
sAmountField.setValue(m_Amount);
kAmountField.setValue(m_Amount);
/**
* Get Data from Grid
*/
m_AD_Client_ID = ((Integer) m_mTab.getValue("AD_Client_ID")).intValue();
m_Cash_As_Payment = MSysConfig.getBooleanValue("CASH_AS_PAYMENT", true, m_AD_Client_ID);
m_AD_Org_ID = ((Integer) m_mTab.getValue("AD_Org_ID")).intValue();
m_C_BPartner_ID = ((Integer) m_mTab.getValue("C_BPartner_ID")).intValue();
m_PaymentRule = (String) m_mTab.getValue("PaymentRule");
m_C_Currency_ID = ((Integer) m_mTab.getValue("C_Currency_ID")).intValue();
m_DateAcct = (Timestamp) m_mTab.getValue("DateAcct");
if (m_mTab.getValue("C_PaymentTerm_ID") != null)
m_C_PaymentTerm_ID = ((Integer) m_mTab.getValue("C_PaymentTerm_ID")).intValue();
// Existing Payment
if (m_mTab.getValue("C_Payment_ID") != null) {
m_C_Payment_ID = ((Integer) m_mTab.getValue("C_Payment_ID")).intValue();
if (m_C_Payment_ID != 0) {
m_mPayment = new MPayment(Env.getCtx(), m_C_Payment_ID, null);
// full copy
m_mPaymentOriginal = new MPayment(Env.getCtx(), m_C_Payment_ID, null);
// CreditCard
m_CCType = m_mPayment.getCreditCardType();
kNumberField.setText(m_mPayment.getCreditCardNumber());
kExpField.setText(m_mPayment.getCreditCardExp(null));
kApprovalField.setText(m_mPayment.getVoiceAuthCode());
kStatus.setText(m_mPayment.getR_PnRef());
kAmountField.setValue(m_mPayment.getPayAmt());
// if approved/paid, don't let it change
kTypeCombo.setEnabled(!m_mPayment.isApproved());
kNumberField.setReadonly(m_mPayment.isApproved());
kExpField.setReadonly(m_mPayment.isApproved());
kApprovalField.setReadonly(m_mPayment.isApproved());
kOnline.setEnabled(!m_mPayment.isApproved());
kAmountField.setReadWrite(!m_mPayment.isApproved());
// Check
m_C_BankAccount_ID = m_mPayment.getC_BankAccount_ID();
sRoutingField.setText(m_mPayment.getRoutingNo());
sNumberField.setText(m_mPayment.getAccountNo());
sCheckField.setText(m_mPayment.getCheckNo());
sStatus.setText(m_mPayment.getR_PnRef());
sAmountField.setValue(m_mPayment.getPayAmt());
// Transfer
tRoutingField.setText(m_mPayment.getRoutingNo());
tNumberField.setText(m_mPayment.getAccountNo());
tStatus.setText(m_mPayment.getR_PnRef());
// Cash
bAmountField.setValue(m_mPayment.getPayAmt());
}
}
if (m_mPayment == null) {
m_mPayment = new MPayment(Env.getCtx(), 0, null);
m_mPayment.setAD_Org_ID(m_AD_Org_ID);
m_mPayment.setAmount(m_C_Currency_ID, m_Amount);
}
// Existing Cashbook entry
m_cashLine = null;
m_C_CashLine_ID = 0;
if (m_mTab.getValue("C_CashLine_ID") != null) {
m_C_CashLine_ID = ((Integer) m_mTab.getValue("C_CashLine_ID")).intValue();
if (m_C_CashLine_ID == 0)
m_cashLine = null;
else {
m_cashLine = new MCashLine(Env.getCtx(), m_C_CashLine_ID, null);
m_DateAcct = m_cashLine.getStatementDate();
m_C_CashBook_ID = m_cashLine.getCashBook().getC_CashBook_ID();
bAmountField.setValue(m_cashLine.getAmount());
}
}
// Accounting Date
bDateField.setValue(m_DateAcct);
if (s_Currencies == null)
loadCurrencies();
// Is the currency an EMU currency?
Integer C_Currency_ID = new Integer(m_C_Currency_ID);
if (s_Currencies.containsKey(C_Currency_ID)) {
Enumeration<Integer> en = s_Currencies.keys();
while (en.hasMoreElements()) {
Object key = en.nextElement();
bCurrencyCombo.addItem(s_Currencies.get(key));
sCurrencyCombo.addItem(s_Currencies.get(key));
}
sCurrencyCombo.addActionListener(this);
sCurrencyCombo.setSelectedKeyNamePair(s_Currencies.get(C_Currency_ID));
bCurrencyCombo.addActionListener(this);
bCurrencyCombo.setSelectedKeyNamePair(s_Currencies.get(C_Currency_ID));
} else // No EMU Currency
{
// Cash
bCurrencyLabel.setVisible(false);
bCurrencyCombo.setVisible(false);
// Check
sCurrencyLabel.setVisible(false);
sCurrencyCombo.setVisible(false);
}
/**
* Payment Combo
*/
if (m_PaymentRule == null)
m_PaymentRule = "";
ValueNamePair vp = null;
HashMap<String, String> values = button.getValues();
Object[] a = values.keySet().toArray();
for (int i = 0; i < a.length; i++) {
// used for Panel selection
String PaymentRule = (String) a[i];
if (// SO
X_C_Order.PAYMENTRULE_DirectDebit.equals(PaymentRule) && !m_isSOTrx)
continue;
else if (// PO
X_C_Order.PAYMENTRULE_DirectDeposit.equals(PaymentRule) && m_isSOTrx)
continue;
ValueNamePair pp = new ValueNamePair(PaymentRule, (String) values.get(a[i]));
paymentCombo.addItem(pp);
if (// to select
PaymentRule.toString().equals(m_PaymentRule))
vp = pp;
}
// Set PaymentRule
paymentCombo.addActionListener(this);
if (vp != null) {
paymentCombo.setSelectedValueNamePair(vp);
onPaymentComboSelection();
}
/**
* Load Payment Terms
*/
String SQL = MRole.getDefault().addAccessSQL("SELECT C_PaymentTerm_ID, Name FROM C_PaymentTerm WHERE IsActive='Y' ORDER BY Name", "C_PaymentTerm", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
KeyNamePair kp = null;
try {
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
int key = rs.getInt(1);
String name = rs.getString(2);
KeyNamePair pp = new KeyNamePair(key, name);
pTermCombo.addItem(pp);
if (key == m_C_PaymentTerm_ID)
kp = pp;
}
rs.close();
pstmt.close();
} catch (SQLException ept) {
log.log(Level.SEVERE, SQL, ept);
}
// Set Selection
if (kp != null)
pTermCombo.setSelectedKeyNamePair(kp);
/**
* Load Accounts
*/
SQL = "SELECT a.C_BP_BankAccount_ID, NVL(b.Name, ' ')||'_'||NVL(a.AccountNo, ' ') AS Acct " + "FROM C_BP_BankAccount a" + " LEFT OUTER JOIN C_Bank b ON (a.C_Bank_ID=b.C_Bank_ID) " + "WHERE C_BPartner_ID=?" + "AND a.IsActive='Y' AND a.IsACH='Y'";
try {
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, m_C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
int key = rs.getInt(1);
String name = rs.getString(2);
KeyNamePair pp = new KeyNamePair(key, name);
tAccountCombo.addItem(pp);
}
rs.close();
pstmt.close();
} catch (SQLException eac) {
log.log(Level.SEVERE, SQL, eac);
}
/**
* Load Credit Cards
*/
ValueNamePair[] ccs = m_mPayment.getCreditCards();
vp = null;
for (int i = 0; i < ccs.length; i++) {
kTypeCombo.addItem(ccs[i]);
if (ccs[i].getValue().equals(m_CCType))
vp = ccs[i];
}
// Set Selection
if (vp != null)
kTypeCombo.setSelectedValueNamePair(vp);
/**
* Load Bank Accounts
*/
SQL = MRole.getDefault().addAccessSQL("SELECT C_BankAccount_ID, Name || ' ' || AccountNo, IsDefault " + "FROM C_BankAccount ba" + " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID) " + "WHERE b.IsActive='Y'", "ba", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
kp = null;
try {
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
int key = rs.getInt(1);
String name = rs.getString(2);
KeyNamePair pp = new KeyNamePair(key, name);
sBankAccountCombo.addItem(pp);
bBankAccountCombo.addItem(pp);
if (key == m_C_BankAccount_ID)
kp = pp;
if (// Default
kp == null && rs.getString(3).equals("Y"))
kp = pp;
}
rs.close();
pstmt.close();
} catch (SQLException ept) {
log.log(Level.SEVERE, SQL, ept);
}
// Set Selection
if (kp != null) {
sBankAccountCombo.setSelectedKeyNamePair(kp);
bBankAccountCombo.setSelectedKeyNamePair(kp);
}
/**
* Load Cash Books
*/
SQL = MRole.getDefault().addAccessSQL("SELECT C_CashBook_ID, Name, AD_Org_ID FROM C_CashBook WHERE IsActive='Y'", "C_CashBook", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
kp = null;
try {
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
int key = rs.getInt(1);
String name = rs.getString(2);
KeyNamePair pp = new KeyNamePair(key, name);
bCashBookCombo.addItem(pp);
if (key == m_C_CashBook_ID)
kp = pp;
if (// Default Org
kp == null && key == m_AD_Org_ID)
kp = pp;
}
rs.close();
pstmt.close();
} catch (SQLException epc) {
log.log(Level.SEVERE, SQL, epc);
}
// Set Selection
if (kp != null) {
bCashBookCombo.setSelectedKeyNamePair(kp);
if (m_C_CashBook_ID == 0)
// set to default to avoid 'cashbook changed' message
m_C_CashBook_ID = kp.getKey();
}
//
return true;
}
Aggregations