use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class PromotionValidator method increasePromotionCounter.
private void increasePromotionCounter(MOrder order) {
MOrderLine[] lines = order.getLines(false, null);
String promotionCode = (String) order.get_Value("PromotionCode");
for (MOrderLine ol : lines) {
if (ol.getC_Charge_ID() > 0) {
Integer promotionID = (Integer) ol.get_Value("M_Promotion_ID");
if (promotionID != null && promotionID.intValue() > 0) {
int M_PromotionPreCondition_ID = findPromotionPreConditionId(order, promotionCode, promotionID);
if (M_PromotionPreCondition_ID > 0) {
String update = "UPDATE M_PromotionPreCondition SET PromotionCounter = PromotionCounter + 1 WHERE M_PromotionPreCondition_ID = ?";
DB.executeUpdate(update, M_PromotionPreCondition_ID, order.get_TrxName());
}
}
}
}
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class PromotionValidator method decreasePromotionCounter.
private void decreasePromotionCounter(MOrder order) {
MOrderLine[] lines = order.getLines(false, null);
String promotionCode = (String) order.get_Value("PromotionCode");
for (MOrderLine ol : lines) {
if (ol.getC_Charge_ID() > 0) {
Integer promotionID = (Integer) ol.get_Value("M_Promotion_ID");
if (promotionID != null && promotionID.intValue() > 0) {
int M_PromotionPreCondition_ID = findPromotionPreConditionId(order, promotionCode, promotionID);
if (M_PromotionPreCondition_ID > 0) {
String update = "UPDATE M_PromotionPreCondition SET PromotionCounter = PromotionCounter - 1 WHERE M_PromotionPreCondition_ID = ?";
DB.executeUpdate(update, M_PromotionPreCondition_ID, order.get_TrxName());
}
}
}
}
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class PromotionValidator method modelChange.
public String modelChange(PO po, int type) throws Exception {
if (po instanceof MOrderLine) {
if (type == TYPE_AFTER_DELETE) {
MOrderLine ol = (MOrderLine) po;
MOrder order = ol.getParent();
String promotionCode = (String) order.get_Value("PromotionCode");
if (ol.getC_Charge_ID() > 0) {
Integer promotionID = (Integer) ol.get_Value("M_Promotion_ID");
if (promotionID != null && promotionID.intValue() > 0) {
int M_PromotionPreCondition_ID = findPromotionPreConditionId(order, promotionCode, promotionID);
if (M_PromotionPreCondition_ID > 0) {
String update = "UPDATE M_PromotionPreCondition SET PromotionCounter = PromotionCounter - 1 WHERE M_PromotionPreCondition_ID = ?";
DB.executeUpdate(update, M_PromotionPreCondition_ID, order.get_TrxName());
}
}
}
}
}
return null;
}
use of org.compiere.model.MOrderLine in project adempiere by adempiere.
the class Doc_Order method getCommitmentsSales.
// getCommitmentRelease
/**
* Get Commitments Sales
* @param doc document
* @param maxQty Qty invoiced/matched
* @param C_OrderLine_ID invoice line
* @return commitments (order lines)
*/
protected static DocLine[] getCommitmentsSales(Doc doc, BigDecimal maxQty, int M_InOutLine_ID) {
int precision = -1;
//
ArrayList<DocLine> list = new ArrayList<DocLine>();
String sql = "SELECT * FROM C_OrderLine ol " + "WHERE EXISTS " + "(SELECT * FROM M_InOutLine il " + "WHERE il.C_OrderLine_ID=ol.C_OrderLine_ID" + " AND il.M_InOutLine_ID=?)";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_InOutLine_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_MatchPO method loadDocumentDetails.
/**
* Load Specific Document Details
* @return error message or null
*/
protected String loadDocumentDetails() {
setC_Currency_ID(Doc.NO_CURRENCY);
MMatchPO matchPO = (MMatchPO) getPO();
setDateDoc(matchPO.getDateTrx());
//
m_M_AttributeSetInstance_ID = matchPO.getM_AttributeSetInstance_ID();
setQty(matchPO.getQty());
//
m_C_OrderLine_ID = matchPO.getC_OrderLine_ID();
m_oLine = new MOrderLine(getCtx(), m_C_OrderLine_ID, getTrxName());
//
m_M_InOutLine_ID = matchPO.getM_InOutLine_ID();
m_ioLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
m_C_InvoiceLine_ID = matchPO.getC_InvoiceLine_ID();
//
m_pc = new ProductCost(Env.getCtx(), getM_Product_ID(), m_M_AttributeSetInstance_ID, getTrxName());
m_pc.setQty(getQty());
return null;
}
Aggregations