Search in sources :

Example 1 with PriceSpecificationType

use of de.metas.pricing.conditions.PriceSpecificationType in project metasfresh-webui-api by metasfresh.

the class PricingConditionsView method updateOrderLineRecord.

private void updateOrderLineRecord(@NonNull final PricingConditionsBreak pricingConditionsBreak, @Nullable final Money basePrice) {
    final IOrderDAO ordersRepo = Services.get(IOrderDAO.class);
    final IOrderLineBL orderLineBL = Services.get(IOrderLineBL.class);
    final I_C_OrderLine orderLineRecord = ordersRepo.getOrderLineById(getOrderLineId());
    orderLineRecord.setIsTempPricingConditions(pricingConditionsBreak.isTemporaryPricingConditionsBreak());
    if (pricingConditionsBreak.isTemporaryPricingConditionsBreak()) {
        orderLineRecord.setM_DiscountSchema_ID(-1);
        orderLineRecord.setM_DiscountSchemaBreak_ID(-1);
        final PriceSpecification price = pricingConditionsBreak.getPriceSpecification();
        final PriceSpecificationType type = price.getType();
        if (type == PriceSpecificationType.NONE) {
        // 
        } else if (type == PriceSpecificationType.BASE_PRICING_SYSTEM) {
            assumeNotNull(basePrice, "If type={}, then the given basePrice may not be null; pricingConditionsBreak={}", type, pricingConditionsBreak);
            final BigDecimal priceEntered = limitPrice(basePrice.toBigDecimal(), orderLineRecord);
            orderLineRecord.setIsManualPrice(true);
            orderLineRecord.setPriceEntered(priceEntered);
            orderLineRecord.setC_Currency_ID(basePrice.getCurrencyId().getRepoId());
            orderLineRecord.setBase_PricingSystem_ID(price.getBasePricingSystemId().getRepoId());
        } else if (type == PriceSpecificationType.FIXED_PRICE) {
            final Money fixedPrice = price.getFixedPrice();
            Check.assumeNotNull(fixedPrice, "fixedPrice shall not be null for {}", price);
            final BigDecimal priceEntered = limitPrice(fixedPrice.toBigDecimal(), orderLineRecord);
            orderLineRecord.setIsManualPrice(true);
            orderLineRecord.setPriceEntered(priceEntered);
            orderLineRecord.setC_Currency_ID(fixedPrice.getCurrencyId().getRepoId());
            orderLineRecord.setBase_PricingSystem_ID(-1);
        }
        orderLineRecord.setIsManualDiscount(true);
        orderLineRecord.setDiscount(pricingConditionsBreak.getDiscount().toBigDecimal());
        // make sure it's not overwritten by whatever the system comes up with when we save the orderLine.
        orderLineRecord.setIsManualPaymentTerm(true);
        orderLineRecord.setC_PaymentTerm_Override_ID(PaymentTermId.toRepoId(pricingConditionsBreak.getDerivedPaymentTermIdOrNull()));
        orderLineRecord.setPaymentDiscount(Percent.toBigDecimalOrNull(pricingConditionsBreak.getPaymentDiscountOverrideOrNull()));
        // 
        // PriceActual & Discount
        Percent discountEffective = pricingConditionsBreak.getDiscount();
        final BigDecimal priceActual = discountEffective.subtractFromBase(orderLineRecord.getPriceEntered(), CurrencyPrecision.TWO.toInt());
        final BigDecimal priceActualEffective = limitPrice(priceActual, orderLineRecord);
        if (priceActualEffective.compareTo(priceActual) != 0) {
            discountEffective = PriceAndDiscount.calculateDiscountFromPrices(orderLineRecord.getPriceEntered(), priceActualEffective, CurrencyPrecision.TWO);
        }
        // 
        orderLineRecord.setIsManualDiscount(true);
        orderLineRecord.setDiscount(discountEffective.toBigDecimal());
        orderLineRecord.setPriceActual(priceActualEffective);
    } else {
        final PricingConditionsBreakId pricingConditionsBreakId = pricingConditionsBreak.getId();
        orderLineRecord.setM_DiscountSchema_ID(pricingConditionsBreakId.getDiscountSchemaId());
        orderLineRecord.setM_DiscountSchemaBreak_ID(pricingConditionsBreakId.getDiscountSchemaBreakId());
        orderLineRecord.setIsManualDiscount(false);
        orderLineRecord.setIsManualPrice(false);
        orderLineRecord.setIsManualPaymentTerm(false);
        final OrderLinePriceUpdateRequest orderLinePriceUpdateRequest = OrderLinePriceUpdateRequest.prepare(orderLineRecord).pricingConditionsBreakOverride(pricingConditionsBreak).build();
        orderLineBL.updatePrices(orderLinePriceUpdateRequest);
    }
    orderLineBL.updateLineNetAmtFromQtyEntered(orderLineRecord);
    orderLineBL.setTaxAmtInfo(orderLineRecord);
    InterfaceWrapperHelper.save(orderLineRecord);
}
Also used : IOrderLineBL(de.metas.order.IOrderLineBL) PricingConditionsBreakId(de.metas.pricing.conditions.PricingConditionsBreakId) Money(de.metas.money.Money) IOrderDAO(de.metas.order.IOrderDAO) OrderLinePriceUpdateRequest(de.metas.order.OrderLinePriceUpdateRequest) Percent(de.metas.util.lang.Percent) PriceSpecificationType(de.metas.pricing.conditions.PriceSpecificationType) PriceSpecification(de.metas.pricing.conditions.PriceSpecification) I_C_OrderLine(de.metas.interfaces.I_C_OrderLine) BigDecimal(java.math.BigDecimal)

