Search in sources :

Example 6 with Tax

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

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

the class MoveTemplateService method generateMove.

@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(MoveTemplate moveTemplate, List<HashMap<String, Object>> dataList) throws AxelorException {
    List<Long> moveList = new ArrayList<>();
    BigDecimal hundred = new BigDecimal(100);
    for (HashMap<String, Object> data : dataList) {
        LocalDate moveDate = LocalDate.parse(data.get("date").toString(), DateTimeFormatter.ISO_DATE);
        boolean isDebit = false;
        Partner debitPartner = null;
        Partner creditPartner = null;
        BigDecimal moveBalance = new BigDecimal(data.get("moveBalance").toString());
        Partner partner = null;
        if (data.get("debitPartner") != null) {
            debitPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("debitPartner")).get("id").toString()));
            partner = debitPartner;
        }
        if (data.get("creditPartner") != null) {
            creditPartner = partnerRepo.find(Long.parseLong(((HashMap<String, Object>) data.get("creditPartner")).get("id").toString()));
            partner = creditPartner;
        }
        if (moveTemplate.getJournal().getCompany() != null) {
            Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, partner, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
            int counter = 1;
            for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
                partner = null;
                if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.DEBIT)) {
                    isDebit = true;
                    if (moveTemplateLine.getHasPartnerToDebit()) {
                        partner = debitPartner;
                    }
                } else if (moveTemplateLine.getDebitCreditSelect().equals(MoveTemplateLineRepository.CREDIT)) {
                    isDebit = false;
                    if (moveTemplateLine.getHasPartnerToCredit()) {
                        partner = creditPartner;
                    }
                }
                BigDecimal amount = moveBalance.multiply(moveTemplateLine.getPercentage()).divide(hundred, RoundingMode.HALF_UP);
                MoveLine moveLine = moveLineService.createMoveLine(move, partner, moveTemplateLine.getAccount(), amount, isDebit, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
                move.getMoveLineList().add(moveLine);
                Tax tax = moveTemplateLine.getTax();
                if (tax != null) {
                    TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
                    if (taxLine != null) {
                        moveLine.setTaxLine(taxLine);
                        moveLine.setTaxRate(taxLine.getValue());
                        moveLine.setTaxCode(tax.getCode());
                    }
                }
                moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
                moveLineService.generateAnalyticMoveLines(moveLine);
                counter++;
            }
            if (moveTemplate.getAutomaticallyValidate()) {
                moveValidateService.validate(move);
            }
            moveRepo.save(move);
            moveList.add(move.getId());
        }
    }
    return moveList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Tax(com.axelor.apps.account.db.Tax) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Move(com.axelor.apps.account.db.Move) MoveTemplateLine(com.axelor.apps.account.db.MoveTemplateLine) MoveLine(com.axelor.apps.account.db.MoveLine) Partner(com.axelor.apps.base.db.Partner) Transactional(com.google.inject.persist.Transactional)

Example 8 with Tax

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

the class MoveTemplateService method generateMove.

@Transactional(rollbackOn = { Exception.class })
public List<Long> generateMove(LocalDate moveDate, List<HashMap<String, Object>> moveTemplateList) throws AxelorException {
    List<Long> moveList = new ArrayList<>();
    for (HashMap<String, Object> moveTemplateMap : moveTemplateList) {
        MoveTemplate moveTemplate = moveTemplateRepo.find(Long.valueOf((Integer) moveTemplateMap.get("id")));
        if (moveTemplate.getJournal().getCompany() != null) {
            Move move = moveService.getMoveCreateService().createMove(moveTemplate.getJournal(), moveTemplate.getJournal().getCompany(), null, null, moveDate, null, MoveRepository.TECHNICAL_ORIGIN_TEMPLATE, 0);
            int counter = 1;
            for (MoveTemplateLine moveTemplateLine : moveTemplate.getMoveTemplateLineList()) {
                BigDecimal amount = moveTemplateLine.getDebit().add(moveTemplateLine.getCredit());
                MoveLine moveLine = moveLineService.createMoveLine(move, moveTemplateLine.getPartner(), moveTemplateLine.getAccount(), amount, moveTemplateLine.getDebit().compareTo(BigDecimal.ZERO) > 0, moveDate, moveDate, counter, moveTemplate.getFullName(), moveTemplateLine.getName());
                move.getMoveLineList().add(moveLine);
                Tax tax = moveTemplateLine.getTax();
                if (tax != null) {
                    TaxLine taxLine = taxService.getTaxLine(tax, moveDate);
                    if (taxLine != null) {
                        moveLine.setTaxLine(taxLine);
                        moveLine.setTaxRate(taxLine.getValue());
                        moveLine.setTaxCode(tax.getCode());
                    }
                }
                moveLine.setAnalyticDistributionTemplate(moveTemplateLine.getAnalyticDistributionTemplate());
                moveLineService.generateAnalyticMoveLines(moveLine);
                counter++;
            }
            if (moveTemplate.getAutomaticallyValidate()) {
                moveValidateService.validate(move);
            }
            moveRepo.save(move);
            moveList.add(move.getId());
        }
    }
    return moveList;
}
Also used : ArrayList(java.util.ArrayList) Tax(com.axelor.apps.account.db.Tax) MoveTemplate(com.axelor.apps.account.db.MoveTemplate) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine) Move(com.axelor.apps.account.db.Move) MoveTemplateLine(com.axelor.apps.account.db.MoveTemplateLine) MoveLine(com.axelor.apps.account.db.MoveLine) Transactional(com.google.inject.persist.Transactional)

Example 9 with Tax

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

