Search in sources :

Example 26 with MOrderLine

use of org.compiere.model.MOrderLine in project adempiere by adempiere.

the class CPOS method configureBPartner.

/**
	 * 	Set BPartner, update price list and locations
	 *  Configuration of Business Partner has priority over POS configuration
	 *	@param p_C_BPartner_ID id
	 */
/**
	 * set BPartner and save
	 */
public void configureBPartner(int partnerId) {
    //	Valid if has a Order
    if (isCompleted() || isVoided())
        return;
    log.fine("CPOS.setC_BPartner_ID=" + partnerId);
    boolean isSamePOSPartner = false;
    //	Validate BPartner
    if (partnerId == 0) {
        isSamePOSPartner = true;
        partnerId = entityPOS.getC_BPartnerCashTrx_ID();
    }
    //	Get BPartner
    partner = MBPartner.get(ctx, partnerId);
    if (partner == null || partner.get_ID() == 0) {
        throw new AdempierePOSException("POS.NoBPartnerForOrder");
    } else {
        log.info("CPOS.SetC_BPartner_ID -" + partner);
        currentOrder.setBPartner(partner);
        //	
        MBPartnerLocation[] partnerLocations = partner.getLocations(true);
        if (partnerLocations.length > 0) {
            for (MBPartnerLocation partnerLocation : partnerLocations) {
                if (partnerLocation.isBillTo())
                    currentOrder.setBill_Location_ID(partnerLocation.getC_BPartner_Location_ID());
                if (partnerLocation.isShipTo())
                    currentOrder.setShip_Location_ID(partnerLocation.getC_BPartner_Location_ID());
            }
        }
        //	Validate Same BPartner
        if (isSamePOSPartner) {
            if (currentOrder.getPaymentRule() == null)
                currentOrder.setPaymentRule(MOrder.PAYMENTRULE_Cash);
        }
        //	Set Sales Representative
        currentOrder.setSalesRep_ID(entityPOS.getSalesRep_ID());
        //	Save Header
        currentOrder.saveEx();
        //	Load Price List Version
        MPriceListVersion priceListVersion = loadPriceListVersion(currentOrder.getM_PriceList_ID());
        MProductPrice[] productPrices = priceListVersion.getProductPrice("AND EXISTS(" + "SELECT 1 " + "FROM C_OrderLine ol " + "WHERE ol.C_Order_ID = " + currentOrder.getC_Order_ID() + " " + "AND ol.M_Product_ID = M_ProductPrice.M_Product_ID)");
        //	Update Lines
        MOrderLine[] lines = currentOrder.getLines();
        //	Delete if not exist in price list
        for (MOrderLine line : lines) {
            //	Verify if exist
            if (existInPriceList(line.getM_Product_ID(), productPrices)) {
                line.setC_BPartner_ID(partner.getC_BPartner_ID());
                line.setC_BPartner_Location_ID(currentOrder.getC_BPartner_Location_ID());
                line.setPrice();
                line.setTax();
                line.saveEx();
            } else {
                line.deleteEx(true);
            }
        }
    }
}
Also used : AdempierePOSException(org.adempiere.pos.AdempierePOSException) MPriceListVersion(org.compiere.model.MPriceListVersion) MOrderLine(org.compiere.model.MOrderLine) MBPartnerLocation(org.compiere.model.MBPartnerLocation) MProductPrice(org.compiere.model.MProductPrice)

Example 27 with MOrderLine

use of org.compiere.model.MOrderLine in project adempiere by adempiere.

the class CPOS method addOrUpdateLine.

/**
	 * Create new Line
	 * @param product
	 * @param qtyOrdered
	 * @param productPricing
     * @return
     */
public MOrderLine addOrUpdateLine(MProduct product, BigDecimal qtyOrdered, MProductPricing productPricing) {
    //	Valid Complete
    if (!isDrafted())
        return null;
    // catch Exceptions at order.getLines()
    MOrderLine[] lines = currentOrder.getLines(true, "Line");
    for (MOrderLine line : lines) {
        if (line.getM_Product_ID() == product.getM_Product_ID()) {
            //increase qty
            setOrderLineId(line.getC_OrderLine_ID());
            BigDecimal currentPrice = line.getPriceEntered();
            BigDecimal currentQty = line.getQtyEntered();
            BigDecimal totalQty = currentQty.add(qtyOrdered);
            //	Set or Add Qty
            line.setQty(isAddQty() ? totalQty : qtyOrdered);
            //	sets List/limit
            line.setPrice(currentPrice);
            line.saveEx();
            return line;
        }
    }
    //create new line
    MOrderLine line = new MOrderLine(currentOrder);
    line.setProduct(product);
    line.setQty(qtyOrdered);
    //	
    //	sets List/limit
    line.setPrice();
    if (productPricing.getPriceStd().signum() > 0) {
        line.setPriceLimit(productPricing.getPriceLimit());
        line.setPrice(productPricing.getPriceStd());
        line.setPriceList(productPricing.getPriceList());
        setPriceLimit(productPricing.getPriceLimit());
        //setPrice(productPricing.getPriceStd());
        setPriceList(productPricing.getPriceList());
        BigDecimal percentageDiscount = line.getDiscount();
        setDiscountPercentage(percentageDiscount);
    }
    //	Save Line
    setOrderLineId(line.getC_OrderLine_ID());
    line.saveEx();
    return line;
}
Also used : MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 28 with MOrderLine

use of org.compiere.model.MOrderLine in project adempiere by adempiere.

the class CPOS method updateLine.

/**
	 * Update Line
	 * @param orderLineId
	 * @param qtyOrdered
	 * @param priceLimit
	 * @param priceEntered
	 * @param priceList
     * @param discountPercentage
	 * @return
     */
