Пример #1
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            MRfQ rfq = new MRfQ(GetCtx(), _C_RfQ_ID, Get_TrxName());

            if (rfq.Get_ID() == 0)
            {
                throw new ArgumentException("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 ArgumentException("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 (_C_DocType_ID != 0)
                {
                    order.SetC_DocTypeTarget_ID(_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.Save();
                //
                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());
                            Decimal?price = qty.GetNetAmt();
                            ol.SetPrice(price == null?Env.ZERO:price.Value);
                            ol.Save();
                        }
                    }
                }
                response.SetC_Order_ID(order.GetC_Order_ID());
                response.Save();
                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    = 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.Save();
                        noOrders++;
                        //AddLog(0, null, null, order.GetDocumentNo());
                        AddLog(0, DateTime.Now, 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());
                            Decimal?price = qty.GetNetAmt();
                            ol.SetPriceActual(price);
                            ol.Save();
                        }
                    }   //	for all Qtys
                }       //	for all Response Lines
                if (order != null)
                {
                    response.SetC_Order_ID(order.GetC_Order_ID());
                    response.Save();
                }
            }

            return("#" + noOrders);
        }
Пример #2
0
        /// <summary>
        /// Rank Lines
        /// </summary>
        /// <param name="rfq">RfQ</param>
        /// <param name="responses">responses</param>
        /// @SuppressWarnings("unchecked")
        private void RankLines(MRfQ rfq, MRfQResponse[] responses)
        {
            MRfQLine[] rfqLines = rfq.GetLines();
            if (rfqLines.Length == 0)
            {
                throw new ArgumentException("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);
                    //genrate rank for product
                    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.Save();
                            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
                    {
                        try
                        {
                            Array.Sort(respQtys, respQtys[0]);
                            // Arrays.sort(respQtys, respQtys[0]);
                            //Array.Sort(respQtys, respQtys);
                        }
                        catch { }
                        int     lastRank = 1;           //	multiple rank #1
                        Decimal?lastAmt  = Env.ZERO;
                        for (int rank = 0; rank < respQtys.Length; rank++)
                        {
                            //get the quantity of first record in the sorded array
                            MRfQResponseLineQty qty = respQtys[rank];
                            if (!qty.IsActive() || qty.GetRanking() == 999)
                            {
                                continue;
                            }
                            Decimal?netAmt = qty.GetNetAmt();
                            if (netAmt == null)
                            {
                                qty.SetRanking(999);
                                log.Fine("  - Rank 999: " + qty);
                            }
                            else
                            {
                                if (lastAmt.Value.CompareTo(netAmt.Value) != 0)
                                {
                                    lastRank = rank + 1;
                                    lastAmt  = qty.GetNetAmt();
                                }
                                qty.SetRanking(lastRank);
                                log.Fine("  - Rank " + lastRank + ": " + qty);
                            }
                            qty.Save();
                            //
                            if (rank == 0)      //	Update RfQ
                            {
                                rfqQty.SetBestResponseAmt(qty.GetNetAmt());
                                rfqQty.Save();
                            }
                        }
                    }
                } //	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.Save();
                            break;
                        }
                    }
                }
                response.SetRanking(ranking);
                response.Save();
                log.Fine("- Response Ranking " + ranking + ": " + response);
                if (!rfq.IsQuoteSelectedLines())        //	no total selected winner if not all lines
                {
                    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.Save();
                log.Fine("- Response Winner: " + winner);
            }
        }
