Search in sources :

Example 6 with MPriceListVersion

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

the class InventoryUtil method getCreatePriceList.

public static MPriceList getCreatePriceList(String value, boolean IsSOPriceList) {
    Properties ctx = Env.getCtx();
    int C_Currency_ID = Env.getContextAsInt(ctx, "$C_Currency_ID");
    String whereClause = MPriceList.COLUMNNAME_Name + "=?" + " AND " + MPriceList.COLUMNNAME_IsSOPriceList + "=?" + " AND " + MPriceList.COLUMNNAME_C_Currency_ID + "=?";
    MPriceList pl = new Query(ctx, MPriceList.Table_Name, whereClause, null).setParameters(new Object[] { value, IsSOPriceList, C_Currency_ID }).setClient_ID().setOnlyActiveRecords(true).firstOnly();
    if (pl == null) {
        pl = new MPriceList(ctx, 0, null);
        pl.setName(value);
        pl.setIsSOPriceList(IsSOPriceList);
        pl.setC_Currency_ID(C_Currency_ID);
    }
    setGeneratedTag(pl);
    pl.setIsTaxIncluded(false);
    pl.saveEx();
    //
    Timestamp ValidFrom = TimeUtil.getDay(1970, 1, 1);
    MPriceListVersion plv = pl.getPriceListVersion(ValidFrom);
    if (plv == null) {
        plv = new MPriceListVersion(pl);
        plv.setValidFrom(ValidFrom);
        plv.setM_DiscountSchema_ID(getM_DiscountSchema_ID());
        setGeneratedTag(plv);
        plv.saveEx();
    }
    //
    return pl;
}
Also used : Query(org.compiere.model.Query) MPriceListVersion(org.compiere.model.MPriceListVersion) MPriceList(org.compiere.model.MPriceList) Properties(java.util.Properties) Timestamp(java.sql.Timestamp)

Example 7 with MPriceListVersion

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

the class MPriceListVersionTest method testQuery.

public void testQuery() throws Exception {
    MPriceListVersion plv = new MPriceListVersion(getCtx(), 101, getTrxName());
    //red1 tested also with (true) and (false)
    MProductPrice[] pp = plv.getProductPrice("AND isActive='Y'");
    assertTrue("product must have prices", pp.length > 0);
}
Also used : MPriceListVersion(org.compiere.model.MPriceListVersion) MProductPrice(org.compiere.model.MProductPrice)

Example 8 with MPriceListVersion

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

the class InventoryUtil method getCreatePriceList.

public static MPriceList getCreatePriceList(String value, boolean IsSOPriceList) {
    Properties ctx = Env.getCtx();
    int C_Currency_ID = Env.getContextAsInt(ctx, "$C_Currency_ID");
    String whereClause = MPriceList.COLUMNNAME_Name + "=?" + " AND " + MPriceList.COLUMNNAME_IsSOPriceList + "=?" + " AND " + MPriceList.COLUMNNAME_C_Currency_ID + "=?";
    MPriceList pl = new Query(ctx, MPriceList.Table_Name, whereClause, null).setParameters(new Object[] { value, IsSOPriceList, C_Currency_ID }).setClient_ID().setOnlyActiveRecords(true).firstOnly();
    if (pl == null) {
        pl = new MPriceList(ctx, 0, null);
        pl.setName(value);
        pl.setIsSOPriceList(IsSOPriceList);
        pl.setC_Currency_ID(C_Currency_ID);
    }
    setGeneratedTag(pl);
    pl.setIsTaxIncluded(false);
    pl.saveEx();
    //
    Timestamp ValidFrom = TimeUtil.getDay(1970, 1, 1);
    MPriceListVersion plv = pl.getPriceListVersion(ValidFrom);
    if (plv == null) {
        plv = new MPriceListVersion(pl);
        plv.setValidFrom(ValidFrom);
        plv.setM_DiscountSchema_ID(getM_DiscountSchema_ID());
        setGeneratedTag(plv);
        plv.saveEx();
    }
    //
    return pl;
}
Also used : Query(org.compiere.model.Query) MPriceListVersion(org.compiere.model.MPriceListVersion) MPriceList(org.compiere.model.MPriceList) Properties(java.util.Properties) Timestamp(java.sql.Timestamp)

