Search in sources :

Example 61 with MBPartner

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

the class Generator method generateSessionEquiv.

private void generateSessionEquiv(HttpServletCM thisServlet, HttpServletRequest httpRequest, Properties ctx) {
    xmlCode.append("<session>\n");
    HttpSession thisSession = httpRequest.getSession(false);
    if (thisSession != null) {
        if (thisSession.getAttribute(WebInfo.NAME) != null) {
            WebInfo wi = (WebInfo) thisSession.getAttribute(WebInfo.NAME);
            xmlCode.append("<WebInfo>\n");
            xmlCode.append("<Info><![CDATA[" + wi.getInfo() + "]]></Info>\n");
            if (wi.getUser_ID() > 0) {
                MUser thisUser = MUser.get(ctx, wi.getAD_User_ID());
                xmlCode = thisUser.get_xmlString(xmlCode);
                MBPartner thisBPartner = new MBPartner(ctx, wi.getC_BPartner_ID(), null);
                if (thisBPartner != null)
                    xmlCode = thisBPartner.get_xmlString(xmlCode);
                MBPartnerLocation thisBPartnerLocation = thisBPartner.getPrimaryC_BPartner_Location();
                if (thisBPartnerLocation != null)
                    xmlCode = thisBPartnerLocation.get_xmlString(xmlCode);
                MLocation thisLocation = MLocation.getBPLocation(ctx, thisBPartnerLocation.get_ID(), null);
                if (thisLocation != null)
                    xmlCode = thisLocation.get_xmlString(xmlCode);
                MBPBankAccount[] theseBPBankAccount = thisBPartner.getBankAccounts(true);
                if (theseBPBankAccount != null && theseBPBankAccount.length > 0)
                    for (int i = 0; i < theseBPBankAccount.length; i++) xmlCode = theseBPBankAccount[i].get_xmlString(xmlCode);
                if (thisSession.getAttribute("EMail") == null)
                    thisSession.setAttribute("EMail", thisUser.getEMail());
            }
            if (wi.getWebUser().getPasswordMessage() != null) {
                xmlCode.append("<PasswordMessage><![CDATA[" + wi.getWebUser().getPasswordMessage() + "]]></PasswordMessage>\n");
                wi.getWebUser().setPasswordMessage(null);
            }
            if (wi.getWebUser().getSaveErrorMessage() != null) {
                xmlCode.append("<SaveErrorMessage><![CDATA[" + wi.getWebUser().getSaveErrorMessage() + "]]></SaveErrorMessage>\n");
                wi.getWebUser().setSaveErrorMessage(null);
            }
            if (thisSession.getAttribute("hdrMessage") != null) {
                xmlCode.append("<hdrMessage><![CDATA[" + thisSession.getAttribute("hdrMessage") + "]]></hdrMessage>\n");
                thisSession.removeAttribute("hdrMessage");
            }
            xmlCode.append("<WebUser>\n");
            xmlCode.append("<LoggedIn>" + wi.getWebUser().isLoggedIn() + "</LoggedIn>\n");
            xmlCode.append("</WebUser>\n");
            xmlCode.append("</WebInfo>\n");
        }
        if (thisSession.getAttribute("EMail") != null)
            xmlCode.append("<EMail><![CDATA[" + thisSession.getAttribute("EMail") + "]]></EMail>\n");
    }
    xmlCode.append("</session>\n");
}
Also used : HttpSession(javax.servlet.http.HttpSession) MBPBankAccount(org.compiere.model.MBPBankAccount) MBPartner(org.compiere.model.MBPartner) WebInfo(org.compiere.util.WebInfo) MUser(org.compiere.model.MUser) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Example 62 with MBPartner

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

the class RfQCreatePO method doIt.

//	prepare
/**
	 * 	Process.
	 * 	Create purchase order(s) for the resonse(s) and lines marked as 
	 * 	Selected Winner using the selected Purchase Quantity (in RfQ Line Quantity) . 
	 * 	If a Response is marked as Selected Winner, all lines are created 
	 * 	(and Selected Winner of other responses ignored).  
	 * 	If there is no response marked as Selected Winner, the lines are used.
	 *	@return message
	 */
