Search in sources :

Example 6 with MProductPrice

use of org.compiere.model.MProductPrice 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 7 with MProductPrice

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

the class InventoryUtil method getCreateProductPrice.

public static MProductPrice getCreateProductPrice(String ctxPriceList, int M_Product_ID, int price) {
    Properties ctx = Env.getCtx();
    int M_PriceList_ID = Env.getContextAsInt(ctx, ctxPriceList);
    MPriceList pl = MPriceList.get(ctx, M_PriceList_ID, null);
    MPriceListVersion plv = pl.getPriceListVersion(null);
    //
    BigDecimal priceBD = BigDecimal.valueOf(price);
    MProductPrice pp = MProductPrice.get(ctx, plv.get_ID(), M_Product_ID, null);
    if (pp == null) {
        pp = new MProductPrice(plv, M_Product_ID, priceBD, priceBD, priceBD);
    }
    pp.setPrices(priceBD, priceBD, priceBD);
    pp.saveEx();
    return pp;
}
Also used : MPriceListVersion(org.compiere.model.MPriceListVersion) MPriceList(org.compiere.model.MPriceList) Properties(java.util.Properties) BigDecimal(java.math.BigDecimal) MProductPrice(org.compiere.model.MProductPrice)

Example 8 with MProductPrice

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

the class WAttributeGrid method addProduct.

//	getGridElement
/**
	 * 	Add Product
	 *	@param element panel
	 *	@param product product
	 */
private void addProduct(Panel element, MProduct product) {
    int M_Product_ID = product.getM_Product_ID();
    Vbox pe = new Vbox();
    pe.setStyle("border-width: thin; border-color: blue;");
    //	Product Value - Price
    pe.appendChild(new Label(product.getValue()));
    String formatted = "";
    if (m_M_PriceList_Version_ID != 0) {
        MProductPrice pp = MProductPrice.get(Env.getCtx(), m_M_PriceList_Version_ID, M_Product_ID, null);
        if (pp != null) {
            BigDecimal price = pp.getPriceStd();
            formatted = m_price.format(price);
        } else
            formatted = "-";
    }
    pe.appendChild(new Label(formatted));
    //	Product Name - Qty
    pe.appendChild(new Label(product.getName()));
    formatted = "";
    if (m_M_Warehouse_ID != 0) {
        BigDecimal qty = MStorage.getQtyAvailable(m_M_Warehouse_ID, M_Product_ID, 0, null);
        if (qty == null)
            formatted = "-";
        else
            formatted = m_qty.format(qty);
    }
    pe.appendChild(new Label(formatted));
    //
    element.appendChild(pe);
}
Also used : Label(org.adempiere.webui.component.Label) Vbox(org.zkoss.zul.Vbox) BigDecimal(java.math.BigDecimal) MProductPrice(org.compiere.model.MProductPrice)

Example 9 with MProductPrice

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

the class CopyProduct method doIt.