Example 2 with PriceSpecificationType

use of de.metas.pricing.conditions.PriceSpecificationType in project metasfresh-webui-api by metasfresh.

the class PricingConditionsRowActions method toPartialPriceChange.

private static PartialPriceChange toPartialPriceChange(final List<JSONDocumentChangedEvent> fieldChangeRequests, final CurrencyId defaultCurrencyId) {
    final PartialPriceChangeBuilder builder = PartialPriceChange.builder().defaultCurrencyId(defaultCurrencyId);
    for (final JSONDocumentChangedEvent fieldChangeRequest : fieldChangeRequests) {
        final String fieldName = fieldChangeRequest.getPath();
        builder.changedFieldName(fieldName);
        if (PricingConditionsRow.FIELDNAME_BasePriceType.equals(fieldName)) {
            final LookupValue priceTypeLookupValue = fieldChangeRequest.getValueAsStringLookupValue();
            final PriceSpecificationType priceType = priceTypeLookupValue != null ? PriceSpecificationType.ofCode(priceTypeLookupValue.getIdAsString()) : null;
            builder.priceType(priceType);
        } else if (PricingConditionsRow.FIELDNAME_BasePricingSystem.equals(fieldName)) {
            final LookupValue pricingSystem = fieldChangeRequest.getValueAsIntegerLookupValue();
            final PricingSystemId pricingSystemId = pricingSystem != null ? PricingSystemId.ofRepoIdOrNull(pricingSystem.getIdAsInt()) : null;
            builder.basePricingSystemId(Optional.ofNullable(pricingSystemId));
        } else if (PricingConditionsRow.FIELDNAME_PricingSystemSurcharge.equals(fieldName)) {
            builder.pricingSystemSurchargeAmt(fieldChangeRequest.getValueAsBigDecimal(BigDecimal.ZERO));
        } else if (PricingConditionsRow.FIELDNAME_BasePrice.equals(fieldName)) {
            builder.fixedPriceAmt(fieldChangeRequest.getValueAsBigDecimal(BigDecimal.ZERO));
        } else if (PricingConditionsRow.FIELDNAME_C_Currency_ID.equals(fieldName)) {
            final LookupValue currency = fieldChangeRequest.getValueAsIntegerLookupValue();
            final CurrencyId currencyId = currency != null ? CurrencyId.ofRepoIdOrNull(currency.getIdAsInt()) : null;
            builder.currencyId(currencyId);
            if (currencyId != null) {
                builder.defaultCurrencyId(currencyId);
            }
        }
    }
    return builder.build();
}
Also used : PartialPriceChangeBuilder(de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowChangeRequest.PartialPriceChange.PartialPriceChangeBuilder) PriceSpecificationType(de.metas.pricing.conditions.PriceSpecificationType) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) PricingSystemId(de.metas.pricing.PricingSystemId) CurrencyId(de.metas.money.CurrencyId) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Aggregations

PriceSpecificationType (de.metas.pricing.conditions.PriceSpecificationType)2 I_C_OrderLine (de.metas.interfaces.I_C_OrderLine)1 CurrencyId (de.metas.money.CurrencyId)1 Money (de.metas.money.Money)1 IOrderDAO (de.metas.order.IOrderDAO)1 IOrderLineBL (de.metas.order.IOrderLineBL)1 OrderLinePriceUpdateRequest (de.metas.order.OrderLinePriceUpdateRequest)1 PricingSystemId (de.metas.pricing.PricingSystemId)1 PriceSpecification (de.metas.pricing.conditions.PriceSpecification)1 PricingConditionsBreakId (de.metas.pricing.conditions.PricingConditionsBreakId)1 PartialPriceChangeBuilder (de.metas.ui.web.order.pricingconditions.view.PricingConditionsRowChangeRequest.PartialPriceChange.PartialPriceChangeBuilder)1 LookupValue (de.metas.ui.web.window.datatypes.LookupValue)1 JSONDocumentChangedEvent (de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent)1 Percent (de.metas.util.lang.Percent)1 BigDecimal (java.math.BigDecimal)1