use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class ProjectTaskBusinessProjectServiceImpl method computeUnitPrice.
private BigDecimal computeUnitPrice(ProjectTask projectTask) throws AxelorException {
Product product = projectTask.getProduct();
Company company = projectTask.getProject() != null ? projectTask.getProject().getCompany() : null;
BigDecimal unitPrice = (BigDecimal) productCompanyService.get(product, "salePrice", company);
PriceList priceList = partnerPriceListService.getDefaultPriceList(projectTask.getProject().getClientPartner(), PriceListRepository.TYPE_SALE);
if (priceList == null) {
return unitPrice;
}
PriceListLine priceListLine = this.getPriceListLine(projectTask, priceList, unitPrice);
Map<String, Object> discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, unitPrice);
if (discounts == null) {
return unitPrice;
} else {
unitPrice = priceListService.computeDiscount(unitPrice, (Integer) discounts.get("discountTypeSelect"), (BigDecimal) discounts.get("discountAmount"));
}
return unitPrice;
}
use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class ProjectTaskBusinessProjectServiceImpl method create.
@Override
public ProjectTask create(SaleOrderLine saleOrderLine, Project project, User assignedTo) throws AxelorException {
ProjectTask task = create(saleOrderLine.getFullName() + "_task", project, assignedTo);
task.setProduct(saleOrderLine.getProduct());
task.setUnit(saleOrderLine.getUnit());
task.setCurrency(project.getClientPartner().getCurrency());
if (project.getPriceList() != null) {
PriceListLine line = priceListLineRepo.findByPriceListAndProduct(project.getPriceList(), saleOrderLine.getProduct());
if (line != null) {
task.setUnitPrice(line.getAmount());
}
}
if (task.getUnitPrice() == null) {
Company company = saleOrderLine.getSaleOrder() != null ? saleOrderLine.getSaleOrder().getCompany() : null;
task.setUnitPrice((BigDecimal) productCompanyService.get(saleOrderLine.getProduct(), "salePrice", company));
}
task.setDescription(saleOrderLine.getDescription());
task.setQuantity(saleOrderLine.getQty());
task.setSaleOrderLine(saleOrderLine);
task.setToInvoice(saleOrderLine.getSaleOrder() != null ? saleOrderLine.getSaleOrder().getToInvoiceViaTask() : false);
return task;
}
use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class ProjectTaskBusinessProjectServiceImpl method updateDiscount.
@Override
public ProjectTask updateDiscount(ProjectTask projectTask) {
PriceList priceList = projectTask.getProject().getPriceList();
if (priceList == null) {
this.emptyDiscounts(projectTask);
return projectTask;
}
PriceListLine priceListLine = this.getPriceListLine(projectTask, priceList, projectTask.getUnitPrice());
Map<String, Object> discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, projectTask.getUnitPrice());
if (discounts == null) {
this.emptyDiscounts(projectTask);
} else {
projectTask.setDiscountTypeSelect((Integer) discounts.get("discountTypeSelect"));
projectTask.setDiscountAmount((BigDecimal) discounts.get("discountAmount"));
if (discounts.get("price") != null) {
projectTask.setPriceDiscounted((BigDecimal) discounts.get("price"));
}
}
return projectTask;
}
use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.
the class PurchaseOrderInvoiceProjectServiceImpl method createInvoiceLine.
@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, PurchaseOrderLine purchaseOrderLine) throws AxelorException {
Product product = purchaseOrderLine.getProduct();
Company company = purchaseOrderLine.getPurchaseOrder() != null ? purchaseOrderLine.getPurchaseOrder().getCompany() : null;
BigDecimal price = (BigDecimal) productCompanyService.get(product, "costPrice", company);
BigDecimal discountAmount = price;
int discountTypeSelect = 1;
if (invoice.getPartner().getChargeBackPurchaseSelect() == PartnerRepository.CHARGING_BACK_TYPE_PRICE_LIST) {
PriceList priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(invoice.getPartner(), PriceListRepository.TYPE_SALE);
if (priceList != null) {
PriceListLine priceListLine = purchaseOrderLineServiceImpl.getPriceListLine(purchaseOrderLine, priceList, price);
if (priceListLine != null) {
discountTypeSelect = priceListLine.getTypeSelect();
}
if ((appBusinessProjectService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appBusinessProjectService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
price = priceListService.computeDiscount(price, (int) discounts.get("discountTypeSelect"), discountAmount);
}
} else {
Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
if (discounts != null) {
discountAmount = (BigDecimal) discounts.get("discountAmount");
if (discounts.get("price") != null) {
price = (BigDecimal) discounts.get("price");
}
}
}
}
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, (String) productCompanyService.get(product, "name", company), price, price, price, purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), null, InvoiceLineGenerator.DEFAULT_SEQUENCE, discountAmount, discountTypeSelect, null, null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
} else if (invoice.getPartner().getChargeBackPurchaseSelect() == PartnerRepository.CHARGING_BACK_TYPE_PERCENTAGE) {
price = price.multiply(invoice.getPartner().getChargeBackPurchase().divide(new BigDecimal(100), appBusinessProjectService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP)).setScale(appBusinessProjectService.getNbDecimalDigitForUnitPrice(), BigDecimal.ROUND_HALF_UP);
InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, (String) productCompanyService.get(product, "name", company), price, price, price, purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), null, InvoiceLineGenerator.DEFAULT_SEQUENCE, discountAmount, discountTypeSelect, null, null, false) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
invoiceLines.add(invoiceLine);
return invoiceLines;
}
};
return invoiceLineGenerator.creates();
} else {
InvoiceLineGeneratorSupplyChain invoiceLineGenerator = new InvoiceLineGeneratorSupplyChain(invoice, product, purchaseOrderLine.getProductName(), purchaseOrderLine.getDescription(), purchaseOrderLine.getQty(), purchaseOrderLine.getUnit(), purchaseOrderLine.getSequence(), false, null, purchaseOrderLine, null) {
@Override
public List<InvoiceLine> creates() throws AxelorException {
InvoiceLine invoiceLine = this.createInvoiceLine();
invoiceLine.setProject(purchaseOrderLine.getProject());
List<InvoiceLine> invoiceLines = new ArrayList<InvoiceLine>();
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 InvoiceLineServiceImpl method getDiscountsFromPriceLists.
@Override
public Map<String, Object> getDiscountsFromPriceLists(Invoice invoice, InvoiceLine invoiceLine, BigDecimal price) {
Map<String, Object> discounts = null;
PriceList priceList = invoice.getPriceList();
if (priceList != null) {
PriceListLine priceListLine = this.getPriceListLine(invoiceLine, priceList, price);
discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, price);
}
return discounts;
}
Aggregations