示例#1
0
        /// <summary>
        /// Process
        /// VFramwork.Process.SvrProcess#doIt()
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            log.Info("doIt - From_RfQ_ID=" + _From_RfQ_ID + ", To_RfQ_ID=" + p_To_RfQ_ID);
            //
            MRfQ to = new MRfQ(GetCtx(), p_To_RfQ_ID, Get_TrxName());

            if (to.Get_ID() == 0)
            {
                throw new ArgumentException("No To RfQ found");
            }
            MRfQ from = new MRfQ(GetCtx(), _From_RfQ_ID, Get_TrxName());

            if (from.Get_ID() == 0)
            {
                throw new ArgumentException("No From RfQ found");
            }

            //	Copy Lines
            int counter = 0;

            MRfQLine[] lines = from.GetLines();
            for (int i = 0; i < lines.Length; i++)
            {
                MRfQLine newLine = new MRfQLine(to);
                newLine.SetLine(lines[i].GetLine());
                newLine.SetDescription(lines[i].GetDescription());
                newLine.SetHelp(lines[i].GetHelp());
                newLine.SetM_Product_ID(lines[i].GetM_Product_ID());
                newLine.SetM_AttributeSetInstance_ID(lines[i].GetM_AttributeSetInstance_ID());
                //	newLine.setDateWorkStart();
                //	newLine.setDateWorkComplete();
                newLine.SetDeliveryDays(lines[i].GetDeliveryDays());
                newLine.Save();
                //	Copy Qtys
                MRfQLineQty[] qtys = lines[i].GetQtys();
                for (int j = 0; j < qtys.Length; j++)
                {
                    MRfQLineQty newQty = new MRfQLineQty(newLine);
                    newQty.SetC_UOM_ID(qtys[j].GetC_UOM_ID());
                    newQty.SetQty(qtys[j].GetQty());
                    newQty.SetIsOfferQty(qtys[j].IsOfferQty());
                    newQty.SetIsPurchaseQty(qtys[j].IsPurchaseQty());
                    newQty.SetMargin(qtys[j].GetMargin());
                    newQty.Save();
                }
                counter++;
            }   //	copy all lines
            return("# " + counter);
        }
示例#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);
            }
        }
        /// <summary>
        /// Process.
        /// A Sales Order is created for the entered Business Partner.
        /// A sales order line is created for each RfQ line quantity,
        /// where "Offer Quantity" is selected.
        /// If on the RfQ Line Quantity, an offer amount is entered (not 0),
        /// that price is used.
        /// If a magin is entered on RfQ Line Quantity, it overwrites the
        /// general margin.  The margin is the percentage added to the
        /// Best Response Amount.
        /// </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("doIt - " + rfq);

            if (rfq.GetC_BPartner_ID() == 0 || rfq.GetC_BPartner_Location_ID() == 0)
            {
                throw new Exception("No Business Partner/Location");
            }
            MBPartner bp = new MBPartner(GetCtx(), rfq.GetC_BPartner_ID(), Get_TrxName());

            MOrder order = new MOrder(GetCtx(), 0, Get_TrxName());

            order.SetIsSOTrx(true);
            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(rfq.GetC_BPartner_Location_ID());
            order.SetSalesRep_ID(rfq.GetSalesRep_ID());
            if (rfq.GetDateWorkComplete() != null)
            {
                order.SetDatePromised(rfq.GetDateWorkComplete());
            }
            order.Save();

            MRfQLine[] lines = rfq.GetLines();
            for (int i = 0; i < lines.Length; i++)
            {
                MRfQLine      line = lines[i];
                MRfQLineQty[] qtys = line.GetQtys();
                for (int j = 0; j < qtys.Length; j++)
                {
                    MRfQLineQty qty = qtys[j];
                    if (qty.IsActive() && qty.IsOfferQty())
                    {
                        MOrderLine ol = new MOrderLine(order);
                        ol.SetM_Product_ID(line.GetM_Product_ID(),
                                           qty.GetC_UOM_ID());
                        ol.SetDescription(line.GetDescription());
                        ol.SetQty(qty.GetQty());
                        //
                        Decimal price = qty.GetOfferAmt();
                        if (Env.Signum(price) == 0)
                        {
                            price = qty.GetBestResponseAmt();
                            if (Env.Signum(price) == 0)
                            {
                                price = Env.ZERO;
                                log.Warning(" - BestResponse=0 - " + qty);
                            }
                            else
                            {
                                Decimal margin = qty.GetMargin();
                                if (Env.Signum(margin) == 0)
                                {
                                    margin = rfq.GetMargin();
                                }
                                if (Env.Signum(margin) != 0)
                                {
                                    margin = Decimal.Add(margin, ONEHUNDRED);
                                    price  = Decimal.Round(Decimal.Divide(Decimal.Multiply(price, margin),
                                                                          ONEHUNDRED), 2, MidpointRounding.AwayFromZero);
                                }
                            }
                        }       //	price
                        ol.SetPrice(price);
                        ol.Save();
                    } //	Offer Qty
                }     //	All Qtys
            }         //	All Lines
            rfq.SetC_Order_ID(order.GetC_Order_ID());
            rfq.Save();
            return(order.GetDocumentNo());
        }
