/// <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); }
/// <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()); }