Search in sources :

Example 16 with InvoiceLine

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

the class SaleOrderInvoiceServiceImpl method createInvoiceAndLines.

public Invoice createInvoiceAndLines(SaleOrder saleOrder, List<SaleOrderLineTax> taxLineList, Product invoicingProduct, BigDecimal percentToInvoice, int operationSubTypeSelect, Account partnerAccount) throws AxelorException {
    InvoiceGenerator invoiceGenerator = this.createInvoiceGenerator(saleOrder);
    Invoice invoice = invoiceGenerator.generate();
    List<InvoiceLine> invoiceLinesList = (taxLineList != null && !taxLineList.isEmpty()) ? this.createInvoiceLinesFromTax(invoice, taxLineList, invoicingProduct, percentToInvoice) : this.createInvoiceLinesFromSO(invoice, saleOrder, invoicingProduct, percentToInvoice);
    invoiceGenerator.populate(invoice, invoiceLinesList);
    invoice.setAddressStr(saleOrder.getMainInvoicingAddressStr());
    invoice.setOperationSubTypeSelect(operationSubTypeSelect);
    if (partnerAccount != null) {
        Partner partner = invoice.getPartner();
        if (partner != null) {
            partnerAccount = Beans.get(FiscalPositionAccountService.class).getAccount(partner.getFiscalPosition(), partnerAccount);
        }
        invoice.setPartnerAccount(partnerAccount);
    }
    return invoice;
}
Also used : Invoice(com.axelor.apps.account.db.Invoice) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) InvoiceGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceGenerator) Partner(com.axelor.apps.base.db.Partner)

Example 17 with InvoiceLine

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

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

the class MoveLineServiceImpl method createMoveLines.

/**
 * Créer les lignes d'écritures comptables d'une facture.
 *
 * @param invoice
 * @param move
 * @param consolidate
 * @return
 */
