Search in sources :

Example 11 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class BankTransfer method generateBankTransfer.

//	doIt
/**
	 * Generate BankTransfer()
	 *
	 */
private void generateBankTransfer() {
    MBankAccount mBankFrom = new MBankAccount(getCtx(), p_From_C_BankAccount_ID, get_TrxName());
    MBankAccount mBankTo = new MBankAccount(getCtx(), p_To_C_BankAccount_ID, get_TrxName());
    MPayment paymentBankFrom = new MPayment(getCtx(), 0, get_TrxName());
    paymentBankFrom.setC_BankAccount_ID(mBankFrom.getC_BankAccount_ID());
    paymentBankFrom.setDocumentNo(p_DocumentNo);
    paymentBankFrom.setDateAcct(p_DateAcct);
    paymentBankFrom.setDateTrx(p_StatementDate);
    paymentBankFrom.setTenderType(MPayment.TENDERTYPE_DirectDeposit);
    paymentBankFrom.setDescription(p_Description);
    paymentBankFrom.setC_BPartner_ID(p_C_BPartner_ID);
    paymentBankFrom.setC_Currency_ID(p_C_Currency_ID);
    if (p_C_ConversionType_ID > 0)
        paymentBankFrom.setC_ConversionType_ID(p_C_ConversionType_ID);
    paymentBankFrom.setPayAmt(p_Amount);
    paymentBankFrom.setOverUnderAmt(Env.ZERO);
    paymentBankFrom.setC_DocType_ID(false);
    paymentBankFrom.setC_Charge_ID(p_C_Charge_ID);
    paymentBankFrom.saveEx();
    paymentBankFrom.processIt(MPayment.DOCACTION_Complete);
    paymentBankFrom.saveEx();
    MPayment paymentBankTo = new MPayment(getCtx(), 0, get_TrxName());
    paymentBankTo.setC_BankAccount_ID(mBankTo.getC_BankAccount_ID());
    paymentBankTo.setDocumentNo(p_DocumentNo);
    paymentBankTo.setDateAcct(p_DateAcct);
    paymentBankTo.setDateTrx(p_StatementDate);
    paymentBankTo.setTenderType(MPayment.TENDERTYPE_DirectDeposit);
    paymentBankTo.setDescription(p_Description);
    paymentBankTo.setC_BPartner_ID(p_C_BPartner_ID);
    paymentBankTo.setC_Currency_ID(p_C_Currency_ID);
    if (p_C_ConversionType_ID > 0)
        paymentBankFrom.setC_ConversionType_ID(p_C_ConversionType_ID);
    paymentBankTo.setPayAmt(p_Amount);
    paymentBankTo.setOverUnderAmt(Env.ZERO);
    paymentBankTo.setC_DocType_ID(true);
    paymentBankTo.setC_Charge_ID(p_C_Charge_ID);
    paymentBankTo.saveEx();
    paymentBankTo.processIt(MPayment.DOCACTION_Complete);
    paymentBankTo.saveEx();
    m_created++;
    return;
}
Also used : MPayment(org.compiere.model.MPayment) MBankAccount(org.compiere.model.MBankAccount)

Example 12 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class BankStatementPayment method createPayment.

//	createPayment
/**
	 * 	Create actual Payment
	 *	@param C_Invoice_ID invoice
	 *	@param C_BPartner_ID partner ignored when invoice exists
	 *	@param C_Currency_ID currency
	 *	@param StmtAmt statement amount
	 *	@param TrxAmt transaction amt
	 *	@param C_BankAccount_ID bank account
	 *	@param DateTrx transaction date
	 *	@param DateAcct	accounting date
	 *	@param Description description
	 *	@param AD_Org_ID org
	 *	@return payment
	 */
