use of org.compiere.model.MPayment in project adempiere by adempiere.
the class VPayment 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(VButton button) throws Exception {
m_DocStatus = (String) m_mTab.getValue("DocStatus");
log.config(m_DocStatus);
if (m_mTab.getValue("C_BPartner_ID") == null) {
ADialog.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 / Closed
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) {
ADialog.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());
kNameField.setText(m_mPayment.getA_Name());
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.setReadWrite(!m_mPayment.isApproved());
kNumberField.setReadWrite(!m_mPayment.isApproved());
kNameField.setReadWrite(!m_mPayment.isApproved());
kExpField.setReadWrite(!m_mPayment.isApproved());
kApprovalField.setReadWrite(!m_mPayment.isApproved());
kOnline.setReadWrite(!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.setSelectedItem(s_Currencies.get(C_Currency_ID));
bCurrencyCombo.addActionListener(this);
bCurrencyCombo.setSelectedItem(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<?, ?> 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.setSelectedItem(vp);
/**
* 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.setSelectedItem(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'";
kp = null;
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);
// kp = pp;
}
rs.close();
pstmt.close();
} catch (SQLException eac) {
log.log(Level.SEVERE, SQL, eac);
}
// Set Selection
if (kp != null)
tAccountCombo.setSelectedItem(kp);
/**
* 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.setSelectedItem(vp);
/**
* Load Bank Accounts
*/
SQL = MRole.getDefault().addAccessSQL("SELECT C_BankAccount_ID, ba.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);
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.setSelectedItem(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.setSelectedItem(kp);
if (m_C_CashBook_ID == 0)
// set to default to avoid 'cashbook changed' message
m_C_CashBook_ID = kp.getKey();
}
//
return true;
}
use of org.compiere.model.MPayment in project adempiere by adempiere.
the class ReverseTheSalesTransaction method doIt.
@Override
protected String doIt() throws Exception {
today = new Timestamp(System.currentTimeMillis());
// Get Order
MOrder sourceOrder = new MOrder(getCtx(), getOrderId(), get_TrxName());
// Get Invoices for ths order
MInOut[] shipments = sourceOrder.getShipments();
// If not exist invoice then only is necessary reverse shipment
if (shipments.length > 0) {
// Validate if partner not is POS partner standard then reverse shipment
if (sourceOrder.getC_BPartner_ID() != getInvoicePartnerId() || isCancelled()) {
cancelShipments(shipments);
}
}
MInvoice[] invoices = sourceOrder.getInvoices();
if (invoices.length > 0) {
if (sourceOrder.getC_BPartner_ID() != getInvoicePartnerId() || isCancelled())
cancelInvoices();
}
//Cancel original payment
for (MPayment payment : cancelPayments(sourceOrder, today)) addLog(payment.getDocumentInfo());
sourceOrder.processIt(DocAction.ACTION_Close);
sourceOrder.saveEx();
return "@Ok@";
}
use of org.compiere.model.MPayment in project adempiere by adempiere.
the class ReverseTheSalesTransaction method cancelPayments.
public static List<MPayment> cancelPayments(MOrder sourceOrder, Timestamp today) {
List<MPayment> payments = new ArrayList<>();
List<MPayment> sourcePayments = MPayment.getOfOrder(sourceOrder);
for (MPayment sourcePayment : sourcePayments) {
MPayment payment = new MPayment(sourceOrder.getCtx(), 0, sourceOrder.get_TrxName());
PO.copyValues(sourcePayment, payment);
payment.setDateTrx(today);
payment.setC_Order_ID(sourceOrder.getC_Order_ID());
payment.setDateAcct(today);
payment.addDescription(" @From@ " + sourcePayment.getDocumentNo());
payment.setIsReceipt(false);
payment.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_APPayment));
payment.setDocAction(DocAction.ACTION_Complete);
payment.setDocStatus(DocAction.STATUS_Drafted);
payment.setIsPrepayment(true);
payment.saveEx();
payment.processIt(DocAction.ACTION_Complete);
payment.saveEx();
payments.add(payment);
}
return payments;
}
use of org.compiere.model.MPayment in project adempiere by adempiere.
the class CloseStatementPOS method getBankStatements.
private LinkedHashMap<Integer, MBankStatement> getBankStatements() {
if (baskStatements != null && baskStatements.size() > 0)
return baskStatements;
baskStatements = new LinkedHashMap<Integer, MBankStatement>();
List<MPayment> payments = (List<MPayment>) getInstancesForSelection(get_TrxName());
payments.stream().forEach(payment -> {
Integer bankStatementLineId = getSelectionAsInt(payment.get_ID(), "BSL_C_BankStatementLine_ID");
if (bankStatementLineId != null && bankStatementLineId > 0) {
MBankStatementLine bankStatementLine = new MBankStatementLine(getCtx(), bankStatementLineId, get_TrxName());
MBankStatement bankStatement = bankStatementLine.getParent();
if (!baskStatements.containsKey(bankStatement.get_ID()))
baskStatements.put(bankStatement.get_ID(), bankStatement);
}
});
return baskStatements;
}
use of org.compiere.model.MPayment in project adempiere by adempiere.
the class CreateOrderBasedOnAnother method createPayments.
/**
* Create payment for new Order
* @param sourceOrder
* @param targetOrder
*/
private void createPayments(MOrder sourceOrder, MOrder targetOrder) {
for (MPayment sourcePayment : MPayment.getOfOrder(sourceOrder)) {
MPayment payment = new MPayment(getCtx(), 0, get_TrxName());
PO.copyValues(sourcePayment, payment);
payment.setDateTrx(today);
payment.setDateAcct(today);
payment.setC_Order_ID(targetOrder.getC_Order_ID());
payment.setC_BPartner_ID(targetOrder.getC_BPartner_ID());
payment.setC_Invoice_ID(-1);
payment.addDescription(Msg.parseTranslation(sourceOrder.getCtx(), " @From@ ") + sourcePayment.getDocumentNo());
payment.setIsReceipt(true);
payment.setC_DocType_ID(MDocType.getDocType(MDocType.DOCBASETYPE_ARReceipt, sourceOrder.getAD_Org_ID()));
payment.setIsPrepayment(true);
payment.saveEx();
payment.processIt(getDocumentAction());
payment.saveEx();
addLog(payment.getDocumentInfo());
}
}
Aggregations