@Override
protected String doIt() throws Exception {
    int toMProductID = getRecord_ID();
    log.info("From M_Product_ID=" + m_copyFromId + " to " + toMProductID);
    if (toMProductID == 0)
        throw new IllegalArgumentException("Target M_Product_ID == 0");
    if (m_copyFromId == 0)
        throw new IllegalArgumentException("Source M_Product_ID == 0");
    // Get product price from the source product
    List<MProductPrice> prices = new Query(getCtx(), MProductPrice.Table_Name, "M_Product_ID=?", get_TrxName()).setParameters(new Object[] { m_copyFromId }).setOnlyActiveRecords(true).list();
    // Copy prices
    MProductPrice priceSrc;
    MProductPrice priceDst;
    for (Iterator<MProductPrice> it = prices.iterator(); it.hasNext(); ) {
        priceSrc = it.next();
        priceDst = new MProductPrice(getCtx(), 0, get_TrxName());
        priceDst.setM_Product_ID(toMProductID);
        priceDst.setM_PriceList_Version_ID(priceSrc.getM_PriceList_Version_ID());
        priceDst.setPrices(priceSrc.getPriceList(), priceSrc.getPriceStd(), priceSrc.getPriceLimit());
        priceDst.saveEx(get_TrxName());
    }
    int count = prices.size();
    // Copy substitutes
    List<X_M_Substitute> subs = new Query(getCtx(), X_M_Substitute.Table_Name, "M_Product_ID=? and NOT substitute_ID=?", get_TrxName()).setParameters(new Object[] { m_copyFromId, toMProductID }).setOnlyActiveRecords(true).list();
    X_M_Substitute subSrc;
    X_M_Substitute subDst;
    for (Iterator<X_M_Substitute> it = subs.iterator(); it.hasNext(); ) {
        subSrc = it.next();
        subDst = new X_M_Substitute(getCtx(), 0, get_TrxName());
        subDst.setM_Product_ID(toMProductID);
        subDst.setSubstitute_ID(subSrc.getSubstitute_ID());
        subDst.setName(subSrc.getName());
        subDst.setDescription(subSrc.getDescription());
        subDst.saveEx(get_TrxName());
    }
    count += subs.size();
    // Copy related
    List<X_M_RelatedProduct> related = new Query(getCtx(), X_M_RelatedProduct.Table_Name, "M_Product_ID=? and NOT relatedProduct_ID=?", get_TrxName()).setParameters(new Object[] { m_copyFromId, toMProductID }).setOnlyActiveRecords(true).list();
    X_M_RelatedProduct relatedSrc;
    X_M_RelatedProduct relatedDst;
    for (Iterator<X_M_RelatedProduct> it = related.iterator(); it.hasNext(); ) {
        relatedSrc = it.next();
        relatedDst = new X_M_RelatedProduct(getCtx(), 0, get_TrxName());
        relatedDst.setM_Product_ID(toMProductID);
        relatedDst.setRelatedProduct_ID(relatedSrc.getRelatedProduct_ID());
        relatedDst.setRelatedProductType(relatedSrc.getRelatedProductType());
        relatedDst.setName(relatedSrc.getName());
        relatedDst.setDescription(relatedSrc.getDescription());
        relatedDst.saveEx(get_TrxName());
    }
    count += related.size();
    // Copy replenish
    List<X_M_Replenish> replenish = new Query(getCtx(), X_M_Replenish.Table_Name, "M_Product_ID=?", get_TrxName()).setParameters(new Object[] { m_copyFromId }).setOnlyActiveRecords(true).list();
    X_M_Replenish replenishSrc;
    X_M_Replenish replenishDst;
    for (Iterator<X_M_Replenish> it = replenish.iterator(); it.hasNext(); ) {
        replenishSrc = it.next();
        replenishDst = new X_M_Replenish(getCtx(), 0, get_TrxName());
        replenishDst.setM_Product_ID(toMProductID);
        replenishDst.setM_Warehouse_ID(replenishSrc.getM_Warehouse_ID());
        replenishDst.setM_WarehouseSource_ID(replenishSrc.getM_WarehouseSource_ID());
        replenishDst.setReplenishType(replenishSrc.getReplenishType());
        replenishDst.setM_Locator_ID(replenishSrc.getM_Locator_ID());
        replenishDst.setLevel_Min(replenishSrc.getLevel_Min());
        replenishDst.setLevel_Max(replenishSrc.getLevel_Max());
        replenishDst.saveEx(get_TrxName());
    }
    count += replenish.size();
    // Don't copy purchasing since it demands a unique vendor product no
    /*
		List<MProductPO> poList = new Query(getCtx(), MProductPO.Table_Name, "M_Product_ID=? AND Discontinued='N'", get_TrxName())
									.setParameters(new Object[]{m_copyFromId})
									.setOnlyActiveRecords(true)
									.list();
		MProductPO poSrc;
		MProductPO poDst;
		for (Iterator<MProductPO> it = poList.iterator(); it.hasNext();) {
			poSrc = it.next();
			poDst = new MProductPO(getCtx(), 0, get_TrxName());
			poDst.setM_Product_ID(toMProductID);
			poDst.setC_BPartner_ID(poSrc.getC_BPartner_ID());
			poDst.setC_Currency_ID(poSrc.getC_Currency_ID());
			poDst.setC_UOM_ID(poSrc.getC_UOM_ID());
			poDst.setCostPerOrder(poSrc.getCostPerOrder());
			poDst.setDeliveryTime_Actual(poSrc.getDeliveryTime_Actual());
			poDst.setDeliveryTime_Promised(poSrc.getDeliveryTime_Promised());
			poDst.setIsCurrentVendor(poSrc.isCurrentVendor());
			poDst.setManufacturer(poSrc.getManufacturer());
			poDst.setOrder_Min(poSrc.getOrder_Min());
			poDst.setOrder_Pack(poSrc.getOrder_Pack());
			poDst.setPriceEffective(poSrc.getPriceEffective());
			poDst.setPriceLastInv(poSrc.getPriceLastInv());
			poDst.setPriceLastPO(poSrc.getPriceLastPO());
			poDst.setPriceList(poSrc.getPriceList());
			poDst.setPricePO(poSrc.getPricePO());
			poDst.setQualityRating(poSrc.getQualityRating());
			poDst.setRoyaltyAmt(poSrc.getRoyaltyAmt());
			// Don't set vendor product no or UPC since that's likely to be different
			poDst.setVendorCategory(poSrc.getVendorCategory());
			poDst.saveEx(get_TrxName()); 
		}
		
		count += poList.size();
		 */
    // Copy business partner
    List<MBPartnerProduct> bpList = new Query(getCtx(), MBPartnerProduct.Table_Name, "M_Product_ID=?", get_TrxName()).setParameters(new Object[] { m_copyFromId }).setOnlyActiveRecords(true).list();
    MBPartnerProduct bpSrc;
    MBPartnerProduct bpDst;
    for (Iterator<MBPartnerProduct> it = bpList.iterator(); it.hasNext(); ) {
        bpSrc = it.next();
        bpDst = new MBPartnerProduct(getCtx(), 0, get_TrxName());
        bpDst.setC_BPartner_ID(bpSrc.getC_BPartner_ID());
        bpDst.setDescription(bpSrc.getDescription());
        bpDst.setIsManufacturer(bpSrc.isManufacturer());
        bpDst.setM_Product_ID(toMProductID);
        bpDst.setManufacturer(bpSrc.getManufacturer());
        bpDst.setQualityRating(bpSrc.getQualityRating());
        bpDst.setShelfLifeMinDays(bpSrc.getShelfLifeMinDays());
        bpDst.setShelfLifeMinPct(bpSrc.getShelfLifeMinPct());
        bpDst.setVendorCategory(bpSrc.getVendorCategory());
        bpDst.setVendorProductNo(bpSrc.getVendorProductNo());
        bpDst.saveEx(get_TrxName());
    }
    count += bpList.size();
    // Copy download
    List<MProductDownload> dlList = new Query(getCtx(), MProductDownload.Table_Name, "M_Product_ID=?", get_TrxName()).setParameters(new Object[] { m_copyFromId }).setOnlyActiveRecords(true).list();
    MProductDownload dlSrc;
    MProductDownload dlDst;
    for (Iterator<MProductDownload> it = dlList.iterator(); it.hasNext(); ) {
        dlSrc = it.next();
        dlDst = new MProductDownload(getCtx(), 0, get_TrxName());
        dlDst.setM_Product_ID(toMProductID);
        dlDst.setName(dlSrc.getName());
        dlDst.setDownloadURL(dlSrc.getDownloadURL());
        dlDst.saveEx(get_TrxName());
    }
    count += dlList.size();
    // TODO Auto-generated method stub
    return "@Copied@=" + count;
}
Also used : MBPartnerProduct(org.compiere.model.MBPartnerProduct) X_M_Substitute(org.compiere.model.X_M_Substitute) Query(org.compiere.model.Query) X_M_Replenish(org.compiere.model.X_M_Replenish) MProductDownload(org.compiere.model.MProductDownload) X_M_RelatedProduct(org.compiere.model.X_M_RelatedProduct) MProductPrice(org.compiere.model.MProductPrice)