private MPayment createPayment(int C_Invoice_ID, int C_BPartner_ID, int C_Currency_ID, BigDecimal StmtAmt, BigDecimal TrxAmt, int C_BankAccount_ID, Timestamp DateTrx, Timestamp DateAcct, String Description, int AD_Org_ID) {
    //	Trx Amount = Payment overwrites Statement Amount if defined
    BigDecimal PayAmt = TrxAmt;
    if (PayAmt == null || Env.ZERO.compareTo(PayAmt) == 0)
        PayAmt = StmtAmt;
    if (C_Invoice_ID == 0 && (PayAmt == null || Env.ZERO.compareTo(PayAmt) == 0))
        throw new IllegalStateException("@PayAmt@ = 0");
    if (PayAmt == null)
        PayAmt = Env.ZERO;
    //
    MPayment payment = new MPayment(getCtx(), 0, get_TrxName());
    payment.setAD_Org_ID(AD_Org_ID);
    payment.setC_BankAccount_ID(C_BankAccount_ID);
    payment.setTenderType(MPayment.TENDERTYPE_Check);
    if (DateTrx != null)
        payment.setDateTrx(DateTrx);
    else if (DateAcct != null)
        payment.setDateTrx(DateAcct);
    if (DateAcct != null)
        payment.setDateAcct(DateAcct);
    else
        payment.setDateAcct(payment.getDateTrx());
    payment.setDescription(Description);
    //
    if (C_Invoice_ID != 0) {
        MInvoice invoice = new MInvoice(getCtx(), C_Invoice_ID, null);
        //	Receipt
        payment.setC_DocType_ID(invoice.isSOTrx());
        payment.setC_Invoice_ID(invoice.getC_Invoice_ID());
        payment.setC_BPartner_ID(invoice.getC_BPartner_ID());
        if (//	explicit Amount
        PayAmt.signum() != 0) {
            payment.setC_Currency_ID(C_Currency_ID);
            if (invoice.isSOTrx())
                payment.setPayAmt(PayAmt);
            else
                //	payment is likely to be negative
                payment.setPayAmt(PayAmt.negate());
            payment.setOverUnderAmt(invoice.getGrandTotal(true).subtract(payment.getPayAmt()));
        } else // set Pay Amout from Invoice
        {
            payment.setC_Currency_ID(invoice.getC_Currency_ID());
            payment.setPayAmt(invoice.getGrandTotal(true));
        }
    } else if (C_BPartner_ID != 0) {
        payment.setC_BPartner_ID(C_BPartner_ID);
        payment.setC_Currency_ID(C_Currency_ID);
        if (//	Payment
        PayAmt.signum() < 0) {
            payment.setPayAmt(PayAmt.abs());
            payment.setC_DocType_ID(false);
        } else //	Receipt
        {
            payment.setPayAmt(PayAmt);
            payment.setC_DocType_ID(true);
        }
    } else
        return null;
    payment.saveEx();
    //
    payment.processIt(MPayment.DOCACTION_Complete);
    payment.saveEx();
    return payment;
}
Also used : MPayment(org.compiere.model.MPayment) MInvoice(org.compiere.model.MInvoice) BigDecimal(java.math.BigDecimal)

Example 13 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class CreateFromStatement method save.

/**
	 *  Save Statement - Insert Data
	 *  @return true if saved
	 */
