Search in sources :

Example 1 with FreightServiceInterface

use of org.eevolution.service.FreightServiceInterface in project adempiere by adempiere.

the class FreightRule method calculate.

@Override
public BigDecimal calculate(Properties ctx, int productId, int shipperId, int locationFromId, int locationToId, int freightCategoryId, int currencyId, Timestamp date, String trxName) {
    MProduct product = MProduct.get(ctx, productId);
    BigDecimal freightRateAmount = BigDecimal.ZERO;
    FreightServiceInterface freightService = new FreightService();
    BigDecimal freightRate = getFreightRate(ctx, shipperId, freightCategoryId, currencyId, locationFromId, locationToId, date, trxName);
    if (freightRate.signum() != 0)
        freightRateAmount = product.getWeight().multiply(freightRate);
    else
        freightRateAmount = BigDecimal.ZERO;
    return freightRateAmount;
}
Also used : MProduct(org.compiere.model.MProduct) FreightServiceInterface(org.eevolution.service.FreightServiceInterface) FreightService(org.eevolution.service.FreightService) BigDecimal(java.math.BigDecimal)

Example 2 with FreightServiceInterface

use of org.eevolution.service.FreightServiceInterface in project adempiere by adempiere.

the class FreightRule method getFreightRate.

/**
     * get Freight Rate
     * @param ctx
     * @param shipperId
     * @param freightCategoryId
     * @param currencyId
     * @param date
     * @param trxName
     * @return
     */
public BigDecimal getFreightRate(Properties ctx, int shipperId, int freightCategoryId, int currencyId, int locationFromId, int locationToId, Timestamp date, String trxName) {
    MLocation locationFrom = MLocation.get(ctx, locationFromId, trxName);
    MLocation locationTo = MLocation.get(ctx, locationToId, trxName);
    Optional<Integer> countryFromOptionalId;
    Optional<Integer> regionFromOptionalId;
    if (locationFrom != null && locationFrom.get_ID() > 0) {
        countryFromOptionalId = Optional.ofNullable(locationFrom.getC_Country_ID());
        regionFromOptionalId = Optional.ofNullable(locationFrom.getC_Region_ID());
    } else {
        countryFromOptionalId = Optional.empty();
        regionFromOptionalId = Optional.empty();
    }
    Optional<Integer> countryToOptionalId;
    Optional<Integer> regionToOptionalId;
    if (locationTo != null && locationTo.get_ID() > 0) {
        countryToOptionalId = Optional.ofNullable(locationTo.getC_Country_ID());
        regionToOptionalId = Optional.ofNullable(locationTo.getC_Region_ID());
    } else {
        countryToOptionalId = Optional.empty();
        regionToOptionalId = Optional.empty();
    }
    FreightServiceInterface freightService = new FreightService();
    Optional<MFreight> freightOptioonal = freightService.getFreightValid(ctx, shipperId, freightCategoryId, currencyId, date, trxName).stream().filter(freight -> {
        if (freight.getC_Country_ID() == 0 && freight.getTo_Country_ID() == 0)
            return true;
        else if (freight.getC_Country_ID() == 0 && (countryToOptionalId.isPresent() && countryToOptionalId.get() == freight.getTo_Country_ID()))
            return true;
        else if ((countryFromOptionalId.isPresent() && countryFromOptionalId.get() == freight.getC_Country_ID()) && (countryToOptionalId.isPresent() && countryToOptionalId.get() == freight.getTo_Country_ID()))
            return true;
        else
            return false;
    }).filter(freight -> {
        if (freight.getC_Region_ID() == 0 && freight.getTo_Region_ID() == 0)
            return true;
        else if (freight.getC_Region_ID() == 0 && (regionToOptionalId.isPresent() && regionToOptionalId.get() == freight.getTo_Region_ID()))
            return true;
        else if ((regionFromOptionalId.isPresent() && regionFromOptionalId.get() == freight.getC_Region_ID()) && (regionToOptionalId.isPresent() && regionToOptionalId.get() == freight.getTo_Region_ID()))
            return true;
        else
            return false;
    }).findFirst();
    if (freightOptioonal.isPresent()) {
        return freightOptioonal.get().getFreightAmt();
    } else {
        return BigDecimal.ZERO;
    }
}
Also used : BigDecimal(java.math.BigDecimal) MLocation(org.compiere.model.MLocation) Properties(java.util.Properties) FreightService(org.eevolution.service.FreightService) FreightServiceInterface(org.eevolution.service.FreightServiceInterface) Timestamp(java.sql.Timestamp) MFreight(org.compiere.model.MFreight) Optional(java.util.Optional) MProduct(org.compiere.model.MProduct) MFreight(org.compiere.model.MFreight) FreightServiceInterface(org.eevolution.service.FreightServiceInterface) MLocation(org.compiere.model.MLocation) FreightService(org.eevolution.service.FreightService)

Aggregations

BigDecimal (java.math.BigDecimal)2 MProduct (org.compiere.model.MProduct)2 FreightService (org.eevolution.service.FreightService)2 FreightServiceInterface (org.eevolution.service.FreightServiceInterface)2 Timestamp (java.sql.Timestamp)1 Optional (java.util.Optional)1 Properties (java.util.Properties)1 MFreight (org.compiere.model.MFreight)1 MLocation (org.compiere.model.MLocation)1