Example 9 with MPriceListVersion

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

the class CPOS method loadPriceListVersion.

//	getM_PriceList_ID
/**
	 * Load Price List Version from Price List
	 * @param priceListId
	 * @return
	 * @return MPriceListVersion
	 */
protected MPriceListVersion loadPriceListVersion(int priceListId) {
    priceListVersionId = 0;
    this.priceListId = priceListId;
    MPriceList priceList = MPriceList.get(ctx, priceListId, null);
    //
    MPriceListVersion priceListVersion = priceList.getPriceListVersion(getToday());
    if (priceListVersion != null && priceListVersion.getM_PriceList_Version_ID() != 0) {
        priceListVersionId = priceListVersion.getM_PriceList_Version_ID();
    }
    //	Default Return
    return priceListVersion;
}
Also used : MPriceListVersion(org.compiere.model.MPriceListVersion) MPriceList(org.compiere.model.MPriceList)

Example 10 with MPriceListVersion

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

the class CopyPriceToStandard method doIt.

protected String doIt() throws Exception {
    MAcctSchema accountSchema = MAcctSchema.get(getCtx(), getAccountingSchemaId());
    MCostElement costElement = MCostElement.get(getCtx(), getCostElementId());
    if (!MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType()))
        throw new AdempiereException("Only Material Cost Elements are allowed");
    AtomicInteger countUpdated = new AtomicInteger(0);
    MPriceListVersion priceListVersion = new MPriceListVersion(getCtx(), getPriceListVersionId(), get_TrxName());
    Arrays.stream(priceListVersion.getProductPrice(" AND " + MProductPrice.COLUMNNAME_PriceStd + " <> 0")).forEach(productPrice -> {
        final BigDecimal price;
        int currencyId = priceListVersion.getPriceList().getC_Currency_ID();
        if (currencyId != accountSchema.getC_Currency_ID()) {
            price = MConversionRate.convert(getCtx(), productPrice.getPriceStd(), currencyId, accountSchema.getC_Currency_ID(), getAD_Client_ID(), getOrganizationId());
        } else
            price = productPrice.getPriceStd();
        MProduct product = MProduct.get(getCtx(), productPrice.getM_Product_ID());
        CostDimension costDimension = new CostDimension(product, accountSchema, getCostTypeId(), getOrganizationId(), 0, 0, getCostElementId());
        List<MCost> costs = costDimension.toQuery(MCost.class, get_TrxName()).list();
        costs.stream().filter(cost -> cost != null && cost.getM_CostElement_ID() == costElement.get_ID()).findFirst().ifPresent(cost -> {
            cost.setFutureCostPrice(price);
            cost.saveEx();
            countUpdated.getAndUpdate(count -> count + 1);
        });
    });
    return "@Updated@ # " + countUpdated;
}
Also used : MCostElement(org.compiere.model.MCostElement) MAcctSchema(org.compiere.model.MAcctSchema) MProduct(org.compiere.model.MProduct) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AdempiereException(org.adempiere.exceptions.AdempiereException) MCost(org.compiere.model.MCost) MPriceListVersion(org.compiere.model.MPriceListVersion) CostDimension(org.adempiere.engine.CostDimension) BigDecimal(java.math.BigDecimal)

Aggregations

MPriceListVersion (org.compiere.model.MPriceListVersion)11 MPriceList (org.compiere.model.MPriceList)8 MProductPrice (org.compiere.model.MProductPrice)7 BigDecimal (java.math.BigDecimal)6 Properties (java.util.Properties)4 Query (org.compiere.model.Query)3 Timestamp (java.sql.Timestamp)2 MProduct (org.compiere.model.MProduct)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CostDimension (org.adempiere.engine.CostDimension)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 AdempierePOSException (org.adempiere.pos.AdempierePOSException)1 MAccount (org.compiere.model.MAccount)1 MAcctSchema (org.compiere.model.MAcctSchema)1 MBPartnerLocation (org.compiere.model.MBPartnerLocation)1 MCost (org.compiere.model.MCost)1 MCostElement (org.compiere.model.MCostElement)1