protected String doIt() throws Exception {
    MRfQ rfq = new MRfQ(getCtx(), p_C_RfQ_ID, get_TrxName());
    if (rfq.get_ID() == 0)
        throw new IllegalArgumentException("No RfQ found");
    log.info(rfq.toString());
    //	Complete 
    MRfQResponse[] responses = rfq.getResponses(true, true);
    log.config("#Responses=" + responses.length);
    if (responses.length == 0)
        throw new IllegalArgumentException("No completed RfQ Responses found");
    //	Winner for entire RfQ
    for (int i = 0; i < responses.length; i++) {
        MRfQResponse response = responses[i];
        if (!response.isSelectedWinner())
            continue;
        //
        MBPartner bp = new MBPartner(getCtx(), response.getC_BPartner_ID(), get_TrxName());
        log.config("Winner=" + bp);
        MOrder order = new MOrder(getCtx(), 0, get_TrxName());
        order.setIsSOTrx(false);
        if (p_C_DocType_ID != 0)
            order.setC_DocTypeTarget_ID(p_C_DocType_ID);
        else
            order.setC_DocTypeTarget_ID();
        order.setBPartner(bp);
        order.setC_BPartner_Location_ID(response.getC_BPartner_Location_ID());
        order.setSalesRep_ID(rfq.getSalesRep_ID());
        if (response.getDateWorkComplete() != null)
            order.setDatePromised(response.getDateWorkComplete());
        else if (rfq.getDateWorkComplete() != null)
            order.setDatePromised(rfq.getDateWorkComplete());
        order.saveEx();
        //
        MRfQResponseLine[] lines = response.getLines(false);
        for (int j = 0; j < lines.length; j++) {
            //	Respones Line
            MRfQResponseLine line = lines[j];
            if (!line.isActive())
                continue;
            MRfQResponseLineQty[] qtys = line.getQtys(false);
            //	Response Line Qty
            for (int k = 0; k < qtys.length; k++) {
                MRfQResponseLineQty qty = qtys[k];
                //	Create PO Lline for all Purchase Line Qtys
                if (qty.getRfQLineQty().isActive() && qty.getRfQLineQty().isPurchaseQty()) {
                    MOrderLine ol = new MOrderLine(order);
                    ol.setM_Product_ID(line.getRfQLine().getM_Product_ID(), qty.getRfQLineQty().getC_UOM_ID());
                    ol.setDescription(line.getDescription());
                    ol.setQty(qty.getRfQLineQty().getQty());
                    BigDecimal price = qty.getNetAmt();
                    ol.setPrice();
                    ol.setPrice(price);
                    ol.saveEx();
                }
            }
        }
        response.setC_Order_ID(order.getC_Order_ID());
        response.saveEx();
        return order.getDocumentNo();
    }
    //	Selected Winner on Line Level
    int noOrders = 0;
    for (int i = 0; i < responses.length; i++) {
        MRfQResponse response = responses[i];
        MBPartner bp = null;
        MOrder order = null;
        //	For all Response Lines
        MRfQResponseLine[] lines = response.getLines(false);
        for (int j = 0; j < lines.length; j++) {
            MRfQResponseLine line = lines[j];
            if (!line.isActive() || !line.isSelectedWinner())
                continue;
            //	New/different BP
            if (bp == null || bp.getC_BPartner_ID() != response.getC_BPartner_ID()) {
                bp = new MBPartner(getCtx(), response.getC_BPartner_ID(), get_TrxName());
                order = null;
            }
            log.config("Line=" + line + ", Winner=" + bp);
            //	New Order
            if (order == null) {
                order = new MOrder(getCtx(), 0, get_TrxName());
                order.setIsSOTrx(false);
                order.setC_DocTypeTarget_ID();
                order.setBPartner(bp);
                order.setC_BPartner_Location_ID(response.getC_BPartner_Location_ID());
                order.setSalesRep_ID(rfq.getSalesRep_ID());
                order.saveEx();
                noOrders++;
                addLog(0, null, null, order.getDocumentNo());
            }
            //	For all Qtys
            MRfQResponseLineQty[] qtys = line.getQtys(false);
            for (int k = 0; k < qtys.length; k++) {
                MRfQResponseLineQty qty = qtys[k];
                if (qty.getRfQLineQty().isActive() && qty.getRfQLineQty().isPurchaseQty()) {
                    MOrderLine ol = new MOrderLine(order);
                    ol.setM_Product_ID(line.getRfQLine().getM_Product_ID(), qty.getRfQLineQty().getC_UOM_ID());
                    ol.setDescription(line.getDescription());
                    ol.setQty(qty.getRfQLineQty().getQty());
                    BigDecimal price = qty.getNetAmt();
                    ol.setPrice();
                    ol.setPrice(price);
                    ol.saveEx();
                }
            }
        //	for all Qtys
        }
        //	for all Response Lines
        if (order != null) {
            response.setC_Order_ID(order.getC_Order_ID());
            response.saveEx();
        }
    }
    return "#" + noOrders;
}
Also used : MBPartner(org.compiere.model.MBPartner) MRfQResponseLineQty(org.compiere.model.MRfQResponseLineQty) MRfQResponseLine(org.compiere.model.MRfQResponseLine) BigDecimal(java.math.BigDecimal) MOrder(org.compiere.model.MOrder) MRfQ(org.compiere.model.MRfQ) MRfQResponse(org.compiere.model.MRfQResponse) MOrderLine(org.compiere.model.MOrderLine)