Пример #3
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            MRfQ rfq = new MRfQ(GetCtx(), _C_RfQ_ID, Get_TrxName());

            if (rfq.Get_ID() == 0)
            {
                throw new ArgumentException("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 ArgumentException("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 (_C_DocType_ID != 0)
                {
                    order.SetC_DocTypeTarget_ID(_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());
                //Added by Neha Thakur--To set Payment Method,Payment Rule and Payment Method(Button)
                if (bp.GetVA009_PO_PaymentMethod_ID() == 0)
                {
                    result = GetPaymentMethod(rfq.GetAD_Org_ID());
                    if (result != null && result.Tables[0].Rows.Count > 0)
                    {
                        order.SetVA009_PaymentMethod_ID(Util.GetValueOfInt(result.Tables[0].Rows[0]["VA009_PaymentMethod_ID"]));
                        order.SetPaymentMethod(Util.GetValueOfString(result.Tables[0].Rows[0]["VA009_PaymentBaseType"]));
                        order.SetPaymentRule(Util.GetValueOfString(result.Tables[0].Rows[0]["VA009_PaymentBaseType"]));
                    }
                }
                else
                {
                    order.SetVA009_PaymentMethod_ID(bp.GetVA009_PO_PaymentMethod_ID());
                    order.SetPaymentMethod(GetPaymentBaseType(bp.GetVA009_PO_PaymentMethod_ID()));
                    order.SetPaymentRule(PaymentBaseType);
                }
                if (response.GetDateWorkComplete() != null)
                {
                    order.SetDatePromised(response.GetDateWorkComplete());
                }
                else if (rfq.GetDateWorkComplete() != null)
                {
                    order.SetDatePromised(rfq.GetDateWorkComplete());
                }
                order.Save();
                //
                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());
                            Decimal?price = qty.GetNetAmt();
                            ol.SetPrice(price == null ? Env.ZERO : price.Value);
                            // Work done to set prices on purchase order and attributesetinstance from rfq line. Done by mohit asked by pradeep- 11 January 2019
                            MRfQLine Rfqline = new MRfQLine(GetCtx(), line.GetC_RfQLine_ID(), null);
                            ol.SetM_AttributeSetInstance_ID(Rfqline.GetM_AttributeSetInstance_ID());
                            ol.SetPriceActual(price);
                            ol.SetPriceEntered(price);
                            ol.SetPriceList(price);
                            ol.Save();
                        }
                    }
                }
                response.SetC_Order_ID(order.GetC_Order_ID());
                response.Save();
                return(order.GetDocumentNo());
            }


            //	Selected Winner on Line Level
            StringBuilder Orderno  = new StringBuilder();
            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    = 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);
                        // Adde by mohit to set selected document type on purchase order.- 11 january 2019
                        if (_C_DocType_ID != 0)
                        {
                            order.SetC_DocTypeTarget_ID(_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());
                        order.SetAD_Org_ID(rfq.GetAD_Org_ID());
                        //Added by Neha Thakur--To set Payment Method,Payment Rule and Payment Method(Button)
                        if (bp.GetVA009_PO_PaymentMethod_ID() == 0)
                        {
                            result = null;
                            result = GetPaymentMethod(rfq.GetAD_Org_ID());
                            if (result != null && result.Tables[0].Rows.Count > 0)
                            {
                                order.SetVA009_PaymentMethod_ID(Util.GetValueOfInt(result.Tables[0].Rows[0]["VA009_PaymentMethod_ID"]));
                                order.SetPaymentMethod(Util.GetValueOfString(result.Tables[0].Rows[0]["VA009_PaymentBaseType"]));
                                order.SetPaymentRule(Util.GetValueOfString(result.Tables[0].Rows[0]["VA009_PaymentBaseType"]));
                            }
                        }
                        else
                        {
                            order.SetVA009_PaymentMethod_ID(bp.GetVA009_PO_PaymentMethod_ID());
                            order.SetPaymentMethod(GetPaymentBaseType(bp.GetVA009_PO_PaymentMethod_ID()));
                            order.SetPaymentRule(PaymentBaseType);
                        }
                        order.Save();
                        noOrders++;
                        //AddLog(0, null, null, order.GetDocumentNo());
                        AddLog(0, DateTime.Now, 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());
                            Decimal?price = qty.GetNetAmt();
                            ol.SetPriceActual(price);
                            // Work done to set prices on purchase order and attributesetinstance from rfq line. Done by mohit asked by pradeep- 11 January 2019
                            MRfQLine Rfqline = new MRfQLine(GetCtx(), line.GetC_RfQLine_ID(), null);
                            ol.SetM_AttributeSetInstance_ID(Rfqline.GetM_AttributeSetInstance_ID());
                            ol.SetPriceActual(price);
                            ol.SetPriceEntered(price);
                            ol.SetPriceList(price);
                            ol.Save();
                        }
                    }   //	for all Qtys
                }       //	for all Response Lines
                if (order != null)
                {
                    //Check Orderno. Already existing
                    if (Orderno.Length > 0)
                    {
                        Orderno.Append(",");
                    }
                    Orderno.Append(order.GetDocumentNo());
                    response.SetC_Order_ID(order.GetC_Order_ID());
                    response.Save();
                }
            }
            // Show the message in RfQ after click Create Purchase Order button
            return(Msg.GetMsg(GetCtx(), "VIS_PurchaseOrder", "") + " " + Orderno);
        }