use of org.compiere.model.MOrderLine 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;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class ARequest method actionPerformed.
// getZoomTargets
/**
* Listner
* @param e event
*/
public void actionPerformed(ActionEvent e) {
MQuery query = null;
if (e.getSource() == m_active) {
query = new MQuery("");
String where = "(" + m_where + ") AND Processed='N'";
query.addRestriction(where);
query.setRecordCount(0);
} else if (e.getSource() == m_all) {
query = new MQuery("");
query.addRestriction(m_where.toString());
query.setRecordCount(0);
} else if (e.getSource() == m_new) {
query = new MQuery("");
query.addRestriction("1=2");
query.setRecordCount(0);
}
//
// 232=all - 201=my
int AD_Window_ID = 232;
AWindow frame = new AWindow(m_graphicsconfig);
if (!frame.initWindow(AD_Window_ID, query))
return;
AEnv.addToWindowManager(frame);
// New - set Table/Record
if (e.getSource() == m_new) {
GridTab tab = frame.getAPanel().getCurrentTab();
tab.dataNew(false);
tab.setValue("AD_Table_ID", new Integer(m_AD_Table_ID));
tab.setValue("Record_ID", new Integer(m_Record_ID));
//
if (m_C_BPartner_ID != 0)
tab.setValue("C_BPartner_ID", new Integer(m_C_BPartner_ID));
//
if (m_AD_Table_ID == I_C_BPartner.Table_ID)
tab.setValue("C_BPartner_ID", new Integer(m_Record_ID));
else if (m_AD_Table_ID == I_AD_User.Table_ID)
tab.setValue("AD_User_ID", new Integer(m_Record_ID));
else //
if (m_AD_Table_ID == I_C_Project.Table_ID)
tab.setValue("C_Project_ID", new Integer(m_Record_ID));
else if (m_AD_Table_ID == I_A_Asset.Table_ID)
tab.setValue("A_Asset_ID", new Integer(m_Record_ID));
else //
if (m_AD_Table_ID == I_C_Order.Table_ID)
tab.setValue("C_Order_ID", new Integer(m_Record_ID));
else if (m_AD_Table_ID == I_C_Invoice.Table_ID)
tab.setValue("C_Invoice_ID", new Integer(m_Record_ID));
else //
if (m_AD_Table_ID == I_M_Product.Table_ID)
tab.setValue("M_Product_ID", new Integer(m_Record_ID));
else if (m_AD_Table_ID == I_C_Payment.Table_ID)
tab.setValue("C_Payment_ID", new Integer(m_Record_ID));
else //
if (m_AD_Table_ID == I_M_InOut.Table_ID)
tab.setValue("M_InOut_ID", new Integer(m_Record_ID));
else if (m_AD_Table_ID == I_M_RMA.Table_ID)
tab.setValue("M_RMA_ID", new Integer(m_Record_ID));
else //
if (m_AD_Table_ID == I_C_Campaign.Table_ID)
tab.setValue("C_Campaign_ID", new Integer(m_Record_ID));
else //
if (m_AD_Table_ID == I_R_Request.Table_ID)
tab.setValue(MRequest.COLUMNNAME_R_RequestRelated_ID, new Integer(m_Record_ID));
else // FR [2842165] - Order Ref link from SO line creating new request
if (m_AD_Table_ID == I_C_OrderLine.Table_ID) {
MOrderLine oLine = new MOrderLine(Env.getCtx(), m_Record_ID, null);
if (oLine != null) {
tab.setValue(MOrderLine.COLUMNNAME_C_Order_ID, new Integer(oLine.getC_Order_ID()));
}
}
}
AEnv.showCenterScreen(frame);
frame = null;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class MRPSchedule method schedule.
// doIt
private void schedule(MPPMRP mrp) {
if (!mrp.is_Changed())
return;
processRecords++;
if (MPPMRP.ORDERTYPE_Forecast.equals(mrp.getOrderType())) {
MForecastLine forecastLine = (MForecastLine) mrp.getM_ForecastLine();
if (forecastLine != null) {
forecastLine.setDatePromised(mrp.getDatePromised());
forecastLine.setSalesRep_ID(mrp.getPlanner_ID());
forecastLine.saveEx();
}
} else if (MPPMRP.ORDERTYPE_MaterialRequisition.equals(mrp.getOrderType())) {
MRequisition requisition = (MRequisition) mrp.getM_Requisition();
if (requisition != null) {
requisition.setDateDoc(mrp.getDateStartSchedule());
requisition.setDateRequired(mrp.getDatePromised());
requisition.setAD_User_ID(mrp.getPlanner_ID());
requisition.setPriorityRule(mrp.getPriority());
requisition.saveEx();
}
} else if (MPPMRP.ORDERTYPE_ManufacturingOrder.equals(mrp.getOrderType())) {
MPPOrder order = (MPPOrder) mrp.getPP_Order();
if (order != null) {
order.setDateStartSchedule(mrp.getDateStartSchedule());
order.setDateFinishSchedule(mrp.getDateFinishSchedule());
order.setDatePromised(mrp.getDatePromised());
order.setPlanner_ID(mrp.getPlanner_ID());
if (mrp.getPriority() != null)
order.setPriorityRule(mrp.getPriority());
order.setLine(lineNo);
order.saveEx();
}
} else if (MPPMRP.ORDERTYPE_DistributionOrder.equals(mrp.getOrderType())) {
MDDOrderLine orderLine = (MDDOrderLine) mrp.getDD_OrderLine();
if (orderLine != null) {
orderLine.setDateOrdered(mrp.getDateStartSchedule());
orderLine.setDatePromised(mrp.getDatePromised());
orderLine.saveEx();
MDDOrder order = orderLine.getParent();
order.setSalesRep_ID(mrp.getPlanner_ID());
order.setPriorityRule(mrp.getPriority());
order.saveEx();
}
} else if (MPPMRP.ORDERTYPE_SalesOrder.equals(mrp.getOrderType())) {
MOrderLine orderLine = (MOrderLine) mrp.getC_OrderLine();
if (orderLine != null) {
orderLine.setDateOrdered(mrp.getDateStartSchedule());
orderLine.setDatePromised(mrp.getDatePromised());
orderLine.saveEx();
MOrder order = orderLine.getParent();
order.setSalesRep_ID(mrp.getPlanner_ID());
order.setPriorityRule(mrp.getPriority());
order.saveEx();
}
} else if (MPPMRP.ORDERTYPE_PurchaseOrder.equals(mrp.getOrderType())) {
MOrderLine orderLine = (MOrderLine) mrp.getC_OrderLine();
if (orderLine != null) {
orderLine.setDateOrdered(mrp.getDateStartSchedule());
orderLine.setDatePromised(mrp.getDatePromised());
orderLine.saveEx();
MOrder order = orderLine.getParent();
order.setSalesRep_ID(mrp.getPlanner_ID());
order.setPriorityRule(mrp.getPriority());
order.saveEx();
}
}
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class WBOMDrop method cmd_saveOrder.
// cmd_save
/**
* Save to Order
* @param C_Order_ID id
* @return true if saved
*/
private boolean cmd_saveOrder(int C_Order_ID) {
log.config("C_Order_ID=" + C_Order_ID);
MOrder order = new MOrder(Env.getCtx(), C_Order_ID, null);
if (order.get_ID() == 0) {
log.log(Level.SEVERE, "Not found - C_Order_ID=" + C_Order_ID);
return false;
}
int lineCount = 0;
// for all bom lines
for (int i = 0; i < m_selectionList.size(); i++) {
if (isSelectionSelected(m_selectionList.get(i))) {
BigDecimal qty = m_qtyList.get(i).getValue();
int M_Product_ID = m_productList.get(i).intValue();
// Create Line
MOrderLine ol = new MOrderLine(order);
ol.setM_Product_ID(M_Product_ID, true);
ol.setQty(qty);
ol.setPrice();
ol.setTax();
if (ol.save())
lineCount++;
else
log.log(Level.SEVERE, "Line not saved");
}
// line selected
}
// for all bom lines
FDialog.info(-1, this, order.getDocumentInfo() + " " + Msg.translate(Env.getCtx(), "Inserted") + "=" + lineCount);
log.config("#" + lineCount);
return true;
}
Aggregations