use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class Doc_Order method loadLines.
// loadDocumentDetails
/**
* Load Invoice Line
* @param order order
* @return DocLine Array
*/
private DocLine[] loadLines(MOrder order) {
ArrayList<DocLine> list = new ArrayList<DocLine>();
MOrderLine[] lines = order.getLines();
for (int i = 0; i < lines.length; i++) {
MOrderLine line = lines[i];
DocLine docLine = new DocLine(line, this);
BigDecimal Qty = line.getQtyOrdered();
docLine.setQty(Qty, order.isSOTrx());
//
BigDecimal PriceActual = line.getPriceActual();
BigDecimal PriceCost = null;
if (// PO
getDocumentType().equals(DOCTYPE_POrder))
PriceCost = line.getPriceCost();
BigDecimal LineNetAmt = null;
if (PriceCost != null && PriceCost.signum() != 0)
LineNetAmt = Qty.multiply(PriceCost);
else
LineNetAmt = line.getLineNetAmt();
// DR
docLine.setAmount(LineNetAmt);
BigDecimal PriceList = line.getPriceList();
int C_Tax_ID = docLine.getC_Tax_ID();
// Correct included Tax
if (isTaxIncluded() && C_Tax_ID != 0) {
MTax tax = MTax.get(getCtx(), C_Tax_ID);
if (!tax.isZeroTax()) {
BigDecimal LineNetAmtTax = tax.calculateTax(LineNetAmt, true, getStdPrecision());
log.fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
LineNetAmt = LineNetAmt.subtract(LineNetAmtTax);
for (int t = 0; t < m_taxes.length; t++) {
if (m_taxes[t].getC_Tax_ID() == C_Tax_ID) {
m_taxes[t].addIncludedTax(LineNetAmtTax);
break;
}
}
BigDecimal PriceListTax = tax.calculateTax(PriceList, true, getStdPrecision());
PriceList = PriceList.subtract(PriceListTax);
}
}
// correct included Tax
docLine.setAmount(LineNetAmt, PriceList, Qty);
list.add(docLine);
}
// Return Array
DocLine[] dl = new DocLine[list.size()];
list.toArray(dl);
return dl;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class Doc_Order method getCommitments.
// updateProductPO
/**
* Get Commitments
* @param doc document
* @param maxQty Qty invoiced/matched
* @param C_InvoiceLine_ID invoice line
* @return commitments (order lines)
*/
protected static DocLine[] getCommitments(Doc doc, BigDecimal maxQty, int C_InvoiceLine_ID) {
int precision = -1;
//
ArrayList<DocLine> list = new ArrayList<DocLine>();
String sql = "SELECT * FROM C_OrderLine ol " + "WHERE EXISTS " + "(SELECT * FROM C_InvoiceLine il " + "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND il.C_InvoiceLine_ID=?)" + " OR EXISTS " + "(SELECT * FROM M_MatchPO po " + "WHERE po.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND po.C_InvoiceLine_ID=?)";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, C_InvoiceLine_ID);
pstmt.setInt(2, C_InvoiceLine_ID);
rs = pstmt.executeQuery();
while (rs.next()) {
if (maxQty.signum() == 0)
continue;
MOrderLine line = new MOrderLine(doc.getCtx(), rs, null);
DocLine docLine = new DocLine(line, doc);
// Currency
if (precision == -1) {
doc.setC_Currency_ID(docLine.getC_Currency_ID());
precision = MCurrency.getStdPrecision(doc.getCtx(), docLine.getC_Currency_ID());
}
// Qty
BigDecimal Qty = line.getQtyOrdered().max(maxQty);
docLine.setQty(Qty, false);
//
BigDecimal PriceActual = line.getPriceActual();
BigDecimal PriceCost = line.getPriceCost();
BigDecimal LineNetAmt = null;
if (PriceCost != null && PriceCost.signum() != 0)
LineNetAmt = Qty.multiply(PriceCost);
else if (Qty.equals(maxQty))
LineNetAmt = line.getLineNetAmt();
else
LineNetAmt = Qty.multiply(PriceActual);
maxQty = maxQty.subtract(Qty);
// DR
docLine.setAmount(LineNetAmt);
BigDecimal PriceList = line.getPriceList();
int C_Tax_ID = docLine.getC_Tax_ID();
// Correct included Tax
if (C_Tax_ID != 0 && line.getParent().isTaxIncluded()) {
MTax tax = MTax.get(doc.getCtx(), C_Tax_ID);
if (!tax.isZeroTax()) {
BigDecimal LineNetAmtTax = tax.calculateTax(LineNetAmt, true, precision);
s_log.fine("LineNetAmt=" + LineNetAmt + " - Tax=" + LineNetAmtTax);
LineNetAmt = LineNetAmt.subtract(LineNetAmtTax);
BigDecimal PriceListTax = tax.calculateTax(PriceList, true, precision);
PriceList = PriceList.subtract(PriceListTax);
}
}
// correct included Tax
docLine.setAmount(LineNetAmt, PriceList, Qty);
list.add(docLine);
}
} catch (Exception e) {
s_log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Return Array
DocLine[] dl = new DocLine[list.size()];
list.toArray(dl);
return dl;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class Doc_Order method loadRequisitions.
// loadLines
/**
* Load Requisitions
* @return requisition lines of Order
*/
private DocLine[] loadRequisitions() {
MOrder order = (MOrder) getPO();
MOrderLine[] oLines = order.getLines();
HashMap<Integer, BigDecimal> qtys = new HashMap<Integer, BigDecimal>();
for (int i = 0; i < oLines.length; i++) {
MOrderLine line = oLines[i];
qtys.put(new Integer(line.getC_OrderLine_ID()), line.getQtyOrdered());
}
//
ArrayList<DocLine> list = new ArrayList<DocLine>();
String sql = "SELECT * FROM M_RequisitionLine rl " + "WHERE EXISTS (SELECT * FROM C_Order o " + " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID) " + "WHERE ol.C_OrderLine_ID=rl.C_OrderLine_ID" + " AND o.C_Order_ID=?) " + "ORDER BY rl.C_OrderLine_ID";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, order.getC_Order_ID());
rs = pstmt.executeQuery();
while (rs.next()) {
MRequisitionLine line = new MRequisitionLine(getCtx(), rs, null);
DocLine docLine = new DocLine(line, this);
// Quantity - not more then OrderLine
// Issue: Split of Requisition to multiple POs & different price
Integer key = new Integer(line.getC_OrderLine_ID());
BigDecimal maxQty = qtys.get(key);
BigDecimal Qty = line.getQty().max(maxQty);
if (Qty.signum() == 0)
continue;
docLine.setQty(Qty, false);
qtys.put(key, maxQty.subtract(Qty));
//
BigDecimal PriceActual = line.getPriceActual();
BigDecimal LineNetAmt = line.getLineNetAmt();
if (line.getQty().compareTo(Qty) != 0)
LineNetAmt = PriceActual.multiply(Qty);
// DR
docLine.setAmount(LineNetAmt);
list.add(docLine);
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// Return Array
DocLine[] dls = new DocLine[list.size()];
list.toArray(dls);
return dls;
}
use of org.compiere.model.MOrderLine 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.MOrderLine in project adempiere by adempiere.
the class InventoryUtil method createInOut.
public static MInOut createInOut(MMDocument doc, String trxName) {
MOrder order;
if (MDocType.DOCBASETYPE_MaterialReceipt.equals(doc.DocBaseType)) {
order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_PurchaseOrder, doc.PODocumentNo).document;
} else if (MDocType.DOCBASETYPE_MaterialDelivery.equals(doc.DocBaseType)) {
order = (MOrder) doc.scenario.get(MDocType.DOCBASETYPE_SalesOrder, doc.PODocumentNo).document;
} else {
throw new IllegalArgumentException("DocBaseType not supported - " + doc);
}
// if (trxName != null && trxName.equals(order.get_TrxName()))
// throw new AdempiereException("Internal exception - not same trxName");
MInOut io = new MInOut(order, 0, doc.Date);
setGeneratedTag(io);
io.saveEx();
//
MInOutLine iol = null;
for (MOrderLine oline : order.getLines(true, null)) {
iol = new MInOutLine(io);
iol.setOrderLine(oline, 0, doc.Qty);
iol.setQty(doc.Qty);
iol.saveEx();
break;
}
//
doc.document = io;
processDocument(doc, MInOut.DOCACTION_Complete, MInOut.DOCSTATUS_Completed);
if (!Util.isEmpty(doc.ASI)) {
iol.load(trxName);
doc.scenario.registerASICode(doc.ASI, iol.getM_AttributeSetInstance_ID(), !io.isSOTrx());
}
return io;
}
Aggregations