Search in sources :

Example 1 with MRfQResponse

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

the class WebInfo method getRfQResponse.

//	getRfQs
/**
	 * 	Get RfQ Response.
	 * 	Needs to have ID set first
	 *	@return rfq of BP with ID
	 */
public MRfQResponse getRfQResponse() {
    m_infoMessage = null;
    MRfQResponse retValue = null;
    String sql = "SELECT * FROM C_RfQResponse " + "WHERE C_RfQ_ID=?" + " AND C_BPartner_ID=? AND IsActive='Y'";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_id);
        pstmt.setInt(2, getC_BPartner_ID());
        rs = pstmt.executeQuery();
        if (rs.next())
            retValue = new MRfQResponse(m_ctx, rs, null);
    } catch (Exception e) {
        log.log(Level.SEVERE, "C_RfQResponse_ID=" + m_id, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    //	No Response existing
    if (retValue == null) {
        MRfQ rfq = new MRfQ(m_ctx, m_id, null);
        //	We can create a Response ?
        if (rfq.get_ID() != 0 && rfq.isSelfService() && rfq.isRfQResponseAccepted() && !rfq.isInvitedVendorsOnly() && getC_BPartner_ID() > 0 && getAD_User_ID() > 0) {
            MBPartner bp = new MBPartner(m_ctx, getC_BPartner_ID(), null);
            bp.setPrimaryAD_User_ID(getAD_User_ID());
            //	may have no lines
            retValue = new MRfQResponse(rfq, bp);
            retValue.saveEx();
        }
    }
    //
    log.fine("C_RfQResponse_ID=" + m_id + " - " + retValue);
    return retValue;
}
Also used : MRfQ(org.compiere.model.MRfQ) ResultSet(java.sql.ResultSet) MRfQResponse(org.compiere.model.MRfQResponse) PreparedStatement(java.sql.PreparedStatement) MBPartner(org.compiere.model.MBPartner)

Example 2 with MRfQResponse

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

the class RfQResponseRank method rankLines.

//	doIt
/**************************************************************************
	 * 	Rank Lines
	 *	@param rfq RfQ 
	 *	@param responses responses
	 */
@SuppressWarnings("unchecked")
private void rankLines(MRfQ rfq, MRfQResponse[] responses) {
    MRfQLine[] rfqLines = rfq.getLines();
    if (rfqLines.length == 0)
        throw new IllegalArgumentException("No RfQ Lines found");
    //	 for all lines
    for (int i = 0; i < rfqLines.length; i++) {
        //	RfQ Line
        MRfQLine rfqLine = rfqLines[i];
        if (!rfqLine.isActive())
            continue;
        log.fine("rankLines - " + rfqLine);
        MRfQLineQty[] rfqQtys = rfqLine.getQtys();
        for (int j = 0; j < rfqQtys.length; j++) {
            //	RfQ Line Qty
            MRfQLineQty rfqQty = rfqQtys[j];
            if (!rfqQty.isActive() || !rfqQty.isRfQQty())
                continue;
            log.fine("rankLines Qty - " + rfqQty);
            MRfQResponseLineQty[] respQtys = rfqQty.getResponseQtys(false);
            for (int kk = 0; kk < respQtys.length; kk++) {
                //	Response Line Qty
                MRfQResponseLineQty respQty = respQtys[kk];
                if (!respQty.isActive() || !respQty.isValidAmt()) {
                    respQty.setRanking(999);
                    respQty.saveEx();
                    log.fine("  - ignored: " + respQty);
                }
            }
            //	for all respones line qtys
            //	Rank RfQ Line Qtys
            respQtys = rfqQty.getResponseQtys(false);
            if (respQtys.length == 0)
                log.fine("  - No Qtys with valid Amounts");
            else {
                Arrays.sort(respQtys, respQtys[0]);
                //	multiple rank #1
                int lastRank = 1;
                BigDecimal lastAmt = Env.ZERO;
                int rank = 0;
                for (int k = 0; k < respQtys.length; k++) {
                    MRfQResponseLineQty qty = respQtys[k];
                    if (!qty.isActive() || qty.getRanking() == 999) {
                        continue;
                    }
                    BigDecimal netAmt = qty.getNetAmt();
                    if (netAmt == null) {
                        qty.setRanking(999);
                        qty.saveEx();
                        log.fine("  - Rank 999: " + qty);
                        continue;
                    }
                    if (lastAmt.compareTo(netAmt) != 0) {
                        lastRank = rank + 1;
                        lastAmt = qty.getNetAmt();
                    }
                    qty.setRanking(lastRank);
                    log.fine("  - Rank " + lastRank + ": " + qty);
                    qty.saveEx();
                    //	
                    if (//	Update RfQ
                    rank == 0) {
                        rfqQty.setBestResponseAmt(qty.getNetAmt());
                        rfqQty.saveEx();
                    }
                    rank++;
                }
            }
        }
    //	for all rfq line qtys
    }
    //	 for all rfq lines
    //	Select Winner based on line ranking
    MRfQResponse winner = null;
    for (int ii = 0; ii < responses.length; ii++) {
        MRfQResponse response = responses[ii];
        if (response.isSelectedWinner())
            response.setIsSelectedWinner(false);
        int ranking = 0;
        MRfQResponseLine[] respLines = response.getLines(false);
        for (int jj = 0; jj < respLines.length; jj++) {
            //	Response Line
            MRfQResponseLine respLine = respLines[jj];
            if (!respLine.isActive())
                continue;
            if (respLine.isSelectedWinner())
                respLine.setIsSelectedWinner(false);
            MRfQResponseLineQty[] respQtys = respLine.getQtys(false);
            for (int kk = 0; kk < respQtys.length; kk++) {
                //	Response Line Qty
                MRfQResponseLineQty respQty = respQtys[kk];
                if (!respQty.isActive())
                    continue;
                ranking += respQty.getRanking();
                if (respQty.getRanking() == 1 && respQty.getRfQLineQty().isPurchaseQty()) {
                    respLine.setIsSelectedWinner(true);
                    respLine.saveEx();
                    break;
                }
            }
        }
        response.setRanking(ranking);
        response.saveEx();
        log.fine("- Response Ranking " + ranking + ": " + response);
        if (//	no total selected winner if not all lines
        !rfq.isQuoteSelectedLines()) {
            if (winner == null && ranking > 0)
                winner = response;
            if (winner != null && response.getRanking() > 0 && response.getRanking() < winner.getRanking())
                winner = response;
        }
    }
    if (winner != null) {
        winner.setIsSelectedWinner(true);
        winner.saveEx();
        log.fine("- Response Winner: " + winner);
    }
}
Also used : MRfQLine(org.compiere.model.MRfQLine) MRfQLineQty(org.compiere.model.MRfQLineQty) MRfQResponse(org.compiere.model.MRfQResponse) MRfQResponseLineQty(org.compiere.model.MRfQResponseLineQty) BigDecimal(java.math.BigDecimal) MRfQResponseLine(org.compiere.model.MRfQResponseLine)

Example 3 with MRfQResponse

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

the class RfQClose method doIt.

//	prepare
/**
	 * 	Process
	 *	@see org.compiere.process.SvrProcess#doIt()
	 *	@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("doIt - " + rfq);
    //
    rfq.setProcessed(true);
    rfq.saveEx();
    //
    int counter = 0;
    MRfQResponse[] responses = rfq.getResponses(false, false);
    for (int i = 0; i < responses.length; i++) {
        responses[i].setProcessed(true);
        responses[i].saveEx();
        counter++;
    }
    //
    return "# " + counter;
}
Also used : MRfQ(org.compiere.model.MRfQ) MRfQResponse(org.compiere.model.MRfQResponse)

Example 4 with MRfQResponse

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

the class RfQCreate method doIt.

//	prepare
/**
	 *  Perform process.
	 *  @return Message (translated text)
	 *  @throws Exception if not successful
	 */
protected String doIt() throws Exception {
    MRfQ rfq = new MRfQ(getCtx(), p_C_RfQ_ID, get_TrxName());
    log.info("doIt - " + rfq + ", Send=" + p_IsSendRfQ);
    String error = rfq.checkQuoteTotalAmtOnly();
    if (error != null && error.length() > 0)
        throw new Exception(error);
    int counter = 0;
    int sent = 0;
    int notSent = 0;
    //	Get all existing responses
    MRfQResponse[] responses = rfq.getResponses(false, false);
    //	Topic
    MRfQTopic topic = new MRfQTopic(getCtx(), rfq.getC_RfQ_Topic_ID(), get_TrxName());
    MRfQTopicSubscriber[] subscribers = topic.getSubscribers();
    for (int i = 0; i < subscribers.length; i++) {
        MRfQTopicSubscriber subscriber = subscribers[i];
        boolean skip = false;
        //	existing response
        for (int r = 0; r < responses.length; r++) {
            if (subscriber.getC_BPartner_ID() == responses[r].getC_BPartner_ID() && subscriber.getC_BPartner_Location_ID() == responses[r].getC_BPartner_Location_ID()) {
                skip = true;
                break;
            }
        }
        if (skip)
            continue;
        //	Create Response
        MRfQResponse response = new MRfQResponse(rfq, subscriber);
        if (//	no lines
        response.get_ID() == 0)
            continue;
        counter++;
        if (p_IsSendRfQ) {
            commitEx();
            if (response.sendRfQ())
                sent++;
            else
                notSent++;
        }
    }
    //	for all subscribers
    String retValue = "@Created@ " + counter;
    if (p_IsSendRfQ)
        retValue += " - @IsSendRfQ@=" + sent + " - @Error@=" + notSent;
    return retValue;
}
Also used : MRfQTopicSubscriber(org.compiere.model.MRfQTopicSubscriber) MRfQTopic(org.compiere.model.MRfQTopic) MRfQ(org.compiere.model.MRfQ) MRfQResponse(org.compiere.model.MRfQResponse)

Example 5 with MRfQResponse

use of org.compiere.model.MRfQResponse 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)

Aggregations

MRfQResponse (org.compiere.model.MRfQResponse)10 MRfQ (org.compiere.model.MRfQ)5 BigDecimal (java.math.BigDecimal)2 MBPartner (org.compiere.model.MBPartner)2 MRfQResponseLine (org.compiere.model.MRfQResponseLine)2 MRfQResponseLineQty (org.compiere.model.MRfQResponseLineQty)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Properties (java.util.Properties)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 HttpSession (javax.servlet.http.HttpSession)1 MOrder (org.compiere.model.MOrder)1 MOrderLine (org.compiere.model.MOrderLine)1 MRfQLine (org.compiere.model.MRfQLine)1 MRfQLineQty (org.compiere.model.MRfQLineQty)1 MRfQTopic (org.compiere.model.MRfQTopic)1 MRfQTopicSubscriber (org.compiere.model.MRfQTopicSubscriber)1 WebUser (org.compiere.util.WebUser)1