use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class WPayment method checkMandatory.
// saveChanges
/**
* Check Mandatory
* @return true if all mandatory items are OK
*/
private boolean checkMandatory() {
log.config("VPayment.checkMandatory");
ValueNamePair vp = paymentCombo.getSelectedItem().toValueNamePair();
String PaymentRule = vp.getValue();
// only Payment Rule
if (m_onlyRule)
return true;
//
int C_BankAccount_ID = 0;
/***********************
* Mandatory Data Check
*/
boolean dataOK = true;
// B (Cash) (Currency)
if (PaymentRule.equals(MOrder.PAYMENTRULE_Cash)) {
if (m_Cash_As_Payment) {
ListItem selected = bBankAccountCombo.getSelectedItem();
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
if (kp != null)
C_BankAccount_ID = kp.getKey();
}
} else // K (CreditCard) Type, Number, Exp, Approval
if (PaymentRule.equals(MOrder.PAYMENTRULE_CreditCard)) {
// Validation of the credit card number is moved to the payment processor.
// Different payment processors can have different validation rules.
} else // T (Transfer) BPartner_Bank
if (PaymentRule.equals(X_C_Order.PAYMENTRULE_DirectDeposit) || PaymentRule.equals(X_C_Order.PAYMENTRULE_DirectDebit)) {
ListItem selected = tAccountCombo.getSelectedItem();
KeyNamePair bpba = selected != null ? selected.toKeyNamePair() : null;
if (bpba == null) {
FDialog.error(m_WindowNo, this, "PaymentBPBankNotFound");
dataOK = false;
}
} else // P (PaymentTerm) PaymentTerm
if (PaymentRule.equals(X_C_Order.PAYMENTRULE_OnCredit)) {
// ok
} else // S (Check) (Currency) CheckNo, Routing
if (PaymentRule.equals(MOrder.PAYMENTRULE_Check)) {
ListItem selected = sBankAccountCombo.getSelectedItem();
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
if (kp != null)
C_BankAccount_ID = kp.getKey();
String error = MPaymentValidate.validateRoutingNo(sRoutingField.getText());
if (error.length() != 0) {
FDialog.error(m_WindowNo, this, error);
dataOK = false;
}
error = MPaymentValidate.validateAccountNo(sNumberField.getText());
if (error.length() != 0) {
FDialog.error(m_WindowNo, this, error);
dataOK = false;
}
error = MPaymentValidate.validateCheckNo(sCheckField.getText());
if (error.length() != 0) {
FDialog.error(m_WindowNo, this, error);
dataOK = false;
}
} else {
log.log(Level.SEVERE, "Unknown PaymentRule " + PaymentRule);
return false;
}
// find Bank Account if not qualified yet
if (("KTSD".indexOf(PaymentRule) != -1 || (PaymentRule.equals(MOrder.PAYMENTRULE_Cash) && m_Cash_As_Payment)) && C_BankAccount_ID == 0) {
// Check & Cash (Payment) must have a bank account
if (C_BankAccount_ID == 0 && (PaymentRule.equals(MOrder.PAYMENTRULE_Check)) || (PaymentRule.equals(MOrder.PAYMENTRULE_Cash) && m_Cash_As_Payment)) {
FDialog.error(m_WindowNo, this, "FillMandatory", bBankAccountLabel.getValue());
dataOK = false;
}
}
//
log.config("OK=" + dataOK);
return dataOK;
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class WPayment method saveChangesInTrx.
// saveChanges
/**************************************************************************
* Save Changes
* @return true, if eindow can exit
*/
private boolean saveChangesInTrx(final String trxName) {
// set trxname for class objects
if (m_cashLine != null)
m_cashLine.set_TrxName(trxName);
if (m_mPayment != null)
m_mPayment.set_TrxName(trxName);
if (m_mPaymentOriginal != null)
m_mPaymentOriginal.set_TrxName(trxName);
ValueNamePair vp = paymentCombo.getSelectedItem().toValueNamePair();
String newPaymentRule = vp.getValue();
log.info("New Rule: " + newPaymentRule);
// only Payment Rule
if (m_onlyRule) {
if (!newPaymentRule.equals(m_PaymentRule))
m_mTab.setValue("PaymentRule", newPaymentRule);
return true;
}
// New Values
Timestamp newDateAcct = m_DateAcct;
int newC_PaymentTerm_ID = m_C_PaymentTerm_ID;
int newC_CashLine_ID = m_C_CashLine_ID;
int newC_CashBook_ID = m_C_CashBook_ID;
String newCCType = m_CCType;
int newC_BankAccount_ID = 0;
String payTypes = m_Cash_As_Payment ? "KTSDB" : "KTSD";
// B (Cash) (Currency)
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_Cash)) {
if (m_Cash_As_Payment) {
// get bank account
ListItem selected = bBankAccountCombo.getSelectedItem();
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
if (kp != null)
newC_BankAccount_ID = kp.getKey();
} else {
// get cash book
ListItem selected = bCashBookCombo.getSelectedItem();
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
if (kp != null)
newC_CashBook_ID = kp.getKey();
}
newDateAcct = (Timestamp) bDateField.getValue();
// Get changes to cash amount
m_mPayment.setAmount(m_C_Currency_ID, (BigDecimal) bAmountField.getValue());
m_Amount = (BigDecimal) bAmountField.getValue();
} else // K (CreditCard) Type, Number, Exp, Approval
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_CreditCard)) {
ListItem selected = kTypeCombo.getSelectedItem();
vp = selected != null ? selected.toValueNamePair() : null;
if (vp != null)
newCCType = vp.getValue();
} else // T (Transfer) BPartner_Bank
if (newPaymentRule.equals(MOrder.PAYMENTRULE_DirectDeposit) || newPaymentRule.equals(MOrder.PAYMENTRULE_DirectDebit)) {
tAccountCombo.getSelectedItem();
} else // P (PaymentTerm) PaymentTerm
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_OnCredit)) {
ListItem selected = pTermCombo.getSelectedItem();
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
if (kp != null)
newC_PaymentTerm_ID = kp.getKey();
} else // S (Check) (Currency) CheckNo, Routing
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_Check)) {
ListItem selected = sBankAccountCombo.getSelectedItem();
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
if (kp != null)
newC_BankAccount_ID = kp.getKey();
} else
return false;
/***********************
* Changed PaymentRule
*/
if (!newPaymentRule.equals(m_PaymentRule)) {
log.fine("Changed PaymentRule: " + m_PaymentRule + " -> " + newPaymentRule);
// We had a CashBook Entry
if (m_PaymentRule.equals(X_C_Order.PAYMENTRULE_Cash)) {
log.fine("Old Cash - " + m_cashLine);
if (m_cashLine != null) {
MCashLine cl = m_cashLine.createReversal();
if (cl.save())
log.config("CashCancelled");
else
FDialog.error(m_WindowNo, this, "PaymentError", "CashNotCancelled");
}
// reset
newC_CashLine_ID = 0;
} else // We had a change in Payment type (e.g. Check to CC)
if (payTypes.indexOf(m_PaymentRule) != -1 && payTypes.indexOf(newPaymentRule) != -1 && m_mPaymentOriginal != null) {
log.fine("Old Payment(1) - " + m_mPaymentOriginal);
m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct);
boolean ok = m_mPaymentOriginal.processIt(DocAction.ACTION_Reverse_Correct);
m_mPaymentOriginal.saveEx();
if (ok)
log.info("Payment Canecelled - " + m_mPaymentOriginal);
else
FDialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCancelled " + m_mPaymentOriginal.getDocumentNo());
m_mPayment.resetNew();
} else // We had a Payment and something else (e.g. Check to Cash)
if (payTypes.indexOf(m_PaymentRule) != -1 && payTypes.indexOf(newPaymentRule) == -1) {
log.fine("Old Payment(2) - " + m_mPaymentOriginal);
if (m_mPaymentOriginal != null) {
m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct);
boolean ok = m_mPaymentOriginal.processIt(DocAction.ACTION_Reverse_Correct);
m_mPaymentOriginal.saveEx();
if (// Cancel Payment
ok) {
log.fine("PaymentCancelled " + m_mPayment.getDocumentNo());
m_mTab.getTableModel().dataSave(true);
m_mPayment.resetNew();
m_mPayment.setAmount(m_C_Currency_ID, m_Amount);
} else
FDialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCancelled " + m_mPayment.getDocumentNo());
}
}
}
// Get Order and optionally Invoice
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Order_ID");
int C_Invoice_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Invoice_ID");
if (C_Invoice_ID == 0 && m_DocStatus.equals("CO"))
C_Invoice_ID = getInvoiceID(C_Order_ID);
// Amount sign negative, if ARC (Credit Memo) or API (AP Invoice)
boolean negateAmt = false;
MInvoice invoice = null;
if (C_Invoice_ID != 0) {
invoice = new MInvoice(Env.getCtx(), C_Invoice_ID, null);
negateAmt = invoice.isCreditMemo();
}
MOrder order = null;
if (invoice == null && C_Order_ID != 0)
order = new MOrder(Env.getCtx(), C_Order_ID, null);
BigDecimal payAmount = m_Amount;
if (negateAmt)
payAmount = m_Amount.negate();
// Info
log.config("C_Order_ID=" + C_Order_ID + ", C_Invoice_ID=" + C_Invoice_ID + ", NegateAmt=" + negateAmt);
/***********************
* CashBook
*/
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_Cash) && !m_Cash_As_Payment) {
log.fine("Cash");
if (C_Invoice_ID == 0 && order == null) {
log.config("No Invoice!");
FDialog.error(m_WindowNo, this, "PaymentError", "CashNotCreated");
} else {
payAmount = (BigDecimal) bAmountField.getValue();
// Changed Amount
if (m_cashLine != null && payAmount.compareTo(m_cashLine.getAmount()) != 0) {
log.config("Changed CashBook Amount");
m_cashLine.setAmount((BigDecimal) bAmountField.getValue());
m_cashLine.saveEx();
}
// Different Date/CashBook
if (m_cashLine != null && (newC_CashBook_ID != m_C_CashBook_ID || !TimeUtil.isSameDay(m_cashLine.getStatementDate(), newDateAcct))) {
log.config("Changed CashBook/Date: " + m_C_CashBook_ID + "->" + newC_CashBook_ID);
MCashLine reverse = m_cashLine.createReversal();
reverse.saveEx();
m_cashLine = null;
}
// Create new
if (m_cashLine == null) {
log.config("New CashBook");
int C_Currency_ID = 0;
if (invoice != null)
C_Currency_ID = invoice.getC_Currency_ID();
if (C_Currency_ID == 0 && order != null)
C_Currency_ID = order.getC_Currency_ID();
MCash cash = null;
if (newC_CashBook_ID != 0)
cash = MCash.get(Env.getCtx(), newC_CashBook_ID, newDateAcct, null);
else
// Default
cash = MCash.get(Env.getCtx(), m_AD_Org_ID, newDateAcct, C_Currency_ID, null);
if (cash == null || cash.get_ID() == 0)
FDialog.error(m_WindowNo, this, "PaymentError", CLogger.retrieveErrorString("CashNotCreated"));
else {
MCashLine cl = new MCashLine(cash);
//ADialog.info(m_WindowNo, this, "m_cashLine - New Cashbook", "Amount: "+cl.getAmount());
if (invoice != null)
// overrides amount
cl.setInvoice(invoice);
if (order != null) {
// overrides amount
cl.setOrder(order, null);
m_needSave = true;
}
cl.setAmount((BigDecimal) bAmountField.getValue());
cl.saveEx();
log.config("CashCreated");
if (invoice == null && C_Invoice_ID != 0) {
invoice = new MInvoice(Env.getCtx(), C_Invoice_ID, null);
}
if (invoice != null) {
invoice.setC_CashLine_ID(cl.getC_CashLine_ID());
invoice.saveEx(trxName);
}
if (order == null && C_Order_ID != 0) {
order = new MOrder(Env.getCtx(), C_Order_ID, null);
}
if (order != null) {
order.setC_CashLine_ID(cl.getC_CashLine_ID());
order.saveEx(trxName);
}
log.config("Update Order & Invoice with CashLine");
}
}
}
// have invoice
}
/***********************
* Payments
*/
if (("KS".indexOf(newPaymentRule) != -1) || (newPaymentRule.equals(MOrder.PAYMENTRULE_Cash) && m_Cash_As_Payment)) {
log.fine("Payment - " + newPaymentRule);
// Set Amount
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
if (newPaymentRule.equals(MOrder.PAYMENTRULE_CreditCard)) {
m_mPayment.setCreditCard(MPayment.TRXTYPE_Sales, newCCType, kNumberField.getText(), "", kExpField.getText());
// Get changes to credit card amount
m_mPayment.setAmount(m_C_Currency_ID, (BigDecimal) kAmountField.getValue());
m_mPayment.setPaymentProcessor();
} else if (newPaymentRule.equals(MOrder.PAYMENTRULE_DirectDeposit) || newPaymentRule.equals(MOrder.PAYMENTRULE_DirectDebit)) {
m_mPayment.setBankACH(newC_BankAccount_ID, m_isSOTrx, newPaymentRule, tRoutingField.getText(), tNumberField.getText());
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
} else if (newPaymentRule.equals(MOrder.PAYMENTRULE_Check)) {
m_mPayment.setBankCheck(newC_BankAccount_ID, m_isSOTrx, sRoutingField.getText(), sNumberField.getText(), sCheckField.getText());
// Get changes to check amount
m_mPayment.setAmount(m_C_Currency_ID, (BigDecimal) sAmountField.getValue());
} else if (newPaymentRule.equals(MOrder.PAYMENTRULE_Cash)) {
// Get changes to cash amount
m_mPayment.setTenderType(MPayment.TENDERTYPE_Cash);
m_mPayment.setBankCash(newC_BankAccount_ID, m_isSOTrx, MPayment.TENDERTYPE_Cash);
m_mPayment.setAmount(m_C_Currency_ID, payAmount);
}
m_mPayment.setC_BPartner_ID(m_C_BPartner_ID);
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
if (order != null) {
m_mPayment.setC_Order_ID(C_Order_ID);
m_needSave = true;
}
m_mPayment.setDateTrx(m_DateAcct);
m_mPayment.setDateAcct(m_DateAcct);
m_mPayment.saveEx();
// Save/Post
if (m_mPayment.get_ID() > 0 && MPayment.DOCSTATUS_Drafted.equals(m_mPayment.getDocStatus())) {
boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete);
m_mPayment.saveEx();
if (ok)
FDialog.info(m_WindowNo, this, "PaymentCreated", m_mPayment.getDocumentNo());
else
FDialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated");
} else
log.fine("NotDraft " + m_mPayment);
}
/**********************
* Save Values to mTab
*/
log.config("Saving changes");
//
if (!newPaymentRule.equals(m_PaymentRule))
m_mTab.setValue("PaymentRule", newPaymentRule);
//
if (!newDateAcct.equals(m_DateAcct))
m_mTab.setValue("DateAcct", newDateAcct);
//
if (newC_PaymentTerm_ID != m_C_PaymentTerm_ID)
m_mTab.setValue("C_PaymentTerm_ID", new Integer(newC_PaymentTerm_ID));
// Set Payment
if (m_mPayment.getC_Payment_ID() != m_C_Payment_ID) {
if (m_mPayment.getC_Payment_ID() == 0)
m_mTab.setValue("C_Payment_ID", null);
else
m_mTab.setValue("C_Payment_ID", new Integer(m_mPayment.getC_Payment_ID()));
}
// Set Cash
if (newC_CashLine_ID != m_C_CashLine_ID) {
if (newC_CashLine_ID == 0)
m_mTab.setValue("C_CashLine_ID", null);
else
m_mTab.setValue("C_CashLine_ID", new Integer(newC_CashLine_ID));
}
return true;
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class WPayment method onPaymentComboSelection.
private void onPaymentComboSelection() {
// get selection
ListItem selectedItem = paymentCombo.getSelectedItem();
ValueNamePair pp = selectedItem != null ? selectedItem.toValueNamePair() : null;
if (pp != null) {
String s = pp.getValue().toLowerCase();
if (X_C_Order.PAYMENTRULE_DirectDebit.equalsIgnoreCase(s))
s = X_C_Order.PAYMENTRULE_DirectDeposit.toLowerCase();
s += "Panel";
// switch to panel
show(s);
//Bojana&Daniel
//If Invoice is Vendor invoice then Cash has to be created by negative amount
int C_Invoice_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Invoice_ID");
MInvoice invoice_tmp = new MInvoice(Env.getCtx(), C_Invoice_ID, null);
if (!invoice_tmp.isSOTrx()) {
bAmountField.setValue(m_Amount.negate());
} else {
bAmountField.setValue(m_Amount);
}
invoice_tmp = null;
}
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class WFileImport method cmd_loadFormat.
// cmd_loadFile
/**
* Load Format
*/
private void cmd_loadFormat() {
// clear panel
previewPanel.getChildren().clear();
ListItem listitem = pickFormat.getSelectedItem();
String formatName = (String) listitem.getValue();
if (formatName.equals(s_none))
return;
m_format = ImpFormat.load(formatName);
if (m_format == null) {
FDialog.error(m_WindowNo, this, formatName);
return;
}
// pointers
int size = m_format.getRowCount();
m_labels = new Label[size];
m_fields = new Textbox[size];
for (int i = 0; i < size; i++) {
ImpFormatRow row = m_format.getRow(i);
m_labels[i] = new Label(row.getColumnName());
Hbox hbox = new Hbox();
hbox.setWidth("100%");
hbox.setWidths("30%, 70%");
hbox.setStyle("padding-bottom: 3px");
hbox.appendChild(m_labels[i].rightAlign());
int length = row.getEndNo() - row.getStartNo();
if (length <= 5)
length = 5;
else if (length > 20)
length = 20;
m_fields[i] = new Textbox();
m_fields[i].setStyle("margin-left: 2px");
hbox.appendChild(m_fields[i]);
previewPanel.appendChild(hbox);
}
m_record = -1;
record.setValue("------");
previewPanel.invalidate();
}
use of org.adempiere.webui.component.ListItem in project adempiere by adempiere.
the class FindWindow method setValues.
// createFields
/**
* sets the list of values of column and operator listboxes
* @param listColumn column
* @param listOperator operator
**/
private void setValues(Listbox listColumn, Listbox listOperator, String[] fields) {
// 0 = Columns
ArrayList<ValueNamePair> items = new ArrayList<ValueNamePair>();
for (int c = 0; c < m_findFields.length; c++) {
GridField field = m_findFields[c];
String columnName = field.getColumnName();
String header = field.getHeader();
if (header == null || header.length() == 0) {
header = Msg.translate(Env.getCtx(), columnName);
if (header == null || header.length() == 0)
continue;
}
if (field.isKey())
header += (" (ID)");
ValueNamePair pp = new ValueNamePair(columnName, header);
items.add(pp);
}
ValueNamePair[] cols = new ValueNamePair[items.size()];
items.toArray(cols);
// sort alpha
Arrays.sort(cols);
ValueNamePair[] op = MQuery.OPERATORS;
if (fields == null) {
listColumn.appendItem("", "");
for (ValueNamePair item : cols) listColumn.appendItem(item.getName(), item.getValue());
listColumn.setSelectedIndex(0);
for (ValueNamePair item : op) listOperator.appendItem(item.getName(), item.getValue());
listOperator.setSelectedIndex(0);
} else {
// 0 - column
String columnName = fields.length > 0 ? fields[0] : "";
// 1 - operator
String operator = fields.length > 1 ? fields[1] : "";
boolean selected = false;
listColumn.appendItem("", "");
for (int i = 0; i < cols.length; i++) {
ValueNamePair item = cols[i];
ListItem li = listColumn.appendItem(item.getName(), item.getValue());
if (item.getValue().equals(columnName)) {
listColumn.setSelectedItem(li);
selected = true;
}
}
if (!selected)
listColumn.setSelectedIndex(0);
selected = false;
for (int i = 0; i < op.length; i++) {
ValueNamePair item = op[i];
ListItem li = listOperator.appendItem(item.getName(), item.getValue());
if (item.getValue().equals(operator)) {
listOperator.setSelectedItem(li);
selected = true;
}
}
if (!selected)
listOperator.setSelectedIndex(0);
}
}
Aggregations