@Override
public List<MoveLine> createMoveLines(Invoice invoice, Move move, Company company, Partner partner, Account partnerAccount, boolean consolidate, boolean isPurchase, boolean isDebitCustomer) throws AxelorException {
    log.debug("Création des lignes d'écriture comptable de la facture/l'avoir {}", invoice.getInvoiceId());
    List<MoveLine> moveLines = new ArrayList<MoveLine>();
    Set<AnalyticAccount> analyticAccounts = new HashSet<AnalyticAccount>();
    int moveLineId = 1;
    if (partner == null) {
        throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.MOVE_LINE_1), invoice.getInvoiceId());
    }
    if (partnerAccount == null) {
        throw new AxelorException(invoice, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.MOVE_LINE_2), invoice.getInvoiceId());
    }
    String origin = invoice.getInvoiceId();
    if (InvoiceToolService.isPurchase(invoice)) {
        origin = invoice.getSupplierInvoiceNb();
    }
    // Creation of partner move line
    MoveLine moveLine1 = this.createMoveLine(move, partner, partnerAccount, invoice.getInTaxTotal(), invoice.getCompanyInTaxTotal(), null, isDebitCustomer, invoice.getInvoiceDate(), invoice.getDueDate(), invoice.getOriginDate(), moveLineId++, origin, null);
    moveLines.add(moveLine1);
    AnalyticMoveLineRepository analyticMoveLineRepository = Beans.get(AnalyticMoveLineRepository.class);
    // Creation of product move lines for each invoice line
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        BigDecimal companyExTaxTotal = invoiceLine.getCompanyExTaxTotal();
        if (companyExTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
            analyticAccounts.clear();
            Account account = invoiceLine.getAccount();
            if (account == null) {
                throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_4), invoiceLine.getName(), company.getName());
            }
            companyExTaxTotal = invoiceLine.getCompanyExTaxTotal();
            log.debug("Traitement de la ligne de facture : compte comptable = {}, montant = {}", new Object[] { account.getName(), companyExTaxTotal });
            if (invoiceLine.getAnalyticDistributionTemplate() == null && (invoiceLine.getAnalyticMoveLineList() == null || invoiceLine.getAnalyticMoveLineList().isEmpty()) && account.getAnalyticDistributionAuthorized() && account.getAnalyticDistributionRequiredOnInvoiceLines()) {
                throw new AxelorException(move, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.ANALYTIC_DISTRIBUTION_MISSING), invoiceLine.getName(), company.getName());
            }
            MoveLine moveLine = this.createMoveLine(move, partner, account, invoiceLine.getExTaxTotal(), companyExTaxTotal, null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, invoiceLine.getProductName());
            moveLine.setAnalyticDistributionTemplate(invoiceLine.getAnalyticDistributionTemplate());
            if (invoiceLine.getAnalyticMoveLineList() != null && !invoiceLine.getAnalyticMoveLineList().isEmpty()) {
                for (AnalyticMoveLine invoiceAnalyticMoveLine : invoiceLine.getAnalyticMoveLineList()) {
                    AnalyticMoveLine analyticMoveLine = analyticMoveLineRepository.copy(invoiceAnalyticMoveLine, false);
                    analyticMoveLine.setTypeSelect(AnalyticMoveLineRepository.STATUS_REAL_ACCOUNTING);
                    analyticMoveLine.setInvoiceLine(null);
                    analyticMoveLine.setAccount(moveLine.getAccount());
                    analyticMoveLine.setAccountType(moveLine.getAccount().getAccountType());
                    analyticMoveLineService.updateAnalyticMoveLine(analyticMoveLine, moveLine.getDebit().add(moveLine.getCredit()), moveLine.getDate());
                    moveLine.addAnalyticMoveLineListItem(analyticMoveLine);
                }
            } else {
                generateAnalyticMoveLines(moveLine);
            }
            TaxLine taxLine = invoiceLine.getTaxLine();
            if (taxLine != null) {
                moveLine.setTaxLine(taxLine);
                moveLine.setTaxRate(taxLine.getValue());
                moveLine.setTaxCode(taxLine.getTax().getCode());
            }
            moveLines.add(moveLine);
        }
    }
    // Creation of tax move lines for each invoice line tax
    for (InvoiceLineTax invoiceLineTax : invoice.getInvoiceLineTaxList()) {
        BigDecimal companyTaxTotal = invoiceLineTax.getCompanyTaxTotal();
        if (companyTaxTotal.compareTo(BigDecimal.ZERO) != 0) {
            Tax tax = invoiceLineTax.getTaxLine().getTax();
            boolean hasFixedAssets = !invoiceLineTax.getSubTotalOfFixedAssets().equals(BigDecimal.ZERO);
            boolean hasOtherAssets = !invoiceLineTax.getSubTotalExcludingFixedAssets().equals(BigDecimal.ZERO);
            Account account;
            MoveLine moveLine;
            if (hasFixedAssets && invoiceLineTax.getCompanySubTotalOfFixedAssets().compareTo(BigDecimal.ZERO) != 0) {
                account = taxAccountService.getAccount(tax, company, isPurchase, true);
                if (account == null) {
                    throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), tax.getName(), company.getName());
                }
                moveLine = this.createMoveLine(move, partner, account, invoiceLineTax.getSubTotalOfFixedAssets(), invoiceLineTax.getCompanySubTotalOfFixedAssets(), null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, null);
                moveLine.setTaxLine(invoiceLineTax.getTaxLine());
                moveLine.setTaxRate(invoiceLineTax.getTaxLine().getValue());
                moveLine.setTaxCode(tax.getCode());
                moveLines.add(moveLine);
            }
            if (hasOtherAssets && invoiceLineTax.getCompanySubTotalExcludingFixedAssets().compareTo(BigDecimal.ZERO) != 0) {
                account = taxAccountService.getAccount(tax, company, isPurchase, false);
                if (account == null) {
                    throw new AxelorException(move, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MOVE_LINE_6), tax.getName(), company.getName());
                }
                moveLine = this.createMoveLine(move, partner, account, invoiceLineTax.getSubTotalExcludingFixedAssets(), invoiceLineTax.getCompanySubTotalExcludingFixedAssets(), null, !isDebitCustomer, invoice.getInvoiceDate(), null, invoice.getOriginDate(), moveLineId++, origin, null);
                moveLine.setTaxLine(invoiceLineTax.getTaxLine());
                moveLine.setTaxRate(invoiceLineTax.getTaxLine().getValue());
                moveLine.setTaxCode(tax.getCode());
                moveLines.add(moveLine);
            }
        }
    }
    if (consolidate) {
        this.consolidateMoveLines(moveLines);
    }
    return moveLines;
}
Also used : AxelorException(com.axelor.exception.AxelorException) AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) Account(com.axelor.apps.account.db.Account) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) ArrayList(java.util.ArrayList) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) Tax(com.axelor.apps.account.db.Tax) AnalyticAccount(com.axelor.apps.account.db.AnalyticAccount) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) AnalyticMoveLineRepository(com.axelor.apps.account.db.repo.AnalyticMoveLineRepository) TaxPaymentMoveLine(com.axelor.apps.account.db.TaxPaymentMoveLine) MoveLine(com.axelor.apps.account.db.MoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) HashSet(java.util.HashSet) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 19 with InvoiceLine

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

the class CancelState method process.

@Override
public void process() throws AxelorException {
    workflowService.beforeCancel(invoice);
    if (invoice.getStatusSelect() == InvoiceRepository.STATUS_VENTILATED && invoice.getCompany().getAccountConfig().getAllowCancelVentilatedInvoice()) {
        cancelMove();
    }
    setStatus();
    if (Beans.get(AccountConfigService.class).getAccountConfig(invoice.getCompany()).getIsManagePassedForPayment()) {
        setPfpStatus();
    }
    budgetService.updateBudgetLinesFromInvoice(invoice);
    for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
        invoiceLine.clearBudgetDistributionList();
    }
    workflowService.afterCancel(invoice);
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine)

Example 20 with InvoiceLine

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

the class ValidateState method generateBudgetDistribution.

private void generateBudgetDistribution(Invoice invoice) {
    if (invoice.getInvoiceLineList() != null) {
        for (InvoiceLine invoiceLine : invoice.getInvoiceLineList()) {
            if (invoiceLine.getBudget() != null && (invoiceLine.getBudgetDistributionList() == null || invoiceLine.getBudgetDistributionList().isEmpty())) {
                BudgetDistribution budgetDistribution = new BudgetDistribution();
                budgetDistribution.setBudget(invoiceLine.getBudget());
                budgetDistribution.setAmount(invoiceLine.getCompanyExTaxTotal());
                invoiceLine.addBudgetDistributionListItem(budgetDistribution);
            }
        }
    }
}
Also used : InvoiceLine(com.axelor.apps.account.db.InvoiceLine) BudgetDistribution(com.axelor.apps.account.db.BudgetDistribution)

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