public boolean save(IMiniTable miniTable, String trxName) {
    //  fixed values
    MBankStatement bs = new MBankStatement(Env.getCtx(), m_Record_ID, trxName);
    log.config(bs.toString());
    //  Lines
    for (int i = 0; i < miniTable.getRowCount(); i++) {
        if (((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) {
            //  1-DateTrx
            Timestamp trxDate = (Timestamp) miniTable.getValueAt(i, 1);
            //  2-C_Payment_ID
            KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2);
            int C_Payment_ID = pp.getKey();
            //  3-Currency
            pp = (KeyNamePair) miniTable.getValueAt(i, 3);
            int C_Currency_ID = pp.getKey();
            //  5- Conv Amt
            BigDecimal TrxAmt = (BigDecimal) miniTable.getValueAt(i, 5);
            log.fine("Line Date=" + trxDate + ", Payment=" + C_Payment_ID + ", Currency=" + C_Currency_ID + ", Amt=" + TrxAmt);
            //	
            MBankStatementLine bsl = new MBankStatementLine(bs);
            // BF3439695 - Create from for Statement Line picks wrong date
            bsl.setDateAcct(bs.getStatementDate());
            bsl.setStatementLineDate(bs.getStatementDate());
            bsl.setValutaDate(trxDate);
            bsl.setPayment(new MPayment(Env.getCtx(), C_Payment_ID, trxName));
            bsl.setTrxAmt(TrxAmt);
            bsl.setStmtAmt(TrxAmt);
            bsl.setC_Currency_ID(m_BankAccount.getC_Currency_ID());
            if (!bsl.save())
                log.log(Level.SEVERE, "Line not created #" + i);
        }
    //   if selected
    }
    //  for all rows
    return true;
}
Also used : MPayment(org.compiere.model.MPayment) MBankStatement(org.compiere.model.MBankStatement) KeyNamePair(org.compiere.util.KeyNamePair) MBankStatementLine(org.compiere.model.MBankStatementLine) Timestamp(java.sql.Timestamp) BigDecimal(java.math.BigDecimal)

Example 14 with MPayment

use of org.compiere.model.MPayment in project adempiere by adempiere.

the class OrderServlet method doPost.

//	doGet
/**
	 *  Process the HTTP Post request
	 *
	 *  @param request request
	 *  @param response response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.info("Post from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
    Properties ctx = JSPEnv.getCtx(request);
    HttpSession session = request.getSession(true);
    session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
    //	Web User/Basket
    WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
    WebBasket wb = (WebBasket) session.getAttribute(WebBasket.NAME);
    MOrder order = null;
    boolean done = false;
    String url = "/paymentInfo.jsp";
    //	Not logged in
    if (wu == null || !wu.isLoggedIn()) {
        //	indicate checkout
        session.setAttribute("CheckOut", "Y");
        url = "/login.jsp";
        done = true;
    } else
        //	Order parameter
        order = getOrder(request, ctx);
    //	We have an Order
    if (!done && order != null) {
        if (processOrder(request, order))
            url = "/orders.jsp";
        else {
            WebOrder wo = new WebOrder(order);
            MPayment p = createPayment(session, ctx, wu, wo);
            if (p != null) {
                session.setAttribute(PaymentServlet.ATTR_PAYMENT, p);
                session.setAttribute(WebOrder.NAME, wo);
            } else
                url = "/orders.jsp";
        }
        done = true;
    }
    //	Nothing in basket
    if (!done && (wb == null || wb.getLineCount() == 0)) {
        url = "/basket.jsp";
        done = true;
    }
    //	Create Order & Payment Info
    if (!done) {
        WebOrder wo = new WebOrder(wu, wb, ctx);
        //	We have an order - do delete basket & checkout indicator
        if (wo.isInProgress() || wo.isCompleted()) {
            session.removeAttribute(CheckOutServlet.ATTR_CHECKOUT);
            session.removeAttribute(WebBasket.NAME);
            sendEMail(request, ctx, wo, wu);
        }
        //	If the Order is negative, don't create a payment
        if (wo.getGrandTotal().compareTo(Env.ZERO) > 0) {
            session.setAttribute(WebOrder.NAME, wo);
            MPayment p = createPayment(session, ctx, wu, wo);
            if (p == null) {
                WebUtil.createForwardPage(response, "Payment could not be created", "orders.jsp", 5);
                return;
            } else
                session.setAttribute(PaymentServlet.ATTR_PAYMENT, p);
        } else {
            url = "/orders.jsp";
        }
    }
    log.info("Forward to " + url);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
}
Also used : MOrder(org.compiere.model.MOrder) HttpSession(javax.servlet.http.HttpSession) MPayment(org.compiere.model.MPayment) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 15 with MPayment

use of org.compiere.model.MPayment 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;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) MCashLine(org.compiere.model.MCashLine) MPayment(org.compiere.model.MPayment) ResultSet(java.sql.ResultSet) ValueNamePair(org.compiere.util.ValueNamePair) KeyNamePair(org.compiere.util.KeyNamePair)

Aggregations

MPayment (org.compiere.model.MPayment)47 BigDecimal (java.math.BigDecimal)14 MInvoice (org.compiere.model.MInvoice)12 Timestamp (java.sql.Timestamp)8 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 ArrayList (java.util.ArrayList)7 MCashLine (org.compiere.model.MCashLine)5 AdempiereSystemError (org.compiere.util.AdempiereSystemError)5 MAllocationLine (org.compiere.model.MAllocationLine)4 MBankStatement (org.compiere.model.MBankStatement)4 MOrder (org.compiere.model.MOrder)4 Properties (java.util.Properties)3 RequestDispatcher (javax.servlet.RequestDispatcher)3 HttpSession (javax.servlet.http.HttpSession)3 MAllocationHdr (org.compiere.model.MAllocationHdr)3 MBankAccount (org.compiere.model.MBankAccount)3 MBankStatementLine (org.compiere.model.MBankStatementLine)3 AdempiereUserError (org.compiere.util.AdempiereUserError)3 KeyNamePair (org.compiere.util.KeyNamePair)3