Example 63 with MBPartner

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

the class RequestInvoice method invoiceNew.

//	invoiceDone
/**
	 * 	New Invoice
	 *	@param request request
	 */
private void invoiceNew(MRequest request) {
    m_invoice = new MInvoice(getCtx(), 0, get_TrxName());
    m_invoice.setIsSOTrx(true);
    MBPartner partner = new MBPartner(getCtx(), request.getC_BPartner_ID(), null);
    m_invoice.setBPartner(partner);
    m_invoice.saveEx();
    m_linecount = 0;
}
Also used : MInvoice(org.compiere.model.MInvoice) MBPartner(org.compiere.model.MBPartner)

Example 64 with MBPartner

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

the class MWFActivity method getSummary.

//	toStringX
/**
	 * 	Get Document Summary
	 *	@return PO Summary
	 */
public String getSummary() {
    PO po = getPO();
    if (po == null)
        return null;
    StringBuffer sb = new StringBuffer();
    String[] keyColumns = po.get_KeyColumns();
    if ((keyColumns != null) && (keyColumns.length > 0))
        sb.append(Msg.getElement(getCtx(), keyColumns[0])).append(" ");
    int index = po.get_ColumnIndex("DocumentNo");
    if (index != -1)
        sb.append(po.get_Value(index)).append(": ");
    index = po.get_ColumnIndex("SalesRep_ID");
    Integer sr = null;
    if (index != -1)
        sr = (Integer) po.get_Value(index);
    else {
        index = po.get_ColumnIndex("AD_User_ID");
        if (index != -1)
            sr = (Integer) po.get_Value(index);
    }
    if (sr != null) {
        MUser user = MUser.get(getCtx(), sr.intValue());
        if (user != null)
            sb.append(user.getName()).append(" ");
    }
    //
    index = po.get_ColumnIndex("C_BPartner_ID");
    if (index != -1) {
        Integer bp = (Integer) po.get_Value(index);
        if (bp != null) {
            MBPartner partner = MBPartner.get(getCtx(), bp.intValue());
            if (partner != null)
                sb.append(partner.getName()).append(" ");
        }
    }
    return sb.toString();
}
Also used : MBPartner(org.compiere.model.MBPartner) MUser(org.compiere.model.MUser) Savepoint(java.sql.Savepoint) PO(org.compiere.model.PO)

