Search in sources :

Example 66 with MOrderLine

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());
                }
            }
        }
    }
}
Also used : MOrderLine(org.compiere.model.MOrderLine)

Example 67 with MOrderLine

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());
                }
            }
        }
    }
}
Also used : MOrderLine(org.compiere.model.MOrderLine)

Example 68 with MOrderLine

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;
}
Also used : MOrder(org.compiere.model.MOrder) MOrderLine(org.compiere.model.MOrderLine)

Example 69 with MOrderLine

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;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MTax(org.compiere.model.MTax) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal) SQLException(java.sql.SQLException)

Example 70 with MOrderLine

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;
}
Also used : ProductCost(org.compiere.model.ProductCost) MMatchPO(org.compiere.model.MMatchPO) MInOutLine(org.compiere.model.MInOutLine) MOrderLine(org.compiere.model.MOrderLine)

Aggregations

MOrderLine (org.compiere.model.MOrderLine)74 MOrder (org.compiere.model.MOrder)37 BigDecimal (java.math.BigDecimal)35 MInOutLine (org.compiere.model.MInOutLine)15 MProduct (org.compiere.model.MProduct)12 MBPartner (org.compiere.model.MBPartner)11 MInOut (org.compiere.model.MInOut)9 ResultSet (java.sql.ResultSet)8 ArrayList (java.util.ArrayList)8 Query (org.compiere.model.Query)8 PreparedStatement (java.sql.PreparedStatement)6 MInvoice (org.compiere.model.MInvoice)6 MInvoiceLine (org.compiere.model.MInvoiceLine)6 AdempiereException (org.adempiere.exceptions.AdempiereException)5 MLocator (org.compiere.model.MLocator)5 SQLException (java.sql.SQLException)4 Timestamp (java.sql.Timestamp)4 MRMALine (org.compiere.model.MRMALine)4 MDocType (org.compiere.model.MDocType)3 MMatchPO (org.compiere.model.MMatchPO)3