Search in sources :

Example 21 with PriceList

use of com.axelor.apps.base.db.PriceList in project axelor-open-suite by axelor.

the class TimesheetProjectServiceImpl method createInvoiceLines.

@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
    if (!Beans.get(AppHumanResourceService.class).isApp("business-project")) {
        return super.createInvoiceLines(invoice, timesheetLineList, priority);
    }
    List<InvoiceLine> invoiceLineList = new ArrayList<InvoiceLine>();
    int count = 0;
    DateTimeFormatter ddmmFormat = DateTimeFormatter.ofPattern("dd/MM");
    HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<String, Object[]>();
    // Check if a consolidation by product and user must be done
    boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
    for (TimesheetLine timesheetLine : timesheetLineList) {
        Object[] tabInformations = new Object[6];
        tabInformations[0] = timesheetLine.getProduct();
        tabInformations[1] = timesheetLine.getUser();
        // Start date
        tabInformations[2] = timesheetLine.getDate();
        // End date, useful only for consolidation
        tabInformations[3] = timesheetLine.getDate();
        tabInformations[4] = timesheetLine.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration();
        tabInformations[5] = timesheetLine.getProject();
        String key = null;
        if (consolidate) {
            key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().getId() + "|" + timesheetLine.getProject().getId();
            if (timeSheetInformationsMap.containsKey(key)) {
                tabInformations = timeSheetInformationsMap.get(key);
                // Update date
                if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[2]) < 0) {
                    // If date is lower than start date then replace start date by this one
                    tabInformations[2] = timesheetLine.getDate();
                } else if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[3]) > 0) {
                    // If date is upper than end date then replace end date by this one
                    tabInformations[3] = timesheetLine.getDate();
                }
                tabInformations[4] = ((BigDecimal) tabInformations[4]).add(timesheetLine.getDurationForCustomer() != null ? this.computeDurationForCustomer(timesheetLine) : timesheetLine.getHoursDuration());
            } else {
                timeSheetInformationsMap.put(key, tabInformations);
            }
        } else {
            key = String.valueOf(timesheetLine.getId());
            timeSheetInformationsMap.put(key, tabInformations);
        }
    }
    for (Object[] timesheetInformations : timeSheetInformationsMap.values()) {
        String strDate = null;
        Product product = (Product) timesheetInformations[0];
        User user = (User) timesheetInformations[1];
        LocalDate startDate = (LocalDate) timesheetInformations[2];
        LocalDate endDate = (LocalDate) timesheetInformations[3];
        BigDecimal hoursDuration = (BigDecimal) timesheetInformations[4];
        Project project = (Project) timesheetInformations[5];
        PriceList priceList = project.getPriceList();
        if (consolidate) {
            if (startDate != null && endDate != null) {
                strDate = startDate.format(ddmmFormat) + " - " + endDate.format(ddmmFormat);
            }
        } else {
            if (startDate != null) {
                strDate = startDate.format(ddmmFormat);
            }
        }
        invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
        invoiceLineList.get(invoiceLineList.size() - 1).setProject(project);
        count++;
    }
    return invoiceLineList;
}
Also used : User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Project(com.axelor.apps.project.db.Project) DateTimeFormatter(java.time.format.DateTimeFormatter) PriceList(com.axelor.apps.base.db.PriceList)

Example 22 with PriceList

use of com.axelor.apps.base.db.PriceList 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 23 with PriceList

use of com.axelor.apps.base.db.PriceList 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 24 with PriceList

use of com.axelor.apps.base.db.PriceList 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

PriceList (com.axelor.apps.base.db.PriceList)24 AxelorException (com.axelor.exception.AxelorException)13 ArrayList (java.util.ArrayList)12 Company (com.axelor.apps.base.db.Company)11 Partner (com.axelor.apps.base.db.Partner)11 List (java.util.List)11 Currency (com.axelor.apps.base.db.Currency)9 PriceListLine (com.axelor.apps.base.db.PriceListLine)7 Wizard (com.axelor.apps.base.db.Wizard)7 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)7 LocalDate (java.time.LocalDate)7 Map (java.util.Map)7 BigDecimal (java.math.BigDecimal)6 Invoice (com.axelor.apps.account.db.Invoice)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 PaymentMode (com.axelor.apps.account.db.PaymentMode)5 SaleOrder (com.axelor.apps.sale.db.SaleOrder)5 PaymentCondition (com.axelor.apps.account.db.PaymentCondition)4 PartnerPriceList (com.axelor.apps.base.db.PartnerPriceList)4 Product (com.axelor.apps.base.db.Product)4