use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class RequisitionPOCreate method newLine.
// closeOrder
/**
* New Order Line (different Product)
* @param rLine request line
* @throws Exception
*/
private void newLine(MRequisitionLine rLine) throws Exception {
if (m_orderLine != null) {
m_orderLine.saveEx();
}
m_orderLine = null;
MProduct product = MProduct.get(getCtx(), rLine.getM_Product_ID());
// Get Business Partner
int C_BPartner_ID = rLine.getC_BPartner_ID();
if (C_BPartner_ID != 0) {
;
} else if (rLine.getC_Charge_ID() != 0) {
MCharge charge = MCharge.get(getCtx(), rLine.getC_Charge_ID());
C_BPartner_ID = charge.getC_BPartner_ID();
if (C_BPartner_ID == 0) {
throw new AdempiereUserError("No Vendor for Charge " + charge.getName());
}
} else {
// Find Strategic Vendor for Product
// TODO: refactor
MProductPO[] ppos = MProductPO.getOfProduct(getCtx(), product.getM_Product_ID(), null);
for (int i = 0; i < ppos.length; i++) {
if (ppos[i].isCurrentVendor() && ppos[i].getC_BPartner_ID() != 0) {
C_BPartner_ID = ppos[i].getC_BPartner_ID();
break;
}
}
if (C_BPartner_ID == 0 && ppos.length > 0) {
C_BPartner_ID = ppos[0].getC_BPartner_ID();
}
if (C_BPartner_ID == 0) {
throw new NoVendorForProductException(product.getName());
}
}
if (!isGenerateForVendor(C_BPartner_ID)) {
log.info("Skip for partner " + C_BPartner_ID);
return;
}
// New Order - Different Vendor
if (m_order == null || m_order.getC_BPartner_ID() != C_BPartner_ID || m_order.getDatePromised().compareTo(rLine.getDateRequired()) != 0) {
newOrder(rLine, C_BPartner_ID);
}
// No Order Line
m_orderLine = new MOrderLine(m_order);
m_orderLine.setDatePromised(rLine.getDateRequired());
if (product != null) {
m_orderLine.setProduct(product);
m_orderLine.setM_AttributeSetInstance_ID(rLine.getM_AttributeSetInstance_ID());
} else {
m_orderLine.setC_Charge_ID(rLine.getC_Charge_ID());
m_orderLine.setPriceActual(rLine.getPriceActual());
}
m_orderLine.setAD_Org_ID(rLine.getAD_Org_ID());
// Prepare Save
m_M_Product_ID = rLine.getM_Product_ID();
m_M_AttributeSetInstance_ID = rLine.getM_AttributeSetInstance_ID();
m_orderLine.saveEx();
}
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 FreightModelValidator method modelChange.
/**
* @param po persistent object
* @param type TYPE_
* @return
* @throws Exception
*/
@Override
public String modelChange(PO po, int type) throws Exception {
//Calcualte Freigh for Sales Order Line
if (ModelValidator.TYPE_BEFORE_CHANGE == type) {
if (po instanceof MOrderLine) {
MOrderLine orderLine = (MOrderLine) po;
if (MOrder.DELIVERYVIARULE_Shipper.equals(orderLine.getParent().getDeliveryViaRule())) {
BigDecimal freightRate = getFreight(orderLine, null);
orderLine.setFreightAmt(freightRate.multiply(orderLine.getQtyOrdered()));
if (!MOrder.FREIGHTCOSTRULE_FreightIncluded.equals(orderLine.getParent().getFreightCostRule()) && freightRate.signum() != 0) {
BigDecimal price = orderLine.getPriceActual().add(freightRate);
orderLine.setPriceEntered(price);
orderLine.setPriceActual(price);
orderLine.setLineNetAmt();
}
}
}
//Calcualte Freigh for Disribution Order Line
if (po instanceof MDDOrderLine) {
MDDOrderLine orderLine = (MDDOrderLine) po;
if (MDDOrder.DELIVERYVIARULE_Shipper.equals(orderLine.getParent().getDeliveryViaRule()))
orderLine.setFreightAmt(getFreight(orderLine, null).multiply(orderLine.getQtyOrdered()));
}
//Calcualte Freigh for InOutBound Order Line
if (po instanceof MWMInOutBoundLine) {
MWMInOutBoundLine orderLine = (MWMInOutBoundLine) po;
if (MWMInOutBound.DELIVERYVIARULE_Shipper.equals(orderLine.getParent().getDeliveryViaRule()))
orderLine.setFreightAmt(getFreight(orderLine).multiply(orderLine.getMovementQty()));
}
}
return null;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class InOutGenerate method generate.
// doIt
/**
* Generate Shipments
* @param pstmt Order Query
* @return info
*/
private String generate(PreparedStatement pstmt) {
try {
ResultSet rs = pstmt.executeQuery();
while (// Order
rs.next()) {
MOrder order = new MOrder(getCtx(), rs, get_TrxName());
// New Header different Shipper, Shipment Location
if (!p_ConsolidateDocument || (m_shipment != null && (m_shipment.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() || m_shipment.getM_Shipper_ID() != order.getM_Shipper_ID())))
completeShipment();
log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule());
//
Timestamp minGuaranteeDate = m_movementDate;
boolean completeOrder = MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
// OrderLine WHERE
String where = " AND M_Warehouse_ID=" + p_M_Warehouse_ID;
if (p_DatePromised != null)
where += " AND (TRUNC(DatePromised)<=" + DB.TO_DATE(p_DatePromised, true) + " OR DatePromised IS NULL)";
// Exclude Auto Delivery if not Force
if (!MOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule()))
where += " AND (C_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE C_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))";
// Exclude Unconfirmed
if (!p_IsUnconfirmedInOut)
where += " AND NOT EXISTS (SELECT * FROM M_InOutLine iol" + " INNER JOIN M_InOut io ON (iol.M_InOut_ID=io.M_InOut_ID) " + "WHERE iol.C_OrderLine_ID=C_OrderLine.C_OrderLine_ID AND io.DocStatus IN ('IP','WC'))";
// Deadlock Prevention - Order by M_Product_ID
MOrderLine[] lines = order.getLines(where, "C_BPartner_Location_ID, M_Product_ID");
for (int i = 0; i < lines.length; i++) {
MOrderLine line = lines[i];
if (line.getM_Warehouse_ID() != p_M_Warehouse_ID)
continue;
log.fine("check: " + line);
BigDecimal onHand = Env.ZERO;
BigDecimal toDeliver = line.getQtyOrdered().subtract(line.getQtyDelivered());
MProduct product = line.getProduct();
// Nothing to Deliver
if (product != null && toDeliver.signum() == 0)
continue;
// or it's a charge - Bug#: 1603966
if (line.getC_Charge_ID() != 0 && toDeliver.signum() == 0)
continue;
// Check / adjust for confirmations
BigDecimal unconfirmedShippedQty = Env.ZERO;
if (p_IsUnconfirmedInOut && product != null && toDeliver.signum() != 0) {
String where2 = "EXISTS (SELECT * FROM M_InOut io WHERE io.M_InOut_ID=M_InOutLine.M_InOut_ID AND io.DocStatus IN ('IP','WC'))";
MInOutLine[] iols = MInOutLine.getOfOrderLine(getCtx(), line.getC_OrderLine_ID(), where2, null);
for (int j = 0; j < iols.length; j++) unconfirmedShippedQty = unconfirmedShippedQty.add(iols[j].getMovementQty());
String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty + " - ToDeliver=" + toDeliver + "->";
toDeliver = toDeliver.subtract(unconfirmedShippedQty);
logInfo += toDeliver;
if (toDeliver.signum() < 0) {
toDeliver = Env.ZERO;
logInfo += " (set to 0)";
}
// Adjust On Hand
onHand = onHand.subtract(unconfirmedShippedQty);
log.fine(logInfo);
}
// Comments & lines w/o product & services
if ((product == null || !product.isStocked()) && (// comments
line.getQtyOrdered().signum() == 0 || // lines w/o product
toDeliver.signum() != 0)) {
if (// printed later
!MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()))
createLine(order, line, toDeliver, null, false);
continue;
}
// Stored Product
String MMPolicy = product.getMMPolicy();
MStorage[] storages = getStorages(line.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
for (int j = 0; j < storages.length; j++) {
MStorage storage = storages[j];
onHand = onHand.add(storage.getQtyOnHand());
}
boolean fullLine = onHand.compareTo(toDeliver) >= 0 || toDeliver.signum() < 0;
// Complete Order
if (completeOrder && !fullLine) {
log.fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
completeOrder = false;
break;
} else // Complete Line
if (fullLine && MOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) {
log.fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + line);
//
createLine(order, line, toDeliver, storages, false);
} else // Availability
if (MOrder.DELIVERYRULE_Availability.equals(order.getDeliveryRule()) && (onHand.signum() > 0 || toDeliver.signum() < 0)) {
BigDecimal deliver = toDeliver;
if (deliver.compareTo(onHand) > 0)
deliver = onHand;
log.fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
//
createLine(order, line, deliver, storages, false);
} else // Force
if (MOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) {
BigDecimal deliver = toDeliver;
log.fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
//
createLine(order, line, deliver, storages, true);
} else // Manual
if (MOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule()))
log.fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + line);
else
log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
}
// Complete Order successful
if (completeOrder && MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) {
for (int i = 0; i < lines.length; i++) {
MOrderLine line = lines[i];
if (line.getM_Warehouse_ID() != p_M_Warehouse_ID)
continue;
MProduct product = line.getProduct();
BigDecimal toDeliver = line.getQtyOrdered().subtract(line.getQtyDelivered());
//
MStorage[] storages = null;
if (product != null && product.isStocked()) {
String MMPolicy = product.getMMPolicy();
storages = getStorages(line.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
}
//
createLine(order, line, toDeliver, storages, false);
}
}
m_line += 1000;
}
// while order
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, m_sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
completeShipment();
return "@Created@ = " + m_created;
}
Aggregations