示例#4
0
        /// <summary>
        /// </summary>
        /// <param name="_ds"></param> dataset contains all the records according to selection criteria.
        /// <returns></returns> returns the final message.
        private string CreateRfQ(DataSet _ds)
        {
            MRfQ   rfq = null;
            int    Requisition_ID = 0, LineNo = 0;
            string message = "";

            for (int i = 0; i < _ds.Tables[0].Rows.Count; i++)
            {
                // If document is not consolidated
                if (!isConsolidate)
                {
                    if (rfq == null || Requisition_ID != Util.GetValueOfInt(_ds.Tables[0].Rows[i]["M_Requisition_ID"]))
                    {
                        LineNo         = 0;
                        Requisition_ID = Util.GetValueOfInt(_ds.Tables[0].Rows[i]["M_Requisition_ID"]);
                        rfq            = new MRfQ(GetCtx(), 0, Get_TrxName());
                        rfq.SetAD_Org_ID(AD_Org_ID);
                        rfq.SetName("Name");
                        rfq.SetSalesRep_ID(GetCtx().GetAD_User_ID());
                        rfq.SetC_RfQ_Topic_ID(RfQTopic_ID);
                        rfq.SetM_Requisition_ID(Requisition_ID);
                        rfq.SetDateWorkStart(System.DateTime.Now);
                        rfq.SetDateResponse(DateResponse);      // Added by Bharat on 15 Jan 2019 as asked by Puneet
                        if (Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["DateRequired"]) >= System.DateTime.Now)
                        {
                            rfq.SetDateWorkComplete(Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["DateRequired"]));
                        }
                        if (string.IsNullOrEmpty(RfQtype))
                        {
                            rfq.SetQuoteType("S");
                        }
                        else
                        {
                            rfq.SetQuoteType(RfQtype);
                        }
                        rfq.SetIsInvitedVendorsOnly(true);
                        rfq.SetIsQuoteAllQty(true);
                        rfq.SetIsRfQResponseAccepted(true);
                        rfq.SetC_Currency_ID(C_Currency_ID);
                        if (rfq.Save())
                        {
                            DB.ExecuteQuery("UPDATE C_Rfq SET Name='" + rfq.GetDocumentNo() + "' WHERE C_RfQ_ID= " + rfq.GetC_RfQ_ID(), null, Get_TrxName());
                            if (message == "")
                            {
                                message = Msg.GetMsg(GetCtx(), "RfQGeneratedSuccess") + " =" + rfq.GetDocumentNo();
                            }
                            else
                            {
                                message = message + "," + rfq.GetDocumentNo();
                            }
                        }
                        else
                        {
                            ValueNamePair vp = VLogger.RetrieveError();
                            if (vp != null)
                            {
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "RfQHeadNotSaved") + "- " + vp.Name);
                            }
                            else
                            {
                                Get_TrxName().Rollback();
                                return(Msg.GetMsg(GetCtx(), "RfQHeadNotSaved"));
                            }
                        }
                    }
                }
                // If document is consolidated
                else
                {
                    if (rfq == null)
                    {
                        rfq = new MRfQ(GetCtx(), 0, Get_TrxName());
                        rfq.SetAD_Org_ID(AD_Org_ID);
                        rfq.SetName("Name");
                        rfq.SetSalesRep_ID(GetCtx().GetAD_User_ID());
                        rfq.SetC_RfQ_Topic_ID(RfQTopic_ID);
                        rfq.SetDateWorkStart(System.DateTime.Now);
                        rfq.SetDateResponse(DateResponse);      // Added by Bharat on 15 Jan 2019 as asked by Puneet
                        if (Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["DateRequired"]) >= System.DateTime.Now)
                        {
                            rfq.SetDateWorkComplete(Util.GetValueOfDateTime(_ds.Tables[0].Rows[i]["DateRequired"]));
                        }
                        if (string.IsNullOrEmpty(RfQtype))
                        {
                            rfq.SetQuoteType("S");
                        }
                        else
                        {
                            rfq.SetQuoteType(RfQtype);
                        }
                        rfq.SetIsInvitedVendorsOnly(true);
                        rfq.SetIsQuoteAllQty(true);
                        rfq.SetIsRfQResponseAccepted(true);
                        rfq.SetC_Currency_ID(C_Currency_ID);
                        if (!rfq.Save())
                        {
                            ValueNamePair vp = VLogger.RetrieveError();
                            if (vp != null)
                            {
                                Get_TrxName().Rollback();
                                return("RFQ Not Saved - " + vp.Name);
                            }
                            else
                            {
                                Get_TrxName().Rollback();
                                return("RFQ Not Saved");
                            }
                        }
                        else
                        {
                            DB.ExecuteQuery("UPDATE C_Rfq SET Name='" + rfq.GetDocumentNo() + "' WHERE C_RfQ_ID= " + rfq.GetC_RfQ_ID(), null, Get_TrxName());
                        }
                        message = "RfQ Generated =" + rfq.GetDocumentNo();
                    }
                }
                LineNo = LineNo + 10;
                // Create RfQ line
                MRfQLine RfqLine = new MRfQLine(rfq);
                RfqLine.SetLine(LineNo);
                RfqLine.SetM_RequisitionLine_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["M_RequisitionLine_ID"]));
                RfqLine.SetM_Product_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["M_Product_ID"]));
                if (Util.GetValueOfInt(_ds.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]) > 0)
                {
                    RfqLine.SetM_AttributeSetInstance_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["M_AttributeSetInstance_ID"]));
                }
                RfqLine.SetDescription(Util.GetValueOfString(_ds.Tables[0].Rows[i]["Description"]));
                if (RfqLine.Save())
                {
                    // Create RfQ Qty
                    MRfQLineQty RfQLineQty = new MRfQLineQty(RfqLine);
                    RfQLineQty.SetC_UOM_ID(Util.GetValueOfInt(_ds.Tables[0].Rows[i]["C_UOM_ID"]));
                    RfQLineQty.SetQty(Util.GetValueOfDecimal(_ds.Tables[0].Rows[i]["Qty"]));
                    RfQLineQty.SetIsPurchaseQty(true);
                    RfQLineQty.SetIsRfQQty(true);
                    if (!RfQLineQty.Save())
                    {
                        ValueNamePair vp = VLogger.RetrieveError();
                        if (vp != null)
                        {
                            Get_TrxName().Rollback();
                            return(Msg.GetMsg(GetCtx(), "RfQLineQtyNotSaved") + "- " + vp.Name);
                        }
                        else
                        {
                            Get_TrxName().Rollback();
                            return(Msg.GetMsg(GetCtx(), "RfQLineQtyNotSaved"));
                        }
                    }
                }
                else
                {
                    ValueNamePair vp = VLogger.RetrieveError();
                    if (vp != null)
                    {
                        Get_TrxName().Rollback();
                        return(Msg.GetMsg(GetCtx(), "RfQLineNotSaved") + "- " + vp.Name);
                    }
                    else
                    {
                        Get_TrxName().Rollback();
                        return(Msg.GetMsg(GetCtx(), "RfQLineNotSaved"));
                    }
                }
            }

            return(message);
        }