the class AccountingCutOffServiceImpl method generateTaxMoveLine.

protected void generateTaxMoveLine(Move move, MoveLine productMoveLine, String origin, boolean isPurchase, boolean isFixedAssets, String moveDescription) throws AxelorException {
    TaxLine taxLine = productMoveLine.getTaxLine();
    Tax tax = taxLine.getTax();
    Account taxAccount = taxAccountService.getAccount(tax, move.getCompany(), isPurchase, isFixedAssets);
    BigDecimal currencyTaxAmount = InvoiceLineManagement.computeAmount(productMoveLine.getCurrencyAmount(), taxLine.getValue());
    MoveLine taxMoveLine = moveLineService.createMoveLine(move, move.getPartner(), taxAccount, currencyTaxAmount, productMoveLine.getDebit().compareTo(BigDecimal.ZERO) == 1, productMoveLine.getOriginDate(), ++counter, origin, moveDescription);
    taxMoveLine.setDate(move.getDate());
    taxMoveLine.setDueDate(move.getDate());
    move.addMoveLineListItem(taxMoveLine);
}
Also used : Account(com.axelor.apps.account.db.Account) MoveLine(com.axelor.apps.account.db.MoveLine) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine) Tax(com.axelor.apps.account.db.Tax) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 10 with Tax

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

the class IrrecoverableService method createIrrecoverableMove.

/**
 * Fonction permettant de créer l'écriture de passage en irrécouvrable d'une échéance
 *
 * @param moveLine Une écriture d'échéance
 * @return
 * @throws AxelorException
 */
public Move createIrrecoverableMove(MoveLine moveLine, String irrecoverableName) throws AxelorException {
    Company company = moveLine.getMove().getCompany();
    Partner payerPartner = moveLine.getPartner();
    BigDecimal amount = moveLine.getAmountRemaining();
    AccountConfig accountConfig = company.getAccountConfig();
    // Move
    Move move = moveService.getMoveCreateService().createMove(accountConfig.getIrrecoverableJournal(), company, null, payerPartner, null, MoveRepository.TECHNICAL_ORIGIN_AUTOMATIC, moveLine.getMove().getFunctionalOriginSelect());
    int seq = 1;
    // Credit MoveLine Customer account (411, 416, ...)
    MoveLine creditMoveLine = moveLineService.createMoveLine(move, payerPartner, moveLine.getAccount(), amount, false, appAccountService.getTodayDate(company), seq, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine);
    Reconcile reconcile = reconcileService.createReconcile(moveLine, creditMoveLine, amount, false);
    if (reconcile != null) {
        reconcileService.confirmReconcile(reconcile, true);
    }
    Tax tax = accountConfig.getIrrecoverableStandardRateTax();
    BigDecimal taxRate = taxService.getTaxRate(tax, appAccountService.getTodayDate(company));
    // Debit MoveLine 654. (irrecoverable account)
    BigDecimal divid = taxRate.add(BigDecimal.ONE);
    BigDecimal irrecoverableAmount = amount.divide(divid, 6, RoundingMode.HALF_UP).setScale(AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_UP);
    MoveLine creditMoveLine1 = moveLineService.createMoveLine(move, payerPartner, accountConfig.getIrrecoverableAccount(), irrecoverableAmount, true, appAccountService.getTodayDate(company), 2, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine1);
    // Debit MoveLine 445 (Tax account)
    Account taxAccount = taxAccountService.getAccount(tax, company, false, false);
    BigDecimal taxAmount = amount.subtract(irrecoverableAmount);
    MoveLine creditMoveLine2 = moveLineService.createMoveLine(move, payerPartner, taxAccount, taxAmount, true, appAccountService.getTodayDate(company), 3, irrecoverableName, moveLine.getDescription());
    move.getMoveLineList().add(creditMoveLine2);
    return move;
}
Also used : Account(com.axelor.apps.account.db.Account) Company(com.axelor.apps.base.db.Company) Move(com.axelor.apps.account.db.Move) MoveLine(com.axelor.apps.account.db.MoveLine) InvoiceLineTax(com.axelor.apps.account.db.InvoiceLineTax) Tax(com.axelor.apps.account.db.Tax) Partner(com.axelor.apps.base.db.Partner) BigDecimal(java.math.BigDecimal) AccountConfig(com.axelor.apps.account.db.AccountConfig) Reconcile(com.axelor.apps.account.db.Reconcile)

Aggregations

Tax (com.axelor.apps.account.db.Tax)11 MoveLine (com.axelor.apps.account.db.MoveLine)6 BigDecimal (java.math.BigDecimal)6 Account (com.axelor.apps.account.db.Account)4 Move (com.axelor.apps.account.db.Move)4 TaxLine (com.axelor.apps.account.db.TaxLine)4 InvoiceLineTax (com.axelor.apps.account.db.InvoiceLineTax)3 Company (com.axelor.apps.base.db.Company)3 AxelorException (com.axelor.exception.AxelorException)3 Transactional (com.google.inject.persist.Transactional)3 ArrayList (java.util.ArrayList)3 AccountConfig (com.axelor.apps.account.db.AccountConfig)2 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)2 MoveTemplateLine (com.axelor.apps.account.db.MoveTemplateLine)2 Partner (com.axelor.apps.base.db.Partner)2 AccountManagement (com.axelor.apps.account.db.AccountManagement)1 AnalyticAccount (com.axelor.apps.account.db.AnalyticAccount)1 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)1 IrrecoverablePaymentScheduleLineLine (com.axelor.apps.account.db.IrrecoverablePaymentScheduleLineLine)1 Journal (com.axelor.apps.account.db.Journal)1