use of org.compiere.model.MRfQLine in project adempiere by adempiere.
the class RfQCreateSO method doIt.
// prepare
/**
* 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.
* @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);
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 (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(rfq.getC_BPartner_Location_ID());
order.setSalesRep_ID(rfq.getSalesRep_ID());
if (rfq.getDateWorkComplete() != null)
order.setDatePromised(rfq.getDateWorkComplete());
order.saveEx();
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());
//
BigDecimal price = qty.getOfferAmt();
if (price == null || price.signum() == 0) {
price = qty.getBestResponseAmt();
if (price == null || price.signum() == 0) {
price = Env.ZERO;
log.warning(" - BestResponse=0 - " + qty);
} else {
BigDecimal margin = qty.getMargin();
if (margin == null || margin.signum() == 0)
margin = rfq.getMargin();
if (margin != null && margin.signum() != 0) {
margin = margin.add(ONEHUNDRED);
price = price.multiply(margin).divide(ONEHUNDRED, 2, BigDecimal.ROUND_HALF_UP);
}
}
}
// price
ol.setPrice(price);
ol.saveEx();
}
// Offer Qty
}
// All Qtys
}
// All Lines
//
rfq.setC_Order_ID(order.getC_Order_ID());
rfq.saveEx();
return order.getDocumentNo();
}
use of org.compiere.model.MRfQLine 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.MRfQLine in project adempiere by adempiere.
the class RfQCopyLines method doIt.
// prepare
/**
* Process
* @see org.compiere.process.SvrProcess#doIt()
* @return message
*/
protected String doIt() throws Exception {
log.info("doIt - From_RfQ_ID=" + p_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 IllegalArgumentException("No To RfQ found");
MRfQ from = new MRfQ(getCtx(), p_From_RfQ_ID, get_TrxName());
if (from.get_ID() == 0)
throw new IllegalArgumentException("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.saveEx();
// 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.saveEx();
}
counter++;
}
//
return "# " + counter;
}
use of org.compiere.model.MRfQLine in project adempiere by adempiere.
the class CreateRfQAction method createRfQLine.
private void createRfQLine(int rfqId, DefaultMutableTreeNode node) {
BOMLineWrapper sourceLine = (BOMLineWrapper) node.getUserObject();
BigDecimal qtyReq = reasoner.getSumQtyRequired(sourceLine);
// No requirement qty
if (qtyReq.compareTo(BigDecimal.ZERO) <= 0) {
return;
}
MRfQ rfq = new MRfQ(Env.getCtx(), rfqId, null);
MRfQLine targetLine = new MRfQLine(Env.getCtx(), 0, null);
targetLine.setC_RfQ_ID(rfqId);
targetLine.setLine(lineCount(rfqId) + 1);
targetLine.setM_AttributeSetInstance_ID(sourceLine.getM_AttributeSetInstance_ID());
targetLine.setM_Product_ID(sourceLine.getM_Product_ID());
targetLine.setDateWorkStart(rfq.getDateWorkStart());
targetLine.setDateWorkComplete(rfq.getDateWorkComplete());
savePO(targetLine);
if (!successful()) {
return;
}
MRfQLineQty lineQty = new MRfQLineQty(Env.getCtx(), 0, null);
//lineQty.setQty(reasoner.calculateRequiredProducts(sourceLine));
lineQty.setQty(qtyReq);
lineQty.setC_UOM_ID(sourceLine.getC_UOM_ID());
lineQty.setC_RfQLine_ID(targetLine.get_ID());
lineQty.setIsRfQQty(true);
lineQty.setIsPurchaseQty(true);
savePO(lineQty);
}
Aggregations