Example 65 with MBPartner

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

the class WebUser method load.

/**
	 * 	Load Contact
	 * 	@param email email
	 *	@param password optional password
	 */
private void load(String email, String password) {
    log.info(email + " - AD_Client_ID=" + m_AD_Client_ID);
    String sql = "SELECT * " + "FROM AD_User " + "WHERE AD_Client_ID=?" + " AND TRIM(EMail)=?";
    if (email == null)
        email = "";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_AD_Client_ID);
        pstmt.setString(2, email.trim());
        rs = pstmt.executeQuery();
        if (rs.next()) {
            m_bpc = new MUser(m_ctx, rs, null);
            log.fine("Found BPC=" + m_bpc);
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	Check Password
    m_passwordOK = false;
    //	We have a password
    if (m_bpc != null && password != null && authenticateHash(password))
        m_passwordOK = true;
    if (m_passwordOK || m_bpc == null)
        m_passwordMessage = null;
    else
        setPasswordOK(false, password);
    //	Load BPartner
    if (m_bpc != null) {
        m_bp = new MBPartner(m_ctx, m_bpc.getC_BPartner_ID(), null);
        log.fine("Found BP=" + m_bp);
    } else
        m_bp = null;
    //	Load Loacation
    if (m_bpc != null) {
        if (m_bpc.getC_BPartner_Location_ID() != 0) {
            m_bpl = new MBPartnerLocation(m_ctx, m_bpc.getC_BPartner_Location_ID(), null);
            log.fine("Found BPL=" + m_bpl);
        } else {
            MBPartnerLocation[] bpls = m_bp.getLocations(false);
            if (bpls != null && bpls.length > 0) {
                m_bpl = bpls[0];
                log.fine("Found BPL=" + m_bpl);
            }
        }
        if (m_bpl != null) {
            m_loc = MLocation.get(m_ctx, m_bpl.getC_Location_ID(), null);
            log.fine("Found LOC=" + m_loc);
        } else
            m_loc = null;
    } else {
        m_bpl = null;
        m_loc = null;
    }
    //	Make sure that all entities exist
    if (m_bpc == null) {
        m_bpc = new MUser(m_ctx, 0, null);
        m_bpc.setEMail(email);
        m_bpc.setPassword(password);
    }
    if (m_bp == null) {
        //	template
        m_bp = new MBPartner(m_ctx);
        m_bp.setIsCustomer(true);
    }
    if (m_bpl == null)
        m_bpl = new MBPartnerLocation(m_bp);
    if (m_loc == null)
        m_loc = new MLocation(m_ctx, 0, null);
    //
    log.config(m_bp + " - " + m_bpc);
}
Also used : ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MBPartner(org.compiere.model.MBPartner) MUser(org.compiere.model.MUser) MLocation(org.compiere.model.MLocation) MBPartnerLocation(org.compiere.model.MBPartnerLocation)

Aggregations

MBPartner (org.compiere.model.MBPartner)78 BigDecimal (java.math.BigDecimal)21 ResultSet (java.sql.ResultSet)14 MBPartnerLocation (org.compiere.model.MBPartnerLocation)14 AdempiereException (org.adempiere.exceptions.AdempiereException)13 MLocation (org.compiere.model.MLocation)13 MOrder (org.compiere.model.MOrder)13 PreparedStatement (java.sql.PreparedStatement)11 MOrderLine (org.compiere.model.MOrderLine)11 MUser (org.compiere.model.MUser)11 MInvoice (org.compiere.model.MInvoice)10 MOrg (org.compiere.model.MOrg)9 Query (org.compiere.model.Query)9 MWarehouse (org.compiere.model.MWarehouse)8 SQLException (java.sql.SQLException)7 MClient (org.compiere.model.MClient)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereUserError (org.compiere.util.AdempiereUserError)7 Timestamp (java.sql.Timestamp)6 MDDOrder (org.eevolution.model.MDDOrder)6