apply changes from VPayment and some cleanup
This commit is contained in:
parent
3b06eb7a0a
commit
9d7e263183
|
@ -21,7 +21,6 @@ import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -56,15 +55,17 @@ import org.compiere.model.MOrder;
|
||||||
import org.compiere.model.MPayment;
|
import org.compiere.model.MPayment;
|
||||||
import org.compiere.model.MPaymentValidate;
|
import org.compiere.model.MPaymentValidate;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.X_C_Order;
|
import org.compiere.model.X_C_Order;
|
||||||
import org.compiere.process.DocAction;
|
import org.compiere.process.DocAction;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.DisplayType;
|
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.KeyNamePair;
|
import org.compiere.util.KeyNamePair;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
import org.compiere.util.TimeUtil;
|
import org.compiere.util.TimeUtil;
|
||||||
|
import org.compiere.util.Trx;
|
||||||
|
import org.compiere.util.TrxRunnable;
|
||||||
import org.compiere.util.ValueNamePair;
|
import org.compiere.util.ValueNamePair;
|
||||||
import org.zkoss.zk.ui.event.Event;
|
import org.zkoss.zk.ui.event.Event;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
|
@ -178,6 +179,7 @@ public class WPayment extends Window
|
||||||
/** Invoice Currency */
|
/** Invoice Currency */
|
||||||
private int m_C_Currency_ID = 0;
|
private int m_C_Currency_ID = 0;
|
||||||
private int m_AD_Client_ID = 0;
|
private int m_AD_Client_ID = 0;
|
||||||
|
private boolean m_Cash_As_Payment = true;
|
||||||
private int m_AD_Org_ID = 0;
|
private int m_AD_Org_ID = 0;
|
||||||
private int m_C_BPartner_ID = 0;
|
private int m_C_BPartner_ID = 0;
|
||||||
private BigDecimal m_Amount = Env.ZERO; // Payment Amount
|
private BigDecimal m_Amount = Env.ZERO; // Payment Amount
|
||||||
|
@ -185,7 +187,6 @@ public class WPayment extends Window
|
||||||
private boolean m_initOK = false;
|
private boolean m_initOK = false;
|
||||||
/** Only allow changing Rule */
|
/** Only allow changing Rule */
|
||||||
private boolean m_onlyRule = false;
|
private boolean m_onlyRule = false;
|
||||||
private DecimalFormat m_Format = DisplayType.getNumberFormat(DisplayType.Amount);
|
|
||||||
private static Hashtable<Integer,KeyNamePair> s_Currencies = null; // EMU Currencies
|
private static Hashtable<Integer,KeyNamePair> s_Currencies = null; // EMU Currencies
|
||||||
|
|
||||||
private boolean m_needSave = false;
|
private boolean m_needSave = false;
|
||||||
|
@ -197,7 +198,6 @@ public class WPayment extends Window
|
||||||
private Borderlayout mainLayout = new Borderlayout();
|
private Borderlayout mainLayout = new Borderlayout();
|
||||||
private Panel northPanel = new Panel();
|
private Panel northPanel = new Panel();
|
||||||
private Panel centerPanel = new Panel();
|
private Panel centerPanel = new Panel();
|
||||||
// private FlowLayout northLayout = new FlowLayout();
|
|
||||||
private Listbox paymentCombo = ListboxFactory.newDropdownListbox();
|
private Listbox paymentCombo = ListboxFactory.newDropdownListbox();
|
||||||
private Label paymentLabel = new Label();
|
private Label paymentLabel = new Label();
|
||||||
private List<Panel> centerLayout = new ArrayList<Panel>();
|
private List<Panel> centerLayout = new ArrayList<Panel>();
|
||||||
|
@ -244,6 +244,8 @@ public class WPayment extends Window
|
||||||
private Button sOnline = new Button();
|
private Button sOnline = new Button();
|
||||||
private Listbox sBankAccountCombo = ListboxFactory.newDropdownListbox();
|
private Listbox sBankAccountCombo = ListboxFactory.newDropdownListbox();
|
||||||
private Label sBankAccountLabel = new Label();
|
private Label sBankAccountLabel = new Label();
|
||||||
|
private Listbox bBankAccountCombo = ListboxFactory.newDropdownListbox();
|
||||||
|
private Label bBankAccountLabel = new Label();
|
||||||
private Grid pPanelLayout = GridFactory.newGridLayout();
|
private Grid pPanelLayout = GridFactory.newGridLayout();
|
||||||
private Label bCashBookLabel = new Label();
|
private Label bCashBookLabel = new Label();
|
||||||
private Listbox bCashBookCombo = ListboxFactory.newDropdownListbox();
|
private Listbox bCashBookCombo = ListboxFactory.newDropdownListbox();
|
||||||
|
@ -272,7 +274,6 @@ public class WPayment extends Window
|
||||||
mainLayout.appendChild(center);
|
mainLayout.appendChild(center);
|
||||||
center.appendChild(centerPanel);
|
center.appendChild(centerPanel);
|
||||||
//
|
//
|
||||||
// northPanel.setLayout(northLayout);
|
|
||||||
paymentLabel.setText(Msg.translate(Env.getCtx(), "PaymentRule"));
|
paymentLabel.setText(Msg.translate(Env.getCtx(), "PaymentRule"));
|
||||||
North north = new North();
|
North north = new North();
|
||||||
north.setStyle("border: none");
|
north.setStyle("border: none");
|
||||||
|
@ -285,11 +286,8 @@ public class WPayment extends Window
|
||||||
// CreditCard
|
// CreditCard
|
||||||
kPanel.appendChild(kLayout);
|
kPanel.appendChild(kLayout);
|
||||||
kNumberField.setWidth("160pt");
|
kNumberField.setWidth("160pt");
|
||||||
// kNumberField.setHeight("21em");
|
|
||||||
kExpField.setWidth("40pt");
|
kExpField.setWidth("40pt");
|
||||||
// kExpField.setHeight("21em");
|
|
||||||
kApprovalField.setWidth("120pt");
|
kApprovalField.setWidth("120pt");
|
||||||
// kApprovalField.setHeight("21em");
|
|
||||||
kTypeLabel.setText(Msg.translate(Env.getCtx(), "CreditCardType"));
|
kTypeLabel.setText(Msg.translate(Env.getCtx(), "CreditCardType"));
|
||||||
kNumberLabel.setText(Msg.translate(Env.getCtx(), "CreditCardNumber"));
|
kNumberLabel.setText(Msg.translate(Env.getCtx(), "CreditCardNumber"));
|
||||||
kExpLabel.setText(Msg.getMsg(Env.getCtx(), "Expires"));
|
kExpLabel.setText(Msg.getMsg(Env.getCtx(), "Expires"));
|
||||||
|
@ -381,16 +379,13 @@ public class WPayment extends Window
|
||||||
sPanel.appendChild(sPanelLayout);
|
sPanel.appendChild(sPanelLayout);
|
||||||
sBankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
|
sBankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
|
||||||
sAmountLabel.setText(Msg.getMsg(Env.getCtx(), "Amount"));
|
sAmountLabel.setText(Msg.getMsg(Env.getCtx(), "Amount"));
|
||||||
//sAmountField.setText("");
|
|
||||||
sRoutingLabel.setText(Msg.translate(Env.getCtx(), "RoutingNo"));
|
sRoutingLabel.setText(Msg.translate(Env.getCtx(), "RoutingNo"));
|
||||||
sNumberLabel.setText(Msg.translate(Env.getCtx(), "AccountNo"));
|
sNumberLabel.setText(Msg.translate(Env.getCtx(), "AccountNo"));
|
||||||
sCheckLabel.setText(Msg.translate(Env.getCtx(), "CheckNo"));
|
sCheckLabel.setText(Msg.translate(Env.getCtx(), "CheckNo"));
|
||||||
sCheckField.setCols(8);
|
sCheckField.setCols(8);
|
||||||
sCurrencyLabel.setText(Msg.translate(Env.getCtx(), "C_Currency_ID"));
|
sCurrencyLabel.setText(Msg.translate(Env.getCtx(), "C_Currency_ID"));
|
||||||
sNumberField.setWidth("100pt");
|
sNumberField.setWidth("100pt");
|
||||||
// sNumberField.setHeight("100em");
|
|
||||||
sRoutingField.setWidth("70pt");
|
sRoutingField.setWidth("70pt");
|
||||||
// sRoutingField.setHeight("21em");
|
|
||||||
sStatus.setText(" ");
|
sStatus.setText(" ");
|
||||||
sOnline.setLabel(Msg.getMsg(Env.getCtx(), "Online"));
|
sOnline.setLabel(Msg.getMsg(Env.getCtx(), "Online"));
|
||||||
LayoutUtils.addSclass("action-text-button", sOnline);
|
LayoutUtils.addSclass("action-text-button", sOnline);
|
||||||
|
@ -464,8 +459,14 @@ public class WPayment extends Window
|
||||||
|
|
||||||
rows = bPanelLayout.newRows();
|
rows = bPanelLayout.newRows();
|
||||||
row = rows.newRow();
|
row = rows.newRow();
|
||||||
row.appendChild(bCashBookLabel.rightAlign());
|
if (m_Cash_As_Payment) {
|
||||||
row.appendChild(bCashBookCombo);
|
bBankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
|
||||||
|
row.appendChild(bBankAccountLabel.rightAlign());
|
||||||
|
row.appendChild(bBankAccountCombo);
|
||||||
|
} else {
|
||||||
|
row.appendChild(bCashBookLabel.rightAlign());
|
||||||
|
row.appendChild(bCashBookCombo);
|
||||||
|
}
|
||||||
|
|
||||||
row = rows.newRow();
|
row = rows.newRow();
|
||||||
row.appendChild(bCurrencyLabel.rightAlign());
|
row.appendChild(bCurrencyLabel.rightAlign());
|
||||||
|
@ -554,6 +555,7 @@ public class WPayment extends Window
|
||||||
* Get Data from Grid
|
* Get Data from Grid
|
||||||
*/
|
*/
|
||||||
m_AD_Client_ID = ((Integer)m_mTab.getValue("AD_Client_ID")).intValue();
|
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_AD_Org_ID = ((Integer)m_mTab.getValue("AD_Org_ID")).intValue();
|
||||||
m_C_BPartner_ID = ((Integer)m_mTab.getValue("C_BPartner_ID")).intValue();
|
m_C_BPartner_ID = ((Integer)m_mTab.getValue("C_BPartner_ID")).intValue();
|
||||||
m_PaymentRule = (String)m_mTab.getValue("PaymentRule");
|
m_PaymentRule = (String)m_mTab.getValue("PaymentRule");
|
||||||
|
@ -595,6 +597,8 @@ public class WPayment extends Window
|
||||||
tRoutingField.setText(m_mPayment.getRoutingNo());
|
tRoutingField.setText(m_mPayment.getRoutingNo());
|
||||||
tNumberField.setText(m_mPayment.getAccountNo());
|
tNumberField.setText(m_mPayment.getAccountNo());
|
||||||
tStatus.setText(m_mPayment.getR_PnRef());
|
tStatus.setText(m_mPayment.getR_PnRef());
|
||||||
|
// Cash
|
||||||
|
bAmountField.setValue(m_mPayment.getPayAmt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_mPayment == null)
|
if (m_mPayment == null)
|
||||||
|
@ -719,7 +723,6 @@ public class WPayment extends Window
|
||||||
SQL = "SELECT a.C_BP_BankAccount_ID, NVL(b.Name, ' ')||a.AccountNo AS Acct "
|
SQL = "SELECT a.C_BP_BankAccount_ID, NVL(b.Name, ' ')||a.AccountNo AS Acct "
|
||||||
+ "FROM C_BP_BankAccount a,C_Bank b "
|
+ "FROM C_BP_BankAccount a,C_Bank b "
|
||||||
+ "WHERE C_BPartner_ID=? AND a.IsActive='Y'";
|
+ "WHERE C_BPartner_ID=? AND a.IsActive='Y'";
|
||||||
kp = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
|
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
|
||||||
|
@ -731,7 +734,6 @@ public class WPayment extends Window
|
||||||
String name = rs.getString(2);
|
String name = rs.getString(2);
|
||||||
KeyNamePair pp = new KeyNamePair(key, name);
|
KeyNamePair pp = new KeyNamePair(key, name);
|
||||||
tAccountCombo.addItem(pp);
|
tAccountCombo.addItem(pp);
|
||||||
// kp = pp;
|
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
|
@ -740,9 +742,6 @@ public class WPayment extends Window
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, SQL, eac);
|
log.log(Level.SEVERE, SQL, eac);
|
||||||
}
|
}
|
||||||
// Set Selection
|
|
||||||
if (kp != null)
|
|
||||||
tAccountCombo.setSelectedKeyNamePair(kp);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Credit Cards
|
* Load Credit Cards
|
||||||
|
@ -779,6 +778,7 @@ public class WPayment extends Window
|
||||||
String name = rs.getString(2);
|
String name = rs.getString(2);
|
||||||
KeyNamePair pp = new KeyNamePair(key, name);
|
KeyNamePair pp = new KeyNamePair(key, name);
|
||||||
sBankAccountCombo.addItem(pp);
|
sBankAccountCombo.addItem(pp);
|
||||||
|
bBankAccountCombo.addItem(pp);
|
||||||
if (key == m_C_BankAccount_ID)
|
if (key == m_C_BankAccount_ID)
|
||||||
kp = pp;
|
kp = pp;
|
||||||
if (kp == null && rs.getString(3).equals("Y")) // Default
|
if (kp == null && rs.getString(3).equals("Y")) // Default
|
||||||
|
@ -793,7 +793,10 @@ public class WPayment extends Window
|
||||||
}
|
}
|
||||||
// Set Selection
|
// Set Selection
|
||||||
if (kp != null)
|
if (kp != null)
|
||||||
|
{
|
||||||
sBankAccountCombo.setSelectedKeyNamePair(kp);
|
sBankAccountCombo.setSelectedKeyNamePair(kp);
|
||||||
|
bBankAccountCombo.setSelectedKeyNamePair(kp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -966,13 +969,49 @@ public class WPayment extends Window
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
* Save Changes
|
||||||
|
* @return true, if Window can exit
|
||||||
|
*/
|
||||||
|
private boolean saveChanges() {
|
||||||
|
|
||||||
|
// BF [ 1920179 ] perform the save in a trx's context.
|
||||||
|
final boolean[] success = new boolean[] { false };
|
||||||
|
final TrxRunnable r = new TrxRunnable() {
|
||||||
|
|
||||||
|
public void run(String trxName) {
|
||||||
|
success[0] = saveChangesInTrx(trxName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
Trx.run(r);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
success[0] = false;
|
||||||
|
FDialog.error(m_WindowNo, this, "PaymentError", e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
if (m_cashLine != null)
|
||||||
|
m_cashLine.set_TrxName(null);
|
||||||
|
if (m_mPayment != null)
|
||||||
|
m_mPayment.set_TrxName(null);
|
||||||
|
if (m_mPaymentOriginal != null)
|
||||||
|
m_mPayment.set_TrxName(null);
|
||||||
|
return success[0];
|
||||||
|
} // saveChanges
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Save Changes
|
* Save Changes
|
||||||
* @return true, if eindow can exit
|
* @return true, if eindow can exit
|
||||||
*/
|
*/
|
||||||
private boolean saveChanges()
|
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();
|
ValueNamePair vp = paymentCombo.getSelectedItem().toValueNamePair();
|
||||||
String newPaymentRule = vp.getValue();
|
String newPaymentRule = vp.getValue();
|
||||||
log.info("New Rule: " + newPaymentRule);
|
log.info("New Rule: " + newPaymentRule);
|
||||||
|
@ -992,14 +1031,25 @@ public class WPayment extends Window
|
||||||
int newC_CashBook_ID = m_C_CashBook_ID;
|
int newC_CashBook_ID = m_C_CashBook_ID;
|
||||||
String newCCType = m_CCType;
|
String newCCType = m_CCType;
|
||||||
int newC_BankAccount_ID = 0;
|
int newC_BankAccount_ID = 0;
|
||||||
|
String payTypes = m_Cash_As_Payment ? "KTSDB" : "KTSD";
|
||||||
|
|
||||||
// B (Cash) (Currency)
|
// B (Cash) (Currency)
|
||||||
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_Cash))
|
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_Cash))
|
||||||
{
|
{
|
||||||
ListItem selected = bCashBookCombo.getSelectedItem();
|
if (m_Cash_As_Payment){
|
||||||
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
|
// get bank account
|
||||||
if (kp != null)
|
ListItem selected = bBankAccountCombo.getSelectedItem();
|
||||||
newC_CashBook_ID = kp.getKey();
|
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();
|
newDateAcct = (Timestamp)bDateField.getValue();
|
||||||
|
|
||||||
// Get changes to cash amount
|
// Get changes to cash amount
|
||||||
|
@ -1043,18 +1093,6 @@ public class WPayment extends Window
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// find Bank Account if not qualified yet
|
|
||||||
if ("KTSD".indexOf(newPaymentRule) != -1 && newC_BankAccount_ID == 0)
|
|
||||||
{
|
|
||||||
String tender = MPayment.TENDERTYPE_CreditCard;
|
|
||||||
if (newPaymentRule.equals(MOrder.PAYMENTRULE_DirectDeposit))
|
|
||||||
tender = MPayment.TENDERTYPE_DirectDeposit;
|
|
||||||
else if (newPaymentRule.equals(MOrder.PAYMENTRULE_DirectDebit))
|
|
||||||
tender = MPayment.TENDERTYPE_DirectDebit;
|
|
||||||
else if (newPaymentRule.equals(MOrder.PAYMENTRULE_Check))
|
|
||||||
tender = MPayment.TENDERTYPE_Check;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***********************
|
/***********************
|
||||||
* Changed PaymentRule
|
* Changed PaymentRule
|
||||||
*/
|
*/
|
||||||
|
@ -1076,7 +1114,7 @@ public class WPayment extends Window
|
||||||
newC_CashLine_ID = 0; // reset
|
newC_CashLine_ID = 0; // reset
|
||||||
}
|
}
|
||||||
// We had a change in Payment type (e.g. Check to CC)
|
// We had a change in Payment type (e.g. Check to CC)
|
||||||
else if ("KTSD".indexOf(m_PaymentRule) != -1 && "KTSD".indexOf(newPaymentRule) != -1 && m_mPaymentOriginal != null)
|
else if (payTypes.indexOf(m_PaymentRule) != -1 && payTypes.indexOf(newPaymentRule) != -1 && m_mPaymentOriginal != null)
|
||||||
{
|
{
|
||||||
log.fine("Old Payment(1) - " + m_mPaymentOriginal);
|
log.fine("Old Payment(1) - " + m_mPaymentOriginal);
|
||||||
m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct);
|
m_mPaymentOriginal.setDocAction(DocAction.ACTION_Reverse_Correct);
|
||||||
|
@ -1089,7 +1127,7 @@ public class WPayment extends Window
|
||||||
m_mPayment.resetNew();
|
m_mPayment.resetNew();
|
||||||
}
|
}
|
||||||
// We had a Payment and something else (e.g. Check to Cash)
|
// We had a Payment and something else (e.g. Check to Cash)
|
||||||
else if ("KTSD".indexOf(m_PaymentRule) != -1 && "KTSD".indexOf(newPaymentRule) == -1)
|
else if (payTypes.indexOf(m_PaymentRule) != -1 && payTypes.indexOf(newPaymentRule) == -1)
|
||||||
{
|
{
|
||||||
log.fine("Old Payment(2) - " + m_mPaymentOriginal);
|
log.fine("Old Payment(2) - " + m_mPaymentOriginal);
|
||||||
if (m_mPaymentOriginal != null)
|
if (m_mPaymentOriginal != null)
|
||||||
|
@ -1139,10 +1177,9 @@ public class WPayment extends Window
|
||||||
/***********************
|
/***********************
|
||||||
* CashBook
|
* CashBook
|
||||||
*/
|
*/
|
||||||
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_Cash))
|
if (newPaymentRule.equals(X_C_Order.PAYMENTRULE_Cash) && !m_Cash_As_Payment)
|
||||||
{
|
{
|
||||||
log.fine("Cash");
|
log.fine("Cash");
|
||||||
String description = (String)m_mTab.getValue("DocumentNo");
|
|
||||||
|
|
||||||
if (C_Invoice_ID == 0 && order == null)
|
if (C_Invoice_ID == 0 && order == null)
|
||||||
{
|
{
|
||||||
|
@ -1157,11 +1194,8 @@ public class WPayment extends Window
|
||||||
&& payAmount.compareTo(m_cashLine.getAmount()) != 0)
|
&& payAmount.compareTo(m_cashLine.getAmount()) != 0)
|
||||||
{
|
{
|
||||||
log.config("Changed CashBook Amount");
|
log.config("Changed CashBook Amount");
|
||||||
//m_cashLine.setAmount(payAmount);
|
|
||||||
m_cashLine.setAmount((BigDecimal) bAmountField.getValue());
|
m_cashLine.setAmount((BigDecimal) bAmountField.getValue());
|
||||||
// ADialog.info(m_WindowNo, this, "m_cashLine - Changed Amount", "Amount: "+m_cashLine.getAmount());
|
m_cashLine.saveEx();
|
||||||
if (m_cashLine.save())
|
|
||||||
log.config("CashAmt Changed");
|
|
||||||
}
|
}
|
||||||
// Different Date/CashBook
|
// Different Date/CashBook
|
||||||
if (m_cashLine != null
|
if (m_cashLine != null
|
||||||
|
@ -1170,8 +1204,7 @@ public class WPayment extends Window
|
||||||
{
|
{
|
||||||
log.config("Changed CashBook/Date: " + m_C_CashBook_ID + "->" + newC_CashBook_ID);
|
log.config("Changed CashBook/Date: " + m_C_CashBook_ID + "->" + newC_CashBook_ID);
|
||||||
MCashLine reverse = m_cashLine.createReversal();
|
MCashLine reverse = m_cashLine.createReversal();
|
||||||
if (!reverse.save())
|
reverse.saveEx();
|
||||||
FDialog.error(m_WindowNo, this, "PaymentError", "CashNotCancelled");
|
|
||||||
m_cashLine = null;
|
m_cashLine = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1204,29 +1237,25 @@ public class WPayment extends Window
|
||||||
m_needSave = true;
|
m_needSave = true;
|
||||||
}
|
}
|
||||||
cl.setAmount((BigDecimal)bAmountField.getValue());
|
cl.setAmount((BigDecimal)bAmountField.getValue());
|
||||||
if (cl.save())
|
cl.saveEx();
|
||||||
|
log.config("CashCreated");
|
||||||
|
if (invoice == null && C_Invoice_ID != 0)
|
||||||
{
|
{
|
||||||
log.config("CashCreated");
|
invoice = new MInvoice (Env.getCtx(), C_Invoice_ID, null);
|
||||||
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.save();
|
|
||||||
}
|
|
||||||
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.save();
|
|
||||||
}
|
|
||||||
log.config("Update Order & Invoice with CashLine");
|
|
||||||
}
|
}
|
||||||
else
|
if (invoice != null) {
|
||||||
FDialog.error(m_WindowNo, this, "PaymentError", "CashNotCreated");
|
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
|
} // have invoice
|
||||||
|
@ -1234,7 +1263,8 @@ public class WPayment extends Window
|
||||||
/***********************
|
/***********************
|
||||||
* Payments
|
* Payments
|
||||||
*/
|
*/
|
||||||
if ("KS".indexOf(newPaymentRule) != -1)
|
if (("KS".indexOf(newPaymentRule) != -1) ||
|
||||||
|
(newPaymentRule.equals(MOrder.PAYMENTRULE_Cash) && m_Cash_As_Payment))
|
||||||
{
|
{
|
||||||
log.fine("Payment - " + newPaymentRule);
|
log.fine("Payment - " + newPaymentRule);
|
||||||
// Set Amount
|
// Set Amount
|
||||||
|
@ -1261,6 +1291,13 @@ public class WPayment extends Window
|
||||||
// Get changes to check amount
|
// Get changes to check amount
|
||||||
m_mPayment.setAmount(m_C_Currency_ID, (BigDecimal) sAmountField.getValue());
|
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_BPartner_ID(m_C_BPartner_ID);
|
||||||
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
|
m_mPayment.setC_Invoice_ID(C_Invoice_ID);
|
||||||
if (order != null)
|
if (order != null)
|
||||||
|
@ -1270,14 +1307,13 @@ public class WPayment extends Window
|
||||||
}
|
}
|
||||||
m_mPayment.setDateTrx(m_DateAcct);
|
m_mPayment.setDateTrx(m_DateAcct);
|
||||||
m_mPayment.setDateAcct(m_DateAcct);
|
m_mPayment.setDateAcct(m_DateAcct);
|
||||||
if (!m_mPayment.save())
|
m_mPayment.saveEx();
|
||||||
FDialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated");
|
|
||||||
|
|
||||||
// Save/Post
|
// Save/Post
|
||||||
if (m_mPayment.get_ID() > 0 && MPayment.DOCSTATUS_Drafted.equals(m_mPayment.getDocStatus()))
|
if (m_mPayment.get_ID() > 0 && MPayment.DOCSTATUS_Drafted.equals(m_mPayment.getDocStatus()))
|
||||||
{
|
{
|
||||||
boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete);
|
boolean ok = m_mPayment.processIt(DocAction.ACTION_Complete);
|
||||||
m_mPayment.save();
|
m_mPayment.saveEx();
|
||||||
if (ok)
|
if (ok)
|
||||||
FDialog.info(m_WindowNo, this, "PaymentCreated", m_mPayment.getDocumentNo());
|
FDialog.info(m_WindowNo, this, "PaymentCreated", m_mPayment.getDocumentNo());
|
||||||
else
|
else
|
||||||
|
@ -1334,10 +1370,6 @@ public class WPayment extends Window
|
||||||
if (m_onlyRule)
|
if (m_onlyRule)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
Timestamp DateAcct = m_DateAcct;
|
|
||||||
int C_PaymentTerm_ID = m_C_PaymentTerm_ID;
|
|
||||||
int C_CashBook_ID = m_C_CashBook_ID;
|
|
||||||
String CCType = m_CCType;
|
|
||||||
//
|
//
|
||||||
int C_BankAccount_ID = 0;
|
int C_BankAccount_ID = 0;
|
||||||
|
|
||||||
|
@ -1348,41 +1380,20 @@ public class WPayment extends Window
|
||||||
// B (Cash) (Currency)
|
// B (Cash) (Currency)
|
||||||
if (PaymentRule.equals(MOrder.PAYMENTRULE_Cash))
|
if (PaymentRule.equals(MOrder.PAYMENTRULE_Cash))
|
||||||
{
|
{
|
||||||
ListItem selected = bCashBookCombo.getSelectedItem();
|
if (m_Cash_As_Payment)
|
||||||
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
|
{
|
||||||
if (kp != null)
|
ListItem selected = bBankAccountCombo.getSelectedItem();
|
||||||
C_CashBook_ID = kp.getKey();
|
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
|
||||||
DateAcct = (Timestamp)bDateField.getValue();
|
if (kp != null)
|
||||||
|
C_BankAccount_ID = kp.getKey();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// K (CreditCard) Type, Number, Exp, Approval
|
// K (CreditCard) Type, Number, Exp, Approval
|
||||||
else if (PaymentRule.equals(MOrder.PAYMENTRULE_CreditCard))
|
else if (PaymentRule.equals(MOrder.PAYMENTRULE_CreditCard))
|
||||||
{
|
{
|
||||||
ListItem selected = kTypeCombo.getSelectedItem();
|
// Validation of the credit card number is moved to the payment processor.
|
||||||
vp = selected != null ? selected.toValueNamePair() : null;
|
// Different payment processors can have different validation rules.
|
||||||
if (vp != null)
|
|
||||||
CCType = vp.getValue();
|
|
||||||
//
|
|
||||||
String error = MPaymentValidate.validateCreditCardNumber(kNumberField.getText(), CCType);
|
|
||||||
if (error.length() != 0)
|
|
||||||
{
|
|
||||||
if (error.indexOf('?') == -1)
|
|
||||||
{
|
|
||||||
FDialog.error(m_WindowNo, this, error);
|
|
||||||
dataOK = false;
|
|
||||||
}
|
|
||||||
else // warning
|
|
||||||
{
|
|
||||||
if (!FDialog.ask(m_WindowNo, this, error))
|
|
||||||
dataOK = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
error = MPaymentValidate.validateCreditCardExp(kExpField.getText());
|
|
||||||
if(error.length() != 0)
|
|
||||||
{
|
|
||||||
FDialog.error(m_WindowNo, this, error);
|
|
||||||
dataOK = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// T (Transfer) BPartner_Bank
|
// T (Transfer) BPartner_Bank
|
||||||
|
@ -1402,10 +1413,7 @@ public class WPayment extends Window
|
||||||
// P (PaymentTerm) PaymentTerm
|
// P (PaymentTerm) PaymentTerm
|
||||||
else if (PaymentRule.equals(X_C_Order.PAYMENTRULE_OnCredit))
|
else if (PaymentRule.equals(X_C_Order.PAYMENTRULE_OnCredit))
|
||||||
{
|
{
|
||||||
ListItem selected = pTermCombo.getSelectedItem();
|
// ok
|
||||||
KeyNamePair kp = selected != null ? selected.toKeyNamePair() : null;
|
|
||||||
if (kp != null)
|
|
||||||
C_PaymentTerm_ID = kp.getKey();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// S (Check) (Currency) CheckNo, Routing
|
// S (Check) (Currency) CheckNo, Routing
|
||||||
|
@ -1441,19 +1449,15 @@ public class WPayment extends Window
|
||||||
}
|
}
|
||||||
|
|
||||||
// find Bank Account if not qualified yet
|
// find Bank Account if not qualified yet
|
||||||
if ("KTSD".indexOf(PaymentRule) != -1 && C_BankAccount_ID == 0)
|
if (("KTSD".indexOf(PaymentRule) != -1 ||
|
||||||
|
(PaymentRule.equals(MOrder.PAYMENTRULE_Cash) && m_Cash_As_Payment))
|
||||||
|
&& C_BankAccount_ID == 0)
|
||||||
{
|
{
|
||||||
String tender = MPayment.TENDERTYPE_CreditCard;
|
// Check & Cash (Payment) must have a bank account
|
||||||
if (PaymentRule.equals(MOrder.PAYMENTRULE_DirectDeposit))
|
if (C_BankAccount_ID == 0 && (PaymentRule.equals(MOrder.PAYMENTRULE_Check)) ||
|
||||||
tender = MPayment.TENDERTYPE_DirectDeposit;
|
(PaymentRule.equals(MOrder.PAYMENTRULE_Cash) && m_Cash_As_Payment))
|
||||||
else if (PaymentRule.equals(MOrder.PAYMENTRULE_DirectDebit))
|
{
|
||||||
tender = MPayment.TENDERTYPE_DirectDebit;
|
FDialog.error(m_WindowNo, this, "FillMandatory", bBankAccountLabel.getValue());
|
||||||
else if (PaymentRule.equals(MOrder.PAYMENTRULE_Check))
|
|
||||||
tender = MPayment.TENDERTYPE_Check;
|
|
||||||
// Check must have a bank account
|
|
||||||
if (C_BankAccount_ID == 0 && "S".equals(PaymentRule))
|
|
||||||
{
|
|
||||||
FDialog.error(m_WindowNo, this, "PaymentNoProcessor");
|
|
||||||
dataOK = false;
|
dataOK = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue