use of org.compiere.model.MRfQResponseLineQty 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);
}
}
use of org.compiere.model.MRfQResponseLineQty in project adempiere by adempiere.
the class RfQServlet method updateResponse.
// doPost
/**
* Update Response
* @param request request
* @param rfqResponse response
* @return msg
*/
private String updateResponse(HttpServletRequest request, MRfQResponse rfqResponse) {
log.fine("updateResponse - " + rfqResponse);
String saveError = "RfQ NOT updated";
String msg = "RfQ updated";
// RfQ Response
rfqResponse.setName(WebUtil.getParameter(request, "Name"));
rfqResponse.setDescription(WebUtil.getParameter(request, "Description"));
rfqResponse.setHelp(WebUtil.getParameter(request, "Help"));
rfqResponse.setDateWorkStart(WebUtil.getParameterAsDate(request, "DateWorkStart"));
rfqResponse.setDateWorkComplete(WebUtil.getParameterAsDate(request, "DateWorkComplete"));
rfqResponse.setDeliveryDays(WebUtil.getParameterAsInt(request, "DeliveryDays"));
rfqResponse.setPrice(WebUtil.getParameterAsBD(request, "Price"));
rfqResponse.setIsSelfService(true);
rfqResponse.setDateResponse(new Timestamp(System.currentTimeMillis()));
// Check for Completeness
if (WebUtil.getParameterAsBoolean(request, "IsComplete")) {
String msgComplete = rfqResponse.checkComplete();
if (msgComplete != null && msgComplete.length() > 0)
msg = msgComplete;
}
if (!rfqResponse.save())
return saveError;
// RfQ Response Line
MRfQResponseLine[] lines = rfqResponse.getLines(false);
for (int i = 0; i < lines.length; i++) {
MRfQResponseLine line = lines[i];
if (!line.isActive())
continue;
String paraAdd = "_" + line.getC_RfQResponseLine_ID();
line.setDescription(WebUtil.getParameter(request, "Description" + paraAdd));
line.setHelp(WebUtil.getParameter(request, "Help" + paraAdd));
line.setDateWorkStart(WebUtil.getParameterAsDate(request, "DateWorkStart" + paraAdd));
line.setDateWorkComplete(WebUtil.getParameterAsDate(request, "DateWorkComplete" + paraAdd));
line.setDeliveryDays(WebUtil.getParameterAsInt(request, "DeliveryDays" + paraAdd));
line.setIsSelfService(true);
if (!line.save())
return saveError;
// RfQ Response Line Qty
MRfQResponseLineQty[] qtys = line.getQtys(true);
for (int j = 0; j < qtys.length; j++) {
MRfQResponseLineQty qty = qtys[j];
if (!qty.isActive())
continue;
paraAdd = "_" + qty.getC_RfQResponseLineQty_ID();
qty.setDiscount(WebUtil.getParameterAsBD(request, "Discount" + paraAdd));
qty.setPrice(WebUtil.getParameterAsBD(request, "Price" + paraAdd));
if (!qty.save())
return saveError;
}
}
log.fine("complete - " + rfqResponse);
return msg;
}
use of org.compiere.model.MRfQResponseLineQty 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;
}
Aggregations