Example 10 with MProductPrice

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

the class MProductTest method testPrice.

/*
	public int getProduct_Category_ID(String productCategory) {
		String sql = "select m_product_category_id from m_product_category where name = ?";
		PreparedStatement pstmt = null;
		ResultSet rs = null;

		int M_ProductCategory_ID = -1;

		try {
			pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, getTrxName());
			pstmt.setString(1, productCategory.trim());
			rs = pstmt.executeQuery();


			while (rs.next()) {
				M_ProductCategory_ID = rs.getInt(1);
			}
		} catch (SQLException e) {
			fail(e.getLocalizedMessage());
		} finally {
			DB.close( rs, pstmt );
		}

		return M_ProductCategory_ID;

	}

	public int getUOM_ID(String UOM) {
		System.out.println("In getUOM_ID");

		String sql = "select c_uom_id from c_uom where name = ?";
		PreparedStatement pstmt = null;
		ResultSet rs = null;

		int C_Uom_ID = -1;

		try {
			pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, getTrxName());
			pstmt.setString(1, UOM.trim());
			rs = pstmt.executeQuery();


			while (rs.next()) {
				C_Uom_ID = rs.getInt(1);
			}
		} catch (SQLException e) {
			fail(e.getLocalizedMessage());
		} finally {
			DB.close( rs, pstmt );
		}
		System.out.println("Uom: " + UOM);
		System.out.println("C_Uom_ID: " + C_Uom_ID);

		return C_Uom_ID;

	}
 
	public void testCreateMProduct() {
		MProduct m_product = new MProduct(getCtx(), 0, getTrxName());
		m_product.setAD_Org_ID(0);
		m_product.setProductType (X_I_Product.PRODUCTTYPE_Item);      // I
		m_product.setIsBOM (false);       // N
		m_product.setIsInvoicePrintDetails (false);
		m_product.setIsPickListPrintDetails (false);
		m_product.setIsPurchased (true);  // Y
		m_product.setIsSold (true);       // Y
		m_product.setIsStocked (true);    // Y
		m_product.setIsSummary (false);
		m_product.setIsVerified (false);  // N
		m_product.setIsWebStoreFeatured (false);
		m_product.setIsSelfService(true);
		m_product.setIsExcludeAutoDelivery(false);
		m_product.setProcessing (false);  // N
		m_product.setName("Test Product");  // N
		m_product.setC_UOM_ID(getUOM_ID("Each"));

		boolean saveResult = m_product.saveEx();
		assertEquals("Create new product.", true, saveResult);
	}  
	
	public void testSetBaseInfo() {
		MProductPricing prodprice = new MProductPricing(122,100, new BigDecimal (100),true);
		int uom = 0;
		uom = prodprice.getC_UOM_ID();
		assertTrue("UOM must be correct", uom == 100);
	} */
public void testPrice() {
    MProductPrice test = MProductPrice.get(getCtx(), 105, 124, getTrxName());
    assertTrue("Confirming Prod ID to be true", test.getM_Product_ID() == 124);
}
Also used : MProductPrice(org.compiere.model.MProductPrice)

Aggregations

MProductPrice (org.compiere.model.MProductPrice)12 BigDecimal (java.math.BigDecimal)8 MPriceListVersion (org.compiere.model.MPriceListVersion)7 MPriceList (org.compiere.model.MPriceList)5 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Properties (java.util.Properties)2 MProduct (org.compiere.model.MProduct)2 Query (org.compiere.model.Query)2 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 SQLException (java.sql.SQLException)1 TreeMap (java.util.TreeMap)1 JLabel (javax.swing.JLabel)1 AdempierePOSException (org.adempiere.pos.AdempierePOSException)1 Label (org.adempiere.webui.component.Label)1 ALayoutConstraint (org.compiere.apps.ALayoutConstraint)1 MAccount (org.compiere.model.MAccount)1 MBPartnerLocation (org.compiere.model.MBPartnerLocation)1