Search in sources :

Example 6 with PriceListLine

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;
}
Also used : Company(com.axelor.apps.base.db.Company) PriceListLine(com.axelor.apps.base.db.PriceListLine) Product(com.axelor.apps.base.db.Product) PriceList(com.axelor.apps.base.db.PriceList) BigDecimal(java.math.BigDecimal)

Example 7 with PriceListLine

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;
}
Also used : Company(com.axelor.apps.base.db.Company) PriceListLine(com.axelor.apps.base.db.PriceListLine) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 8 with PriceListLine

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;
}
Also used : PriceListLine(com.axelor.apps.base.db.PriceListLine) PriceList(com.axelor.apps.base.db.PriceList)

Example 9 with PriceListLine

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();
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal) PriceListLine(com.axelor.apps.base.db.PriceListLine) InvoiceLineGeneratorSupplyChain(com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain) ArrayList(java.util.ArrayList) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) PriceList(com.axelor.apps.base.db.PriceList)

Example 10 with PriceListLine

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;
}
Also used : PriceListLine(com.axelor.apps.base.db.PriceListLine) PriceList(com.axelor.apps.base.db.PriceList)

Aggregations

PriceListLine (com.axelor.apps.base.db.PriceListLine)10 PriceList (com.axelor.apps.base.db.PriceList)7 BigDecimal (java.math.BigDecimal)5 Company (com.axelor.apps.base.db.Company)3 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)2 Product (com.axelor.apps.base.db.Product)2 AxelorException (com.axelor.exception.AxelorException)2 ArrayList (java.util.ArrayList)2 PartnerPriceListService (com.axelor.apps.base.service.PartnerPriceListService)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 ProjectTask (com.axelor.apps.project.db.ProjectTask)1 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)1 Transactional (com.google.inject.persist.Transactional)1 List (java.util.List)1