use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class PriceListService method historizePriceList.
@Transactional
public PriceList historizePriceList(PriceList priceList) {
PriceList historizedPriceList = priceListRepo.copy(priceList, false);
historizedPriceList.setIsActive(false);
List<PriceListLine> priceListLineList = priceList.getPriceListLineList();
for (PriceListLine priceListLine : priceListLineList) {
PriceListLine newPriceListLine = priceListLineRepo.copy(priceListLine, false);
newPriceListLine.setPriceList(null);
historizedPriceList.addPriceListLineListItem(newPriceListLine);
}
priceListRepo.save(historizedPriceList);
priceList.addHistorizedPriceListItem(historizedPriceList);
priceListRepo.save(priceList);
return priceList;
}
use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class PriceListService method getPriceListLine.
public PriceListLine getPriceListLine(Product product, BigDecimal qty, PriceList priceList, BigDecimal price) {
PriceListLine priceListLine = null;
List<PriceListLine> priceListLineList = getPriceListLineList(product, qty, priceList);
BigDecimal tempDiscountPrevious = null;
BigDecimal tempDiscountCurrent;
if (priceListLineList != null && !priceListLineList.isEmpty()) {
if (priceListLineList.size() > 1) {
for (PriceListLine tempPriceListLine : priceListLineList) {
tempDiscountCurrent = this.getUnitPriceDiscounted(tempPriceListLine, price);
if (tempDiscountPrevious == null || tempDiscountPrevious.compareTo(tempDiscountCurrent) > 0) {
tempDiscountPrevious = tempDiscountCurrent;
priceListLine = tempPriceListLine;
}
}
} else {
priceListLine = priceListLineList.get(0);
}
}
return priceListLine;
}
use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, Product product, User user, String date, BigDecimal hoursDuration, int priority, PriceList priceList) throws AxelorException {
int discountMethodTypeSelect = PriceListLineRepository.TYPE_DISCOUNT;
int discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
if (product == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
}
BigDecimal price = (BigDecimal) productCompanyService.get(product, "salePrice", invoice.getCompany());
BigDecimal discountAmount = BigDecimal.ZERO;
BigDecimal priceDiscounted = price;
BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(appHumanResourceService.getAppBase().getUnitHours(), (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), hoursDuration, AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, product);
if (priceList != null) {
PriceListLine priceListLine = priceListService.getPriceListLine(product, qtyConverted, priceList, price);
if (priceListLine != null) {
discountMethodTypeSelect = priceListLine.getTypeSelect();
}
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
discountTypeSelect = (int) discounts.get("discountTypeSelect");
priceDiscounted = priceListService.computeDiscount(price, discountTypeSelect, discountAmount);
}
if ((appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountMethodTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
price = priceDiscounted;
}
}
String description = user.getFullName();
String productName = (String) productCompanyService.get(product, "name", invoice.getCompany());
if (date != null) {
productName += " " + "(" + date + ")";
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, productName, price, price, priceDiscounted, description, qtyConverted, (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), null, priority, discountAmount, discountTypeSelect, price.multiply(qtyConverted), null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
List<InvoiceLine> invoiceLines = new ArrayList<>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
}
use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class SaleOrderLineServiceImpl method getDiscountsFromPriceLists.
@Override
public Map<String, Object> getDiscountsFromPriceLists(SaleOrder saleOrder, SaleOrderLine saleOrderLine, BigDecimal price) {
Map<String, Object> discounts = null;
PriceList priceList = saleOrder.getPriceList();
if (priceList != null) {
PriceListLine priceListLine = this.getPriceListLine(saleOrderLine, priceList, price);
discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, price);
if (saleOrder.getTemplate()) {
Integer manualDiscountAmountType = saleOrderLine.getDiscountTypeSelect();
BigDecimal manualDiscountAmount = saleOrderLine.getDiscountAmount();
Integer priceListDiscountAmountType = (Integer) discounts.get("discountTypeSelect");
BigDecimal priceListDiscountAmount = (BigDecimal) discounts.get("discountAmount");
if (!manualDiscountAmountType.equals(priceListDiscountAmountType) && manualDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_PERCENT) && priceListDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_FIXED)) {
priceListDiscountAmount = priceListDiscountAmount.multiply(new BigDecimal(100)).divide(price, 2, RoundingMode.HALF_UP);
} else if (!manualDiscountAmountType.equals(priceListDiscountAmountType) && manualDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_FIXED) && priceListDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_PERCENT)) {
priceListDiscountAmount = priceListDiscountAmount.multiply(price).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
}
if (manualDiscountAmount.compareTo(priceListDiscountAmount) > 0) {
discounts.put("discountAmount", manualDiscountAmount);
discounts.put("discountTypeSelect", manualDiscountAmountType);
}
}
}
return discounts;
}
use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineServiceImpl method getDiscountsFromPriceLists.
@Override
public Map<String, Object> getDiscountsFromPriceLists(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine, BigDecimal price) {
Map<String, Object> discounts = null;
PriceList priceList = purchaseOrder.getPriceList();
if (priceList != null) {
PriceListLine priceListLine = this.getPriceListLine(purchaseOrderLine, priceList, price);
discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, price);
}
return discounts;
}
Aggregations