Search in sources :

Example 51 with Invoice

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

the class SaleOrderInvoiceServiceImpl method generateInvoice.

@Override
@Transactional(rollbackOn = { Exception.class })
public Invoice generateInvoice(SaleOrder saleOrder) throws AxelorException {
    Invoice invoice = this.createInvoice(saleOrder);
    invoice.setDeliveryAddress(saleOrder.getDeliveryAddress());
    invoice.setDeliveryAddressStr(saleOrder.getDeliveryAddressStr());
    invoiceRepo.save(invoice);
    saleOrderRepo.save(fillSaleOrder(saleOrder, invoice));
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) Transactional(com.google.inject.persist.Transactional)

Example 52 with Invoice

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

the class SaleOrderInvoiceServiceImpl method createInvoice.

@Override
public Invoice createInvoice(SaleOrder saleOrder, List<SaleOrderLine> saleOrderLineList, Map<Long, BigDecimal> qtyToInvoiceMap) throws AxelorException {
    InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
    Invoice invoice = invoiceGenerator.generate();
    invoiceGenerator.populate(invoice, this.createInvoiceLines(invoice, saleOrderLineList, qtyToInvoiceMap));
    invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)

Example 53 with Invoice

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

the class IntercoServiceImpl method createIntercoInvoiceLine.

protected InvoiceLine createIntercoInvoiceLine(InvoiceLine invoiceLine, boolean isPurchase) throws AxelorException {
    AccountManagementAccountService accountManagementAccountService = Beans.get(AccountManagementAccountService.class);
    InvoiceLineService invoiceLineService = Beans.get(InvoiceLineService.class);
    Invoice intercoInvoice = invoiceLine.getInvoice();
    Partner partner = intercoInvoice.getPartner();
    if (intercoInvoice.getCompany() != null) {
        Account account = accountManagementAccountService.getProductAccount(invoiceLine.getProduct(), intercoInvoice.getCompany(), partner.getFiscalPosition(), isPurchase, false);
        invoiceLine.setAccount(account);
        TaxLine taxLine = invoiceLineService.getTaxLine(intercoInvoice, invoiceLine, isPurchase);
        invoiceLine.setTaxLine(taxLine);
        invoiceLine.setTaxRate(taxLine.getValue());
        invoiceLine.setTaxCode(taxLine.getTax().getCode());
        TaxEquiv taxEquiv = accountManagementAccountService.getProductTaxEquiv(invoiceLine.getProduct(), intercoInvoice.getCompany(), intercoInvoice.getPartner().getFiscalPosition(), isPurchase);
        invoiceLine.setTaxEquiv(taxEquiv);
        invoiceLine.setCompanyExTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getExTaxTotal(), intercoInvoice));
        invoiceLine.setCompanyInTaxTotal(invoiceLineService.getCompanyExTaxTotal(invoiceLine.getInTaxTotal(), intercoInvoice));
        if (invoiceLine.getAnalyticDistributionTemplate() != null) {
            invoiceLine.setAnalyticDistributionTemplate(accountManagementAccountService.getAnalyticDistributionTemplate(invoiceLine.getProduct(), intercoInvoice.getCompany()));
            List<AnalyticMoveLine> analyticMoveLineList = invoiceLineService.createAnalyticDistributionWithTemplate(invoiceLine);
            analyticMoveLineList.forEach(analyticMoveLine -> analyticMoveLine.setInvoiceLine(invoiceLine));
            invoiceLine.setAnalyticMoveLineList(analyticMoveLineList);
        }
    }
    return invoiceLine;
}
Also used : Account(com.axelor.apps.account.db.Account) Invoice(com.axelor.apps.account.db.Invoice) AccountManagementAccountService(com.axelor.apps.account.service.AccountManagementAccountService) InvoiceLineService(com.axelor.apps.account.service.invoice.InvoiceLineService) Partner(com.axelor.apps.base.db.Partner) TaxEquiv(com.axelor.apps.account.db.TaxEquiv) TaxLine(com.axelor.apps.account.db.TaxLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 54 with Invoice

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

the class BudgetSupplychainService method getDate.

@Override
protected Optional<LocalDate> getDate(BudgetDistribution budgetDistribution) {
    if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
        return super.getDate(budgetDistribution);
    }
    InvoiceLine invoiceLine = budgetDistribution.getInvoiceLine();
    if (invoiceLine == null) {
        return Optional.empty();
    }
    Invoice invoice = invoiceLine.getInvoice();
    if (invoice.getPurchaseOrder() != null) {
        return Optional.of(invoice.getPurchaseOrder().getOrderDate());
    }
    return super.getDate(budgetDistribution);
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 55 with Invoice

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

the class PurchaseOrderInvoiceServiceImpl method generateInvoiceFromTimetableForPurchaseOrder.

@Transactional(rollbackOn = { Exception.class })
protected Invoice generateInvoiceFromTimetableForPurchaseOrder(PurchaseOrder purchaseOrder, List<Long> timetableIdList) throws AxelorException {
    if (ObjectUtils.isEmpty(timetableIdList)) {
        throw new AxelorException(purchaseOrder, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SO_INVOICE_NO_TIMETABLES_SELECTED));
    }
    BigDecimal percentSum = BigDecimal.ZERO;
    List<Timetable> timetableList = new ArrayList<>();
    for (Long timetableId : timetableIdList) {
        Timetable timetable = timetableRepo.find(timetableId);
        timetableList.add(timetable);
        percentSum = percentSum.add(timetable.getPercentage());
    }
    Invoice invoice = generateInvoiceFromLines(purchaseOrder, percentSum);
    for (Timetable timetable : timetableList) {
        timetable.setInvoice(invoice);
        timetable.setInvoiced(true);
        timetableRepo.save(timetable);
    }
    return invoice;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Timetable(com.axelor.apps.supplychain.db.Timetable) Invoice(com.axelor.apps.account.db.Invoice) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

Invoice (com.axelor.apps.account.db.Invoice)195 AxelorException (com.axelor.exception.AxelorException)69 ArrayList (java.util.ArrayList)48 Transactional (com.google.inject.persist.Transactional)46 BigDecimal (java.math.BigDecimal)32 Company (com.axelor.apps.base.db.Company)31 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)29 Partner (com.axelor.apps.base.db.Partner)27 InvoiceRepository (com.axelor.apps.account.db.repo.InvoiceRepository)22 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)22 PaymentMode (com.axelor.apps.account.db.PaymentMode)21 Map (java.util.Map)21 List (java.util.List)20 StockMove (com.axelor.apps.stock.db.StockMove)19 RefundInvoice (com.axelor.apps.account.service.invoice.generator.invoice.RefundInvoice)18 MoveLine (com.axelor.apps.account.db.MoveLine)17 LocalDate (java.time.LocalDate)17 InvoiceGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceGenerator)16 Context (com.axelor.rpc.Context)15 InvoicePayment (com.axelor.apps.account.db.InvoicePayment)14