Search in sources :

Example 71 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceSupplychainRepository method copy.

@Override
public Invoice copy(Invoice entity, boolean deep) {
    Invoice copy = super.copy(entity, deep);
    copy.setSaleOrder(null);
    copy.setPurchaseOrder(null);
    copy.setStockMoveSet(null);
    for (InvoiceLine line : copy.getInvoiceLineList()) {
        line.setSaleOrderLine(null);
        line.setPurchaseOrderLine(null);
        line.setStockMoveLine(null);
        line.setOutgoingStockMove(null);
        line.setIncomingStockMove(null);
    }
    return copy;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 72 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class BudgetService method updateBudgetLinesFromInvoice.

public void updateBudgetLinesFromInvoice(Invoice invoice) {
    List<InvoiceLine> invoiceLineList = invoice.getInvoiceLineList();
    if (invoiceLineList == null) {
        return;
    }
    invoiceLineList.stream().filter(invoiceLine -> invoiceLine.getBudgetDistributionList() != null).flatMap(x -> x.getBudgetDistributionList().stream()).forEach(budgetDistribution -> {
        Budget budget = budgetDistribution.getBudget();
        updateLines(budget);
        computeTotalAmountRealized(budget);
    });
}
Also used : BudgetLineRepository(com.axelor.apps.account.db.repo.BudgetLineRepository) Budget(com.axelor.apps.account.db.Budget) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) BudgetDistributionRepository(com.axelor.apps.account.db.repo.BudgetDistributionRepository) Inject(com.google.inject.Inject) Invoice(com.axelor.apps.account.db.Invoice) Transactional(com.google.inject.persist.Transactional) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) BigDecimal(java.math.BigDecimal) List(java.util.List) BudgetLine(com.axelor.apps.account.db.BudgetLine) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) AxelorException(com.axelor.exception.AxelorException) Beans(com.axelor.inject.Beans) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BudgetRepository(com.axelor.apps.account.db.repo.BudgetRepository) LocalDate(java.time.LocalDate) I18n(com.axelor.i18n.I18n) Optional(java.util.Optional) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) Budget(com.axelor.apps.account.db.Budget)

Example 73 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine 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 74 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine 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 75 with InvoiceLine

use of com.axelor.apps.account.db.InvoiceLine in project axelor-open-suite by axelor.

the class InvoiceServiceImpl method ventilate.

/**
 * Ventilation comptable d'une facture. (Transaction)
 *
 * @param invoice Une facture.
 * @throws AxelorException
 */
@Override
@Transactional(rollbackOn = { Exception.class })
public void ventilate(Invoice invoice) throws AxelorException {
    if (invoice.getPaymentCondition() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_3), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    if (invoice.getPaymentMode() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.INVOICE_GENERATOR_4), I18n.get(com.axelor.apps.base.exceptions.IExceptionMessage.EXCEPTION));
    }
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        Account account = invoiceLine.getAccount();
        if (invoiceLine.getAccount() == null && (invoiceLine.getTypeSelect() == InvoiceLineRepository.TYPE_NORMAL)) {
            throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.VENTILATE_STATE_6), invoiceLine.getProductName());
        }
        if (account != null && !account.getAnalyticDistributionAuthorized() && (invoiceLine.getAnalyticDistributionTemplate() != null || (invoiceLine.getAnalyticMoveLineList() != null && !invoiceLine.getAnalyticMoveLineList().isEmpty()))) {
            throw new AxelorException(invoice, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.VENTILATE_STATE_7));
        }
    }
    log.debug("Ventilation de la facture {}", invoice.getInvoiceId());
    ventilateFactory.getVentilator(invoice).process();
    invoiceRepo.save(invoice);
    if (this.checkEnablePDFGenerationOnVentilation(invoice)) {
        Beans.get(InvoicePrintService.class).printAndSave(invoice, InvoiceRepository.REPORT_TYPE_ORIGINAL_INVOICE, ReportSettings.FORMAT_PDF, null);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Account(com.axelor.apps.account.db.Account) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoicePrintService(com.axelor.apps.account.service.invoice.print.InvoicePrintService) Transactional(com.google.inject.persist.Transactional)

Aggregations

InvoiceLine (com.axelor.apps.account.db.InvoiceLine)80 ArrayList (java.util.ArrayList)36 Invoice (com.axelor.apps.account.db.Invoice)27 BigDecimal (java.math.BigDecimal)22 AxelorException (com.axelor.exception.AxelorException)20 Product (com.axelor.apps.base.db.Product)13 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)12 Transactional (com.google.inject.persist.Transactional)12 Context (com.axelor.rpc.Context)11 Account (com.axelor.apps.account.db.Account)8 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 InvoiceLineService (com.axelor.apps.account.service.invoice.InvoiceLineService)7 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)6 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)6 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)6 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)5 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)5 HashSet (java.util.HashSet)5 List (java.util.List)5