public BigDecimal[] updateLine(int orderLineId, BigDecimal qtyOrdered, BigDecimal priceLimit, BigDecimal priceEntered, BigDecimal priceList, BigDecimal discountPercentage) {
    //	Valid if has a Order
    if (!isDrafted())
        return null;
    //	
    MOrderLine[] orderLines = currentOrder.getLines("AND C_OrderLine_ID = " + orderLineId, "Line");
    BigDecimal lineNetAmt = Env.ZERO;
    BigDecimal taxRate = Env.ZERO;
    BigDecimal grandTotal = Env.ZERO;
    //	Search Line
    for (MOrderLine orderLine : orderLines) {
        //	Valid No changes
        if (qtyOrdered.compareTo(orderLine.getQtyOrdered()) == 0 && priceEntered.compareTo(orderLine.getPriceEntered()) == 0 && discountPercentage.compareTo(orderLine.getDiscount()) == 0) {
            return null;
        }
        if (discountPercentage.compareTo(orderLine.getDiscount()) != 0) {
            BigDecimal discountAmount = orderLine.getPriceList().multiply(discountPercentage.divide(Env.ONEHUNDRED));
            priceEntered = orderLine.getPriceList().subtract(discountAmount);
        }
        orderLine.setPrice(priceEntered);
        orderLine.setQty(qtyOrdered);
        orderLine.setTax();
        orderLine.saveEx();
        //	Set Values for Grand Total
        lineNetAmt = orderLine.getLineNetAmt();
        taxRate = MTax.get(ctx, orderLine.getC_Tax_ID()).getRate();
        if (taxRate == null) {
            taxRate = Env.ZERO;
        } else {
            taxRate = taxRate.divide(Env.ONEHUNDRED);
        }
        //	Calculate Total
        grandTotal = lineNetAmt.add(lineNetAmt.multiply(taxRate));
    }
    //	Return Value
    return new BigDecimal[] { lineNetAmt, taxRate, grandTotal };
}
Also used : MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 29 with MOrderLine

use of org.compiere.model.MOrderLine in project adempiere by adempiere.

the class AbstractMakeToOrder method createOrder.

public MOrder createOrder() {
    MOrder order = new MOrder(getCtx(), 0, trxName);
    order.setAD_Org_ID(AD_Org_ID);
    order.setDateOrdered(today);
    order.setDatePromised(promisedDeta);
    order.setIsSOTrx(true);
    order.setC_DocTypeTarget_ID(C_DocType_ID);
    order.setC_BPartner_ID(C_BPartner_ID);
    order.setAD_User_ID(AD_User_ID);
    order.setM_Warehouse_ID(M_Warehouse_ID);
    order.setDocStatus(MOrder.STATUS_InProgress);
    order.setDocAction(MOrder.DOCACTION_Complete);
    order.saveEx();
    oline = new MOrderLine(order);
    oline.setM_Product_ID(product.get_ID());
    oline.setQty(new BigDecimal(10));
    oline.saveEx();
    order.processIt(MOrder.DOCACTION_Complete);
    return order;
}
Also used : MOrder(org.compiere.model.MOrder) MOrderLine(org.compiere.model.MOrderLine) BigDecimal(java.math.BigDecimal)

Example 30 with MOrderLine

use of org.compiere.model.MOrderLine in project adempiere by adempiere.

the class SalesMgmtValidator method modelChange.

//	initialize
/**
     *	Model Change of a monitored Table.
     *	Called after PO.beforeSave/PO.beforeDelete
     *	when you called addModelChange for the table
     *	@param po persistent object
     *	@param type TYPE_
     *	@return error message or null
     *	@exception Exception if the recipient wishes the change to be not accept.
     */
public String modelChange(PO po, int type) throws Exception {
    log.info(po.get_TableName() + " Type: " + type);
    if (po.get_TableName().equals(MOrder.Table_Name) && (type == ModelValidator.TYPE_AFTER_NEW || type == ModelValidator.TYPE_AFTER_CHANGE)) {
        if (po == null)
            return null;
        MOrder order = (MOrder) po;
        syncOpportunity(order);
    }
    if (po.get_TableName().equals(MOrderLine.Table_Name) && (type == ModelValidator.TYPE_AFTER_NEW || type == ModelValidator.TYPE_AFTER_CHANGE)) {
        if (po == null)
            return null;
        MOrderLine line = (MOrderLine) po;
        MOrder order = (MOrder) line.getC_Order();
        syncOpportunity(order);
    }
    return null;
}
Also used : MOrderLine(org.compiere.model.MOrderLine)

Aggregations

MOrderLine (org.compiere.model.MOrderLine)87 BigDecimal (java.math.BigDecimal)44 MOrder (org.compiere.model.MOrder)42 MInOutLine (org.compiere.model.MInOutLine)16 MProduct (org.compiere.model.MProduct)15 MBPartner (org.compiere.model.MBPartner)14 MInOut (org.compiere.model.MInOut)11 ResultSet (java.sql.ResultSet)10 ArrayList (java.util.ArrayList)8 Query (org.compiere.model.Query)8 PreparedStatement (java.sql.PreparedStatement)7 MInvoice (org.compiere.model.MInvoice)7 MInvoiceLine (org.compiere.model.MInvoiceLine)7 AdempiereException (org.adempiere.exceptions.AdempiereException)6 SQLException (java.sql.SQLException)5 MLocator (org.compiere.model.MLocator)5 Timestamp (java.sql.Timestamp)4 MRMALine (org.compiere.model.MRMALine)4 MBPartnerLocation (org.compiere.model.MBPartnerLocation)3 MDocType (org.compiere.model.MDocType)3