use of de.metas.order.IOrderDAO 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);
}
use of de.metas.order.IOrderDAO in project metasfresh-webui-api by metasfresh.
the class OrderLinePricingConditionsViewFactory method createPricingConditionsRowData.
@Override
protected PricingConditionsRowData createPricingConditionsRowData(@NonNull final CreateViewRequest request) {
final IOrderDAO ordersRepo = Services.get(IOrderDAO.class);
final int orderLineId = CollectionUtils.singleElement(request.getFilterOnlyIds());
Check.assumeGreaterThanZero(orderLineId, "salesOrderLineId");
final I_C_OrderLine orderLine = ordersRepo.getOrderLineById(orderLineId);
final I_C_Order order = orderLine.getC_Order();
final SOTrx soTrx = SOTrx.ofBoolean(order.isSOTrx());
final PricingConditionsRowData rowsData = preparePricingConditionsRowData().pricingConditionsBreaksExtractor(createPricingConditionsBreaksExtractor(orderLine)).basePricingSystemPriceCalculator(new OrderLineBasePricingSystemPriceCalculator(orderLine)).filters(extractFilters(request)).sourceDocumentLine(createSourceDocumentLine(orderLine, soTrx)).load();
return rowsData;
}
use of de.metas.order.IOrderDAO in project metasfresh-webui-api by metasfresh.
the class SalesOrder2PurchaseViewFactory method isSalesOrderCompleted.
private boolean isSalesOrderCompleted(@NonNull final List<PurchaseCandidate> purchaseCandidates) {
final IOrderDAO ordersRepo = Services.get(IOrderDAO.class);
final OrderId salesOrderId = getSingleSalesOrderId(purchaseCandidates);
final I_C_Order salesOrder = ordersRepo.getById(salesOrderId);
final DocStatus docStatus = DocStatus.ofCode(salesOrder.getDocStatus());
return docStatus.isCompleted();
}
Aggregations